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

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

Issue 225513005: chrome.hid : enrich device info with Top-Level collections usages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: enrich device info with hid usages Created 6 years, 8 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
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_mac.h" 5 #include "device/hid/hid_service_mac.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 #include <IOKit/hid/IOHIDManager.h> 8 #include <IOKit/hid/IOHIDManager.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Note that our ownership of hid_device is implied if calling this method. 136 // Note that our ownership of hid_device is implied if calling this method.
137 // It is balanced in PlatformRemoveDevice. 137 // It is balanced in PlatformRemoveDevice.
138 DCHECK(thread_checker_.CalledOnValidThread()); 138 DCHECK(thread_checker_.CalledOnValidThread());
139 139
140 HidDeviceInfo device_info; 140 HidDeviceInfo device_info;
141 device_info.device_id = hid_device; 141 device_info.device_id = hid_device;
142 device_info.vendor_id = 142 device_info.vendor_id =
143 GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)); 143 GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey));
144 device_info.product_id = 144 device_info.product_id =
145 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey)); 145 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey));
146 device_info.usage =
147 GetHidIntProperty(hid_device, CFSTR(kIOHIDPrimaryUsageKey));
148 device_info.usage_page =
149 GetHidIntProperty(hid_device, CFSTR(kIOHIDPrimaryUsagePageKey));
150 device_info.input_report_size = 146 device_info.input_report_size =
151 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxInputReportSizeKey)); 147 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxInputReportSizeKey));
152 device_info.output_report_size = 148 device_info.output_report_size =
153 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxOutputReportSizeKey)); 149 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxOutputReportSizeKey));
154 device_info.feature_report_size = 150 device_info.feature_report_size =
155 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxFeatureReportSizeKey)); 151 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxFeatureReportSizeKey));
152 CFTypeRef deviceUsagePairsRaw = IOHIDDeviceGetProperty(hid_device,
Ken Rockot(use gerrit already) 2014/04/15 17:53:38 nit: Please align arguments. In this case you can
153 CFSTR(kIOHIDDeviceUsagePairsKey));
154 CFArrayRef deviceUsagePairs = base::mac::CFCast<CFArrayRef>(
155 deviceUsagePairsRaw);
156 CFIndex deviceUsagePairsCount = CFArrayGetCount(deviceUsagePairs);
157 for (CFIndex i=0; i<deviceUsagePairsCount; i++) {
Ken Rockot(use gerrit already) 2014/04/15 17:53:38 nit: Please format this code. Missing whitespace (
158 HidUsageAndPage usage_and_page;
159 CFDictionaryRef deviceUsagePair = base::mac::CFCast<CFDictionaryRef>(
160 CFArrayGetValueAtIndex(deviceUsagePairs, i));
161 CFNumberRef usage_page_raw = base::mac::CFCast<CFNumberRef>(
162 CFDictionaryGetValue(deviceUsagePair,
163 CFSTR(kIOHIDDeviceUsagePageKey)));
164 CFNumberGetValue(usage_page_raw,
165 kCFNumberSInt32Type,
166 &usage_and_page.usage_page);
167 CFNumberRef usage_raw = base::mac::CFCast<CFNumberRef>(
168 CFDictionaryGetValue(deviceUsagePair,
169 CFSTR(kIOHIDDeviceUsageKey)));
170 CFNumberGetValue(usage_raw, kCFNumberSInt32Type, &usage_and_page.usage);
171 device_info.usages.push_back(usage_and_page);
172 }
156 device_info.product_name = 173 device_info.product_name =
157 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey)); 174 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey));
158 device_info.serial_number = 175 device_info.serial_number =
159 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey)); 176 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey));
160 AddDevice(device_info); 177 AddDevice(device_info);
161 } 178 }
162 179
163 void HidServiceMac::PlatformRemoveDevice(IOHIDDeviceRef hid_device) { 180 void HidServiceMac::PlatformRemoveDevice(IOHIDDeviceRef hid_device) {
164 DCHECK(thread_checker_.CalledOnValidThread()); 181 DCHECK(thread_checker_.CalledOnValidThread());
165 RemoveDevice(hid_device); 182 RemoveDevice(hid_device);
166 CFRelease(hid_device); 183 CFRelease(hid_device);
167 } 184 }
168 185
169 scoped_refptr<HidConnection> HidServiceMac::Connect( 186 scoped_refptr<HidConnection> HidServiceMac::Connect(
170 const HidDeviceId& device_id) { 187 const HidDeviceId& device_id) {
171 DCHECK(thread_checker_.CalledOnValidThread()); 188 DCHECK(thread_checker_.CalledOnValidThread());
172 HidDeviceInfo device_info; 189 HidDeviceInfo device_info;
173 if (!GetDeviceInfo(device_id, &device_info)) 190 if (!GetDeviceInfo(device_id, &device_info))
174 return NULL; 191 return NULL;
175 return scoped_refptr<HidConnection>(new HidConnectionMac(device_info)); 192 return scoped_refptr<HidConnection>(new HidConnectionMac(device_info));
176 } 193 }
177 194
178 } // namespace device 195 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698