wasabi.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "main.h"
  2. #include "./api__ml_online.h"
  3. #include <api/service/waservicefactory.h>
  4. #include "../nu/Singleton.h"
  5. #include "handler.h"
  6. #include "JSAPI2_Creator.h"
  7. static ULONG wasabiRef = 0;
  8. api_service *WASABI_API_SVC = NULL;
  9. api_application *WASABI_API_APP = NULL;
  10. api_config *AGAVE_API_CONFIG = NULL;
  11. api_language *WASABI_API_LNG = NULL;
  12. api_explorerfindfile *WASABI_API_EXPLORERFINDFILE = NULL;
  13. api_memmgr *WASABI_API_MEMMNGR = NULL;
  14. svc_imageLoader *pngLoaderApi = NULL;
  15. obj_ombrowser *browserManager = NULL;
  16. ifc_omservicemanager *serviceManager = NULL;
  17. ifc_omutility *omUtility = NULL;
  18. JSAPI2::api_security *AGAVE_API_JSAPI2_SECURITY = NULL;
  19. api_auth *AGAVE_API_AUTH = 0;
  20. static JSAPI2Factory jsapi2Factory;
  21. HINSTANCE WASABI_API_LNG_HINST = NULL;
  22. HINSTANCE WASABI_API_ORIG_HINST = NULL;
  23. static BOOL fDefaultsLoaded = FALSE;
  24. static OnlineServicesURIHandler uri_handler;
  25. static SingletonServiceFactory<svc_urihandler, OnlineServicesURIHandler> uri_handler_factory;
  26. EXTERN_C const GUID pngLoaderGUID =
  27. { 0x5e04fb28, 0x53f5, 0x4032, { 0xbd, 0x29, 0x3, 0x2b, 0x87, 0xec, 0x37, 0x25 } };
  28. void *Wasabi_QueryInterface(REFGUID interfaceGuid)
  29. {
  30. waServiceFactory *serviceFactory = WASABI_API_SVC->service_getServiceByGuid(interfaceGuid);
  31. return (NULL != serviceFactory) ? serviceFactory->getInterface() : NULL;
  32. }
  33. void Wasabi_ReleaseInterface(REFGUID interfaceGuid, void *pInstance)
  34. {
  35. if (NULL == pInstance) return;
  36. waServiceFactory *serviceFactory = WASABI_API_SVC->service_getServiceByGuid(interfaceGuid);
  37. if (NULL != serviceFactory) serviceFactory->releaseInterface(pInstance);
  38. }
  39. HRESULT WasabiApi_Initialize(HINSTANCE hInstance, api_service *serviceApi)
  40. {
  41. if (NULL != WASABI_API_SVC)
  42. return S_FALSE;
  43. fDefaultsLoaded = FALSE;
  44. WASABI_API_SVC = serviceApi;
  45. if ((api_service *)1 == WASABI_API_SVC)
  46. WASABI_API_SVC = NULL;
  47. if (NULL == WASABI_API_SVC)
  48. return E_FAIL;
  49. WASABI_API_ORIG_HINST = hInstance;
  50. WASABI_API_LNG_HINST = WASABI_API_ORIG_HINST;
  51. WasabiApi_AddRef();
  52. return S_OK;
  53. }
  54. HRESULT WasabiApi_LoadDefaults()
  55. {
  56. if (NULL == WASABI_API_SVC)
  57. return E_UNEXPECTED;
  58. if (FALSE != fDefaultsLoaded)
  59. return S_FALSE;
  60. WASABI_API_APP = QueryWasabiInterface(api_application, applicationApiServiceGuid);
  61. WASABI_API_LNG = QueryWasabiInterface(api_language, languageApiGUID);
  62. WASABI_API_EXPLORERFINDFILE = QueryWasabiInterface(api_explorerfindfile, ExplorerFindFileApiGUID);
  63. AGAVE_API_CONFIG = QueryWasabiInterface(api_config, AgaveConfigGUID);
  64. AGAVE_API_JSAPI2_SECURITY = QueryWasabiInterface(JSAPI2::api_security, JSAPI2::api_securityGUID);
  65. OMBROWSERMNGR = QueryWasabiInterface(obj_ombrowser, OBJ_OmBrowser);
  66. OMSERVICEMNGR = QueryWasabiInterface(ifc_omservicemanager, IFC_OmServiceManager);
  67. OMUTILITY = QueryWasabiInterface(ifc_omutility, IFC_OmUtility);
  68. AGAVE_API_AUTH = QueryWasabiInterface(api_auth, AuthApiGUID);
  69. if (NULL != WASABI_API_LNG)
  70. WASABI_API_LNG_HINST = WASABI_API_LNG->StartLanguageSupport(WASABI_API_ORIG_HINST, MlOnlineLangGUID);
  71. WASABI_API_SVC->service_register(&jsapi2Factory);
  72. uri_handler_factory.Register(WASABI_API_SVC, &uri_handler);
  73. fDefaultsLoaded = TRUE;
  74. return S_OK;
  75. }
  76. static void WasabiApi_Uninitialize()
  77. {
  78. if (NULL != WASABI_API_SVC)
  79. {
  80. ReleaseWasabiInterface(applicationApiServiceGuid, WASABI_API_APP);
  81. ReleaseWasabiInterface(languageApiGUID, WASABI_API_LNG);
  82. ReleaseWasabiInterface(ExplorerFindFileApiGUID, WASABI_API_EXPLORERFINDFILE);
  83. ReleaseWasabiInterface(AgaveConfigGUID, AGAVE_API_CONFIG);
  84. ReleaseWasabiInterface(memMgrApiServiceGuid, WASABI_API_MEMMNGR);
  85. ReleaseWasabiInterface(pngLoaderGUID, WASABI_API_PNGLOADER);
  86. ReleaseWasabiInterface(JSAPI2::api_securityGUID, AGAVE_API_JSAPI2_SECURITY);
  87. ReleaseWasabiInterface(AuthApiGUID, AGAVE_API_AUTH);
  88. ReleaseWasabiInterface(OBJ_OmBrowser, OMBROWSERMNGR);
  89. ReleaseWasabiInterface(IFC_OmServiceManager, OMSERVICEMNGR);
  90. ReleaseWasabiInterface(IFC_OmUtility, OMUTILITY);
  91. WASABI_API_SVC->service_deregister(&jsapi2Factory);
  92. uri_handler_factory.Deregister(WASABI_API_SVC);
  93. }
  94. WASABI_API_SVC = NULL;
  95. WASABI_API_APP = NULL;
  96. WASABI_API_LNG = NULL;
  97. WASABI_API_EXPLORERFINDFILE = NULL;
  98. AGAVE_API_CONFIG = NULL;
  99. AGAVE_API_JSAPI2_SECURITY = NULL;
  100. AGAVE_API_AUTH = NULL;
  101. OMBROWSERMNGR = NULL;
  102. OMSERVICEMNGR = NULL;
  103. OMUTILITY = NULL;
  104. fDefaultsLoaded = FALSE;
  105. }
  106. ULONG WasabiApi_AddRef()
  107. {
  108. return InterlockedIncrement((LONG*)&wasabiRef);
  109. }
  110. ULONG WasabiApi_Release()
  111. {
  112. if (0 == wasabiRef)
  113. return wasabiRef;
  114. LONG r = InterlockedDecrement((LONG*)&wasabiRef);
  115. if (0 == r)
  116. {
  117. WasabiApi_Uninitialize();
  118. }
  119. return r;
  120. }