1
0

main.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "api.h"
  2. #include "../Agave/Component/ifc_wa5component.h"
  3. #include <api/service/waservicefactory.h>
  4. #include "../nu/Singleton.h"
  5. #include "auth.h"
  6. EXTERN_C const GUID pngLoaderGUID =
  7. { 0x5e04fb28, 0x53f5, 0x4032, { 0xbd, 0x29, 0x3, 0x2b, 0x87, 0xec, 0x37, 0x25 } };
  8. class AuthComponent : public ifc_wa5component
  9. {
  10. public:
  11. void RegisterServices(api_service *service);
  12. int RegisterServicesSafeModeOk();
  13. void DeregisterServices(api_service *service);
  14. protected:
  15. RECVS_DISPATCH;
  16. };
  17. api_service *WASABI_API_SVC=0;
  18. api_application *WASABI_API_APP =0;
  19. api_config *AGAVE_API_CONFIG = 0;
  20. api_syscb *WASABI_API_SYSCB = 0;
  21. api_winamp *WASABI_API_WINAMP = 0;
  22. api_memmgr *WASABI_API_MEMMNGR = NULL;
  23. svc_imageLoader *WASABI_API_PNGLOADER = NULL;
  24. api_language *WASABI_API_LNG = 0;
  25. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  26. static Auth auth;
  27. static SingletonServiceFactory<api_auth, Auth> authFactory;
  28. template <class api_T>
  29. void ServiceBuild(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. api_t = (api_T *)factory->getInterface();
  36. }
  37. }
  38. template <class api_T>
  39. void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
  40. {
  41. if (WASABI_API_SVC && api_t)
  42. {
  43. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  44. if (factory)
  45. factory->releaseInterface(api_t);
  46. }
  47. api_t = 0;
  48. }
  49. void AuthComponent::RegisterServices(api_service *service)
  50. {
  51. WASABI_API_SVC = service;
  52. ServiceBuild(WASABI_API_APP, applicationApiServiceGuid);
  53. ServiceBuild(AGAVE_API_CONFIG, AgaveConfigGUID);
  54. ServiceBuild(WASABI_API_SYSCB, syscbApiServiceGuid);
  55. ServiceBuild(WASABI_API_WINAMP, winampApiGuid);
  56. ServiceBuild(WASABI_API_LNG, languageApiGUID);
  57. // need to have this initialised before we try to do anything with localisation features
  58. WASABI_API_START_LANG(hModule, authLangGUID);
  59. auth.Init();
  60. authFactory.Register(WASABI_API_SVC, &auth);
  61. }
  62. int AuthComponent::RegisterServicesSafeModeOk()
  63. {
  64. return 1;
  65. }
  66. void AuthComponent::DeregisterServices(api_service *service)
  67. {
  68. ServiceRelease(WASABI_API_APP, applicationApiServiceGuid);
  69. ServiceRelease(AGAVE_API_CONFIG, AgaveConfigGUID);
  70. ServiceRelease(WASABI_API_SYSCB, syscbApiServiceGuid);
  71. ServiceRelease(WASABI_API_WINAMP, winampApiGuid);
  72. ServiceRelease(WASABI_API_LNG, languageApiGUID);
  73. ServiceRelease(WASABI_API_MEMMNGR, memMgrApiServiceGuid);
  74. ServiceRelease(WASABI_API_PNGLOADER, pngLoaderGUID);
  75. authFactory.Deregister(WASABI_API_SVC);
  76. auth.Quit();
  77. }
  78. static AuthComponent authComponent;
  79. extern "C" __declspec(dllexport) ifc_wa5component *GetWinamp5SystemComponent()
  80. {
  81. return &authComponent;
  82. }
  83. #define CBCLASS AuthComponent
  84. START_DISPATCH;
  85. VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
  86. CB(15, RegisterServicesSafeModeOk)
  87. VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
  88. END_DISPATCH;
  89. #undef CBCLASS