api_service.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #ifndef _API_SERVICE_H
  3. #define _API_SERVICE_H
  4. #include "../foundation/dispatch.h"
  5. #include "../foundation/types.h"
  6. #include "../foundation/guid.h"
  7. #include "../foundation/error.h"
  8. #include "../service/ifc_servicefactory.h"
  9. // ----------------------------------------------------------------------------
  10. // {6DD93387-6636-4479-B982-9FF5B91CF4B4}
  11. static const GUID service_api_service_guid =
  12. { 0x6dd93387, 0x6636, 0x4479, { 0xb9, 0x82, 0x9f, 0xf5, 0xb9, 0x1c, 0xf4, 0xb4 } };
  13. class NOVTABLE api_service : public Wasabi2::Dispatchable
  14. {
  15. protected:
  16. api_service() : Dispatchable(DISPATCHABLE_VERSION) {}
  17. ~api_service() {}
  18. public:
  19. static GUID GetServiceGUID() { return service_api_service_guid; }
  20. int Register(ifc_serviceFactory *svc) { return Service_Register(svc); }
  21. int Unregister(ifc_serviceFactory *svc) { return Service_Unregister(svc); }
  22. size_t GetServiceCount(GUID svc_type) { return Service_GetServiceCount(svc_type); }
  23. ifc_serviceFactory *EnumService(GUID svc_type, size_t n) { return Service_EnumService(svc_type, n); }
  24. ifc_serviceFactory *EnumService(size_t n) { return Service_EnumService(n); }
  25. ifc_serviceFactory *GetServiceByGUID(GUID guid) { return Service_GetServiceByGUID(guid); }
  26. /* called by a component when it returns NErr_TryAgain from one of the quit-phase functions */
  27. void ComponentDone() { Service_ComponentDone(); }
  28. template <class _t>
  29. int GetService(_t **out_service)
  30. {
  31. ifc_serviceFactory *sf = Service_GetServiceByGUID(_t::GetServiceGUID());
  32. if (!sf)
  33. return NErr_ServiceUnavailable;
  34. _t *service = reinterpret_cast<_t *>(sf->GetInterface());
  35. if (!service)
  36. return NErr_FailedCreate;
  37. *out_service = service;
  38. return NErr_Success;
  39. }
  40. enum
  41. {
  42. DISPATCHABLE_VERSION,
  43. };
  44. protected:
  45. virtual int WASABICALL Service_Register(ifc_serviceFactory *svc)=0;
  46. virtual int WASABICALL Service_Unregister(ifc_serviceFactory *svc)=0;
  47. virtual size_t WASABICALL Service_GetServiceCount(GUID svc_type)=0;
  48. virtual ifc_serviceFactory * WASABICALL Service_EnumService(GUID svc_type, size_t n)=0;
  49. virtual ifc_serviceFactory * WASABICALL Service_EnumService(size_t n)=0;
  50. virtual ifc_serviceFactory * WASABICALL Service_GetServiceByGUID(GUID guid)=0;
  51. virtual void WASABICALL Service_ComponentDone()=0;
  52. };
  53. #endif // !_API_SERVICE_H