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/nu/factoryt.h | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Src/nu/factoryt.h (limited to 'Src/nu/factoryt.h') 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 +#include + +/* +====== Usage ====== +disp_t: your Dispatchable base class +implt_t: your implementation class + +ServiceFactoryT 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 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(new impl_t); } + int svc_supportNonLockingGetInterface() { return 1; } + int svc_releaseInterface(void *ifc) { disp_t *disp = static_cast(ifc); impl_t *impl = static_cast(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 + 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 +}; + -- cgit