1
0

ServiceManager.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include "foundation/guid.h"
  3. #include "service/api_service.h"
  4. #include "nu/AutoLock.h"
  5. #include "foundation/guid.h"
  6. #include <vector>
  7. #include <map>
  8. #include "service/ifc_servicefactory.h"
  9. #include "component/ifc_component_sync.h"
  10. #ifdef _WIN32
  11. #include <Windows.h>
  12. #else
  13. #include <semaphore.h>
  14. #endif
  15. class ServiceManager : public api_service, public ifc_component_sync
  16. {
  17. public:
  18. ServiceManager();
  19. ~ServiceManager();
  20. int WASABICALL Dispatchable_QueryInterface(GUID interface_guid, void **object);
  21. int WASABICALL Service_Register(ifc_serviceFactory *svc);
  22. int WASABICALL Service_Unregister(ifc_serviceFactory *svc);
  23. size_t WASABICALL Service_GetServiceCount(GUID svc_type);
  24. ifc_serviceFactory *WASABICALL Service_EnumService(GUID svc_type, size_t n);
  25. ifc_serviceFactory *WASABICALL Service_EnumService(size_t n);
  26. ifc_serviceFactory *WASABICALL Service_GetServiceByGUID(GUID guid);
  27. void WASABICALL Service_ComponentDone();
  28. private:
  29. int WASABICALL ComponentSync_Wait(size_t count);
  30. int GetServiceIndex(GUID key);
  31. private:
  32. nu::LockGuard serviceGuard;
  33. typedef std::map<GUID, ifc_serviceFactory*> ServiceMap;
  34. ServiceMap services;
  35. std::vector<GUID> services_indexer;
  36. typedef std::vector<ifc_serviceFactory*> ServiceList;
  37. std::map<GUID, ServiceList*> services_by_type;
  38. #ifdef _WIN32
  39. HANDLE component_wait;
  40. #else
  41. sem_t component_wait;
  42. #endif
  43. };
  44. extern ServiceManager service_manager;