diff options
author | Martin Ellis <malard@gmail.com> | 2011-06-12 14:43:07 +0100 |
---|---|---|
committer | Martin Ellis <malard@gmail.com> | 2011-06-12 15:43:23 +0100 |
commit | 72f177a91ea175c20ad96728ddeadf266cf11829 (patch) | |
tree | 4d2b4409d4ff685b14cfa869f930d1e85eff5a43 | |
parent | 467df194f38169949c1f71476757a1a0fb253a65 (diff) |
added: enumerate usb device list add tell KeymapLoader about each device added: when a usb device is activated or removed, tell KeymapLoader about it
-rw-r--r-- | xbmc/Application.cpp | 5 | ||||
-rw-r--r-- | xbmc/win32/WIN32USBScan.cpp | 74 | ||||
-rw-r--r-- | xbmc/windowing/windows/WinEventsWin32.cpp | 8 |
3 files changed, 77 insertions, 10 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 85bf328b65..47a141ed59 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -466,7 +466,6 @@ bool CApplication::Create() * can now be caught using c++ try catch */ win32_exception::install_handler(); - CWIN32USBScan(); #endif // only the InitDirectories* for the current platform should return true @@ -601,6 +600,10 @@ bool CApplication::Create() g_powerManager.Initialize(); +#ifdef _WIN32 + CWIN32USBScan(); +#endif + CLog::Log(LOGNOTICE, "load settings..."); g_guiSettings.Initialize(); // Initialize default Settings - don't move diff --git a/xbmc/win32/WIN32USBScan.cpp b/xbmc/win32/WIN32USBScan.cpp index 705149015d..c22a8dba91 100644 --- a/xbmc/win32/WIN32USBScan.cpp +++ b/xbmc/win32/WIN32USBScan.cpp @@ -1,17 +1,77 @@ #include <setupapi.h> #include "WIN32USBScan.h" +#include "input/KeymapLoader.h" static GUID USB_HID_GUID = { 0x4D1E55B2, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } }; CWIN32USBScan::CWIN32USBScan() { - HDEVINFO hDevInfo; - SP_DEVINFO_DATA DeviceInfoData; + HDEVINFO hDevHandle; + SP_DEVICE_INTERFACE_DATA deviceInterfaceData; + DWORD required = 0; + deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - hDevInfo = SetupDiGetClassDevs(&USB_HID_GUID, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); - for (DWORD i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++) - { + int nBufferSize = 0; + + SP_DEVINFO_DATA devInfoData; + devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); - } + DWORD MemberIndex = 0; + BOOL Result; + + hDevHandle = SetupDiGetClassDevs(&USB_HID_GUID, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + + if (hDevHandle == INVALID_HANDLE_VALUE) + return; + + bool bStart = false; + TCHAR *buffer = NULL; + PSP_DEVICE_INTERFACE_DETAIL_DATA devicedetailData; + do + { + Result = SetupDiEnumDeviceInfo(hDevHandle, MemberIndex, &devInfoData); + + if (Result) + Result = SetupDiEnumDeviceInterfaces(hDevHandle, 0, &USB_HID_GUID, MemberIndex, &deviceInterfaceData); + + if(!Result) + { + SetupDiDestroyDeviceInfoList(hDevHandle); + delete []buffer; + buffer = NULL; + return; + } + + MemberIndex++; + BOOL detailResult = false; + + if(!bStart) + { + // As per MSDN, Get the required buffer size. Call SetupDiGetDeviceInterfaceDetail with a + // NULL DeviceInterfaceDetailData pointer, a DeviceInterfaceDetailDataSize of zero, + // and a valid RequiredSize variable. In response to such a call, this function returns + // the required buffer size at RequiredSize and fails with GetLastError returning + // ERROR_INSUFFICIENT_BUFFER. + // Allocate an appropriately sized buffer and call the function again to get the interface details. + + SetupDiGetDeviceInterfaceDetail(hDevHandle, &deviceInterfaceData, NULL, 0, &required, NULL); + + buffer = new TCHAR[required]; + devicedetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA) buffer; + devicedetailData->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); + nBufferSize = required; + bStart = true; + } + + detailResult = SetupDiGetDeviceInterfaceDetail(hDevHandle, &deviceInterfaceData, devicedetailData, nBufferSize , &required, NULL); + + CStdString dbcc_name(devicedetailData->DevicePath); + dbcc_name = dbcc_name.Mid(dbcc_name.find_last_of('\\')+1, dbcc_name.find_last_of('#') - dbcc_name.find_last_of('\\')); + + CKeymapLoader().DeviceAdded(dbcc_name); + + if(!detailResult) + continue; + + } while(Result); }
\ No newline at end of file diff --git a/xbmc/windowing/windows/WinEventsWin32.cpp b/xbmc/windowing/windows/WinEventsWin32.cpp index d8b8fedf16..13647a230d 100644 --- a/xbmc/windowing/windows/WinEventsWin32.cpp +++ b/xbmc/windowing/windows/WinEventsWin32.cpp @@ -27,6 +27,7 @@ #include "Application.h" #include "input/XBMC_vkeys.h" #include "input/MouseStat.h" +#include "input/KeymapLoader.h" #include "storage/MediaManager.h" #include "windowing/WindowingFactory.h" #include <dbt.h> @@ -36,6 +37,7 @@ #include "guilib/GUIControl.h" // for EVENT_RESULT #include "powermanagement/windows/Win32PowerSyscall.h" #include "Shlobj.h" +#include "settings/Settings.h" #include "settings/AdvancedSettings.h" #ifdef _WIN32 @@ -649,13 +651,15 @@ LRESULT CALLBACK CWinEventsWin32::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, L break; case WM_DEVICECHANGE: PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam; + CStdString dbcc_name(b->dbcc_name); + dbcc_name = dbcc_name.Mid(dbcc_name.find_last_of('\\')+1, dbcc_name.find_last_of('#') - dbcc_name.find_last_of('\\')); switch (wParam) { case DBT_DEVICEARRIVAL: - CLog::Log(LOGDEBUG, "HID Device Arrived"); + CKeymapLoader().DeviceAdded(dbcc_name); break; case DBT_DEVICEREMOVECOMPLETE: - CLog::Log(LOGDEBUG, "HID Device Removed"); + CKeymapLoader().DeviceRemoved(dbcc_name); break; case DBT_DEVNODES_CHANGED: //CLog::Log(LOGDEBUG, "HID Device Changed"); |