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