Wasabi.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author: Ben Allison [email protected]
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include <api.h>
  10. #include "VideoFeedFactory.h"
  11. #include "TagProvider.h"
  12. #include "Singleton.h"
  13. #include "Random.h"
  14. #include "DecodeFile.h"
  15. #include "Language.h"
  16. #include "ExplorerFindFile.h"
  17. #include "../config/config.h"
  18. #include "JSAPI2_Security.h"
  19. #include "GammaManagerAPI.h"
  20. #include "PaletteManager.h"
  21. #include "../nu/ServiceWatcher.h"
  22. #include "JSAPI2_Creator.h"
  23. #include "stats.h"
  24. #include "../nu/Singleton.h"
  25. #include "handler.h"
  26. ServiceWatcher serviceWatcher;
  27. api_playlistmanager *playlistManager=0;
  28. api_playlists *AGAVE_API_PLAYLISTS=0;
  29. api_language *WASABI_API_LNG=0;
  30. api_downloadManager *WAC_API_DOWNLOADMANAGER=0;
  31. api_skin *WASABI_API_SKIN=0;
  32. api_amgsucks *AGAVE_API_AMGSUCKS=0;
  33. api_albumart *AGAVE_API_ALBUMART=0;
  34. // ----- Services -----
  35. api_service *serviceManager = 0;
  36. VideoTextFeed *videoTextFeed = 0;
  37. PlaylistTextFeed *playlistTextFeed = 0;
  38. TagProvider *tagProvider = 0;
  39. SysCallbacks *sysCallbacks = 0;
  40. MemoryManager *memoryManager = 0;
  41. GammaManagerAPI *gammaManager = 0;
  42. PaletteManager *paletteManager = 0;
  43. Metadata *metadata = 0;
  44. Application *application = 0;
  45. DecodeFile *decodeFile = 0;
  46. URLManager *AGAVE_API_URLMANAGER = 0;
  47. ThreadPool *WASABI_API_THREADPOOL = 0;
  48. WinampApi *WASABI_API_WINAMP = 0;
  49. Random random;
  50. WinampURIHandler winamp_uri_handler;
  51. Language *langManager = 0;
  52. ExplorerFindFile *explorerFindFileManager = 0;
  53. // ----- Service Factories -----
  54. static VideoTextFeedFactory *videoTextFeedFactory = 0;
  55. static PlaylistTextFeedFactory *playlistTextFeedFactory = 0;
  56. //TagProviderFactory *tagProviderFactory = 0;
  57. static Singleton2<api_syscb, SysCallbacks> syscbsvc;
  58. static Singleton2<api_config, Config> configSvc;
  59. Config config;
  60. static Singleton2<api_stats, Stats> statsSvc;
  61. // this class is using the RAII concept (resource allocation is initialization)
  62. // it registers services in its constructor, and deregisters in the destructor
  63. class WinampServices
  64. {
  65. public:
  66. WinampServices() :
  67. memoryManagerFactory(memoryManager),
  68. metadataFactory(metadata),
  69. applicationFactory(application),
  70. randomFactory(&random, true),
  71. decodeFileFactory(decodeFile),
  72. languageFactory(langManager),
  73. ExplorerFindFileFactory(explorerFindFileManager),
  74. urlManagerFactory(AGAVE_API_URLMANAGER),
  75. jsapi2_securityFactory(&JSAPI2::security, true),
  76. gammaManagerFactory(gammaManager),
  77. paletteManagerFactory(paletteManager),
  78. threadPoolFactory(WASABI_API_THREADPOOL),
  79. winampFactory(WASABI_API_WINAMP)
  80. {
  81. WASABI_API_SVC->service_register(&jsapi2_creator_factory);
  82. WASABI_API_LNG = langManager;
  83. uriHandlerFactory.Register(WASABI_API_SVC, &winamp_uri_handler);
  84. }
  85. ~WinampServices()
  86. {
  87. WASABI_API_SVC->service_deregister(&jsapi2_creator_factory);
  88. uriHandlerFactory.Deregister(WASABI_API_SVC);
  89. }
  90. Singleton<api_memmgr, MemoryManager> memoryManagerFactory;
  91. Singleton<api_metadata, Metadata> metadataFactory;
  92. Singleton<api_application, Application> applicationFactory;
  93. Singleton<api_random, Random> randomFactory;
  94. Singleton<api_decodefile, DecodeFile> decodeFileFactory;
  95. Singleton<api_language, Language> languageFactory;
  96. Singleton<api_explorerfindfile, ExplorerFindFile> ExplorerFindFileFactory;
  97. Singleton<api_urlmanager, URLManager> urlManagerFactory;
  98. Singleton<JSAPI2::api_security, JSAPI2::Security> jsapi2_securityFactory;
  99. Singleton<api_colorthemes, GammaManagerAPI> gammaManagerFactory;
  100. Singleton<api_palette, PaletteManager> paletteManagerFactory;
  101. Singleton<api_threadpool, ThreadPool> threadPoolFactory;
  102. Singleton<api_winamp, WinampApi> winampFactory;
  103. SingletonServiceFactory<svc_urihandler, WinampURIHandler> uriHandlerFactory;
  104. JSAPI2CreatorFactory jsapi2_creator_factory;
  105. };
  106. WinampServices *services=0;
  107. namespace Wasabi
  108. {
  109. bool loaded = false;
  110. }
  111. void Wasabi_Load()
  112. {
  113. if (!Wasabi::loaded)
  114. {
  115. RegisterConfigGroups(); // TODO: this isn't the best place to set up this config stuff, but it's going here now 'cause it's convienent
  116. serviceManager = new ServiceManager;
  117. syscbsvc.RegisterNew(sysCallbacks);
  118. configSvc.Register(&config);
  119. statsSvc.Register(&stats);
  120. services = new WinampServices();
  121. videoTextFeed = new VideoTextFeed;
  122. serviceManager->service_register(videoTextFeedFactory = new VideoTextFeedFactory);
  123. playlistTextFeed = new PlaylistTextFeed;
  124. serviceManager->service_register(playlistTextFeedFactory = new PlaylistTextFeedFactory);
  125. tagProvider = new TagProvider;
  126. //serviceManager->service_register(tagProviderFactory = new TagProviderFactory);
  127. // watch for services that might be loaded later by plugins
  128. serviceWatcher.WatchWith(serviceManager);
  129. serviceWatcher.WatchFor(&WASABI_API_SKIN, skinApiServiceGuid);
  130. // register for service callbacks in case any of these don't exist yet
  131. WASABI_API_SYSCB->syscb_registerCallback(&serviceWatcher);
  132. Wasabi::loaded = true;
  133. }
  134. }
  135. void Wasabi_Unload()
  136. {
  137. if (Wasabi::loaded)
  138. {
  139. //delete textFeeds;
  140. //textFeeds=0;
  141. serviceWatcher.StopWatching();
  142. serviceWatcher.Clear();
  143. // serviceManager->service_deregister(tagProviderFactory);
  144. serviceManager->service_deregister(videoTextFeedFactory);
  145. serviceManager->service_deregister(playlistTextFeedFactory);
  146. // delete tagProviderFactory; tagProviderFactory = 0;
  147. delete videoTextFeedFactory;
  148. videoTextFeedFactory = 0;
  149. delete playlistTextFeedFactory;
  150. playlistTextFeedFactory = 0;
  151. delete tagProvider;
  152. tagProvider = 0;
  153. delete videoTextFeed;
  154. videoTextFeed = 0;
  155. delete playlistTextFeed;
  156. playlistTextFeed = 0;
  157. WASABI_API_THREADPOOL->Kill();
  158. delete services;
  159. configSvc.Deregister();
  160. statsSvc.Deregister();
  161. syscbsvc.Deregister();
  162. // delete this last
  163. delete static_cast<ServiceManager *>(serviceManager);
  164. serviceManager = 0;
  165. Wasabi::loaded = false;
  166. }
  167. }
  168. // other people's services that we might be interested in
  169. api_tagz *WINAMP5_API_TAGZ = 0;
  170. void Wasabi_FindSystemServices()
  171. {
  172. waServiceFactory *sf;
  173. sf = WASABI_API_SVC->service_getServiceByGuid(tagzGUID);
  174. if (sf)
  175. WINAMP5_API_TAGZ = (api_tagz *)sf->getInterface();
  176. sf = WASABI_API_SVC->service_getServiceByGuid(api_playlistmanagerGUID);
  177. if (sf)
  178. AGAVE_API_PLAYLISTMANAGER = (api_playlistmanager *)sf->getInterface();
  179. sf = WASABI_API_SVC->service_getServiceByGuid(DownloadManagerGUID);
  180. if (sf)
  181. WAC_API_DOWNLOADMANAGER = (api_downloadManager *)sf->getInterface();
  182. sf = WASABI_API_SVC->service_getServiceByGuid(amgSucksGUID);
  183. if (sf)
  184. AGAVE_API_AMGSUCKS = (api_amgsucks *)sf->getInterface();
  185. sf = WASABI_API_SVC->service_getServiceByGuid(api_playlistsGUID);
  186. if (sf)
  187. AGAVE_API_PLAYLISTS = (api_playlists *)sf->getInterface();
  188. sf = WASABI_API_SVC->service_getServiceByGuid(albumArtGUID);
  189. if (sf)
  190. AGAVE_API_ALBUMART = (api_albumart *)sf->getInterface();
  191. }
  192. void Wasabi_ForgetSystemServices()
  193. {
  194. waServiceFactory *sf;
  195. if (WINAMP5_API_TAGZ)
  196. {
  197. sf = WASABI_API_SVC->service_getServiceByGuid(tagzGUID);
  198. if (sf)
  199. sf->releaseInterface(WINAMP5_API_TAGZ);
  200. WINAMP5_API_TAGZ = 0;
  201. }
  202. if (AGAVE_API_PLAYLISTMANAGER)
  203. {
  204. sf = WASABI_API_SVC->service_getServiceByGuid(api_playlistmanagerGUID);
  205. if (sf)
  206. sf->releaseInterface(AGAVE_API_PLAYLISTMANAGER);
  207. AGAVE_API_PLAYLISTMANAGER = 0;
  208. }
  209. if (WAC_API_DOWNLOADMANAGER)
  210. {
  211. sf = WASABI_API_SVC->service_getServiceByGuid(DownloadManagerGUID);
  212. if (sf)
  213. sf->releaseInterface(WAC_API_DOWNLOADMANAGER);
  214. WAC_API_DOWNLOADMANAGER = 0;
  215. }
  216. if (WASABI_API_SKIN)
  217. {
  218. sf = WASABI_API_SVC->service_getServiceByGuid(skinApiServiceGuid);
  219. if (sf)
  220. sf->releaseInterface(WASABI_API_SKIN);
  221. WASABI_API_SKIN = 0;
  222. }
  223. if (AGAVE_API_AMGSUCKS)
  224. {
  225. sf = WASABI_API_SVC->service_getServiceByGuid(amgSucksGUID);
  226. if (sf)
  227. sf->releaseInterface(AGAVE_API_AMGSUCKS);
  228. AGAVE_API_AMGSUCKS = 0;
  229. }
  230. if (AGAVE_API_PLAYLISTS)
  231. {
  232. sf = WASABI_API_SVC->service_getServiceByGuid(api_playlistsGUID);
  233. if (sf)
  234. sf->releaseInterface(AGAVE_API_PLAYLISTS);
  235. AGAVE_API_PLAYLISTS = 0;
  236. }
  237. if (AGAVE_API_ALBUMART)
  238. {
  239. sf = WASABI_API_SVC->service_getServiceByGuid(albumArtGUID);
  240. if (sf)
  241. sf->releaseInterface(AGAVE_API_ALBUMART);
  242. AGAVE_API_ALBUMART = 0;
  243. }
  244. }