api.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "../../Library/ml_pmp/pmp.h"
  2. #include "api.h"
  3. #include <api/service/waservicefactory.h>
  4. api_language *WASABI_API_LNG = 0;
  5. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  6. // Metadata service
  7. api_metadata *AGAVE_API_METADATA=0;
  8. api_playlistmanager *WASABI_API_PLAYLISTMNGR=0;
  9. api_threadpool *WASABI_API_THREADPOOL=0;
  10. api_albumart *AGAVE_API_ALBUMART=0;
  11. api_memmgr *WASABI_API_MEMMGR=0;
  12. api_application *WASABI_API_APP=0;
  13. api_devicemanager *AGAVE_API_DEVICEMANAGER = 0;
  14. extern PMPDevicePlugin plugin;
  15. template <class api_T>
  16. void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
  17. {
  18. if (plugin.service)
  19. {
  20. waServiceFactory *factory = plugin.service->service_getServiceByGuid(factoryGUID_t);
  21. if (factory)
  22. api_t = reinterpret_cast<api_T *>( factory->getInterface() );
  23. }
  24. }
  25. template <class api_T>
  26. void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
  27. {
  28. if (plugin.service && api_t)
  29. {
  30. waServiceFactory *factory = plugin.service->service_getServiceByGuid(factoryGUID_t);
  31. if (factory)
  32. factory->releaseInterface(api_t);
  33. }
  34. api_t = NULL;
  35. }
  36. void WasabiInit()
  37. {
  38. ServiceBuild(WASABI_API_LNG, languageApiGUID);
  39. ServiceBuild(AGAVE_API_METADATA, api_metadataGUID);
  40. ServiceBuild(WASABI_API_PLAYLISTMNGR, api_playlistmanagerGUID);
  41. ServiceBuild(WASABI_API_THREADPOOL, ThreadPoolGUID);
  42. ServiceBuild(AGAVE_API_ALBUMART, albumArtGUID);
  43. ServiceBuild(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  44. ServiceBuild(WASABI_API_APP, applicationApiServiceGuid);
  45. ServiceBuild(AGAVE_API_DEVICEMANAGER, DeviceManagerGUID);
  46. }
  47. void WasabiQuit()
  48. {
  49. ServiceRelease(WASABI_API_LNG, languageApiGUID);
  50. ServiceRelease(WASABI_API_PLAYLISTMNGR, api_playlistmanagerGUID);
  51. ServiceRelease(AGAVE_API_METADATA, api_metadataGUID);
  52. ServiceRelease(WASABI_API_THREADPOOL, ThreadPoolGUID);
  53. ServiceRelease(AGAVE_API_ALBUMART, albumArtGUID);
  54. ServiceRelease(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  55. ServiceRelease(WASABI_API_APP, applicationApiServiceGuid);
  56. ServiceRelease(AGAVE_API_DEVICEMANAGER, DeviceManagerGUID);
  57. }