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_io_handler_win.h" | 5 #include "device/serial/serial_io_handler_win.h" |
6 | 6 |
| 7 #define INITGUID |
| 8 #include <devpkey.h> |
| 9 #include <setupapi.h> |
7 #include <windows.h> | 10 #include <windows.h> |
8 #include <setupapi.h> | |
9 | 11 |
10 #include "base/bind.h" | 12 #include "base/bind.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
13 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
14 #include "device/base/device_info_query_win.h" | 16 #include "device/base/device_info_query_win.h" |
15 #include "device/base/device_monitor_win.h" | 17 #include "device/base/device_monitor_win.h" |
16 #include "third_party/re2/src/re2/re2.h" | 18 #include "third_party/re2/src/re2/re2.h" |
17 | 19 |
18 namespace device { | 20 namespace device { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 void SerialIoHandlerWin::OnDeviceRemoved(const std::string& device_path) { | 198 void SerialIoHandlerWin::OnDeviceRemoved(const std::string& device_path) { |
197 DCHECK(CalledOnValidThread()); | 199 DCHECK(CalledOnValidThread()); |
198 | 200 |
199 DeviceInfoQueryWin device_info_query; | 201 DeviceInfoQueryWin device_info_query; |
200 if (!device_info_query.device_info_list_valid()) { | 202 if (!device_info_query.device_info_list_valid()) { |
201 DVPLOG(1) << "Failed to create a device information set"; | 203 DVPLOG(1) << "Failed to create a device information set"; |
202 return; | 204 return; |
203 } | 205 } |
204 | 206 |
205 // This will add the device so we can query driver info. | 207 // This will add the device so we can query driver info. |
206 if (!device_info_query.AddDevice(device_path.c_str())) { | 208 if (!device_info_query.AddDevice(device_path)) { |
207 DVPLOG(1) << "Failed to get device interface data for " << device_path; | 209 DVPLOG(1) << "Failed to get device interface data for " << device_path; |
208 return; | 210 return; |
209 } | 211 } |
210 | 212 |
211 if (!device_info_query.GetDeviceInfo()) { | 213 if (!device_info_query.GetDeviceInfo()) { |
212 DVPLOG(1) << "Failed to get device info for " << device_path; | 214 DVPLOG(1) << "Failed to get device info for " << device_path; |
213 return; | 215 return; |
214 } | 216 } |
215 | 217 |
216 std::string friendly_name; | 218 std::string friendly_name; |
217 if (!device_info_query.GetDeviceStringProperty(SPDRP_FRIENDLYNAME, | 219 if (!device_info_query.GetDeviceStringProperty(DEVPKEY_Device_FriendlyName, |
218 &friendly_name)) { | 220 &friendly_name)) { |
219 DVPLOG(1) << "Failed to get device service property"; | 221 DVPLOG(1) << "Failed to get device service property"; |
220 return; | 222 return; |
221 } | 223 } |
222 | 224 |
223 std::string com_port; | 225 std::string com_port; |
224 if (!GetCOMPort(friendly_name, &com_port)) { | 226 if (!GetCOMPort(friendly_name, &com_port)) { |
225 DVPLOG(1) << "Failed to get port name from \"" << friendly_name << "\"."; | 227 DVPLOG(1) << "Failed to get port name from \"" << friendly_name << "\"."; |
226 return; | 228 return; |
227 } | 229 } |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 528 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
527 // For COM numbers less than 9, CreateFile is called with a string such as | 529 // For COM numbers less than 9, CreateFile is called with a string such as |
528 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. | 530 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. |
529 if (port_name.length() > std::string("COM9").length()) | 531 if (port_name.length() > std::string("COM9").length()) |
530 return std::string("\\\\.\\").append(port_name); | 532 return std::string("\\\\.\\").append(port_name); |
531 | 533 |
532 return port_name; | 534 return port_name; |
533 } | 535 } |
534 | 536 |
535 } // namespace device | 537 } // namespace device |
OLD | NEW |