From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/Winamp/JSAPI2_CallbackManager.h | 93 +++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Src/Winamp/JSAPI2_CallbackManager.h (limited to 'Src/Winamp/JSAPI2_CallbackManager.h') diff --git a/Src/Winamp/JSAPI2_CallbackManager.h b/Src/Winamp/JSAPI2_CallbackManager.h new file mode 100644 index 00000000..af6d6b12 --- /dev/null +++ b/Src/Winamp/JSAPI2_CallbackManager.h @@ -0,0 +1,93 @@ +#pragma once +#include "../nu/AutoLock.h" +#include +#include "../Components/wac_downloadManager/wac_downloadManager_api.h" + +extern "C" HANDLE DuplicateCurrentThread(); +namespace JSAPI2 +{ + template 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 TransportCallback; + typedef std::vector TransportsList; + TransportsList transports; + + typedef std::vector MediaCoreList; + MediaCoreList mediaCores; + + typedef CallbackInfo AsyncDownloaderCallback; + typedef std::vector AsyncDownloadersList; + AsyncDownloadersList asyncDownloaders; + + Nullsoft::Utility::LockGuard callbackGuard; + }; + + extern CallbackManager callbackManager; +} \ No newline at end of file -- cgit