aboutsummaryrefslogtreecommitdiff
path: root/Src/playlist/main.cpp
blob: 4d7f9fbd18264341c6c0b92352a7ad4570c14a16 (plain) (blame)
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
#include "api__playlist.h"
#include "main.h"

#include "factory_Handler.h"
#include "factory_playlistmanager.h"
#include "factory_playlists.h"
#include "../Winamp/api_random.h"
#include "Playlists.h"
#include "plstring.h"
#include "ScriptObjectFactory.h"
#include "../nu/ServiceWatcher.h"
#include "JSAPI2_Creator.h"

extern Playlists playlists;
int (*warand)(void) = 0;

M3UHandlerFactory       m3uHandlerFactory;
PLSHandlerFactory       plsHandlerFactory;
B4SHandlerFactory       b4sHandlerFactory;
PlaylistManagerFactory  playlistManagerFactory;
PlaylistsFactory        playlistsFactory;
ScriptObjectFactory     scriptObjectFactory;
JSAPI2Factory           jsapi2Factory;
ServiceWatcher          serviceWatcher;
PlaylistComponent       playlistComponent;

api_service            *WASABI_API_SVC            = 0;
api_application        *WASABI_API_APP            = 0;
api_config             *AGAVE_API_CONFIG          = 0;
api_syscb              *WASABI_API_SYSCB          = 0;
api_maki               *WASABI_API_MAKI           = 0;
JSAPI2::api_security   *AGAVE_API_JSAPI2_SECURITY = 0;
api_stats              *AGAVE_API_STATS           = 0;

// wasabi based services for localisation support
api_language *WASABI_API_LNG = 0;
HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;

template <class api_t>
api_t *GetService( GUID serviceGUID )
{
	waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid( serviceGUID );
	if ( sf )
		return (api_t *)sf->getInterface();
	else
		return 0;

}

inline void ReleaseService( GUID serviceGUID, void *service )
{
	if ( service )
	{
		waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid( serviceGUID );
		if ( sf )
			sf->releaseInterface( service );
	}
}

void PlaylistComponent::RegisterServices( api_service *service )
{
	WASABI_API_SVC = service;
	
	warand = QuickService<api_random>( randomApiGUID )->GetFunction();

	WASABI_API_APP            = GetService<api_application>( applicationApiServiceGuid );
	WASABI_API_SYSCB          = GetService<api_syscb>( syscbApiServiceGuid );
	AGAVE_API_CONFIG          = GetService<api_config>( AgaveConfigGUID );
	AGAVE_API_JSAPI2_SECURITY = GetService<JSAPI2::api_security>( JSAPI2::api_securityGUID );
	AGAVE_API_STATS           = GetService<api_stats>( AnonymousStatsGUID );

	serviceWatcher.WatchWith( WASABI_API_SVC );
	serviceWatcher.WatchFor( &WASABI_API_MAKI, makiApiServiceGuid );

	// need to get WASABI_API_APP first
	plstring_init();

	WASABI_API_SVC->service_register( &m3uHandlerFactory );
	WASABI_API_SVC->service_register( &plsHandlerFactory );
	WASABI_API_SVC->service_register( &b4sHandlerFactory );
	WASABI_API_SVC->service_register( &playlistManagerFactory );
	WASABI_API_SVC->service_register( &playlistsFactory );
	WASABI_API_SVC->service_register( &scriptObjectFactory );
	WASABI_API_SVC->service_register( &jsapi2Factory );

	WASABI_API_LNG = GetService<api_language>( languageApiGUID );
	// need to have this initialised before we try to do anything with localisation features
	WASABI_API_START_LANG( hModule, playlistLangGUID );

	// register for service callbacks in case any of these don't exist yet
	WASABI_API_SYSCB->syscb_registerCallback( &serviceWatcher );
}

int PlaylistComponent::RegisterServicesSafeModeOk()
{
	return 1;
}

void PlaylistComponent::DeregisterServices( api_service *service )
{
	playlists.Flush();

	service->service_deregister( &playlistsFactory );
	service->service_deregister( &playlistManagerFactory );
	service->service_deregister( &m3uHandlerFactory );
	service->service_deregister( &plsHandlerFactory );
	service->service_deregister( &b4sHandlerFactory );
	service->service_deregister( &scriptObjectFactory );
	service->service_deregister( &jsapi2Factory );

	serviceWatcher.StopWatching();
	serviceWatcher.Clear();

	ReleaseService( makiApiServiceGuid,        WASABI_API_MAKI );
	ReleaseService( applicationApiServiceGuid, WASABI_API_APP );
	ReleaseService( AgaveConfigGUID,           AGAVE_API_CONFIG );
	ReleaseService( syscbApiServiceGuid,       WASABI_API_SYSCB );
	ReleaseService( languageApiGUID,           WASABI_API_LNG );
	ReleaseService( JSAPI2::api_securityGUID,  AGAVE_API_JSAPI2_SECURITY );
	ReleaseService( AnonymousStatsGUID,        AGAVE_API_STATS );
}

extern "C" __declspec(dllexport) ifc_wa5component *GetWinamp5SystemComponent()
{
	return &playlistComponent;
}

#define CBCLASS PlaylistComponent
START_DISPATCH;
VCB( API_WA5COMPONENT_REGISTERSERVICES,           RegisterServices )
CB(  API_WA5COMPONENT_REGISTERSERVICES_SAFE_MODE, RegisterServicesSafeModeOk )
VCB( API_WA5COMPONENT_DEREEGISTERSERVICES,        DeregisterServices )
END_DISPATCH;
#undef CBCLASS