Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: device/hid/hid_service_win.cc

Issue 317783010: chrome.hid: enrich model with report IDs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix hid.idl comment Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/hid/hid_service_mac.cc ('k') | device/hid/hid_usage_and_page.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/hid/hid_service_win.h" 5 #include "device/hid/hid_service_win.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 device_info.product_id = attrib.ProductID; 180 device_info.product_id = attrib.ProductID;
181 181
182 for (ULONG i = 32; 182 for (ULONG i = 32;
183 HidD_SetNumInputBuffers(device_handle.Get(), i); 183 HidD_SetNumInputBuffers(device_handle.Get(), i);
184 i <<= 1); 184 i <<= 1);
185 185
186 // Get usage and usage page (optional). 186 // Get usage and usage page (optional).
187 PHIDP_PREPARSED_DATA preparsed_data; 187 PHIDP_PREPARSED_DATA preparsed_data;
188 if (HidD_GetPreparsedData(device_handle.Get(), &preparsed_data) && 188 if (HidD_GetPreparsedData(device_handle.Get(), &preparsed_data) &&
189 preparsed_data) { 189 preparsed_data) {
190 HIDP_CAPS capabilities; 190 HIDP_CAPS capabilities = {0};
191 if (HidP_GetCaps(preparsed_data, &capabilities) == HIDP_STATUS_SUCCESS) { 191 if (HidP_GetCaps(preparsed_data, &capabilities) == HIDP_STATUS_SUCCESS) {
192 device_info.input_report_size = capabilities.InputReportByteLength; 192 device_info.max_input_report_size = capabilities.InputReportByteLength;
193 device_info.output_report_size = capabilities.OutputReportByteLength; 193 device_info.max_output_report_size = capabilities.OutputReportByteLength;
194 device_info.feature_report_size = capabilities.FeatureReportByteLength; 194 device_info.max_feature_report_size =
195 device_info.usages.push_back(HidUsageAndPage( 195 capabilities.FeatureReportByteLength;
196 capabilities.Usage, 196 HidCollectionInfo collection_info;
197 static_cast<HidUsageAndPage::Page>(capabilities.UsagePage))); 197 collection_info.usage = HidUsageAndPage(
198 capabilities.Usage,
199 static_cast<HidUsageAndPage::Page>(capabilities.UsagePage));
200 USHORT button_caps_length = capabilities.NumberInputButtonCaps;
201 if (button_caps_length > 0) {
202 scoped_ptr<HIDP_BUTTON_CAPS[]> button_caps(
203 new HIDP_BUTTON_CAPS[button_caps_length]);
204 if (HidP_GetButtonCaps(HidP_Input,
205 &button_caps[0],
206 &button_caps_length,
207 preparsed_data) == HIDP_STATUS_SUCCESS) {
208 for (int i = 0; i < button_caps_length; i++) {
209 int report_id = button_caps[i].ReportID;
210 if (report_id != 0) {
211 collection_info.report_ids.insert(report_id);
212 }
213 }
214 }
215 }
216 USHORT value_caps_length = capabilities.NumberInputValueCaps;
217 if (value_caps_length > 0) {
218 scoped_ptr<HIDP_VALUE_CAPS[]> value_caps(
219 new HIDP_VALUE_CAPS[value_caps_length]);
220 if (HidP_GetValueCaps(HidP_Input,
221 &value_caps[0],
222 &value_caps_length,
223 preparsed_data) == HIDP_STATUS_SUCCESS) {
224 for (int i = 0; i < value_caps_length; i++) {
225 int report_id = value_caps[i].ReportID;
226 if (report_id != 0) {
227 collection_info.report_ids.insert(report_id);
228 }
229 }
230 }
231 }
232 device_info.collections.push_back(collection_info);
198 } 233 }
199 // Detect if the device supports report ids.
200 if (capabilities.NumberInputValueCaps > 0) {
201 scoped_ptr<HIDP_VALUE_CAPS[]> value_caps(
202 new HIDP_VALUE_CAPS[capabilities.NumberInputValueCaps]);
203 USHORT value_caps_length = capabilities.NumberInputValueCaps;
204 if (HidP_GetValueCaps(HidP_Input, &value_caps[0], &value_caps_length,
205 preparsed_data) == HIDP_STATUS_SUCCESS) {
206 device_info.has_report_id = (value_caps[0].ReportID != 0);
207 }
208 }
209 if (!device_info.has_report_id && capabilities.NumberInputButtonCaps > 0)
210 {
211 scoped_ptr<HIDP_BUTTON_CAPS[]> button_caps(
212 new HIDP_BUTTON_CAPS[capabilities.NumberInputButtonCaps]);
213 USHORT button_caps_length = capabilities.NumberInputButtonCaps;
214 if (HidP_GetButtonCaps(HidP_Input,
215 &button_caps[0],
216 &button_caps_length,
217 preparsed_data) == HIDP_STATUS_SUCCESS) {
218 device_info.has_report_id = (button_caps[0].ReportID != 0);
219 }
220 }
221
222 HidD_FreePreparsedData(preparsed_data); 234 HidD_FreePreparsedData(preparsed_data);
223 } 235 }
224 236
225 AddDevice(device_info); 237 AddDevice(device_info);
226 } 238 }
227 239
228 void HidServiceWin::PlatformRemoveDevice(const std::string& device_path) { 240 void HidServiceWin::PlatformRemoveDevice(const std::string& device_path) {
229 RemoveDevice(device_path); 241 RemoveDevice(device_path);
230 } 242 }
231 243
232 void HidServiceWin::GetDevices(std::vector<HidDeviceInfo>* devices) { 244 void HidServiceWin::GetDevices(std::vector<HidDeviceInfo>* devices) {
233 Enumerate(); 245 Enumerate();
234 HidService::GetDevices(devices); 246 HidService::GetDevices(devices);
235 } 247 }
236 248
237 scoped_refptr<HidConnection> HidServiceWin::Connect( 249 scoped_refptr<HidConnection> HidServiceWin::Connect(
238 const HidDeviceId& device_id) { 250 const HidDeviceId& device_id) {
239 HidDeviceInfo device_info; 251 HidDeviceInfo device_info;
240 if (!GetDeviceInfo(device_id, &device_info)) 252 if (!GetDeviceInfo(device_id, &device_info))
241 return NULL; 253 return NULL;
242 scoped_refptr<HidConnectionWin> connection(new HidConnectionWin(device_info)); 254 scoped_refptr<HidConnectionWin> connection(new HidConnectionWin(device_info));
243 if (!connection->available()) { 255 if (!connection->available()) {
244 PLOG(ERROR) << "Failed to open device."; 256 PLOG(ERROR) << "Failed to open device.";
245 return NULL; 257 return NULL;
246 } 258 }
247 return connection; 259 return connection;
248 } 260 }
249 261
250 } // namespace device 262 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_service_mac.cc ('k') | device/hid/hid_usage_and_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698