1
0

wasabi.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. JSAPI2::api_security *AGAVE_API_JSAPI2_SECURITY = NULL;
  8. obj_ombrowser *browserManager = NULL;
  9. api_syscb *WASABI_API_SYSCB = NULL;
  10. ifc_omutility *omUtility = NULL;
  11. HINSTANCE WASABI_API_LNG_HINST = NULL;
  12. HINSTANCE WASABI_API_ORIG_HINST = NULL;
  13. EXTERN_C winampMediaLibraryPlugin plugin;
  14. void *Wasabi_QueryInterface(REFGUID interfaceGuid)
  15. {
  16. waServiceFactory *serviceFactory = plugin.service->service_getServiceByGuid(interfaceGuid);
  17. return (NULL != serviceFactory) ? serviceFactory->getInterface() : NULL;
  18. }
  19. void Wasabi_ReleaseInterface(REFGUID interfaceGuid, void *pInstance)
  20. {
  21. waServiceFactory *serviceFactory = plugin.service->service_getServiceByGuid(interfaceGuid);
  22. if (NULL != serviceFactory) serviceFactory->releaseInterface(pInstance);
  23. }
  24. void Wasabi_SafeRelease(Dispatchable *pDisp)
  25. {
  26. if (NULL != pDisp)
  27. pDisp->Release();
  28. }
  29. BOOL WasabiApi_Initialize(HINSTANCE hInstance)
  30. {
  31. WASABI_API_APP = QueryWasabiInterface(api_application, applicationApiServiceGuid);
  32. WASABI_API_SYSCB = QueryWasabiInterface(api_syscb, syscbApiServiceGuid);
  33. WASABI_API_LNG = QueryWasabiInterface(api_language, languageApiGUID);
  34. AGAVE_API_JSAPI2_SECURITY = QueryWasabiInterface(JSAPI2::api_security, JSAPI2::api_securityGUID);
  35. OMBROWSERMNGR = QueryWasabiInterface(obj_ombrowser, OBJ_OmBrowser);
  36. OMUTILITY = QueryWasabiInterface(ifc_omutility, IFC_OmUtility);
  37. if (NULL != WASABI_API_LNG)
  38. WASABI_API_START_LANG(hInstance, MlNowPlayingLangGUID);
  39. WasabiApi_AddRef();
  40. return TRUE;
  41. }
  42. static void WasabiApi_Uninitialize()
  43. {
  44. ReleaseWasabiInterface(applicationApiServiceGuid, WASABI_API_APP);
  45. ReleaseWasabiInterface(syscbApiServiceGuid, WASABI_API_SYSCB);
  46. ReleaseWasabiInterface(languageApiGUID, WASABI_API_LNG);
  47. ReleaseWasabiInterface(JSAPI2::api_securityGUID, AGAVE_API_JSAPI2_SECURITY);
  48. ReleaseWasabiInterface(OBJ_OmBrowser, OMBROWSERMNGR);
  49. ReleaseWasabiInterface(IFC_OmUtility, OMUTILITY);
  50. WASABI_API_APP = NULL;
  51. WASABI_API_LNG = NULL;
  52. AGAVE_API_JSAPI2_SECURITY = NULL;
  53. }
  54. ULONG WasabiApi_AddRef()
  55. {
  56. return InterlockedIncrement((LONG*)&wasabiRef);
  57. }
  58. ULONG WasabiApi_Release()
  59. {
  60. if (0 == wasabiRef)
  61. return wasabiRef;
  62. LONG r = InterlockedDecrement((LONG*)&wasabiRef);
  63. if (0 == r)
  64. {
  65. WasabiApi_Uninitialize();
  66. }
  67. return r;
  68. }