1
0

ServiceWatcher.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <api/service/api_service.h>
  3. #include <api/syscb/callbacks/svccb.h>
  4. #include <map>
  5. #include <api/syscb/api_syscb.h>
  6. class ServiceWatcher : public SysCallback
  7. {
  8. public:
  9. ServiceWatcher() : serviceManager(0),systemCallbacks(0) {}
  10. ~ServiceWatcher();
  11. void WatchWith(api_service *_serviceApi);
  12. template <class T>
  13. void WatchFor(T **ptr, GUID watchGUID)
  14. {
  15. WatchForT((void **)ptr, watchGUID);
  16. }
  17. void StopWatching();
  18. void Clear();
  19. private:
  20. void WatchForT(void **ptr, GUID watchGUID);
  21. typedef std::map<GUID, void **> WatchList;
  22. WatchList watchList;
  23. FOURCC GetEventType() { return SysCallback::SERVICE; }
  24. int Notify(int msg, intptr_t param1, intptr_t param2);
  25. api_service *serviceManager;
  26. api_syscb *systemCallbacks;
  27. protected:
  28. RECVS_DISPATCH;
  29. };
  30. class ServiceWatcherSingle : public SysCallback
  31. {
  32. public:
  33. ServiceWatcherSingle() : serviceManager(0),systemCallbacks(0),service(0) {}
  34. virtual ~ServiceWatcherSingle();
  35. void WatchWith(api_service *_serviceApi);
  36. template <class T>
  37. void WatchFor(T **ptr, GUID watchGUID)
  38. {
  39. WatchForT((void **)ptr, watchGUID);
  40. }
  41. virtual void OnRegister() {}
  42. virtual void OnDeregister()=0;
  43. void StopWatching();
  44. private:
  45. void WatchForT(void **ptr, GUID watchGUID);
  46. FOURCC GetEventType() { return SysCallback::SERVICE; }
  47. int Notify(int msg, intptr_t param1, intptr_t param2);
  48. api_service *serviceManager;
  49. api_syscb *systemCallbacks;
  50. void **service;
  51. GUID serviceGUID;
  52. protected:
  53. RECVS_DISPATCH;
  54. };