1
0

ObjectFactory.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "service/ifc_servicefactory.h"
  3. #include "ReferenceCounted.h"
  4. /*
  5. ====== Usage ======
  6. disp_t: your Dispatchable base class
  7. implt_t: your implementation class
  8. ObjectFactory<disp_t, impl_t> myFactory;
  9. impl_t myImplementation;
  10. //....
  11. //during service registration
  12. myFactory.Register(WASABI2_API_SVC);
  13. //during service deregistration
  14. myFactory.Deregister(WASABI2_API_SVC);
  15. ==== Class requirements ====
  16. your base or implementation class requires the following three static methods
  17. static FOURCC getServiceType(); // return your type (e.g. WaSvc::OBJECT)... might already be defined in the dispatchable base class
  18. static const char *getServiceName(); // return your service name
  19. static GUID getServiceGuid(); // return your service GUID
  20. */
  21. template <class impl_t, class disp_t>
  22. class CountableObjectFactory : public ifc_serviceFactory
  23. {
  24. public:
  25. CountableObjectFactory()
  26. {
  27. }
  28. ~CountableObjectFactory()
  29. {
  30. }
  31. void Register(api_service *serviceManager)
  32. {
  33. serviceManager->Register(this);
  34. }
  35. void Deregister(api_service *serviceManager)
  36. {
  37. serviceManager->Unregister(this);
  38. }
  39. private:
  40. GUID WASABICALL ServiceFactory_GetServiceType() { return impl_t::GetServiceType(); }
  41. nx_string_t WASABICALL ServiceFactory_GetServiceName() { return impl_t::GetServiceName(); }
  42. GUID WASABICALL ServiceFactory_GetGUID() { return impl_t::GetServiceGUID(); } // GUID per service factory, can be INVALID_GUID
  43. void *WASABICALL ServiceFactory_GetInterface() { return static_cast<disp_t *>(new ReferenceCounted<impl_t>); }
  44. int WASABICALL ServiceFactory_ServiceNotify(int msg, intptr_t param1 = 0, intptr_t param2 = 0) { return 0; }
  45. };