Chromium Code Reviews| Index: device/hid/hid_service_win.cc |
| diff --git a/device/hid/hid_service_win.cc b/device/hid/hid_service_win.cc |
| index 23afa4f40affe0da4e6d4d9d0a8038e5e498ecfe..77a636fe4508e36e5f5bbb548483b11490c4790c 100644 |
| --- a/device/hid/hid_service_win.cc |
| +++ b/device/hid/hid_service_win.cc |
| @@ -15,18 +15,6 @@ |
| #if defined(OS_WIN) |
| -#define INITGUID |
| - |
| -#include <windows.h> |
| -#include <hidclass.h> |
| - |
| -extern "C" { |
| - |
| -#include <hidsdi.h> |
| -#include <hidpi.h> |
| - |
| -} |
| - |
| #include <setupapi.h> |
| #include <winioctl.h> |
| #include "base/win/scoped_handle.h" |
| @@ -159,6 +147,49 @@ void HidServiceWin::Enumerate() { |
| } |
| } |
| +void HidServiceWin::CollectInfoFromButtonCaps( |
| + PHIDP_PREPARSED_DATA preparsed_data, |
| + HIDP_REPORT_TYPE report_type, |
| + USHORT button_caps_length, |
| + HidCollectionInfo* collection_info) { |
| + if (button_caps_length > 0) { |
| + scoped_ptr<HIDP_BUTTON_CAPS[]> button_caps( |
| + new HIDP_BUTTON_CAPS[button_caps_length]); |
| + if (HidP_GetButtonCaps(report_type, |
| + &button_caps[0], |
| + &button_caps_length, |
| + preparsed_data) == HIDP_STATUS_SUCCESS) { |
| + for (int i = 0; i < button_caps_length; i++) { |
|
rpaquay
2014/08/22 21:36:30
Should "i" be unsigned (size_t)?
Reilly Grant (use Gerrit)
2014/08/22 21:54:54
Done.
|
| + int report_id = button_caps[i].ReportID; |
| + if (report_id != 0) { |
| + collection_info->report_ids.insert(report_id); |
| + } |
| + } |
| + } |
| + } |
| +} |
| + |
| +void HidServiceWin::CollectInfoFromValueCaps( |
| + PHIDP_PREPARSED_DATA preparsed_data, |
| + HIDP_REPORT_TYPE report_type, |
| + USHORT value_caps_length, |
| + HidCollectionInfo* collection_info) { |
| + if (value_caps_length > 0) { |
| + scoped_ptr<HIDP_VALUE_CAPS[]> value_caps( |
| + new HIDP_VALUE_CAPS[value_caps_length]); |
| + if (HidP_GetValueCaps( |
| + report_type, &value_caps[0], &value_caps_length, preparsed_data) == |
| + HIDP_STATUS_SUCCESS) { |
| + for (int i = 0; i < value_caps_length; i++) { |
|
rpaquay
2014/08/22 21:36:30
Should "i" be unsigned (size_t)?
Reilly Grant (use Gerrit)
2014/08/22 21:54:54
Done.
|
| + int report_id = value_caps[i].ReportID; |
| + if (report_id != 0) { |
| + collection_info->report_ids.insert(report_id); |
| + } |
| + } |
| + } |
| + } |
| +} |
| + |
| void HidServiceWin::PlatformAddDevice(const std::string& device_path) { |
| HidDeviceInfo device_info; |
| device_info.device_id = device_path; |
| @@ -215,39 +246,32 @@ void HidServiceWin::PlatformAddDevice(const std::string& device_path) { |
| collection_info.usage = HidUsageAndPage( |
| capabilities.Usage, |
| static_cast<HidUsageAndPage::Page>(capabilities.UsagePage)); |
| - USHORT button_caps_length = capabilities.NumberInputButtonCaps; |
| - if (button_caps_length > 0) { |
| - scoped_ptr<HIDP_BUTTON_CAPS[]> button_caps( |
| - new HIDP_BUTTON_CAPS[button_caps_length]); |
| - if (HidP_GetButtonCaps(HidP_Input, |
| - &button_caps[0], |
| - &button_caps_length, |
| - preparsed_data) == HIDP_STATUS_SUCCESS) { |
| - for (int i = 0; i < button_caps_length; i++) { |
| - int report_id = button_caps[i].ReportID; |
| - if (report_id != 0) { |
| - collection_info.report_ids.insert(report_id); |
| - device_info.has_report_id = true; |
| - } |
| - } |
| - } |
| - } |
| - USHORT value_caps_length = capabilities.NumberInputValueCaps; |
| - if (value_caps_length > 0) { |
| - scoped_ptr<HIDP_VALUE_CAPS[]> value_caps( |
| - new HIDP_VALUE_CAPS[value_caps_length]); |
| - if (HidP_GetValueCaps(HidP_Input, |
| - &value_caps[0], |
| - &value_caps_length, |
| - preparsed_data) == HIDP_STATUS_SUCCESS) { |
| - for (int i = 0; i < value_caps_length; i++) { |
| - int report_id = value_caps[i].ReportID; |
| - if (report_id != 0) { |
| - collection_info.report_ids.insert(report_id); |
| - device_info.has_report_id = true; |
| - } |
| - } |
| - } |
| + CollectInfoFromButtonCaps(preparsed_data, |
| + HidP_Input, |
| + capabilities.NumberInputButtonCaps, |
| + &collection_info); |
| + CollectInfoFromButtonCaps(preparsed_data, |
| + HidP_Output, |
| + capabilities.NumberOutputButtonCaps, |
| + &collection_info); |
| + CollectInfoFromButtonCaps(preparsed_data, |
| + HidP_Feature, |
| + capabilities.NumberFeatureButtonCaps, |
| + &collection_info); |
| + CollectInfoFromValueCaps(preparsed_data, |
| + HidP_Input, |
| + capabilities.NumberInputValueCaps, |
| + &collection_info); |
| + CollectInfoFromValueCaps(preparsed_data, |
| + HidP_Output, |
| + capabilities.NumberOutputValueCaps, |
| + &collection_info); |
| + CollectInfoFromValueCaps(preparsed_data, |
| + HidP_Feature, |
| + capabilities.NumberFeatureValueCaps, |
| + &collection_info); |
| + if (!collection_info.report_ids.empty()) { |
| + device_info.has_report_id = true; |
| } |
| device_info.collections.push_back(collection_info); |
| } |