deviceManager.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef _NULLSOFT_WINAMP_DEVICES_DEVICE_MANAGER_HEADER
  2. #define _NULLSOFT_WINAMP_DEVICES_DEVICE_MANAGER_HEADER
  3. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  4. #pragma once
  5. #endif
  6. #include "./api_devicemanager.h"
  7. #include "./deviceObjectStore.h"
  8. #include "./discoveryMonitor.h"
  9. #include <vector>
  10. class DeviceManager : public api_devicemanager
  11. {
  12. protected:
  13. DeviceManager();
  14. ~DeviceManager();
  15. public:
  16. static HRESULT CreateInstance(DeviceManager **instance);
  17. public:
  18. /* Dispatchable */
  19. size_t AddRef();
  20. size_t Release();
  21. int QueryInterface(GUID interface_guid, void **object);
  22. /* api_devicemanager */
  23. size_t TypeRegister(ifc_devicetype **types, size_t count);
  24. size_t TypeRegisterIndirect(const char **names, size_t count, DeviceTypeCreator callback, void *user);
  25. HRESULT TypeUnregister(const char *name);
  26. HRESULT TypeFind(const char *name, ifc_devicetype **type);
  27. HRESULT TypeEnumerate(ifc_deviceobjectenum **enumerator);
  28. size_t ConnectionRegister(ifc_deviceconnection **connections, size_t count);
  29. size_t ConnectionRegisterIndirect(const char **names, size_t count, DeviceConnectionCreator callback, void *user);
  30. HRESULT ConnectionUnregister(const char *name);
  31. HRESULT ConnectionFind(const char *name, ifc_deviceconnection **connection);
  32. HRESULT ConnectionEnumerate(ifc_deviceobjectenum **enumerator);
  33. size_t CommandRegister(ifc_devicecommand **commands, size_t count);
  34. size_t CommandRegisterIndirect(const char **names, size_t count, DeviceCommandCreator callback, void *user);
  35. HRESULT CommandUnregister(const char *name);
  36. HRESULT CommandFind(const char *name, ifc_devicecommand **command);
  37. HRESULT CommandEnumerate(ifc_deviceobjectenum **enumerator);
  38. size_t DeviceRegister(ifc_device **devices, size_t count);
  39. HRESULT DeviceUnregister(const char *name);
  40. HRESULT DeviceFind(const char *name, ifc_device **device);
  41. HRESULT DeviceEnumerate(ifc_deviceobjectenum **enumerator);
  42. HRESULT IsDiscoveryActive();
  43. HRESULT BeginDiscovery();
  44. HRESULT CancelDiscovery();
  45. HRESULT RegisterProvider(ifc_deviceprovider *provider);
  46. HRESULT UnregisterProvider(ifc_deviceprovider *provider);
  47. HRESULT SetProviderActive(ifc_deviceprovider *provider, BOOL activeState);
  48. HRESULT Advise(ifc_devicemanagerevent *handler);
  49. HRESULT Unadvise(ifc_devicemanagerevent *handler);
  50. HRESULT CreateDeviceEventManager(ifc_deviceeventmanager **eventManager);
  51. HRESULT CreateSupportedCommandStore(ifc_devicesupportedcommandstore **store);
  52. HRESULT CreateSupportedCommandEnum(ifc_devicesupportedcommand **commands, size_t count, ifc_devicesupportedcommandenum **enumerator);
  53. HRESULT CreateIconStore(ifc_deviceiconstore **store);
  54. HRESULT CreateType(const char *name, ifc_devicetype **type);
  55. HRESULT CreateCommand(const char *name, ifc_devicecommand **command);
  56. HRESULT CreateConnection(const char *name, ifc_deviceconnection **connection);
  57. protected:
  58. void EventTypeAdded(ifc_devicetype *type);
  59. void EventTypeRemoved(ifc_devicetype *type);
  60. void EventConnectionAdded(ifc_deviceconnection *connection);
  61. void EventConnectionRemoved(ifc_deviceconnection *connection);
  62. void EventCommandAdded(ifc_devicecommand *command);
  63. void EventCommandRemoved(ifc_devicecommand *command);
  64. void EventDeviceAdded(ifc_device *device);
  65. void EventDeviceRemoved(ifc_device *device);
  66. void EventDiscoveryStarted();
  67. void EventDiscoveryFinished();
  68. protected:
  69. static void ObjectAddedCallback(DeviceObjectStore *store, ifc_deviceobject *object, void *userData);
  70. static void ObjectRemovedCallback(DeviceObjectStore *store, ifc_deviceobject *object, void *userData);
  71. protected:
  72. typedef std::vector<ifc_devicemanagerevent*> EventList;
  73. typedef std::vector<ifc_deviceprovider*> ProviderList;
  74. protected:
  75. size_t ref;
  76. DeviceObjectStore typeStore;
  77. DeviceObjectStore connectionStore;
  78. DeviceObjectStore commandStore;
  79. DeviceObjectStore deviceStore;
  80. CRITICAL_SECTION eventLock;
  81. EventList eventList;
  82. CRITICAL_SECTION providerLock;
  83. ProviderList providerList;
  84. DiscoveryMonitor discoveryMonitor;
  85. protected:
  86. RECVS_DISPATCH;
  87. };
  88. #endif // _NULLSOFT_WINAMP_DEVICES_DEVICE_MANAGER_HEADER