main.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "../Agave/Component/ifc_wa5component.h"
  2. #include "api__xspf.h" // services we'll used are extern'd here
  3. #include "XSPFHandlerFactory.h"
  4. // declarations for the pointers to services we'll need
  5. // by convention, these follow the format WASABI_API_* or AGAVE_API_*
  6. // you are free to name it however you want, but this provides good consistency
  7. api_service *WASABI_API_SVC = 0; // the wasabi service manager (our gateway to other services)
  8. api_mldb *AGAVE_API_MLDB = 0; // media library API. we'll retrieve this the first time we need it, because it will load after us
  9. api_tagz *AGAVE_API_TAGZ = 0;
  10. api_application *WASABI_API_APP = 0;
  11. // wasabi based services for localisation support
  12. api_language *WASABI_API_LNG = 0;
  13. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  14. // our service factories that we're going to register
  15. static XSPFHandlerFactory xspfHandlerFactory;
  16. // here is the implementation of our component
  17. // this class contains the methods called during initialization and shutdown
  18. // to register/deregister our component's services
  19. class XSPFComponent : public ifc_wa5component
  20. {
  21. public:
  22. void RegisterServices(api_service *service); // this is where the party is
  23. void DeregisterServices(api_service *service);
  24. protected:
  25. RECVS_DISPATCH; // some boiler-plate code to implement our dispatch table
  26. };
  27. static HINSTANCE GetMyInstance()
  28. {
  29. MEMORY_BASIC_INFORMATION mbi = {0};
  30. if(VirtualQuery(GetMyInstance, &mbi, sizeof(mbi)))
  31. return (HINSTANCE)mbi.AllocationBase;
  32. return NULL;
  33. }
  34. void XSPFComponent::RegisterServices(api_service *service)
  35. {
  36. WASABI_API_SVC = service; // we get passed the service manager and we need to save the pointer
  37. WASABI_API_SVC->service_register(&xspfHandlerFactory);
  38. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(languageApiGUID);
  39. if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());
  40. // need to have this initialised before we try to do anything with localisation features
  41. WASABI_API_START_LANG(GetMyInstance(),playlistLangGUID);
  42. }
  43. void XSPFComponent::DeregisterServices(api_service *service)
  44. {
  45. WASABI_API_SVC->service_deregister(&xspfHandlerFactory);
  46. }
  47. static XSPFComponent xspfComponent;
  48. // Winamp calls this function after it LoadLibrary's your W5S
  49. // you need to turn a pointer to your component.
  50. extern "C" __declspec(dllexport) ifc_wa5component *GetWinamp5SystemComponent()
  51. {
  52. return &xspfComponent;
  53. }
  54. // some boiler-plate code to implement the dispatch table for our component
  55. #define CBCLASS XSPFComponent
  56. START_DISPATCH;
  57. VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
  58. VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
  59. END_DISPATCH;
  60. #undef CBCLASS