1
0

wasabi.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "main.h"
  2. #include "./wasabi.h"
  3. #include <api/service/waservicefactory.h>
  4. static ULONG wasabiRef = 0;
  5. api_application *WASABI_API_APP = NULL;
  6. api_language *WASABI_API_LNG = NULL;
  7. api_explorerfindfile *WASABI_API_EXPLORERFINDFILE = NULL;
  8. obj_ombrowser *browserManager = NULL;
  9. ifc_omservicemanager *serviceManager = NULL;
  10. ifc_omutility *omUtility = NULL;
  11. JSAPI2::api_security *AGAVE_API_JSAPI2_SECURITY = NULL;
  12. HINSTANCE WASABI_API_LNG_HINST = NULL;
  13. HINSTANCE WASABI_API_ORIG_HINST = NULL;
  14. EXTERN_C winampMediaLibraryPlugin plugin;
  15. void *Wasabi_QueryInterface(REFGUID interfaceGuid)
  16. {
  17. waServiceFactory *serviceFactory = plugin.service->service_getServiceByGuid(interfaceGuid);
  18. return (NULL != serviceFactory) ? serviceFactory->getInterface() : NULL;
  19. }
  20. void Wasabi_ReleaseInterface(REFGUID interfaceGuid, void *pInstance)
  21. {
  22. if (NULL == pInstance) return;
  23. waServiceFactory *serviceFactory = plugin.service->service_getServiceByGuid(interfaceGuid);
  24. if (NULL != serviceFactory) serviceFactory->releaseInterface(pInstance);
  25. }
  26. void Wasabi_SafeRelease(Dispatchable *pDisp)
  27. {
  28. if (NULL != pDisp)
  29. pDisp->Release();
  30. }
  31. BOOL WasabiApi_Initialize(HINSTANCE hInstance)
  32. {
  33. WASABI_API_APP = QueryWasabiInterface(api_application, applicationApiServiceGuid);
  34. WASABI_API_LNG = QueryWasabiInterface(api_language, languageApiGUID);
  35. WASABI_API_EXPLORERFINDFILE = QueryWasabiInterface(api_explorerfindfile, ExplorerFindFileApiGUID);
  36. AGAVE_API_JSAPI2_SECURITY = QueryWasabiInterface(JSAPI2::api_security, JSAPI2::api_securityGUID);
  37. OMBROWSERMNGR = QueryWasabiInterface(obj_ombrowser, OBJ_OmBrowser);
  38. OMSERVICEMNGR = QueryWasabiInterface(ifc_omservicemanager, IFC_OmServiceManager);
  39. OMUTILITY = QueryWasabiInterface(ifc_omutility, IFC_OmUtility);
  40. if (NULL != WASABI_API_LNG)
  41. WASABI_API_START_LANG(hInstance, WebDevLangUid);
  42. WasabiApi_AddRef();
  43. return TRUE;
  44. }
  45. static void WasabiApi_Uninitialize()
  46. {
  47. ReleaseWasabiInterface(applicationApiServiceGuid, WASABI_API_APP);
  48. ReleaseWasabiInterface(languageApiGUID, WASABI_API_LNG);
  49. ReleaseWasabiInterface(ExplorerFindFileApiGUID, WASABI_API_EXPLORERFINDFILE);
  50. ReleaseWasabiInterface(JSAPI2::api_securityGUID, AGAVE_API_JSAPI2_SECURITY);
  51. ReleaseWasabiInterface(OBJ_OmBrowser, OMBROWSERMNGR);
  52. ReleaseWasabiInterface(IFC_OmServiceManager, OMSERVICEMNGR);
  53. ReleaseWasabiInterface(IFC_OmUtility, OMUTILITY);
  54. WASABI_API_APP = NULL;
  55. WASABI_API_LNG = NULL;
  56. WASABI_API_EXPLORERFINDFILE = NULL;
  57. AGAVE_API_JSAPI2_SECURITY = NULL;
  58. }
  59. ULONG WasabiApi_AddRef()
  60. {
  61. return InterlockedIncrement((LONG*)&wasabiRef);
  62. }
  63. ULONG WasabiApi_Release()
  64. {
  65. if (0 == wasabiRef)
  66. return wasabiRef;
  67. LONG r = InterlockedDecrement((LONG*)&wasabiRef);
  68. if (0 == r)
  69. {
  70. WasabiApi_Uninitialize();
  71. }
  72. return r;
  73. }