main.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "api.h"
  2. #include "../Agave/Component/ifc_wa5component.h"
  3. #include "CoverDirectory.h"
  4. class CoverDirectoryComponent : public ifc_wa5component
  5. {
  6. public:
  7. void RegisterServices(api_service *service);
  8. void DeregisterServices(api_service *service);
  9. protected:
  10. RECVS_DISPATCH;
  11. };
  12. api_service *WASABI_API_SVC=0;
  13. api_application *WASABI_API_APP =0;
  14. api_config *AGAVE_API_CONFIG = 0;
  15. api_memmgr *WASABI_API_MEMMGR=0;
  16. api_metadata *AGAVE_API_METADATA = 0;
  17. static AlbumArtFactory albumArtFactory;
  18. template <class api_T>
  19. void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
  20. {
  21. if (WASABI_API_SVC)
  22. {
  23. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  24. if (factory)
  25. api_t = (api_T *)factory->getInterface();
  26. }
  27. }
  28. template <class api_T>
  29. void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
  30. {
  31. if (WASABI_API_SVC)
  32. {
  33. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  34. if (factory)
  35. factory->releaseInterface(api_t);
  36. }
  37. api_t = NULL;
  38. }
  39. void CoverDirectoryComponent::RegisterServices(api_service *service)
  40. {
  41. WASABI_API_SVC = service;
  42. ServiceBuild(WASABI_API_APP, applicationApiServiceGuid);
  43. ServiceBuild(AGAVE_API_CONFIG, AgaveConfigGUID);
  44. ServiceBuild(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  45. ServiceBuild(AGAVE_API_METADATA, api_metadataGUID);
  46. WASABI_API_SVC->service_register(&albumArtFactory);
  47. /* uncomment if we need it
  48. WASABI_API_LNG = GetService<api_language>(languageApiGUID);
  49. // need to have this initialised before we try to do anything with localisation features
  50. WASABI_API_START_LANG(hModule,playlistLangGUID);
  51. */
  52. }
  53. void CoverDirectoryComponent::DeregisterServices(api_service *service)
  54. {
  55. ServiceRelease(WASABI_API_APP, applicationApiServiceGuid);
  56. ServiceRelease(AGAVE_API_CONFIG, AgaveConfigGUID);
  57. ServiceRelease(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  58. ServiceRelease(AGAVE_API_METADATA, api_metadataGUID);
  59. WASABI_API_SVC->service_deregister(&albumArtFactory);
  60. /* uncomment if we need it
  61. ReleaseService(languageApiGUID, WASABI_API_LNG);
  62. */
  63. }
  64. static CoverDirectoryComponent coverDirectoryComponent;
  65. extern "C" __declspec(dllexport) ifc_wa5component *GetWinamp5SystemComponent()
  66. {
  67. return &coverDirectoryComponent;
  68. }
  69. #define CBCLASS CoverDirectoryComponent
  70. START_DISPATCH;
  71. VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
  72. VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
  73. END_DISPATCH;
  74. #undef CBCLASS