apiinit.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. #include "./wndmgr/layout.h"
  2. #include <tataki/export.h>
  3. //<?#include "<class data="implementationheader"/>"
  4. #include "apiinit.h"
  5. //?>
  6. #include <api/memmgr/api_memmgr.h>
  7. #define WASABI_SAYMYNAME
  8. #include <wasabicfg.h>
  9. #undef WASABI_SAYMYNAME
  10. #include <api/service/servicei.h>
  11. #include <api/locales/api_localesi.h>
  12. #include <api/config/api_configi.h>
  13. #include <api/config/items/cfgitem.h>
  14. #ifdef WASABI_COMPILE_FONTS
  15. #include <api/font/FontCreator.h>
  16. #include <api/font/fontapi.h>
  17. #endif
  18. #include <api/skin/skinapi.h>
  19. #include <api/skin/groupwndcreate.h>
  20. #include <api/script/makiapi.h>
  21. #include <api/script/objecttable.h>
  22. #include <api/wnd/wndapi.h>
  23. #include <api/wnd/wndclass/foreignwnd.h>
  24. #include <api/wnd/wndclass/clickwnd.h>
  25. #include <api/imgldr/imgldrapi.h>
  26. #ifdef WASABI_COMPILE_FONTS
  27. #ifdef WIN32
  28. # include <api/font/win32/truetypefont_win32.h>
  29. #elif defined(LINUX)
  30. # include <api/font/linux/truetypefont_linux.h>
  31. #else
  32. # error port me
  33. #endif // platform
  34. #endif // fonts
  35. #include <api/wndmgr/wndmgrapi.h>
  36. #ifdef WASABI_COMPILE_MAKIDEBUG
  37. #include <api/script/debugger/debugapi.h>
  38. #endif
  39. #ifdef WASABI_COMPILE_MAKIDEBUG
  40. #include <api/core/api_core.h>
  41. #endif
  42. #ifdef WASABI_COMPILE_FILEREADER
  43. #include <api/filereader/filereaderapi.h>
  44. #ifdef WASABI_COMPILE_ZIPREADER
  45. #include <api/filereader/zip/zipread.h>
  46. #endif
  47. #endif
  48. #ifdef WASABI_COMPILE_LINUX
  49. #include <api/linux/api_linuxi.h>
  50. #endif
  51. #ifdef WASABI_COMPILE_TEXTMODE
  52. #if defined(WIN32)
  53. #include <api/textmode/textmode_win32.h>
  54. #elif defined(LINUX)
  55. #include <api/textmode/textmode_ncurses.h>
  56. #else // dummy
  57. #include <api/textmode/api_textmodeI.h>
  58. #endif
  59. #endif
  60. #if defined(WASABI_COMPILE_COMPONENTS) | defined(GEN_FF) // MULTIAPI-FIXME
  61. #include <api/wac/compon.h>
  62. #endif
  63. #include <api/wndmgr/gc.h>
  64. #include <api/application/api_application.h>
  65. #ifndef WASABI_CUSTOM_MODULE_SVCMGR
  66. DECLARE_MODULE_SVCMGR;
  67. #endif
  68. #ifdef _WIN32
  69. extern HINSTANCE hInstance;
  70. #endif
  71. extern StringW g_resourcepath;
  72. api_application *applicationApi = NULL;
  73. timer_api *timerApi = NULL;
  74. int ApiInit::init(OSMODULEHANDLE hinstance, OSWINDOWHANDLE mainwnd, api_service *wa5_svc)
  75. {
  76. Tataki::Init(wa5_svc);
  77. serviceApi = wa5_svc;
  78. initcount++;
  79. #ifndef WA3COMPATIBILITY
  80. // ------------------------------------------------------------------------
  81. // Init callback system
  82. // ------------------------------------------------------------------------
  83. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(syscbApiServiceGuid);
  84. if (sf) sysCallbackApi = reinterpret_cast<api_syscb *>(sf->getInterface());
  85. // ------------------------------------------------------------------------
  86. // Init application API
  87. // ------------------------------------------------------------------------
  88. sf = WASABI_API_SVC->service_getServiceByGuid(applicationApiServiceGuid);
  89. if (sf) applicationApi = reinterpret_cast<api_application *>(sf->getInterface());
  90. g_resourcepath = StringPathCombine(WASABI_API_APP->path_getAppPath(), WASABI_RESOURCES_SUBDIRECTORY);
  91. // ------------------------------------------------------------------------
  92. // Init centralized memory manager api
  93. // ------------------------------------------------------------------------
  94. sf = WASABI_API_SVC->service_getServiceByGuid(memMgrApiServiceGuid);
  95. if (sf) WASABI_API_MEMMGR = reinterpret_cast<api_memmgr *>(sf->getInterface());
  96. #ifdef WASABI_COMPILE_FILEREADER
  97. // ------------------------------------------------------------------------
  98. // Init file reader api and optional file readers
  99. // ------------------------------------------------------------------------
  100. fr = new FileReaderApi();
  101. fileApi = fr;
  102. WASABI_API_SVC->service_register(frapisvc = new FileReaderApiService());
  103. //WASABI_API_SVC->service_register(&diskReader);
  104. // set up custom file readers
  105. #ifdef WASABI_COMPILE_ZIPREADER
  106. zipRead = new waServiceTSingle<svc_fileReader, ZipRead>;
  107. #endif
  108. #ifdef WASABI_COMPILE_ZIPREADER
  109. WASABI_API_SVC->service_register(zipRead);
  110. #endif
  111. #endif // WASABI_COMPILE_FILEREADER
  112. // ------------------------------------------------------------------------
  113. // Init config api and register optional config items
  114. // ------------------------------------------------------------------------
  115. #ifdef WASABI_COMPILE_CONFIG
  116. cfg = new api_configI();
  117. configApi = cfg;
  118. WASABI_API_SVC->service_register(cfgapisvc = new ConfigApiService());
  119. #endif
  120. // if no static service was ever declared, we need to init it so we don't hit null
  121. INIT_MODULE_SVCMGR();
  122. DebugStringW(L"Auto-initializing %d services (system pass)\n", staticServiceMgr->__m_modules2.getNumItems());
  123. MODULE_SVCMGR_ONINIT2();
  124. #ifdef WASABI_COMPILE_IMGLDR
  125. // ------------------------------------------------------------------------
  126. // Init image loading api and optional image formats
  127. // ------------------------------------------------------------------------
  128. img = new ImgLdrApi();
  129. imgLoaderApi = img;
  130. WASABI_API_SVC->service_register(imgldrapisvc = new ImgLdrApiService());
  131. #endif
  132. #ifdef WASABI_COMPILE_FONTS
  133. // ------------------------------------------------------------------------
  134. // Init font rendering api
  135. // ------------------------------------------------------------------------
  136. font = new FontApi();
  137. fontApi = font;
  138. win32Font = new FontCreator<TrueTypeFont_Win32>;
  139. WASABI_API_SVC->service_register(win32Font);
  140. WASABI_API_SVC->service_register(fontapisvc = new FontApiService());
  141. #endif
  142. #ifdef WASABI_COMPILE_LOCALES
  143. // ------------------------------------------------------------------------
  144. // Init localization
  145. // ------------------------------------------------------------------------
  146. loc = new api_localesI();
  147. localesApi = loc;
  148. WASABI_API_SVC->service_register(localesapisvc = new LocalesApiService());
  149. #endif
  150. // ------------------------------------------------------------------------
  151. // Init timer api
  152. // ------------------------------------------------------------------------
  153. sf = WASABI_API_SVC->service_getServiceByGuid(timerApiServiceGuid);
  154. if (sf) timerApi = reinterpret_cast<timer_api *>(sf->getInterface());
  155. #ifdef WASABI_COMPILE_WND
  156. // ------------------------------------------------------------------------
  157. // Init window api
  158. // ------------------------------------------------------------------------
  159. wnd = new WndApi();
  160. wndApi = wnd;
  161. #ifdef _WIN32
  162. if (mainwnd != NULL)
  163. {
  164. mainWnd = new ForeignWnd(mainwnd, hInstance);
  165. DebugStringW(L"main wnd handle is %x\n", mainWnd->gethWnd());
  166. wnd->main_setRootWnd(mainWnd);
  167. }
  168. else
  169. {
  170. default_mainWnd = new ClickWnd();
  171. default_mainWnd->init(hInstance, NULL, TRUE);
  172. wnd->main_setRootWnd(default_mainWnd);
  173. }
  174. #endif
  175. WASABI_API_SVC->service_register(wndapisvc = new WndApiService());
  176. #endif
  177. // ------------------------------------------------------------------------
  178. // Init media core api
  179. // ------------------------------------------------------------------------
  180. #ifdef WASABI_COMPILE_MEDIACORE
  181. #ifndef WA3COMPATIBILITY
  182. #ifdef WASABI_CUSTOMIMPL_MEDIACORE
  183. coreApi = createCustomCoreApi();
  184. #else
  185. #error "not done yet"
  186. #endif
  187. #endif
  188. WASABI_API_SVC->service_register(coreapisvc = new CoreApiService());
  189. #endif
  190. #ifdef WASABI_COMPILE_WNDMGR
  191. // ------------------------------------------------------------------------
  192. // Init window manager api
  193. // ------------------------------------------------------------------------
  194. wndmgr = new WndMgrApi ();
  195. wndManagerApi = wndmgr;
  196. WASABI_API_SVC->service_register(wndmgrapisvc = new WndMgrApiService());
  197. #endif
  198. #ifdef WASABI_COMPILE_SKIN
  199. // ------------------------------------------------------------------------
  200. // Init skin
  201. // ------------------------------------------------------------------------
  202. skin = new SkinApi();
  203. skinApi = skin;
  204. #ifdef WASABI_COMPILE_COMPONENTS
  205. groupcreate = new waServiceTSingle<svc_windowCreate, GroupWndCreateSvc>;
  206. WASABI_API_SVC->service_register(groupcreate);
  207. #endif
  208. WASABI_API_SVC->service_register(skinapisvc = new SkinApiService());
  209. #endif
  210. #ifdef WASABI_COMPILE_MAKIDEBUG
  211. // ------------------------------------------------------------------------
  212. // Init script debugger api
  213. // ------------------------------------------------------------------------
  214. debug = new MakiDebuggerApi();
  215. debugApi = debug;
  216. WASABI_API_SVC->service_register(makidebugapisvc = new MakiDebugApiService());
  217. #endif
  218. #ifdef WASABI_COMPILE_SKIN
  219. widgets = new Widgets();
  220. #endif
  221. #endif
  222. DebugStringW(L"Auto-initializing %d services (user pass)\n", staticServiceMgr->__m_modules.getNumItems());
  223. MODULE_SVCMGR_ONINIT();
  224. #ifndef WA3COMPATIBILITY
  225. #ifdef WASABI_COMPILE_SCRIPT
  226. // ------------------------------------------------------------------------
  227. // Init scripting api
  228. // ------------------------------------------------------------------------
  229. maki = new api_makiI();
  230. makiApi = maki;
  231. WASABI_API_SVC->service_register(makiapisvc = new MakiApiService());
  232. maki->init();
  233. #ifdef WASABI_COMPILE_WNDMGR
  234. garbageCollector = new GarbageCollector();
  235. #endif
  236. ObjectTable::start();
  237. #endif
  238. #endif //wa3compat
  239. return 1; // success
  240. }
  241. int ApiInit::shutdown()
  242. {
  243. #ifndef WA3COMPATIBILITY
  244. garbageCollector->gccb_onGarbageCollect();
  245. delete garbageCollector;
  246. #ifdef WASABI_COMPILE_SKIN
  247. skin->preShutdown();
  248. #endif
  249. MODULE_SVCMGR_ONSHUTDOWN();
  250. #ifdef _WIN32
  251. ComponentManager::unloadAll();
  252. #else
  253. #warning port me?
  254. #endif
  255. WASABI_API_SVC->service_deregister(skinapisvc);
  256. delete skin;
  257. skinApi = NULL;
  258. delete skinapisvc;
  259. skinapisvc = 0;
  260. #ifdef WASABI_COMPILE_SCRIPT
  261. ObjectTable::shutdown();
  262. #endif
  263. #ifdef WASABI_COMPILE_SKIN
  264. delete widgets;
  265. widgets = NULL;
  266. #endif
  267. WASABI_API_SVC->service_deregister(makiapisvc);
  268. delete maki;
  269. makiApi = NULL;
  270. delete makiapisvc;
  271. makiapisvc = 0;
  272. #ifdef WASABI_COMPILE_COMPONENTS
  273. WASABI_API_SVC->service_deregister(groupcreate);
  274. delete groupcreate;
  275. groupcreate = 0;
  276. #endif
  277. WASABI_API_SVC->service_deregister(win32Font);
  278. delete win32Font;
  279. win32Font = 0;
  280. #ifdef WASABI_COMPILE_MEDIACORE
  281. #ifndef WA3COMPATIBILITY
  282. #ifdef WASABI_CUSTOMIMPL_MEDIACORE
  283. destroyCustomCoreApi(coreApi);
  284. #else
  285. #error "not done yet"
  286. #endif
  287. #endif
  288. WASABI_API_SVC->service_deregister(coreapisvc);
  289. delete coreapisvc;
  290. coreapisvc = 0;
  291. #endif
  292. WASABI_API_SVC->service_deregister(wndmgrapisvc);
  293. delete wndmgr;
  294. wndManagerApi = NULL;
  295. delete wndmgrapisvc;
  296. wndmgrapisvc = 0;
  297. delete loc;
  298. localesApi = NULL;
  299. WASABI_API_SVC->service_deregister(localesapisvc);
  300. delete localesapisvc;
  301. localesapisvc = 0;
  302. #ifdef WASABI_COMPILE_FILEREADER
  303. #ifdef WASABI_COMPILE_ZIPREADER
  304. WASABI_API_SVC->service_deregister(zipRead);
  305. delete zipRead;
  306. #endif
  307. delete fr;
  308. fileApi = NULL;
  309. WASABI_API_SVC->service_deregister(frapisvc);
  310. delete frapisvc;
  311. frapisvc = 0;
  312. #endif
  313. #endif
  314. delete mainWnd;
  315. mainWnd = NULL;
  316. delete default_mainWnd;
  317. default_mainWnd = NULL;
  318. WASABI_API_SVC->service_deregister(wndapisvc);
  319. delete wnd;
  320. wndApi = NULL;
  321. delete wndapisvc;
  322. wndapisvc = 0;
  323. #ifdef WASABI_COMPILE_FONTS
  324. WASABI_API_SVC->service_deregister(fontapisvc);
  325. delete font;
  326. fontApi = NULL;
  327. delete fontapisvc;
  328. fontapisvc = 0;
  329. #endif
  330. #ifndef WA3COMPATIBILITY
  331. delete img;
  332. imgLoaderApi = NULL;
  333. WASABI_API_SVC->service_deregister(imgldrapisvc);
  334. delete imgldrapisvc;
  335. imgldrapisvc = 0;
  336. #ifdef WASABI_COMPILE_CONFIG
  337. WASABI_API_SVC->service_deregister(cfgapisvc);
  338. delete cfg;
  339. configApi = NULL;
  340. delete cfgapisvc;
  341. cfgapisvc = 0;
  342. #endif
  343. MODULE_SVCMGR_ONSHUTDOWN2();
  344. WASABI_API_MEMMGR = NULL;
  345. applicationApi=NULL;
  346. #endif //wa3compatibility
  347. #ifdef WASABI_COMPILE_MAKIDEBUG
  348. delete debug;
  349. debugApi = NULL;
  350. WASABI_API_SVC->service_deregister(makidebugapisvc);
  351. delete makidebugapisvc;
  352. makidebugapisvc = 0;
  353. #endif
  354. if (alphaMgr)
  355. delete alphaMgr;
  356. alphaMgr=0;
  357. // TODO: releaseInterface
  358. timerApi = NULL;
  359. Tataki::Quit();
  360. sysCallbackApi = NULL;
  361. return 1; // success
  362. }
  363. int ApiInit::getInitCount()
  364. {
  365. return initcount;
  366. }
  367. #ifdef WASABI_COMPILE_SKIN
  368. #ifdef WASABI_COMPILE_COMPONENTS
  369. waServiceFactoryI * ApiInit::groupcreate = NULL;
  370. #endif
  371. #endif //WASABI_COMPILE_SKIN
  372. #ifdef WASABI_COMPILE_FONTS
  373. waServiceFactoryI * ApiInit::win32Font = NULL;
  374. FontApiService *ApiInit::fontapisvc = NULL;
  375. #endif //WASABI_COMPILE_FONTS
  376. #ifdef WASABI_COMPILE_SKIN
  377. Widgets * ApiInit::widgets = NULL;
  378. SkinApiService *ApiInit::skinapisvc = NULL;
  379. #endif
  380. #ifdef WASABI_COMPILE_CONFIG
  381. api_configI * ApiInit::cfg = NULL;
  382. ConfigApiService *ApiInit::cfgapisvc = NULL;
  383. #endif
  384. #ifdef WASABI_COMPILE_IMGLDR
  385. ImgLdrApi * ApiInit::img = NULL;
  386. ImgLdrApiService *ApiInit::imgldrapisvc = NULL;
  387. #endif
  388. #ifdef WASABI_COMPILE_FONTS
  389. FontApi * ApiInit::font = NULL;
  390. #endif
  391. #ifdef WASABI_COMPILE_FILEREADER
  392. FileReaderApi * ApiInit::fr = NULL;
  393. #ifdef WASABI_COMPILE_ZIPREADER
  394. waServiceFactoryI * ApiInit::zipRead = NULL;
  395. #endif
  396. FileReaderApiService *ApiInit::frapisvc = NULL;
  397. #endif
  398. #ifdef WASABI_COMPILE_LOCALES
  399. api_localesI * ApiInit::loc = NULL;
  400. LocalesApiService *ApiInit::localesapisvc = NULL;
  401. #endif
  402. #ifdef WASABI_COMPILE_WND
  403. WndApi * ApiInit::wnd = NULL;
  404. ForeignWnd * ApiInit::mainWnd = NULL;
  405. ClickWnd * ApiInit::default_mainWnd = NULL;
  406. WndApiService *ApiInit::wndapisvc = NULL;
  407. #endif
  408. #ifdef WASABI_COMPILE_WNDMGR
  409. WndMgrApi * ApiInit::wndmgr = NULL;
  410. WndMgrApiService *ApiInit::wndmgrapisvc = NULL;
  411. #endif
  412. #ifdef WASABI_COMPILE_SCRIPT
  413. api_makiI * ApiInit::maki = NULL;
  414. MakiApiService *ApiInit::makiapisvc = NULL;
  415. #endif
  416. #ifdef WASABI_COMPILE_SKIN
  417. SkinApi * ApiInit::skin = NULL;
  418. #endif
  419. #ifdef WASABI_COMPILE_MAKIDEBUG
  420. MakiDebuggerApi * ApiInit::debug = NULL;
  421. MakiDebugApiService *ApiInit::makidebugapisvc = NULL;
  422. #endif
  423. #ifdef WASABI_COMPILE_MEDIACORE
  424. CoreApiService *ApiInit::coreapisvc = NULL;
  425. #endif
  426. int ApiInit::initcount = 0;
  427. api_memmgr *memmgrApi = NULL;