2016-08-17 20:04:19 +00:00
|
|
|
#include "boo/inputdev/DeviceFinder.hpp"
|
|
|
|
|
|
|
|
#if _WIN32
|
|
|
|
#include <Dbt.h>
|
2017-05-08 19:09:10 +00:00
|
|
|
#include <hidclass.h>
|
|
|
|
#include <usbiodef.h>
|
2016-08-17 20:04:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
|
|
|
#if _WIN32
|
|
|
|
/* Windows-specific WM_DEVICECHANGED handler */
|
|
|
|
LRESULT DeviceFinder::winDevChangedHandler(WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
PDEV_BROADCAST_HDR dbh = (PDEV_BROADCAST_HDR)lParam;
|
|
|
|
PDEV_BROADCAST_DEVICEINTERFACE dbhi = (PDEV_BROADCAST_DEVICEINTERFACE)lParam;
|
|
|
|
DeviceFinder* finder = instance();
|
|
|
|
if (!finder)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (wParam == DBT_DEVICEARRIVAL)
|
|
|
|
{
|
|
|
|
if (dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
|
|
|
|
{
|
2017-05-08 19:09:10 +00:00
|
|
|
DeviceType type = DeviceType::None;
|
|
|
|
if (dbhi->dbcc_classguid == GUID_DEVINTERFACE_USB_DEVICE)
|
|
|
|
type = DeviceType::USB;
|
|
|
|
else if (dbhi->dbcc_classguid == GUID_DEVINTERFACE_HID)
|
|
|
|
type = DeviceType::HID;
|
|
|
|
|
|
|
|
if (type != DeviceType::None)
|
|
|
|
{
|
2016-08-17 20:04:19 +00:00
|
|
|
#ifdef UNICODE
|
2017-05-08 19:09:10 +00:00
|
|
|
char devPath[1024];
|
|
|
|
wcstombs(devPath, dbhi->dbcc_name, 1024);
|
|
|
|
finder->m_listener->_extDevConnect(devPath);
|
2016-08-17 20:04:19 +00:00
|
|
|
#else
|
2017-05-08 19:09:10 +00:00
|
|
|
finder->m_listener->_extDevConnect(dbhi->dbcc_name);
|
2016-08-17 20:04:19 +00:00
|
|
|
#endif
|
2017-05-08 19:09:10 +00:00
|
|
|
}
|
2016-08-17 20:04:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wParam == DBT_DEVICEREMOVECOMPLETE)
|
|
|
|
{
|
|
|
|
if (dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
|
|
|
|
{
|
2017-05-08 19:09:10 +00:00
|
|
|
DeviceType type = DeviceType::None;
|
|
|
|
if (dbhi->dbcc_classguid == GUID_DEVINTERFACE_USB_DEVICE)
|
|
|
|
type = DeviceType::USB;
|
|
|
|
else if (dbhi->dbcc_classguid == GUID_DEVINTERFACE_HID)
|
|
|
|
type = DeviceType::HID;
|
|
|
|
|
|
|
|
if (type != DeviceType::None)
|
|
|
|
{
|
2016-08-17 20:04:19 +00:00
|
|
|
#ifdef UNICODE
|
2017-05-08 19:09:10 +00:00
|
|
|
char devPath[1024];
|
|
|
|
wcstombs(devPath, dbhi->dbcc_name, 1024);
|
|
|
|
finder->m_listener->_extDevDisconnect(devPath);
|
2016-08-17 20:04:19 +00:00
|
|
|
#else
|
2017-05-08 19:09:10 +00:00
|
|
|
finder->m_listener->_extDevDisconnect(dbhi->dbcc_name);
|
2016-08-17 20:04:19 +00:00
|
|
|
#endif
|
2017-05-08 19:09:10 +00:00
|
|
|
}
|
2016-08-17 20:04:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|