OLD | NEW |
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/IOHIDDevice.h> | 8 #include <IOKit/hid/IOHIDDevice.h> |
| 9 #include <stdint.h> |
9 | 10 |
10 #include <set> | 11 #include <set> |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/bind.h" | 15 #include "base/bind.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/mac/foundation_util.h" | 18 #include "base/mac/foundation_util.h" |
18 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } | 61 } |
61 | 62 |
62 std::string GetHidStringProperty(IOHIDDeviceRef device, CFStringRef key) { | 63 std::string GetHidStringProperty(IOHIDDeviceRef device, CFStringRef key) { |
63 std::string value; | 64 std::string value; |
64 TryGetHidStringProperty(device, key, &value); | 65 TryGetHidStringProperty(device, key, &value); |
65 return value; | 66 return value; |
66 } | 67 } |
67 | 68 |
68 bool TryGetHidDataProperty(IOHIDDeviceRef device, | 69 bool TryGetHidDataProperty(IOHIDDeviceRef device, |
69 CFStringRef key, | 70 CFStringRef key, |
70 std::vector<uint8>* result) { | 71 std::vector<uint8_t>* result) { |
71 CFDataRef ref = | 72 CFDataRef ref = |
72 base::mac::CFCast<CFDataRef>(IOHIDDeviceGetProperty(device, key)); | 73 base::mac::CFCast<CFDataRef>(IOHIDDeviceGetProperty(device, key)); |
73 if (!ref) { | 74 if (!ref) { |
74 return false; | 75 return false; |
75 } | 76 } |
76 STLClearObject(result); | 77 STLClearObject(result); |
77 const uint8* bytes = CFDataGetBytePtr(ref); | 78 const uint8_t* bytes = CFDataGetBytePtr(ref); |
78 result->insert(result->begin(), bytes, bytes + CFDataGetLength(ref)); | 79 result->insert(result->begin(), bytes, bytes + CFDataGetLength(ref)); |
79 return true; | 80 return true; |
80 } | 81 } |
81 | 82 |
82 } // namespace | 83 } // namespace |
83 | 84 |
84 HidServiceMac::HidServiceMac( | 85 HidServiceMac::HidServiceMac( |
85 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) | 86 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) |
86 : file_task_runner_(file_task_runner) { | 87 : file_task_runner_(file_task_runner) { |
87 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 88 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 return nullptr; | 245 return nullptr; |
245 } | 246 } |
246 | 247 |
247 base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( | 248 base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( |
248 IOHIDDeviceCreate(kCFAllocatorDefault, service)); | 249 IOHIDDeviceCreate(kCFAllocatorDefault, service)); |
249 if (!hid_device) { | 250 if (!hid_device) { |
250 HID_LOG(EVENT) << "Unable to create IOHIDDevice object for new device."; | 251 HID_LOG(EVENT) << "Unable to create IOHIDDevice object for new device."; |
251 return nullptr; | 252 return nullptr; |
252 } | 253 } |
253 | 254 |
254 std::vector<uint8> report_descriptor; | 255 std::vector<uint8_t> report_descriptor; |
255 if (!TryGetHidDataProperty(hid_device, CFSTR(kIOHIDReportDescriptorKey), | 256 if (!TryGetHidDataProperty(hid_device, CFSTR(kIOHIDReportDescriptorKey), |
256 &report_descriptor)) { | 257 &report_descriptor)) { |
257 HID_LOG(DEBUG) << "Device report descriptor not available."; | 258 HID_LOG(DEBUG) << "Device report descriptor not available."; |
258 } | 259 } |
259 | 260 |
260 return new HidDeviceInfo( | 261 return new HidDeviceInfo( |
261 entry_id, GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)), | 262 entry_id, GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)), |
262 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey)), | 263 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey)), |
263 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey)), | 264 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey)), |
264 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey)), | 265 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey)), |
265 kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335 | 266 kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335 |
266 report_descriptor); | 267 report_descriptor); |
267 } | 268 } |
268 | 269 |
269 } // namespace device | 270 } // namespace device |
OLD | NEW |