123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #pragma once
- #include "service/ifc_servicefactory.h"
- class WasabiServiceFactory
- {
- public:
- virtual ~WasabiServiceFactory() {}
- virtual void Register(api_service *serviceManager)=0;
- virtual void Deregister(api_service *serviceManager)=0;
- };
- template <class impl_t, class disp_t>
- class SingletonServiceFactory : public ifc_serviceFactory
- {
- public:
- SingletonServiceFactory() : impl(0)
- {
- }
- ~SingletonServiceFactory()
- {
- }
- void Register(api_service *serviceManager, impl_t *new_impl)
- {
- impl=new_impl;
- serviceManager->Register(this);
- }
- void Deregister(api_service *serviceManager)
- {
- if (impl)
- {
- serviceManager->Unregister(this);
- impl=0;
- }
- }
- 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(); }
- void *WASABICALL ServiceFactory_GetInterface() { return static_cast<disp_t *>(impl); }
- int WASABICALL ServiceFactory_ServiceNotify(int msg, intptr_t param1 = 0, intptr_t param2 = 0) { return 0; }
- private:
- impl_t *impl;
- };
- template <class impl_t, class disp_t>
- class SingletonService : public ifc_serviceFactory, public WasabiServiceFactory
- {
- public:
- SingletonService()
- {
- }
- ~SingletonService()
- {
- }
- 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(); }
- void *WASABICALL ServiceFactory_GetInterface() { return static_cast<disp_t *>(&impl); }
- int WASABICALL ServiceFactory_ServiceNotify(int msg, intptr_t param1 = 0, intptr_t param2 = 0) { return 0; }
- private:
- impl_t impl;
- };
|