1
0

eventRelay.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef _NULLSOFT_WINAMP_ML_DEVICES_EVENT_RELAY_HEADER
  2. #define _NULLSOFT_WINAMP_ML_DEVICES_EVENT_RELAY_HEADER
  3. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  4. #pragma once
  5. #endif
  6. #include <wtypes.h>
  7. typedef enum DeviceEvent
  8. {
  9. Event_DeviceAdded = 1,
  10. Event_DeviceRemoved = 2,
  11. Event_DeviceIconChanged = 3,
  12. Event_DeviceDisplayNameChanged = 4,
  13. Event_DeviceAttached = 5,
  14. Event_DeviceDetached = 6,
  15. Event_DeviceHidden = 7,
  16. Event_DeviceShown = 8,
  17. Event_DeviceTotalSpaceChanged = 9,
  18. Event_DeviceUsedSpaceChanged = 10,
  19. Event_DeviceCommandChanged = 11,
  20. Event_DeviceActivityStarted = 12,
  21. Event_DeviceActivityFinished = 13,
  22. Event_DeviceActivityChanged = 14,
  23. Event_DeviceModelChanged = 15,
  24. Event_DeviceStatusChanged = 16,
  25. } DeviceEvent;
  26. typedef enum DeviceTypeEvent
  27. {
  28. Event_TypeRegistered = 1,
  29. Event_TypeUnregistered = 2,
  30. } DeviceTypeEvent;
  31. typedef enum DeviceConnectionEvent
  32. {
  33. Event_ConnectionRegistered = 1,
  34. Event_ConnectionUnregistered = 2,
  35. } DeviceConnectionEvent;
  36. typedef enum DeviceCommandEvent
  37. {
  38. Event_CommandRegistered = 1,
  39. Event_CommandUnregistered = 2,
  40. } DeviceCommandEvent;
  41. typedef enum DeviceDiscoveryEvent
  42. {
  43. Event_DiscoveryStarted = 1,
  44. Event_DiscoveryFinished = 2,
  45. } DeviceDiscoveryEvent;
  46. typedef void (*DeviceEventCb)(ifc_device *device, DeviceEvent eventId, void *user);
  47. typedef void (*DeviceTypeEventCb)(ifc_devicetype *type, DeviceTypeEvent eventId, void *user);
  48. typedef void (*DeviceConnectionEventCb)(ifc_deviceconnection *connection, DeviceConnectionEvent eventId, void *user);
  49. typedef void (*DeviceCommandEventCb)(ifc_devicecommand *command, DeviceCommandEvent eventId, void *user);
  50. typedef void (*DeviceDiscoveryEventCb)(api_devicemanager *manager, DeviceDiscoveryEvent eventId, void *user);
  51. typedef struct DeviceEventCallbacks
  52. {
  53. DeviceEventCb deviceCb;
  54. DeviceTypeEventCb typeCb;
  55. DeviceConnectionEventCb connectionCb;
  56. DeviceCommandEventCb commandCb;
  57. DeviceDiscoveryEventCb discoveryCb;
  58. } DeviceEventCallbacks;
  59. HWND
  60. EventRelay_CreateWindow();
  61. #define EVENTRELAY_WM_FIRST (WM_USER + 10)
  62. #define EVENTRELAY_WM_REGISTER_HANDLER (EVENTRELAY_WM_FIRST + 0)
  63. #define EVENTRELAY_REGISTER_HANDLER(/*HWND*/ _hwnd, /*DeviceEventCallbacks*/ _handler, /*void* */ _user)\
  64. ((size_t)SendMessageW((_hwnd), EVENTRELAY_WM_REGISTER_HANDLER, (WPARAM)(_user), (LPARAM)(_handler)))
  65. #define EVENTRELAY_WM_UNREGISTER_HANDLER (EVENTRELAY_WM_FIRST + 1)
  66. #define EVENTRELAY_UNREGISTER_HANDLER(/*HWND*/ _hwnd, /*size_t*/ _handlerCookie)\
  67. ((BOOL)SendMessageW((_hwnd), EVENTRELAY_WM_UNREGISTER_HANDLER, 0, (LPARAM)(_handlerCookie)))
  68. #define EVENTRELAY_WM_NOTIFY_DEVICE (EVENTRELAY_WM_FIRST + 2)
  69. #define EVENTRELAY_NOTIFY_DEVICE(/*HWND*/ _hwnd, /*ifc_device* */ _device, /*DeviceEvent*/ _eventId)\
  70. { ifc_device *_d = (_device); if (NULL != _d && NULL != (_hwnd)) { _d->AddRef(); \
  71. if (FALSE == ((BOOL)PostMessageW((_hwnd), EVENTRELAY_WM_NOTIFY_DEVICE,\
  72. (WPARAM)(_eventId), (LPARAM)(_d)))) { _d->Release(); }}}
  73. #define EVENTRELAY_WM_NOTIFY_DISCOVERY (EVENTRELAY_WM_FIRST + 3)
  74. #define EVENTRELAY_NOTIFY_DISCOVERY(/*HWND*/ _hwnd, /*api_devicemanager* */ _manager, /*DeviceDiscoveryEvent*/ _eventId)\
  75. { api_devicemanager *_m = (_manager); if (NULL != _m && NULL != (_hwnd)) { _m->AddRef(); \
  76. if (FALSE == ((BOOL)PostMessageW((_hwnd), EVENTRELAY_WM_NOTIFY_DISCOVERY,\
  77. (WPARAM)(_eventId), (LPARAM)(_m)))) { _m->Release(); }}}
  78. #define EVENTRELAY_WM_NOTIFY_TYPE (EVENTRELAY_WM_FIRST + 4)
  79. #define EVENTRELAY_NOTIFY_TYPE(/*HWND*/ _hwnd, /*ifc_devicetype* */ _type, /*DeviceTypeEvent*/ _eventId)\
  80. { ifc_devicetype *_t = (_type); if (NULL != _t && NULL != (_hwnd)) { _t->AddRef(); \
  81. if (FALSE == ((BOOL)PostMessageW((_hwnd), EVENTRELAY_WM_NOTIFY_TYPE,\
  82. (WPARAM)(_eventId), (LPARAM)(_t)))) { _t->Release(); }}}
  83. #define EVENTRELAY_WM_NOTIFY_CONNECTION (EVENTRELAY_WM_FIRST + 5)
  84. #define EVENTRELAY_NOTIFY_CONNECTION(/*HWND*/ _hwnd, /*ifc_deviceconnection* */ _connection, /*DeviceConnectionEvent*/ _eventId)\
  85. { ifc_deviceconnection *_c = (_connection); if (NULL != _c && NULL != (_hwnd)) { _c->AddRef(); \
  86. if (FALSE == ((BOOL)PostMessageW((_hwnd), EVENTRELAY_WM_NOTIFY_CONNECTION,\
  87. (WPARAM)(_eventId), (LPARAM)(_c)))) { _c->Release(); }}}
  88. #define EVENTRELAY_WM_NOTIFY_COMMAND (EVENTRELAY_WM_FIRST + 6)
  89. #define EVENTRELAY_NOTIFY_COMMAND(/*HWND*/ _hwnd, /*ifc_devicecommand* */ _command, /*DeviceCommandEvent*/ _eventId)\
  90. { ifc_devicecommand *_c = (_command); if (NULL != _c && NULL != (_hwnd)) { _c->AddRef(); \
  91. if (FALSE == ((BOOL)PostMessageW((_hwnd), EVENTRELAY_WM_NOTIFY_COMMAND,\
  92. (WPARAM)(_eventId), (LPARAM)(_c)))) { _c->Release(); }}}
  93. #define EVENTRELAY_WM_LAST EVENTRELAY_WM_NOTIFY_COMMAND
  94. #endif //_NULLSOFT_WINAMP_ML_DEVICES_EVENT_RELAY_HEADER