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 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 const ConnectCallback& callback) { | 133 const ConnectCallback& callback) { |
134 DCHECK(thread_checker_.CalledOnValidThread()); | 134 DCHECK(thread_checker_.CalledOnValidThread()); |
135 | 135 |
136 const auto& map_entry = devices().find(device_id); | 136 const auto& map_entry = devices().find(device_id); |
137 if (map_entry == devices().end()) { | 137 if (map_entry == devices().end()) { |
138 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); | 138 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); |
139 return; | 139 return; |
140 } | 140 } |
141 scoped_refptr<HidDeviceInfo> device_info = map_entry->second; | 141 scoped_refptr<HidDeviceInfo> device_info = map_entry->second; |
142 | 142 |
143 io_string_t service_path; | 143 base::ScopedCFTypeRef<CFDictionaryRef> matching_dict( |
144 strncpy(service_path, device_id.c_str(), sizeof service_path); | 144 IORegistryEntryIDMatching(device_id)); |
| 145 |
145 base::mac::ScopedIOObject<io_service_t> service( | 146 base::mac::ScopedIOObject<io_service_t> service( |
146 IORegistryEntryFromPath(kIOMasterPortDefault, service_path)); | 147 IOServiceGetMatchingService(kIOMasterPortDefault, matching_dict.get())); |
147 if (!service.get()) { | 148 if (!service.get()) { |
148 HID_LOG(EVENT) << "IOService not found for path: " << device_id; | 149 HID_LOG(EVENT) << "IOService not found for ID: " << device_id; |
149 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); | 150 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); |
150 return; | 151 return; |
151 } | 152 } |
152 | 153 |
153 base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( | 154 base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( |
154 IOHIDDeviceCreate(kCFAllocatorDefault, service)); | 155 IOHIDDeviceCreate(kCFAllocatorDefault, service)); |
155 if (!hid_device) { | 156 if (!hid_device) { |
156 HID_LOG(EVENT) << "Unable to create IOHIDDevice object."; | 157 HID_LOG(EVENT) << "Unable to create IOHIDDevice object."; |
157 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); | 158 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); |
158 return; | 159 return; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 206 } |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
209 void HidServiceMac::RemoveDevices() { | 210 void HidServiceMac::RemoveDevices() { |
210 DCHECK(thread_checker_.CalledOnValidThread()); | 211 DCHECK(thread_checker_.CalledOnValidThread()); |
211 | 212 |
212 io_service_t device; | 213 io_service_t device; |
213 while ((device = IOIteratorNext(devices_removed_iterator_)) != | 214 while ((device = IOIteratorNext(devices_removed_iterator_)) != |
214 IO_OBJECT_NULL) { | 215 IO_OBJECT_NULL) { |
215 io_string_t service_path; | 216 uint64_t entry_id; |
216 IOReturn result = | 217 IOReturn result = IORegistryEntryGetRegistryEntryID(device, &entry_id); |
217 IORegistryEntryGetPath(device, kIOServicePlane, service_path); | |
218 if (result == kIOReturnSuccess) { | 218 if (result == kIOReturnSuccess) { |
219 RemoveDevice(service_path); | 219 RemoveDevice(entry_id); |
220 } | 220 } |
221 | 221 |
222 // Release reference retained by AddDevices above. | 222 // Release reference retained by AddDevices above. |
223 IOObjectRelease(device); | 223 IOObjectRelease(device); |
224 // Release the reference retained by IOIteratorNext. | 224 // Release the reference retained by IOIteratorNext. |
225 IOObjectRelease(device); | 225 IOObjectRelease(device); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 // static | 229 // static |
230 scoped_refptr<HidDeviceInfo> HidServiceMac::CreateDeviceInfo( | 230 scoped_refptr<HidDeviceInfo> HidServiceMac::CreateDeviceInfo( |
231 io_service_t service) { | 231 io_service_t service) { |
232 io_string_t service_path; | 232 uint64_t entry_id; |
233 IOReturn result = | 233 IOReturn result = IORegistryEntryGetRegistryEntryID(service, &entry_id); |
234 IORegistryEntryGetPath(service, kIOServicePlane, service_path); | |
235 if (result != kIOReturnSuccess) { | 234 if (result != kIOReturnSuccess) { |
236 HID_LOG(EVENT) << "Failed to get IOService path: " << HexErrorCode(result); | 235 HID_LOG(EVENT) << "Failed to get IORegistryEntry ID: " |
| 236 << HexErrorCode(result); |
237 return nullptr; | 237 return nullptr; |
238 } | 238 } |
239 | 239 |
240 base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( | 240 base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( |
241 IOHIDDeviceCreate(kCFAllocatorDefault, service)); | 241 IOHIDDeviceCreate(kCFAllocatorDefault, service)); |
242 if (!hid_device) { | 242 if (!hid_device) { |
243 HID_LOG(EVENT) << "Unable to create IOHIDDevice object for " << service_path | 243 HID_LOG(EVENT) << "Unable to create IOHIDDevice object for new device."; |
244 << "."; | |
245 return nullptr; | 244 return nullptr; |
246 } | 245 } |
247 | 246 |
248 std::vector<uint8> report_descriptor; | 247 std::vector<uint8> report_descriptor; |
249 if (!TryGetHidDataProperty(hid_device, CFSTR(kIOHIDReportDescriptorKey), | 248 if (!TryGetHidDataProperty(hid_device, CFSTR(kIOHIDReportDescriptorKey), |
250 &report_descriptor)) { | 249 &report_descriptor)) { |
251 HID_LOG(EVENT) << "Unable to get report descriptor for " << service_path | 250 HID_LOG(EVENT) << "Unable to get report descriptor for new device."; |
252 << "."; | |
253 return nullptr; | 251 return nullptr; |
254 } | 252 } |
255 | 253 |
256 return new HidDeviceInfo( | 254 return new HidDeviceInfo( |
257 service_path, GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)), | 255 entry_id, GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)), |
258 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey)), | 256 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey)), |
259 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey)), | 257 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey)), |
260 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey)), | 258 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey)), |
261 kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335 | 259 kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335 |
262 report_descriptor); | 260 report_descriptor); |
263 } | 261 } |
264 | 262 |
265 } // namespace device | 263 } // namespace device |
OLD | NEW |