main.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "api__playlist.h"
  2. #include "main.h"
  3. #include "factory_Handler.h"
  4. #include "factory_playlistmanager.h"
  5. #include "factory_playlists.h"
  6. #include "../Winamp/api_random.h"
  7. #include "Playlists.h"
  8. #include "plstring.h"
  9. #include "ScriptObjectFactory.h"
  10. #include "../nu/ServiceWatcher.h"
  11. #include "JSAPI2_Creator.h"
  12. extern Playlists playlists;
  13. int (*warand)(void) = 0;
  14. M3UHandlerFactory m3uHandlerFactory;
  15. PLSHandlerFactory plsHandlerFactory;
  16. B4SHandlerFactory b4sHandlerFactory;
  17. PlaylistManagerFactory playlistManagerFactory;
  18. PlaylistsFactory playlistsFactory;
  19. ScriptObjectFactory scriptObjectFactory;
  20. JSAPI2Factory jsapi2Factory;
  21. ServiceWatcher serviceWatcher;
  22. PlaylistComponent playlistComponent;
  23. api_service *WASABI_API_SVC = 0;
  24. api_application *WASABI_API_APP = 0;
  25. api_config *AGAVE_API_CONFIG = 0;
  26. api_syscb *WASABI_API_SYSCB = 0;
  27. api_maki *WASABI_API_MAKI = 0;
  28. JSAPI2::api_security *AGAVE_API_JSAPI2_SECURITY = 0;
  29. api_stats *AGAVE_API_STATS = 0;
  30. // wasabi based services for localisation support
  31. api_language *WASABI_API_LNG = 0;
  32. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  33. template <class api_t>
  34. api_t *GetService( GUID serviceGUID )
  35. {
  36. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid( serviceGUID );
  37. if ( sf )
  38. return (api_t *)sf->getInterface();
  39. else
  40. return 0;
  41. }
  42. inline void ReleaseService( GUID serviceGUID, void *service )
  43. {
  44. if ( service )
  45. {
  46. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid( serviceGUID );
  47. if ( sf )
  48. sf->releaseInterface( service );
  49. }
  50. }
  51. void PlaylistComponent::RegisterServices( api_service *service )
  52. {
  53. WASABI_API_SVC = service;
  54. warand = QuickService<api_random>( randomApiGUID )->GetFunction();
  55. WASABI_API_APP = GetService<api_application>( applicationApiServiceGuid );
  56. WASABI_API_SYSCB = GetService<api_syscb>( syscbApiServiceGuid );
  57. AGAVE_API_CONFIG = GetService<api_config>( AgaveConfigGUID );
  58. AGAVE_API_JSAPI2_SECURITY = GetService<JSAPI2::api_security>( JSAPI2::api_securityGUID );
  59. AGAVE_API_STATS = GetService<api_stats>( AnonymousStatsGUID );
  60. serviceWatcher.WatchWith( WASABI_API_SVC );
  61. serviceWatcher.WatchFor( &WASABI_API_MAKI, makiApiServiceGuid );
  62. // need to get WASABI_API_APP first
  63. plstring_init();
  64. WASABI_API_SVC->service_register( &m3uHandlerFactory );
  65. WASABI_API_SVC->service_register( &plsHandlerFactory );
  66. WASABI_API_SVC->service_register( &b4sHandlerFactory );
  67. WASABI_API_SVC->service_register( &playlistManagerFactory );
  68. WASABI_API_SVC->service_register( &playlistsFactory );
  69. WASABI_API_SVC->service_register( &scriptObjectFactory );
  70. WASABI_API_SVC->service_register( &jsapi2Factory );
  71. WASABI_API_LNG = GetService<api_language>( languageApiGUID );
  72. // need to have this initialised before we try to do anything with localisation features
  73. WASABI_API_START_LANG( hModule, playlistLangGUID );
  74. // register for service callbacks in case any of these don't exist yet
  75. WASABI_API_SYSCB->syscb_registerCallback( &serviceWatcher );
  76. }
  77. int PlaylistComponent::RegisterServicesSafeModeOk()
  78. {
  79. return 1;
  80. }
  81. void PlaylistComponent::DeregisterServices( api_service *service )
  82. {
  83. playlists.Flush();
  84. service->service_deregister( &playlistsFactory );
  85. service->service_deregister( &playlistManagerFactory );
  86. service->service_deregister( &m3uHandlerFactory );
  87. service->service_deregister( &plsHandlerFactory );
  88. service->service_deregister( &b4sHandlerFactory );
  89. service->service_deregister( &scriptObjectFactory );
  90. service->service_deregister( &jsapi2Factory );
  91. serviceWatcher.StopWatching();
  92. serviceWatcher.Clear();
  93. ReleaseService( makiApiServiceGuid, WASABI_API_MAKI );
  94. ReleaseService( applicationApiServiceGuid, WASABI_API_APP );
  95. ReleaseService( AgaveConfigGUID, AGAVE_API_CONFIG );
  96. ReleaseService( syscbApiServiceGuid, WASABI_API_SYSCB );
  97. ReleaseService( languageApiGUID, WASABI_API_LNG );
  98. ReleaseService( JSAPI2::api_securityGUID, AGAVE_API_JSAPI2_SECURITY );
  99. ReleaseService( AnonymousStatsGUID, AGAVE_API_STATS );
  100. }
  101. extern "C" __declspec(dllexport) ifc_wa5component *GetWinamp5SystemComponent()
  102. {
  103. return &playlistComponent;
  104. }
  105. #define CBCLASS PlaylistComponent
  106. START_DISPATCH;
  107. VCB( API_WA5COMPONENT_REGISTERSERVICES, RegisterServices )
  108. CB( API_WA5COMPONENT_REGISTERSERVICES_SAFE_MODE, RegisterServicesSafeModeOk )
  109. VCB( API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices )
  110. END_DISPATCH;
  111. #undef CBCLASS