diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/nu/factoryt.h | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/nu/factoryt.h')
-rw-r--r-- | Src/nu/factoryt.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Src/nu/factoryt.h b/Src/nu/factoryt.h new file mode 100644 index 00000000..1f6f47f3 --- /dev/null +++ b/Src/nu/factoryt.h @@ -0,0 +1,77 @@ +#pragma once + +#include <api/service/waservicefactoryi.h> +#include <api/service/services.h> + +/* +====== Usage ====== +disp_t: your Dispatchable base class +implt_t: your implementation class + +ServiceFactoryT<disp_t, impl_t> myFactory; +impl_t myImplementation; + +//.... + +//during service registration +myFactory.Register(WASABI_API_SVC); + +//during service deregistration +myFactory.Deregister(WASABI_API_SVC); + +==== Class requirements ==== +your base or implementation class requires the following three static methods +static FOURCC getServiceType(); // return your type (e.g. WaSvc::UNIQUE)... might already be defined in the dispatchable base class +static const char *getServiceName(); // return your service name +static GUID getServiceGuid(); // return your service GUID +must implementation a constructor that requires no parameters +*/ + +template <class disp_t, class impl_t> +class ServiceFactoryT : public waServiceFactory +{ +public: + ServiceFactoryT() + { + } + + ~ServiceFactoryT() + { + } + + void Register(api_service *serviceManager) + { + serviceManager->service_register(this); + } + + void Deregister(api_service *serviceManager) + { + serviceManager->service_deregister(this); + } + +private: + FOURCC svc_serviceType() { return impl_t::getServiceType(); } + const char *svc_getServiceName() { return impl_t::getServiceName(); } + GUID svc_getGuid() { return impl_t::getServiceGuid(); } // GUID per service factory, can be INVALID_GUID + void *svc_getInterface(int global_lock = TRUE) { return static_cast<disp_t *>(new impl_t); } + int svc_supportNonLockingGetInterface() { return 1; } + int svc_releaseInterface(void *ifc) { disp_t *disp = static_cast<disp_t *>(ifc); impl_t *impl = static_cast<impl_t *>(disp); delete impl; return 1; } + const wchar_t *svc_getTestString() { return 0; } + int svc_notify(int msg, int param1 = 0, int param2 = 0) { return 0; } + + +protected: +#define CBCLASS ServiceFactoryT<disp_t, impl_t> + START_DISPATCH_INLINE; + CB(WASERVICEFACTORY_GETSERVICETYPE, svc_serviceType); + CB(WASERVICEFACTORY_GETSERVICENAME, svc_getServiceName); + CB(WASERVICEFACTORY_GETGUID, svc_getGuid); + CB(WASERVICEFACTORY_GETINTERFACE, svc_getInterface); + CB(WASERVICEFACTORY_SUPPORTNONLOCKINGGETINTERFACE, svc_supportNonLockingGetInterface); + CB(WASERVICEFACTORY_RELEASEINTERFACE, svc_releaseInterface); + CB(WASERVICEFACTORY_GETTESTSTRING, svc_getTestString); + CB(WASERVICEFACTORY_SERVICENOTIFY, svc_notify); + END_DISPATCH; +#undef CBCLASS +}; + |