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
|
#pragma once
#include "../nu/AutoLock.h"
#include <vector>
#include "../Components/wac_downloadManager/wac_downloadManager_api.h"
extern "C" HANDLE DuplicateCurrentThread();
namespace JSAPI2
{
template <class API> struct CallbackInfo
{
CallbackInfo()
{
api = 0;
threadId = 0;
threadHandle = 0;
}
CallbackInfo(API *me)
{
api = me;
threadId = GetCurrentThreadId();
threadHandle = DuplicateCurrentThread();
}
~CallbackInfo()
{
CloseHandle(threadHandle);
threadHandle = 0;
}
API *api;
DWORD threadId;
HANDLE threadHandle;
};
class TransportAPI;
class MediaCoreAPI;
class AsyncDownloaderAPI;
class CallbackManager
{
public:
CallbackManager();
public:
/** stuff for Winamp to call to trigger callbacks
** these are primarily responsible for getting over to the correct thread
** to keep that particular logic out of the various functions
*/
void OnStop(int position, int is_full_stop);
void OnPlay(const wchar_t *filename);
void OnPause(bool pause_state);
/** Stuff that's OK to call on any thread
*/
bool OverrideMetadata(const wchar_t *filename, const wchar_t *tag, wchar_t *out, size_t outCch);
/** stuff for Winamp to call to trigger callbacks
** these are primarily responsible for getting over to the correct thread
** to keep that particular logic out of the various functions
*/
void OnInit(const wchar_t *url, const wchar_t *onlinesvcId);
void OnConnect(const wchar_t *url, const wchar_t *onlinesvcId);
void OnData(const wchar_t *url, size_t downloadedlen, size_t totallen, const wchar_t *onlinesvcId);
void OnCancel(const wchar_t *url, const wchar_t *onlinesvcId);
void OnError(const wchar_t *url, int error, const wchar_t *onlinesvcId);
void OnFinish(const wchar_t *url, const wchar_t *destfilename, const wchar_t *onlinesvcId);
public:
/* stuff for other JSAPI2 classes to call */
void Register(JSAPI2::TransportAPI *me);
void Deregister(JSAPI2::TransportAPI *me);
void Register(JSAPI2::MediaCoreAPI *me);
void Deregister(JSAPI2::MediaCoreAPI *me);
void Register(JSAPI2::AsyncDownloaderAPI *me);
void Deregister(JSAPI2::AsyncDownloaderAPI *me);
private:
/* Transport API callbacks */
typedef CallbackInfo<JSAPI2::TransportAPI> TransportCallback;
typedef std::vector<TransportCallback*> TransportsList;
TransportsList transports;
typedef std::vector<MediaCoreAPI*> MediaCoreList;
MediaCoreList mediaCores;
typedef CallbackInfo<JSAPI2::AsyncDownloaderAPI> AsyncDownloaderCallback;
typedef std::vector<AsyncDownloaderCallback*> AsyncDownloadersList;
AsyncDownloadersList asyncDownloaders;
Nullsoft::Utility::LockGuard callbackGuard;
};
extern CallbackManager callbackManager;
}
|