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/serial/serial_device_enumerator_mac.h" | 5 #include "device/serial/serial_device_enumerator_mac.h" |
6 | 6 |
7 #include <IOKit/serial/IOSerialKeys.h> | 7 #include <IOKit/serial/IOSerialKeys.h> |
8 #include <IOKit/usb/IOUSBLib.h> | 8 #include <IOKit/usb/IOUSBLib.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 return static_cast<CFNumberRef>(value); | 58 return static_cast<CFNumberRef>(value); |
59 | 59 |
60 return NULL; | 60 return NULL; |
61 } | 61 } |
62 | 62 |
63 // Searches the specified service for a string property with the specified key, | 63 // Searches the specified service for a string property with the specified key, |
64 // sets value to that property's value, and returns whether the operation was | 64 // sets value to that property's value, and returns whether the operation was |
65 // successful. | 65 // successful. |
66 bool GetStringProperty(io_service_t service, | 66 bool GetStringProperty(io_service_t service, |
67 const CFStringRef key, | 67 const CFStringRef key, |
68 mojo::String* value) { | 68 std::string* value) { |
69 CFStringRef propValue = GetCFStringProperty(service, key); | 69 CFStringRef propValue = GetCFStringProperty(service, key); |
70 if (propValue) { | 70 if (propValue) { |
71 *value = base::SysCFStringRefToUTF8(propValue); | 71 *value = base::SysCFStringRefToUTF8(propValue); |
72 return true; | 72 return true; |
73 } | 73 } |
74 | 74 |
75 return false; | 75 return false; |
76 } | 76 } |
77 | 77 |
78 // Searches the specified service for a uint16_t property with the specified | 78 // Searches the specified service for a uint16_t property with the specified |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 callout_info->vendor_id = vendorId; | 128 callout_info->vendor_id = vendorId; |
129 } | 129 } |
130 | 130 |
131 uint16_t productId; | 131 uint16_t productId; |
132 if (GetUInt16Property(scoped_device.get(), CFSTR(kUSBProductID), | 132 if (GetUInt16Property(scoped_device.get(), CFSTR(kUSBProductID), |
133 &productId)) { | 133 &productId)) { |
134 callout_info->has_product_id = true; | 134 callout_info->has_product_id = true; |
135 callout_info->product_id = productId; | 135 callout_info->product_id = productId; |
136 } | 136 } |
137 | 137 |
138 mojo::String displayName; | 138 std::string display_name; |
139 if (GetStringProperty(scoped_device.get(), CFSTR(kUSBProductString), | 139 if (GetStringProperty(scoped_device.get(), CFSTR(kUSBProductString), |
140 &displayName)) { | 140 &display_name)) { |
141 callout_info->display_name = displayName.PassStorage(); | 141 callout_info->display_name = std::move(display_name); |
142 } | 142 } |
143 | 143 |
144 // Each serial device has two "paths" in /dev/ associated with it: a | 144 // Each serial device has two "paths" in /dev/ associated with it: a |
145 // "dialin" path starting with "tty" and a "callout" path starting with | 145 // "dialin" path starting with "tty" and a "callout" path starting with |
146 // "cu". Each of these is considered a different device from Chrome's | 146 // "cu". Each of these is considered a different device from Chrome's |
147 // standpoint, but both should share the device's USB properties. | 147 // standpoint, but both should share the device's USB properties. |
148 mojo::String dialinDevice; | 148 std::string dialinDevice; |
149 if (GetStringProperty(scoped_device.get(), CFSTR(kIODialinDeviceKey), | 149 if (GetStringProperty(scoped_device.get(), CFSTR(kIODialinDeviceKey), |
150 &dialinDevice)) { | 150 &dialinDevice)) { |
151 serial::DeviceInfoPtr dialin_info = callout_info.Clone(); | 151 serial::DeviceInfoPtr dialin_info = callout_info.Clone(); |
152 dialin_info->path = dialinDevice; | 152 dialin_info->path = dialinDevice; |
153 devices.push_back(std::move(dialin_info)); | 153 devices.push_back(std::move(dialin_info)); |
154 } | 154 } |
155 | 155 |
156 mojo::String calloutDevice; | 156 std::string calloutDevice; |
157 if (GetStringProperty(scoped_device.get(), CFSTR(kIOCalloutDeviceKey), | 157 if (GetStringProperty(scoped_device.get(), CFSTR(kIOCalloutDeviceKey), |
158 &calloutDevice)) { | 158 &calloutDevice)) { |
159 callout_info->path = calloutDevice; | 159 callout_info->path = calloutDevice; |
160 devices.push_back(std::move(callout_info)); | 160 devices.push_back(std::move(callout_info)); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 return devices; | 164 return devices; |
165 } | 165 } |
166 | 166 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 DCHECK(inserted); | 233 DCHECK(inserted); |
234 } | 234 } |
235 for (auto& device : old_devices) { | 235 for (auto& device : old_devices) { |
236 if (devices_seen.insert(device->path).second) | 236 if (devices_seen.insert(device->path).second) |
237 devices.push_back(std::move(device)); | 237 devices.push_back(std::move(device)); |
238 } | 238 } |
239 return devices; | 239 return devices; |
240 } | 240 } |
241 | 241 |
242 } // namespace device | 242 } // namespace device |
OLD | NEW |