1
0

objecttable.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. #include <precomp.h>
  2. #include <api/script/objecttable.h>
  3. #ifndef _NOSTUDIO
  4. #include <api/service/svcs/svc_scriptobji.h>
  5. #include <api/script/scriptobj.h>
  6. #include <api/script/vcputypes.h>
  7. #include <api/script/objects/systemobj.h>
  8. #include <api/script/scriptmgr.h>
  9. #include <api/script/objects/rootobject.h>
  10. #include <api/script/objects/guiobj.h>
  11. #include <api/skin/widgets/group.h>
  12. #ifdef WASABI_WIDGETS_LAYER
  13. #include <api/skin/widgets/layer.h>
  14. #endif
  15. #ifdef WASABI_WIDGETS_ANIMLAYER
  16. #include <api/skin/widgets/animlayer.h>
  17. #endif
  18. #include <AlbumArt.h>
  19. #ifdef WASABI_WIDGETS_BUTTON
  20. #include <api/skin/widgets/button.h>
  21. #endif
  22. #ifdef WASABI_COMPILE_WNDMGR
  23. #ifdef WASABI_WIDGETS_WNDHOLDER
  24. #include <api/wndmgr/container.h>
  25. #endif
  26. #include <api/wndmgr/layout.h>
  27. #endif // wndmgr
  28. #ifdef WASABI_WIDGETS_EDIT
  29. #include <api/skin/widgets/edit.h>
  30. #endif
  31. #ifdef WASABI_WIDGETS_SLIDER
  32. #include <api/skin/widgets/pslider.h>
  33. #endif
  34. #ifdef WASABI_WIDGETS_MEDIAVIS
  35. #include <api/skin/widgets/sa.h>
  36. #endif
  37. #ifdef WASABI_COMPILE_MEDIACORE
  38. #ifdef WASABI_WIDGETS_MEDIAEQCURVE
  39. #include <api/skin/widgets/seqvis.h>
  40. #endif
  41. #ifdef WASABI_WIDGETS_MEDIASTATUS
  42. #include <api/skin/widgets/sstatus.h>
  43. #endif
  44. #endif // mediacore
  45. #ifdef WASABI_WIDGETS_TEXT
  46. #include <api/skin/widgets/text.h>
  47. #endif
  48. #ifdef WASABI_WIDGETS_TGBUTTON
  49. #include <api/skin/widgets/tgbutton.h>
  50. #endif
  51. #ifdef WASABI_WIDGETS_TITLEBAR
  52. #include <api/skin/widgets/title.h>
  53. #endif
  54. #ifdef WASABI_SCRIPTOBJECTS_POPUP
  55. #include <api/script/objects/spopup.h>
  56. #endif
  57. #ifdef WASABI_SCRIPTOBJECTS_MAP
  58. #include <api/script/objects/smap.h>
  59. #endif
  60. #ifdef WASABI_WIDGETS_GROUPLIST
  61. #include <api/skin/widgets/grouplist.h>
  62. #endif
  63. #ifdef WASABI_WIDGETS_COMPBUCK
  64. #include <api/skin/widgets/compbuck2.h>
  65. #endif
  66. #ifdef WASABI_SCRIPTOBJECTS_WAC
  67. #include <api/script/objects/wacobj.h>
  68. #endif
  69. #ifdef WASABI_SCRIPTOBJECTS_LIST
  70. #include <api/script/objects/slist.h>
  71. #endif
  72. #ifdef WASABI_SCRIPTOBJECTS_BITLIST
  73. #include <api/script/objects/sbitlist.h>
  74. #endif
  75. #ifdef WASABI_SCRIPTOBJECTS_REGION
  76. #include <api/script/objects/sregion.h>
  77. #endif
  78. #ifdef WASABI_WIDGETS_MOUSEREDIR
  79. #include <api/skin/widgets/mouseredir.h>
  80. #endif
  81. #ifdef WASABI_WIDGETS_BROWSER
  82. #include <api/skin/widgets/mb/xuibrowser.h>
  83. #endif
  84. #ifdef WASABI_WIDGETS_QUERYLIST
  85. #include <api/skin/widgets/db/xuiquerylist.h>
  86. #endif
  87. #ifdef WASABI_WIDGETS_FILTERLIST
  88. #include <api/skin/widgets/db/xuifilterlist.h>
  89. #endif
  90. #ifdef WASABI_WIDGETS_WNDHOLDER
  91. #include <api/skin/widgets/xuiwndholder.h>
  92. #endif
  93. #ifdef WASABI_WIDGETS_DROPDOWNLIST
  94. #include <api/skin/widgets/dropdownlist.h>
  95. #endif
  96. #ifdef WASABI_SCRIPTOBJECTS_EMBEDDEDXUI
  97. #include <api/wnd/wndclass/embeddedxui.h>
  98. #endif
  99. #ifdef WASABI_WIDGETS_LAYOUTSTATUS
  100. #include <api/skin/widgets/xuistatus.h>
  101. #endif
  102. #ifdef WASABI_WIDGETS_TABSHEET
  103. #include <api/skin/widgets/xuitabsheet.h>
  104. #endif
  105. #ifdef WASABI_WIDGETS_LIST
  106. #include <api/skin/widgets/xuilist.h>
  107. #endif
  108. #ifdef WASABI_WIDGETS_TREE
  109. #include <api/skin/widgets/xuitree.h>
  110. #endif
  111. #ifdef WASABI_WIDGETS_CHECKBOX
  112. #include <api/skin/widgets/xuicheckbox.h>
  113. #endif
  114. #include <api/skin/widgets/xuiframe.h>
  115. //Martin> This fixes Wa5 Menu Xml Object is not instanciable via maki - silly bug
  116. #include <api/skin/widgets/xuimenuso.h>
  117. //fileIO
  118. #include <api/script/objects/sfile.h>
  119. #include <api/script/objects/sxmldoc.h>
  120. //ColorMgr
  121. #include <api/script/objects/scolormgr.h>
  122. #include <api/script/objects/scolor.h>
  123. #include <api/script/objects/sgammaset.h>
  124. #include <api/script/objects/sgammagroup.h>
  125. #include <api/script/objects/sapplication.h>
  126. #include <api/script/objects/sprivate.h>
  127. #include <api/script/vcpu.h>
  128. #include <bfc/ptrlist.h>
  129. #include <api/service/svc_enum.h>
  130. #include <api/service/service.h>
  131. #include <api/service/services.h>
  132. void ObjectTable::start() {
  133. registerClass(rootScriptObjectController);
  134. registerClass(systemController);
  135. #ifdef WASABI_COMPILE_SKIN
  136. registerClass(guiController);
  137. registerClass(groupController);
  138. #ifdef WASABI_SCRIPTOBJECTS_EMBEDDEDXUI
  139. registerClass(embeddedXuiController);
  140. #endif
  141. #ifdef WASABI_WIDGETS_LAYER
  142. registerClass(layerController);
  143. #endif
  144. #ifdef WASABI_WIDGETS_ANIMLAYER
  145. registerClass(animlayerController);
  146. #endif
  147. registerClass(albumartController);
  148. #ifdef WASABI_WIDGETS_BUTTON
  149. registerClass(buttonController);
  150. #endif
  151. #ifdef WASABI_WIDGETS_TGBUTTON
  152. registerClass(tgbuttonController);
  153. #endif
  154. #ifdef WASABI_WIDGETS_COMPBUCK
  155. registerClass(cbucketController);
  156. #endif
  157. #ifdef WASABI_COMPILE_WNDMGR
  158. registerClass(containerController);
  159. registerClass(layoutController);
  160. #endif
  161. #ifdef WASABI_WIDGETS_EDIT
  162. registerClass(editController);
  163. #endif
  164. #ifdef WASABI_WIDGETS_SLIDER
  165. registerClass(sliderController);
  166. #endif
  167. #ifdef WASABI_WIDGETS_MEDIAVIS
  168. registerClass(visController);
  169. #endif
  170. #ifdef WASABI_COMPILE_MEDIACORE
  171. #ifdef WASABI_WIDGETS_MEDIAEQCURVE
  172. registerClass(eqvisController);
  173. #endif
  174. #ifdef WASABI_WIDGETS_MEDIASTATUS
  175. registerClass(statusController);
  176. #endif
  177. #endif // mediacore
  178. #ifdef WASABI_WIDGETS_TEXT
  179. registerClass(textController);
  180. #endif
  181. registerClass(frameController);
  182. #ifdef WASABI_WIDGETS_TITLEBAR
  183. registerClass(titleController);
  184. #endif
  185. #ifdef WASABI_SCRIPTOBJECTS_POPUP
  186. registerClass(popupController);
  187. #endif
  188. #ifdef WASABI_SCRIPTOBJECTS_WAC
  189. registerClass(wacController);
  190. #endif
  191. #endif
  192. #ifdef WASABI_SCRIPTOBJECTS_LIST
  193. registerClass(listController);
  194. #endif
  195. #ifdef WASABI_SCRIPTOBJECTS_BITLIST
  196. registerClass(bitlistController);
  197. #endif
  198. #ifdef WASABI_SCRIPTOBJECTS_REGION
  199. registerClass(regionController);
  200. #endif
  201. #ifdef WASABI_SCRIPTOBJECTS_MAP
  202. registerClass(mapController);
  203. #endif
  204. #ifdef WASABI_COMPILE_SKIN
  205. #ifdef WASABI_WIDGETS_GROUPLIST
  206. registerClass(grouplistController);
  207. #endif
  208. #ifdef WASABI_WIDGETS_MOUSEREDIR
  209. registerClass(mouseredirController);
  210. #endif
  211. #ifdef WASABI_COMPILE_CONFIG
  212. registerClass(cfgGroupController);
  213. #endif
  214. #ifdef WASABI_WIDGETS_BROWSER
  215. registerClass(browserController);
  216. #endif
  217. #ifdef WASABI_WIDGETS_QUERYLIST
  218. registerClass(queryListController);
  219. #endif
  220. #ifdef WASABI_WIDGETS_FILTERLIST
  221. registerClass(filterListController);
  222. #endif
  223. #ifdef WASABI_COMPILE_WNDMGR
  224. #ifdef WASABI_WIDGETS_WNDHOLDER
  225. registerClass(windowHolderController);
  226. #endif
  227. #endif // wndmgr
  228. #ifdef WASABI_WIDGETS_DROPDOWNLIST
  229. registerClass(dropDownListController);
  230. #endif
  231. #ifdef WASABI_WIDGETS_LAYOUTSTATUS
  232. registerClass(layoutStatusController);
  233. #endif
  234. #ifdef WASABI_WIDGETS_TABSHEET
  235. registerClass(tabsheetController);
  236. #endif
  237. #ifdef WASABI_WIDGETS_LIST
  238. registerClass(guiListController);
  239. #endif
  240. #ifdef WASABI_WIDGETS_TREE
  241. registerClass(guiTreeController);
  242. registerClass(treeItemController);
  243. #endif
  244. #ifdef WASABI_WIDGETS_CHECKBOX
  245. registerClass(checkBoxController);
  246. #endif
  247. #endif
  248. registerClass(fileController);
  249. registerClass(xmlDocController);
  250. registerClass(applicationController);
  251. registerClass(SPrivateController);
  252. registerClass(xuiMenuScriptController);
  253. registerClass(colorMgrController);
  254. registerClass(colorController);
  255. registerClass(gammasetController);
  256. registerClass(gammagroupController);
  257. }
  258. void ObjectTable::shutdown() {
  259. for (int i=0;i<classes.getNumItems();i++) {
  260. class_entry *e = classes[i];
  261. unlinkClass(e);
  262. FREE((char *)e->classname);
  263. }
  264. classes.deleteAll();
  265. VCPU::resetDlf();
  266. externalloaded = 0;
  267. }
  268. // unload external classes
  269. void ObjectTable::unloadExternalClasses() {
  270. for (int i=0;i<classes.getNumItems();i++) {
  271. if (classes.enumItem(i)->external) {
  272. class_entry *ce = classes.enumItem(i);
  273. unlinkClass(ce);
  274. classes.removeByPos(i);
  275. i--;
  276. }
  277. }
  278. classidx = classes.getNumItems();
  279. externalloaded = 0;
  280. }
  281. void ObjectTable::unlinkClass(class_entry *e) {
  282. if (e->sf != NULL && !WASABI_API_SVC->service_isvalid(WaSvc::SCRIPTOBJECT, e->sf)) return;
  283. ScriptObjectController *c = e->controller;
  284. const function_descriptor_struct *ds = c->getExportedFunctions();
  285. for (int j=0;j<c->getNumFunctions();j++) {
  286. VCPU::DLF_reset(ds[j].physical_ptr, ds[j].nparams);
  287. }
  288. }
  289. void ObjectTable::loadExternalClasses() {
  290. if (externalloaded) return;
  291. externalloaded = 1;
  292. ExternalScriptObjectEnum soe ;
  293. svc_scriptObject *obj = soe.getFirst();
  294. while (obj) {
  295. obj->onRegisterClasses(rootScriptObjectController);
  296. int g=0;
  297. while (1) {
  298. ScriptObjectController *o = obj->getController(g);
  299. if (!o) break;
  300. //DebugString(StringPrintf("Registering script class %s\n", o->getClassName()));
  301. ObjectTable::registerClass(o, soe.getLastFactory());
  302. g++;
  303. }
  304. WASABI_API_SVC->service_release(obj);
  305. obj = soe.getNext();
  306. }
  307. }
  308. // returns classid. ancestorclass = 0 = Object
  309. int ObjectTable::registerClass(ScriptObjectController *c, waServiceFactory *sf) {
  310. ASSERT(c != NULL);
  311. c->onRegisterClass(rootScriptObjectController);
  312. const wchar_t *classname = c->getClassName();
  313. const wchar_t *ancestorclassname = c->getAncestorClassName();
  314. GUID g = c->getClassGuid();
  315. if (getClassFromName(classname) > -1) {
  316. ASSERTPR(0, StringPrintf("duplicate script class name %S", classname));
  317. #ifdef _WIN32
  318. ExitProcess(0);
  319. #else
  320. exit(0);
  321. #endif
  322. }
  323. if (getClassFromGuid(g) > -1) {
  324. ASSERTPR(0, "duplicate script class guid");
  325. #ifdef _WIN32
  326. ExitProcess(0);
  327. #else
  328. exit(0);
  329. #endif
  330. }
  331. int ancestorclassid = -1;
  332. if (ancestorclassname != NULL)
  333. ancestorclassid = getClassFromName(ancestorclassname);
  334. class_entry * en = new class_entry;
  335. en->classid = CLASS_ID_BASE + classidx++;
  336. c->setClassId(en->classid);
  337. c->setAncestorClassId(ancestorclassid);
  338. en->classname = WCSDUP(classname);
  339. en->controller = c;
  340. en->classGuid = g;
  341. en->ancestorclassid = ancestorclassid;
  342. en->instantiable = c->getInstantiable();
  343. en->referenceable = c->getReferenceable();
  344. en->external = sf != NULL;
  345. en->sf = sf;
  346. classes.addItem(en);
  347. dlfAddClassRef(c, NULL); // FG> fucko
  348. return classes.getNumItems()-1;
  349. }
  350. int ObjectTable::addrefDLF(VCPUdlfEntry *dlf, int id) {
  351. int classid = dlf->basetype;
  352. while (classid) {
  353. class_entry *e = getClassEntry(classid);
  354. if (!e) return 0;
  355. function_descriptor_struct *s = (function_descriptor_struct *)e->controller->getExportedFunctions();
  356. for (int i=0;i<e->controller->getNumFunctions();i++, s++) {
  357. if (!WCSICMP(s->function_name, dlf->functionName)) {
  358. int xid = VCPU::getDLFFromPointer(s->physical_ptr, s->nparams);
  359. if (xid != -1) {
  360. dlf->DLFid = xid;
  361. dlf->ptr = s->physical_ptr;
  362. dlf->nparams = s->nparams;
  363. VCPU::DLF_addref(s->physical_ptr, s->nparams);
  364. return 0;
  365. }
  366. dlf->DLFid = id;
  367. dlf->ptr = s->physical_ptr;
  368. dlf->nparams = s->nparams;
  369. VCPU::setupDLFFunction(s->physical_ptr, s->nparams, id, dlf);
  370. VCPU::DLF_addref(s->physical_ptr, s->nparams);
  371. return 1;
  372. }
  373. }
  374. classid = e->controller->getAncestorClassId();
  375. }
  376. return 0;
  377. }
  378. void ObjectTable::delrefDLF(VCPUdlfEntry *dlf) {
  379. int classid = dlf->basetype;
  380. while (classid) {
  381. class_entry *e = getClassEntry(classid);
  382. if (!e) return;
  383. function_descriptor_struct *s = (function_descriptor_struct *)e->controller->getExportedFunctions();
  384. for (int i=0;i<e->controller->getNumFunctions();i++, s++) {
  385. if (!WCSICMP(s->function_name, dlf->functionName)) {
  386. VCPU::DLF_remref(s->physical_ptr, s->nparams);
  387. return;
  388. }
  389. }
  390. classid = e->controller->getAncestorClassId();
  391. }
  392. }
  393. void ObjectTable::resetDLF(VCPUdlfEntry *dlf) {
  394. int classid = dlf->basetype;
  395. while (classid) {
  396. class_entry *e = getClassEntry(classid);
  397. if (!e) return;
  398. function_descriptor_struct *s = (function_descriptor_struct *)e->controller->getExportedFunctions();
  399. for (int i=0;i<e->controller->getNumFunctions();i++, s++) {
  400. if (!WCSICMP(s->function_name, dlf->functionName)) {
  401. VCPU::DLF_reset(s->physical_ptr, s->nparams);
  402. return;
  403. }
  404. }
  405. classid = e->controller->getAncestorClassId();
  406. }
  407. }
  408. int ObjectTable::getClassFromName(const wchar_t *classname) {
  409. for (int i=0;i<classes.getNumItems();i++) {
  410. if (classes[i] && !WCSICMP(classname, classes[i]->classname)) {
  411. return classes.enumItem(i)->classid;
  412. }
  413. }
  414. return -1;
  415. }
  416. int ObjectTable::getClassFromGuid(GUID g) {
  417. GUID t;
  418. for (int i=0;i<classes.getNumItems();i++) {
  419. t = classes.enumItem(i)->classGuid;
  420. if (g == t)
  421. return classes.enumItem(i)->classid;
  422. }
  423. return -1;
  424. }
  425. const wchar_t *ObjectTable::getClassName(int classid) {
  426. class_entry *e =getClassEntry(classid);
  427. if (!e) return NULL;
  428. return e->classname;
  429. }
  430. int ObjectTable::isExternal(int classid) {
  431. for (int i=0;i<classes.getNumItems();i++)
  432. if (classes.enumItem(i)->classid == classid)
  433. return 1;
  434. return 0;
  435. }
  436. int ObjectTable::getNumGuids() {
  437. return classes.getNumItems();
  438. }
  439. GUID ObjectTable::enumGuid(int i) {
  440. return classes.enumItem(i)->classGuid;
  441. }
  442. const wchar_t *ObjectTable::enumClassName(int n) {
  443. return classes.enumItem(n)->classname;
  444. }
  445. int ObjectTable::getClassEntryIdx(int classid) {
  446. for (int i=0;i<classes.getNumItems();i++)
  447. if (classes[i]->classid == classid)
  448. return i;
  449. return -1;
  450. }
  451. int ObjectTable::isDescendant(int class1, int classid) {
  452. if (classid < CLASS_ID_BASE) return 0;
  453. if (class1 < CLASS_ID_BASE) return 0;
  454. class_entry *e = getClassEntry(classid);
  455. //CUT: class_entry *_e = getClassEntry(class1);
  456. while (e) {
  457. if (class1 == classid) return 1;
  458. e = getClassEntry(e->ancestorclassid);
  459. if (e) classid = e->classid;
  460. }
  461. return 0;
  462. }
  463. int ObjectTable::isClassInstantiable(int classid) {
  464. class_entry *e =getClassEntry(classid);
  465. if (!e) return 0;
  466. return e->instantiable;
  467. }
  468. int ObjectTable::isClassReferenceable(int classid) {
  469. class_entry *e =getClassEntry(classid);
  470. if (!e) return 0;
  471. return e->referenceable;
  472. }
  473. ScriptObject *ObjectTable::instantiate(int classid) {
  474. class_entry *e = getClassEntry(classid);
  475. if (!e) return NULL;
  476. ScriptObject *o = e->controller->instantiate();
  477. return o;
  478. }
  479. void *ObjectTable::encapsulate(int classid, ScriptObject *o) {
  480. class_entry *e = getClassEntry(classid);
  481. if (!e) return NULL;
  482. void *itf = e->controller->encapsulate(o);
  483. if (itf)
  484. o->vcpu_setInterface(e->classGuid, itf);
  485. return itf;
  486. }
  487. void ObjectTable::destroy(ScriptObject *o) {
  488. if (!o) return;
  489. class_entry *e = getClassEntry(getClassFromName(o->vcpu_getClassName()));
  490. if (!e) return;
  491. e->controller->destroy(o);
  492. }
  493. void ObjectTable::deencapsulate(int classid, void *o) {
  494. class_entry *e = getClassEntry(classid);
  495. if (!e) return;
  496. e->controller->deencapsulate(o);
  497. }
  498. const wchar_t *ObjectTable::getFunction(int dlfid, int *n, ScriptObjectController **p)
  499. {
  500. VCPUdlfEntry *e = VCPU::getGlobalDlfEntry(dlfid);
  501. if (p) *p = getClassEntry(e->basetype)->controller;
  502. if (n) *n = e->nparams;
  503. return e->functionName;
  504. }
  505. scriptVar ObjectTable::callFunction(ScriptObject *obj, int dlfid, scriptVar **params) {
  506. VCPUdlfEntry *e = VCPU::getGlobalDlfEntry(dlfid);
  507. VCPU::push(MAKE_SCRIPT_OBJECT(obj));
  508. for (int i=e->nparams-1;i>=0;i--)
  509. VCPU::push(*params[i]);
  510. return VCPU::callDLF(e, -1);
  511. }
  512. int ObjectTable::dlfAddRef(ScriptObjectController *o, const wchar_t *function_name, void *host)
  513. {
  514. ScriptObjectController *_o = o;
  515. while (_o) {
  516. const function_descriptor_struct *s = _o->getExportedFunctions();
  517. for (int i=0;i<_o->getNumFunctions();i++) {
  518. if (!WCSICMP(function_name, s[i].function_name)) {
  519. return dlfAddRef(_o, i, host);
  520. }
  521. }
  522. // function not found, see if ancestor has it
  523. _o = _o->getAncestorController();
  524. }
  525. ASSERTALWAYS(StringPrintf("Function %s not found in %s class object hierarchy", function_name, o->getClassName()));
  526. return -1;
  527. }
  528. int ObjectTable::dlfAddRef(ScriptObjectController *o, int i, void *host) {
  529. const function_descriptor_struct *s = o->getExportedFunctions();
  530. int id = VCPU::getDLFFromPointer(s[i].physical_ptr, s[i].nparams);
  531. if (id < 0) { // not yet set
  532. // allocate new vcpudlfentry and insert it in vcpu
  533. id = VCPU::newDlf();
  534. VCPUdlfEntry e;
  535. e.basetype = o->getClassId();
  536. e.DLFid = id;
  537. // DebugString(" s = %08X\n", s);
  538. // DebugString(" s[i] = %08X\n", s[i]);
  539. ASSERT(s != NULL);
  540. e.functionName = const_cast<wchar_t *>(s[i].function_name);
  541. // DebugString(" %s\n", e.functionName);
  542. e.nparams = s[i].nparams;
  543. e.ptr = s[i].physical_ptr;
  544. e.scriptId = -1;
  545. VCPU::setupDLFFunction(e.ptr, e.nparams, id, &e);
  546. }
  547. VCPU::DLF_addref(s[i].physical_ptr, s[i].nparams);
  548. if (host != NULL) {
  549. hostrefstruct *r = new hostrefstruct;
  550. r->host = host;
  551. r->nargs = s[i].nparams;
  552. r->ptr = s[i].physical_ptr;
  553. hostrefs.addItem(r);
  554. }
  555. return id;
  556. }
  557. void ObjectTable::dlfAddClassRef(ScriptObjectController *o, void *host) {
  558. // while (o) {
  559. //CUT: const function_descriptor_struct *s = o->getExportedFunctions();
  560. for (int i=0;i<o->getNumFunctions();i++) {
  561. dlfAddRef(o, i, host);
  562. }
  563. // o = o->getAncestorController();
  564. // }
  565. }
  566. void ObjectTable::dlfRemRef(void *host) {
  567. for (int i=0;i<hostrefs.getNumItems();i++) {
  568. hostrefstruct *r = hostrefs.enumItem(i);
  569. if (r->host == host) {
  570. //VCPU::DLF_remref(r->ptr, r->nargs); // TODO: re-enable after fixup
  571. delete r;
  572. hostrefs.removeByPos(i);
  573. i--;
  574. }
  575. }
  576. }
  577. int ObjectTable::checkScript(SystemObject *o) {
  578. TList<int> *l = o->getTypesList();
  579. if (!l) return 0;
  580. for (int i=0;i<l->getNumItems();i++) {
  581. if (l->enumItem(i) == -1) {
  582. //#ifdef WASABI_COMPILE_WNDMGR
  583. // WASABI_API_WNDMGR->messageBox("Error while loading a script, a component is missing", "Oops", 0, "", NULL);
  584. //#else
  585. // MessageBox(NULL, "Error while loading a script, a component is missing", "Oops", 0);
  586. //#endif
  587. // return 0;
  588. } else {
  589. }
  590. }
  591. return 1;
  592. }
  593. ScriptObjectController *ObjectTable::getController(GUID g) {
  594. int i = getClassFromGuid(g);
  595. if (i == -1) return NULL;
  596. class_entry *e = getClassEntry(i);
  597. if (e)
  598. return e->controller;
  599. return NULL;
  600. }
  601. class_entry *ObjectTable::getClassEntry(int classid) {
  602. for (int i=0;i<classes.getNumItems();i++)
  603. if (classes[i]->classid == classid)
  604. return classes[i];
  605. return NULL;
  606. }
  607. #ifdef _NOSTUDIO
  608. int ObjectTable::validateMember(int classid, char *member, ControlBlock *parms, int *ret) {
  609. ControlBlock *p = parms;
  610. int r=0;
  611. for (int i=0;i<classes.getNumItems();i++)
  612. if (classes.enumItem(i)->classid == classid) {
  613. const function_descriptor_struct *s = classes.enumItem(i)->controller->getExportedFunctions();
  614. for (int j=0;j<classes.enumItem(i)->controller->getNumFunctions();j++) {
  615. if (STRCASEEQL(s->function_name, member)) {
  616. if (s->nparams == 0 && parms)
  617. wrongParametersNumber(member, s->nparams);
  618. for (int k=0;k<s->nparams&&!r;k++) {
  619. int b = s->param[k];
  620. if (p == NULL) {
  621. wrongParametersNumber(member, s->nparams);
  622. }
  623. if (!::isDescendant(p, b)) {
  624. wrongParameterType(k, member, (char *)getClassName(p->getBaseClass()), (char *)getClassName(classid));
  625. }
  626. p = p->getNext();
  627. }
  628. *ret = tempExternalToInternal(s->return_type);
  629. return 1;
  630. }
  631. s++;
  632. }
  633. }
  634. return 0;
  635. }
  636. #endif
  637. //-----
  638. PtrList < class_entry > ObjectTable::classes;
  639. PtrList < hostrefstruct > ObjectTable::hostrefs;
  640. int ObjectTable::classidx = 0;
  641. int ObjectTable::externalloaded = 0;
  642. #endif