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..3060b2b3766ecb2ac2a0e271266d001c9447baec 100644 |
--- a/device/hid/hid_service_win.cc |
+++ b/device/hid/hid_service_win.cc |
@@ -17,16 +17,6 @@ |
#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 +149,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 (size_t 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); |
+ } |
+ } |
+ } |
+ } |
+} |
+ |
+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 (size_t 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); |
+ } |
+ } |
+ } |
+ } |
+} |
+ |
void HidServiceWin::PlatformAddDevice(const std::string& device_path) { |
HidDeviceInfo device_info; |
device_info.device_id = device_path; |
@@ -215,39 +248,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); |
} |