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/Wasabi/api/service/waservicefactorybase.h | 76 +++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Src/Wasabi/api/service/waservicefactorybase.h (limited to 'Src/Wasabi/api/service/waservicefactorybase.h') diff --git a/Src/Wasabi/api/service/waservicefactorybase.h b/Src/Wasabi/api/service/waservicefactorybase.h new file mode 100644 index 00000000..19c9c56d --- /dev/null +++ b/Src/Wasabi/api/service/waservicefactorybase.h @@ -0,0 +1,76 @@ +#ifndef __WASERVICEFACTORYBASE_IMPL_H +#define __WASERVICEFACTORYBASE_IMPL_H + +/**/ +class CfgItem; +/*?>*/ + +#include "waservicefactoryi.h" + +template +class NOVTABLE waServiceFactoryBaseX : public waServiceFactoryI { +public: + waServiceFactoryBaseX(GUID myGuid = INVALID_GUID) : guid(myGuid) {} + virtual FOURCC svc_serviceType()=0; + virtual const char *svc_getServiceName() { return SERVICE::getServiceName(); } + virtual GUID svc_getGuid() { return guid; } + virtual void *svc_getInterfaceAndLock() {// this is only for back compat + return getInterface(TRUE); + } + + virtual void *svc_getInterface(int global_lock)=0; + virtual int svc_releaseInterface(void *ptr)=0; + + virtual CfgItem *svc_getCfgInterface() { return NULL; } + virtual const wchar_t *svc_getTestString() { return NULL; } + + virtual int svc_notify(int msg, int param1 = 0, int param2 = 0) { return 0; } + +private: + GUID guid; +}; + +// if you derive from this, all you have to do is override the newService() +// and delService() methods... if all you need to do is instantiate a class +// and destroy it use the helper below (waServiceFactoryT) +template +class NOVTABLE waServiceFactoryBase : public waServiceFactoryBaseX { +public: + waServiceFactoryBase(GUID myGuid = INVALID_GUID) : waServiceFactoryBaseX(myGuid) {} + virtual FOURCC svc_serviceType() { return SERVICETYPE::getServiceType(); } + virtual void *svc_getInterface(int global_lock) { // new style, client optionally does the locking + SERVICETYPE *ret = newService(); + if (global_lock) WASABI_API_SVC->service_lock(this, ret); + return ret; + } + virtual int svc_releaseInterface(void *ptr) { + return delService(static_cast(static_cast(ptr))); + } +protected: + virtual SERVICETYPE *newService()=0; + virtual int delService(SERVICETYPE *service)=0; +}; + +// and this one just exposes a service pointer, without factory. note that +// SERVICETYPE and SERVICE do not have to be related (unlike waServiceFactoryBase +// who needs a relationship between the classes in releaseInterface) +template +class NOVTABLE waServiceBase : public waServiceFactoryBaseX { +public: + waServiceBase(GUID myGuid = INVALID_GUID) : waServiceFactoryBaseX(myGuid) {} + virtual FOURCC svc_serviceType() { return SERVICE::getServiceType(); } + virtual void *svc_getInterface(int global_lock) { // new style, client optionally does the locking + SERVICETYPE *ret = getService(); + if (global_lock) WASABI_API_SVC->service_lock(this, ret); + return ret; + } + virtual int svc_releaseInterface(void *ptr) { + return TRUE; + } +protected: + virtual SERVICETYPE *getService()=0; +}; + + + +#endif // __WASERVICEFACTORYBASE_IMPL_H -- cgit