123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- #include "main.h"
- #include "./deviceManagerHandler.h"
- DeviceManagerHandler::DeviceManagerHandler()
- : ref(1), relayWindow(NULL)
- {
- }
- DeviceManagerHandler::~DeviceManagerHandler()
- {
- }
- HRESULT DeviceManagerHandler::CreateInstance(DeviceManagerHandler **instance)
- {
- if (NULL == instance)
- return E_POINTER;
- *instance = new DeviceManagerHandler();
- if (NULL == *instance)
- return E_OUTOFMEMORY;
- return S_OK;
- }
- size_t DeviceManagerHandler::AddRef()
- {
- return InterlockedIncrement((LONG*)&ref);
- }
- size_t DeviceManagerHandler::Release()
- {
- if (0 == ref)
- return ref;
-
- LONG r = InterlockedDecrement((LONG*)&ref);
- if (0 == r)
- delete(this);
-
- return r;
- }
- int DeviceManagerHandler::QueryInterface(GUID interface_guid, void **object)
- {
- if (NULL == object) return E_POINTER;
-
- if (IsEqualIID(interface_guid, IFC_DeviceManagerEvent))
- *object = static_cast<ifc_devicemanagerevent*>(this);
- else
- {
- *object = NULL;
- return E_NOINTERFACE;
- }
- if (NULL == *object)
- return E_UNEXPECTED;
- AddRef();
- return S_OK;
- }
- void DeviceManagerHandler::TypeAdded(api_devicemanager *manager, ifc_devicetype *type)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_TYPE(relayWindow, type, Event_TypeRegistered);
- }
- void DeviceManagerHandler::TypeRemoved(api_devicemanager *manager, ifc_devicetype *type)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_TYPE(relayWindow, type, Event_TypeUnregistered);
- }
- void DeviceManagerHandler::ConnectionAdded(api_devicemanager *manager, ifc_deviceconnection *connection)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_CONNECTION(relayWindow, connection, Event_ConnectionRegistered);
- }
- void DeviceManagerHandler::ConnectionRemoved(api_devicemanager *manager, ifc_deviceconnection *connection)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_CONNECTION(relayWindow, connection, Event_ConnectionUnregistered);
- }
- void DeviceManagerHandler::CommandAdded(api_devicemanager *manager, ifc_devicecommand *command)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_COMMAND(relayWindow, command, Event_CommandRegistered);
- }
- void DeviceManagerHandler::CommandRemoved(api_devicemanager *manager, ifc_devicecommand *command)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_COMMAND(relayWindow, command, Event_CommandUnregistered);
- }
- void DeviceManagerHandler::DeviceAdded(api_devicemanager *manager, ifc_device *device)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceAdded);
- }
- void DeviceManagerHandler::DeviceRemoved(api_devicemanager *manager, ifc_device *device)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceRemoved);
- }
- void DeviceManagerHandler::DiscoveryStarted(api_devicemanager *manager)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_DISCOVERY(relayWindow, manager, Event_DiscoveryStarted);
- }
- void DeviceManagerHandler::DiscoveryFinished(api_devicemanager *manager)
- {
- if (NULL != relayWindow)
- EVENTRELAY_NOTIFY_DISCOVERY(relayWindow, manager, Event_DiscoveryFinished);
- }
- HRESULT DeviceManagerHandler::SetRelayWindow(HWND hwnd)
- {
- relayWindow = hwnd;
- return S_OK;
- }
- HRESULT DeviceManagerHandler::Advise(api_devicemanager *manager)
- {
- HRESULT hr;
-
- if (NULL == manager)
- return E_INVALIDARG;
- hr = manager->Advise(this);
- if (FAILED(hr))
- return hr;
-
- return hr;
- }
- HRESULT DeviceManagerHandler::Unadvise(api_devicemanager *manager)
- {
- HRESULT hr;
- if (NULL == manager)
- return E_INVALIDARG;
- hr = manager->Unadvise(this);
- if (FAILED(hr))
- return hr;
- return hr;
- }
- #define CBCLASS DeviceManagerHandler
- START_DISPATCH;
- CB(ADDREF, AddRef)
- CB(RELEASE, Release)
- CB(QUERYINTERFACE, QueryInterface)
- VCB(API_TYPEADDED, TypeAdded)
- VCB(API_TYPEREMOVED, TypeRemoved)
- VCB(API_CONNECTIONADDED, ConnectionAdded)
- VCB(API_CONNECTIONREMOVED, ConnectionRemoved)
- VCB(API_COMMANDADDED, CommandAdded)
- VCB(API_COMMANDREMOVED, CommandRemoved)
- VCB(API_DEVICEADDED, DeviceAdded)
- VCB(API_DEVICEREMOVED, DeviceRemoved)
- VCB(API_DISCOVERYSTARTED, DiscoveryStarted)
- VCB(API_DISCOVERYFINISHED, DiscoveryFinished)
- END_DISPATCH;
- #undef CBCLASS
|