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/replicant/nswasabi/ObjectFactory.h | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Src/replicant/nswasabi/ObjectFactory.h (limited to 'Src/replicant/nswasabi/ObjectFactory.h') diff --git a/Src/replicant/nswasabi/ObjectFactory.h b/Src/replicant/nswasabi/ObjectFactory.h new file mode 100644 index 00000000..55a99820 --- /dev/null +++ b/Src/replicant/nswasabi/ObjectFactory.h @@ -0,0 +1,57 @@ +#pragma once + +#include "service/ifc_servicefactory.h" +#include "ReferenceCounted.h" +/* +====== Usage ====== +disp_t: your Dispatchable base class +implt_t: your implementation class + +ObjectFactory myFactory; +impl_t myImplementation; + +//.... + +//during service registration +myFactory.Register(WASABI2_API_SVC); + +//during service deregistration +myFactory.Deregister(WASABI2_API_SVC); + +==== Class requirements ==== +your base or implementation class requires the following three static methods +static FOURCC getServiceType(); // return your type (e.g. WaSvc::OBJECT)... might already be defined in the dispatchable base class +static const char *getServiceName(); // return your service name +static GUID getServiceGuid(); // return your service GUID +*/ + +template +class CountableObjectFactory : public ifc_serviceFactory +{ +public: + CountableObjectFactory() + { + } + + ~CountableObjectFactory() + { + } + + void Register(api_service *serviceManager) + { + serviceManager->Register(this); + } + + void Deregister(api_service *serviceManager) + { + serviceManager->Unregister(this); + } + +private: + GUID WASABICALL ServiceFactory_GetServiceType() { return impl_t::GetServiceType(); } + nx_string_t WASABICALL ServiceFactory_GetServiceName() { return impl_t::GetServiceName(); } + GUID WASABICALL ServiceFactory_GetGUID() { return impl_t::GetServiceGUID(); } // GUID per service factory, can be INVALID_GUID + void *WASABICALL ServiceFactory_GetInterface() { return static_cast(new ReferenceCounted); } + int WASABICALL ServiceFactory_ServiceNotify(int msg, intptr_t param1 = 0, intptr_t param2 = 0) { return 0; } +}; + -- cgit