1
0

wasabi.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "main.h"
  2. #include "./wasabi.h"
  3. #include <api/service/waservicefactory.h>
  4. api_application *WASABI_API_APP = NULL;
  5. api_language *WASABI_API_LNG = NULL;
  6. api_devicemanager *WASABI_API_DEVICES = NULL;
  7. api_winamp *WASABI_API_WINAMP = NULL;
  8. HINSTANCE WASABI_API_LNG_HINST = NULL;
  9. HINSTANCE WASABI_API_ORIG_HINST = NULL;
  10. static unsigned long wasabiReference = 0;
  11. static BOOL defaultServicesLoaded = FALSE;
  12. EXTERN_C winampMediaLibraryPlugin plugin;
  13. static void Wasabi_Uninitialize()
  14. {
  15. Wasabi_ReleaseInterface(applicationApiServiceGuid, WASABI_API_APP);
  16. Wasabi_ReleaseInterface(languageApiGUID, WASABI_API_LNG);
  17. Wasabi_ReleaseInterface(DeviceManagerGUID, WASABI_API_DEVICES);
  18. Wasabi_ReleaseInterface(winampApiGuid, WASABI_API_WINAMP);
  19. WASABI_API_APP = NULL;
  20. WASABI_API_LNG = NULL;
  21. WASABI_API_DEVICES = NULL;
  22. WASABI_API_WINAMP = NULL;
  23. defaultServicesLoaded = FALSE;
  24. }
  25. BOOL Wasabi_Initialize(HINSTANCE instance)
  26. {
  27. defaultServicesLoaded = FALSE;
  28. WASABI_API_APP = NULL;
  29. WASABI_API_DEVICES = NULL;
  30. WASABI_API_LNG = NULL;
  31. WASABI_API_ORIG_HINST = instance;
  32. WASABI_API_LNG_HINST = WASABI_API_ORIG_HINST;
  33. Wasabi_AddRef();
  34. return TRUE;
  35. }
  36. BOOL Wasabi_InitializeFromWinamp(HINSTANCE instance, HWND winampWindow)
  37. {
  38. return Wasabi_Initialize(instance);
  39. }
  40. BOOL Wasabi_LoadDefaultServices(void)
  41. {
  42. if (FALSE != defaultServicesLoaded)
  43. return FALSE;
  44. WASABI_API_APP = Wasabi_QueryInterface(api_application, applicationApiServiceGuid);
  45. WASABI_API_DEVICES = Wasabi_QueryInterface(api_devicemanager, DeviceManagerGUID);
  46. WASABI_API_WINAMP = Wasabi_QueryInterface(api_winamp, winampApiGuid);
  47. WASABI_API_LNG = Wasabi_QueryInterface(api_language, languageApiGUID);
  48. if (NULL != WASABI_API_LNG)
  49. {
  50. WASABI_API_LNG_HINST = WASABI_API_LNG->StartLanguageSupport(WASABI_API_ORIG_HINST, MlDevicesLangGUID);
  51. }
  52. defaultServicesLoaded = TRUE;
  53. return TRUE;
  54. }
  55. unsigned long
  56. Wasabi_AddRef(void)
  57. {
  58. return InterlockedIncrement((LONG*)&wasabiReference);
  59. }
  60. unsigned long
  61. Wasabi_Release(void)
  62. {
  63. if (0 == wasabiReference)
  64. return wasabiReference;
  65. LONG r = InterlockedDecrement((LONG*)&wasabiReference);
  66. if (0 == r)
  67. {
  68. Wasabi_Uninitialize();
  69. }
  70. return r;
  71. }
  72. void * Wasabi_QueryInterface0(const GUID &interfaceGuid)
  73. {
  74. waServiceFactory *serviceFactory = plugin.service->service_getServiceByGuid(interfaceGuid);
  75. if (NULL == serviceFactory)
  76. return NULL;
  77. return serviceFactory->getInterface();
  78. }
  79. void Wasabi_ReleaseInterface0(const GUID &interfaceGuid, void *interfaceInstance)
  80. {
  81. waServiceFactory *serviceFactory = plugin.service->service_getServiceByGuid(interfaceGuid);
  82. if (NULL == serviceFactory)
  83. return;
  84. serviceFactory->releaseInterface(interfaceInstance);
  85. }