objcontroller.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #ifndef __SCRIPTOBJECTCONTROLLER_H
  2. #define __SCRIPTOBJECTCONTROLLER_H
  3. #include <api/script/scriptguid.h>
  4. //#include <wasabicfg.h>
  5. #include <bfc/ptrlist.h>
  6. #include <bfc/dispatch.h>
  7. #include <api/script/scriptobj.h>
  8. #include <api/script/vcputypes.h>
  9. #include <api/service/svcs/svc_scriptobj.h>
  10. #define SCRIPT_MAXARGS 10 // 10 args max per function
  11. #define MAKI_CMD_NONE 0
  12. #define MAKI_CMD_SETDLF 1
  13. #define MAKI_CMD_GETDLF 2
  14. #define MAKI_CMD_ADDREF 3
  15. #define MAKI_CMD_REMREF 4
  16. #define MAKI_CMD_RESETDLF 5
  17. #define SCRIPT_FUNCTION_INIT static int __dlfid=-1, __linkcount=0; if (__cmd != NULL) return WASABI_API_MAKI->maki_updateDlf(__cmd, &__dlfid, &__linkcount);
  18. #define SCRIPT_FUNCTION_CHECKABORTEVENT if (__dlfid==-1) RETURN_SCRIPT_VOID;
  19. #define SCRIPT_FUNCTION_CHECKABORTEVENT_SYS(o) { SCRIPT_FUNCTION_CHECKABORTEVENT { SystemObject *so = static_cast<SystemObject *>(o->vcpu_getInterface(systemObjectGuid)); if (!so || !so->isLoaded()) RETURN_SCRIPT_VOID; } }
  20. #define PROCESS_HOOKS0(object, controller) { controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, NULL, 0); }
  21. #define PROCESS_HOOKS1(object, controller, p1) { scriptVar *__table[1] = {&p1}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 1); }
  22. #define PROCESS_HOOKS2(object, controller, p1, p2) { scriptVar *__table[2] = {&p1, &p2}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 2); }
  23. #define PROCESS_HOOKS3(object, controller, p1, p2, p3) { scriptVar *__table[3] = {&p1, &p2, &p3}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 3); }
  24. #define PROCESS_HOOKS4(object, controller, p1, p2, p3, p4) { scriptVar *__table[4] = {&p1, &p2, &p3, &p4}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 4); }
  25. #define PROCESS_HOOKS5(object, controller, p1, p2, p3, p4, p5) { scriptVar *__table[5] = {&p1, &p2, &p3, &p4, &p5}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 5); }
  26. #define PROCESS_HOOKS6(object, controller, p1, p2, p3, p4, p5, p6) { scriptVar *__table[6] = {&p1, &p2, &p3, &p4, &p5, &p6}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 6); }
  27. #define PROCESS_HOOKS7(object, controller, p1, p2, p3, p4, p5, p6, p7) { scriptVar *__table[7] = {&p1, &p2, &p3, &p4, &p5, &p6, &p7}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 7); }
  28. #define PROCESS_HOOKS8(object, controller, p1, p2, p3, p4, p5, p6, p7, p8) { scriptVar *__table[8] = {&p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 8); }
  29. #define PROCESS_HOOKS9(object, controller, p1, p2, p3, p4, p5, p6, p7, p8, p9) { scriptVar *__table[9] = {&p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 9); }
  30. #define PROCESS_HOOKS10(object, controller, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) { scriptVar *__table[10] = {&p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10}; controller->processHooks(static_cast<ScriptObject *>(object), DLF_ID, __table, 10); }
  31. #define SCRIPT_EXEC_EVENT0(object) { return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 0); }
  32. #define SCRIPT_EXEC_EVENT1(object, p1) { WASABI_API_MAKI->maki_pushAny(p1); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 1); }
  33. #define SCRIPT_EXEC_EVENT2(object, p1, p2) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 2); }
  34. #define SCRIPT_EXEC_EVENT3(object, p1, p2, p3) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); WASABI_API_MAKI->maki_pushAny(p3); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 3); }
  35. #define SCRIPT_EXEC_EVENT4(object, p1, p2, p3, p4) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); WASABI_API_MAKI->maki_pushAny(p3); WASABI_API_MAKI->maki_pushAny(p4); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 4); }
  36. #define SCRIPT_EXEC_EVENT5(object, p1, p2, p3, p4, p5) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); WASABI_API_MAKI->maki_pushAny(p3); WASABI_API_MAKI->maki_pushAny(p4); WASABI_API_MAKI->maki_pushAny(p5); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 5); }
  37. #define SCRIPT_EXEC_EVENT6(object, p1, p2, p3, p4, p5, p6) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); WASABI_API_MAKI->maki_pushAny(p3); WASABI_API_MAKI->maki_pushAny(p4); WASABI_API_MAKI->maki_pushAny(p5); WASABI_API_MAKI->maki_pushAny(p6); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 6); }
  38. #define SCRIPT_EXEC_EVENT7(object, p1, p2, p3, p4, p5, p6, p7) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); WASABI_API_MAKI->maki_pushAny(p3); WASABI_API_MAKI->maki_pushAny(p4); WASABI_API_MAKI->maki_pushAny(p5); WASABI_API_MAKI->maki_pushAny(p6); WASABI_API_MAKI->maki_pushAny(p7); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 7); }
  39. #define SCRIPT_EXEC_EVENT8(object, p1, p2, p3, p4, p5, p6, p7, p8) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); WASABI_API_MAKI->maki_pushAny(p3); WASABI_API_MAKI->maki_pushAny(p4); WASABI_API_MAKI->maki_pushAny(p5); WASABI_API_MAKI->maki_pushAny(p6); WASABI_API_MAKI->maki_pushAny(p7); WASABI_API_MAKI->maki_pushAny(p8); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 8); }
  40. #define SCRIPT_EXEC_EVENT9(object, p1, p2, p3, p4, p5, p6, p7, p8, p9) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); WASABI_API_MAKI->maki_pushAny(p3); WASABI_API_MAKI->maki_pushAny(p4); WASABI_API_MAKI->maki_pushAny(p5); WASABI_API_MAKI->maki_pushAny(p6); WASABI_API_MAKI->maki_pushAny(p7); WASABI_API_MAKI->maki_pushAny(p8); WASABI_API_MAKI->maki_pushAny(p9); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 9); }
  41. #define SCRIPT_EXEC_EVENT10(object, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) { WASABI_API_MAKI->maki_pushAny(p1); WASABI_API_MAKI->maki_pushAny(p2); WASABI_API_MAKI->maki_pushAny(p3); WASABI_API_MAKI->maki_pushAny(p4); WASABI_API_MAKI->maki_pushAny(p5); WASABI_API_MAKI->maki_pushAny(p6); WASABI_API_MAKI->maki_pushAny(p7); WASABI_API_MAKI->maki_pushAny(p8); WASABI_API_MAKI->maki_pushAny(p9); WASABI_API_MAKI->maki_pushAny(p10); return WASABI_API_MAKI->maki_triggerEvent(object, DLF_ID, 10); }
  42. #define SCRIPT_FUNCTION_PARAMS maki_cmd *__cmd, int __vsd
  43. #define SCRIPT_CALL NULL, -1
  44. #define GET_SCRIPT_INT(v) WASABI_API_MAKI->maki_getScriptInt(v)
  45. //CUT#define GET_SCRIPT_INT(v) ((v).getAsInt())
  46. #define GET_SCRIPT_BOOLEAN(v) WASABI_API_MAKI->maki_getScriptBoolean(v)
  47. #define GET_SCRIPT_FLOAT(v) WASABI_API_MAKI->maki_getScriptFloat(v)
  48. #define GET_SCRIPT_DOUBLE(v) WASABI_API_MAKI->maki_getScriptDouble(v)
  49. #define GET_SCRIPT_STRING(v) WASABI_API_MAKI->maki_getScriptString(v)
  50. #define GET_SCRIPT_OBJECT(v) WASABI_API_MAKI->maki_getScriptObject(v)
  51. scriptVar COMEXP MAKE_SCRIPT_INT(int i);
  52. scriptVar COMEXP MAKE_SCRIPT_VOID();
  53. scriptVar COMEXP MAKE_SCRIPT_FLOAT(float f);
  54. scriptVar COMEXP MAKE_SCRIPT_DOUBLE(double d);
  55. scriptVar COMEXP MAKE_SCRIPT_BOOLEAN(int b);
  56. scriptVar COMEXP MAKE_SCRIPT_OBJECT(ScriptObject *o);
  57. scriptVar COMEXP MAKE_SCRIPT_STRING(const wchar_t *s);
  58. void COMEXP *GET_SCRIPT_OBJECT_AS(scriptVar v, GUID g);
  59. #define FIXUP_FUNCTION_DLF SCRIPT_FUNCTION_INIT
  60. /*#define FIXUP_FUNCTION_DLF \
  61. static int fn_DLF=-1; \
  62. if (fn_DLF == -1 && DLFid == -1) { RETURN_SCRIPT_ZERO } \
  63. if (fn_DLF == -1 && DLFid != -1 && o == NULL) { \
  64. fn_DLF = DLFid; \
  65. RETURN_SCRIPT_VOID \
  66. } else if (DLFid != -1) { \
  67. ASSERTPR(0, "DLFId already set"); \
  68. RETURN_SCRIPT_VOID \
  69. }*/
  70. #define DLF_ID __dlfid
  71. #define RETURN_SCRIPT_EVENT \
  72. { scriptVar script_event_return={SCRIPT_EVENT,0}; \
  73. return script_event_return; }
  74. #define RETURN_SCRIPT_VOID \
  75. { scriptVar script_event_return={SCRIPT_VOID,0}; \
  76. return script_event_return; }
  77. #define RETURN_SCRIPT_ZERO \
  78. { scriptVar script_event_return={SCRIPT_INT,0}; \
  79. return script_event_return; }
  80. #define RETURN_SCRIPT_NULL \
  81. { scriptVar script_event_return={SCRIPT_OBJECT,NULL}; \
  82. return script_event_return; }
  83. #define SCRIPT_FUNCTION_INT(_class, func, call) \
  84. scriptVar _class::func(int DLFid, ScriptObject *o) { \
  85. FIXUP_FUNCTION_DLF \
  86. ASSERT(o != NULL); \
  87. scriptVar s = SOM::makeVar(SCRIPT_INT); \
  88. SOM::assign(&s, ((_class *)o)->call()); \
  89. return s;\
  90. }
  91. #define DEC_SCRIPT_FUNCTION_INT(func1, func2) \
  92. static scriptVar func1(int DLFid, ScriptObject *o); \
  93. virtual int func2();
  94. #define EVENT_ID __dlfid
  95. typedef struct {
  96. const wchar_t *function_name;
  97. int nparams;
  98. void *physical_ptr;
  99. } function_descriptor_struct;
  100. typedef struct {
  101. ScriptHook *hook;
  102. ScriptObject *object;
  103. } object_hook_struct;
  104. static const GUID ROOT_GUID =
  105. { 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
  106. class ScriptObjectController : public Dispatchable {
  107. protected:
  108. ScriptObjectController() {};
  109. public:
  110. void onRegisterClass(ScriptObjectController *rootController);
  111. GUID getClassGuid();
  112. const wchar_t *getClassName();
  113. const wchar_t *getAncestorClassName();
  114. ScriptObjectController *getAncestorController();
  115. int getNumFunctions();
  116. const function_descriptor_struct *getExportedFunctions();
  117. ScriptObject *instantiate();
  118. void destroy(ScriptObject *o);
  119. void *encapsulate(ScriptObject *o);
  120. void deencapsulate(void *o);
  121. ScriptObject *cast(ScriptObject *o, GUID g);
  122. void setClassId(int id);
  123. int getClassId();
  124. void setAncestorClassId(int id);
  125. int getAncestorClassId();
  126. int getInstantiable();
  127. int getReferenceable();
  128. int processHooks(ScriptObject *o, int dlfid, scriptVar **table, int nparams);
  129. void addClassHook(ScriptHook *h);
  130. void addObjectHook(ScriptHook *h, ScriptObject *o);
  131. void removeHooks(ScriptHook *h);
  132. enum {
  133. GETCLASSGUID = 100,
  134. GETCLASSNAME = 200,
  135. GETANCESTORCLASSNAME = 300,
  136. GETNUMFUNCTIONS = 400,
  137. GETEXPORTEDFUNCTIONS = 500,
  138. INSTANTIATE = 600,
  139. DESTROY = 700,
  140. GETCLASSID = 800,
  141. SETCLASSID = 900,
  142. SETANCESTORCLASSID = 1000,
  143. GETANCESTORCLASSID = 1100,
  144. GETINSTANTIABLE = 1200,
  145. GETREFERENCEABLE = 1300,
  146. PROCESSHOOKS = 1400,
  147. GETANCESTORCONTROLLER = 1500,
  148. ADDCLASSHOOK = 1600,
  149. ADDOBJHOOK = 1700,
  150. REMHOOKS = 1800,
  151. ONREGISTERCLASS = 1900,
  152. ENCAPSULATE = 2000,
  153. DEENCAPSULATE = 2100,
  154. CAST = 2200,
  155. };
  156. };
  157. inline GUID ScriptObjectController::getClassGuid() {
  158. return _call(GETCLASSGUID, ROOT_GUID);
  159. }
  160. inline const wchar_t *ScriptObjectController::getClassName()
  161. {
  162. return _call(GETCLASSNAME, (const wchar_t *)NULL);
  163. }
  164. inline const wchar_t *ScriptObjectController::getAncestorClassName() {
  165. return _call(GETANCESTORCLASSNAME, (const wchar_t *)NULL);
  166. }
  167. inline int ScriptObjectController::getNumFunctions() {
  168. return _call(GETNUMFUNCTIONS, 0);
  169. }
  170. inline const function_descriptor_struct *ScriptObjectController::getExportedFunctions() {
  171. return _call(GETEXPORTEDFUNCTIONS, (const function_descriptor_struct *)NULL);
  172. }
  173. inline ScriptObject *ScriptObjectController::instantiate() {
  174. return _call(INSTANTIATE, (ScriptObject *)NULL);
  175. }
  176. inline void ScriptObjectController::destroy(ScriptObject *o) {
  177. _voidcall(DESTROY, o);
  178. }
  179. inline int ScriptObjectController::getClassId() {
  180. return _call(GETCLASSID, 0);
  181. }
  182. inline void ScriptObjectController::setClassId(int id) {
  183. _voidcall(SETCLASSID, id);
  184. }
  185. inline int ScriptObjectController::getAncestorClassId() {
  186. return _call(GETANCESTORCLASSID, 0);
  187. }
  188. inline void ScriptObjectController::setAncestorClassId(int id) {
  189. _voidcall(SETANCESTORCLASSID, id);
  190. }
  191. inline int ScriptObjectController::getInstantiable() {
  192. return _call(GETINSTANTIABLE, 0);
  193. }
  194. inline int ScriptObjectController::getReferenceable() {
  195. return _call(GETREFERENCEABLE, 0);
  196. }
  197. inline ScriptObjectController *ScriptObjectController::getAncestorController() {
  198. return _call(GETANCESTORCONTROLLER, (ScriptObjectController *)NULL);
  199. }
  200. inline int ScriptObjectController::processHooks(ScriptObject *o, int dlfid, scriptVar **table, int nparams) {
  201. return _call(PROCESSHOOKS, 0, o, dlfid, table, nparams);
  202. }
  203. inline void ScriptObjectController::addClassHook(ScriptHook *h) {
  204. _voidcall(ADDCLASSHOOK, h);
  205. }
  206. inline void ScriptObjectController::addObjectHook(ScriptHook *h, ScriptObject *o) {
  207. _voidcall(ADDOBJHOOK, h, o);
  208. }
  209. inline void ScriptObjectController::removeHooks(ScriptHook *h) {
  210. _voidcall(REMHOOKS, h);
  211. }
  212. inline void ScriptObjectController::onRegisterClass(ScriptObjectController *rootController) {
  213. _voidcall(ONREGISTERCLASS, rootController);
  214. }
  215. inline void *ScriptObjectController::encapsulate(ScriptObject *o) {
  216. return _call(ENCAPSULATE, (void *) NULL, o);
  217. }
  218. inline void ScriptObjectController::deencapsulate(void *o) {
  219. _voidcall(DEENCAPSULATE, o);
  220. }
  221. inline ScriptObject *ScriptObjectController::cast(ScriptObject *o, GUID g) {
  222. return _call(CAST, (ScriptObject *)NULL, o, g);
  223. }
  224. class ScriptObjectControllerI : public ScriptObjectController {
  225. public:
  226. ScriptObjectControllerI();
  227. virtual ~ScriptObjectControllerI();
  228. virtual void onRegisterClass(ScriptObjectController *rootController);
  229. virtual GUID getClassGuid()=0;
  230. virtual const wchar_t *getClassName()=0;
  231. virtual const wchar_t *getAncestorClassName()=0;
  232. virtual ScriptObjectController *getAncestorController()=0;
  233. virtual int getNumFunctions()=0;
  234. virtual const function_descriptor_struct *getExportedFunctions()=0;
  235. virtual ScriptObject *instantiate()=0;
  236. virtual void destroy(ScriptObject *o)=0;
  237. virtual void *encapsulate(ScriptObject *o)=0;
  238. virtual void deencapsulate(void *o)=0;
  239. virtual ScriptObject *cast(ScriptObject *o, GUID g);
  240. virtual void setClassId(int id) { my_class_id = id; }
  241. virtual int getClassId() { return my_class_id; }
  242. virtual void setAncestorClassId(int id) { my_ancestor_class_id = id; }
  243. virtual int getAncestorClassId() { return my_ancestor_class_id; }
  244. virtual int getInstantiable() { return 1; };
  245. virtual int getReferenceable() { return 1; };
  246. virtual int processHooks(ScriptObject *o, int dlfid, scriptVar **table, int nparams);
  247. virtual void addClassHook(ScriptHook *h);
  248. virtual void addObjectHook(ScriptHook *h, ScriptObject *o);
  249. virtual void removeHooks(ScriptHook *h);
  250. private:
  251. int my_class_id;
  252. int my_ancestor_class_id;
  253. PtrList<object_hook_struct> objhooks;
  254. PtrList<ScriptHook> classhooks;
  255. ScriptObjectController *rootController;
  256. int incast;
  257. protected:
  258. RECVS_DISPATCH;
  259. };
  260. #endif