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 | 7 #define INITGUID |
8 #include <devpkey.h> | 8 #include <devpkey.h> |
9 #include <setupapi.h> | 9 #include <setupapi.h> |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // Searches for the COM port in the device's friendly name, assigns its value to | 144 // Searches for the COM port in the device's friendly name, assigns its value to |
145 // com_port, and returns whether the operation was successful. | 145 // com_port, and returns whether the operation was successful. |
146 bool GetCOMPort(const std::string friendly_name, std::string* com_port) { | 146 bool GetCOMPort(const std::string friendly_name, std::string* com_port) { |
147 return RE2::PartialMatch(friendly_name, ".* \\((COM[0-9]+)\\)", com_port); | 147 return RE2::PartialMatch(friendly_name, ".* \\((COM[0-9]+)\\)", com_port); |
148 } | 148 } |
149 | 149 |
150 } // namespace | 150 } // namespace |
151 | 151 |
152 // static | 152 // static |
153 scoped_refptr<SerialIoHandler> SerialIoHandler::Create( | 153 scoped_refptr<SerialIoHandler> SerialIoHandler::Create( |
154 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | |
155 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) { | 154 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) { |
156 return new SerialIoHandlerWin(file_thread_task_runner, ui_thread_task_runner); | 155 return new SerialIoHandlerWin(ui_thread_task_runner); |
157 } | 156 } |
158 | 157 |
159 class SerialIoHandlerWin::UiThreadHelper final | 158 class SerialIoHandlerWin::UiThreadHelper final |
160 : public DeviceMonitorWin::Observer { | 159 : public DeviceMonitorWin::Observer { |
161 public: | 160 public: |
162 UiThreadHelper( | 161 UiThreadHelper( |
163 base::WeakPtr<SerialIoHandlerWin> io_handler, | 162 base::WeakPtr<SerialIoHandlerWin> io_handler, |
164 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) | 163 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) |
165 : device_observer_(this), | 164 : device_observer_(this), |
166 io_handler_(io_handler), | 165 io_handler_(io_handler), |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 351 } |
353 | 352 |
354 if (!SetCommState(file().GetPlatformFile(), &config)) { | 353 if (!SetCommState(file().GetPlatformFile(), &config)) { |
355 VPLOG(1) << "Failed to set serial port info"; | 354 VPLOG(1) << "Failed to set serial port info"; |
356 return false; | 355 return false; |
357 } | 356 } |
358 return true; | 357 return true; |
359 } | 358 } |
360 | 359 |
361 SerialIoHandlerWin::SerialIoHandlerWin( | 360 SerialIoHandlerWin::SerialIoHandlerWin( |
362 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | |
363 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) | 361 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) |
364 : SerialIoHandler(file_thread_task_runner, ui_thread_task_runner), | 362 : SerialIoHandler(ui_thread_task_runner), |
365 event_mask_(0), | 363 event_mask_(0), |
366 is_comm_pending_(false), | 364 is_comm_pending_(false), |
367 helper_(nullptr), | 365 helper_(nullptr), |
368 weak_factory_(this) {} | 366 weak_factory_(this) {} |
369 | 367 |
370 SerialIoHandlerWin::~SerialIoHandlerWin() { | 368 SerialIoHandlerWin::~SerialIoHandlerWin() { |
371 ui_thread_task_runner()->DeleteSoon(FROM_HERE, helper_); | 369 ui_thread_task_runner()->DeleteSoon(FROM_HERE, helper_); |
372 } | 370 } |
373 | 371 |
374 void SerialIoHandlerWin::OnIOCompleted( | 372 void SerialIoHandlerWin::OnIOCompleted( |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 526 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
529 // For COM numbers less than 9, CreateFile is called with a string such as | 527 // For COM numbers less than 9, CreateFile is called with a string such as |
530 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. | 528 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. |
531 if (port_name.length() > std::string("COM9").length()) | 529 if (port_name.length() > std::string("COM9").length()) |
532 return std::string("\\\\.\\").append(port_name); | 530 return std::string("\\\\.\\").append(port_name); |
533 | 531 |
534 return port_name; | 532 return port_name; |
535 } | 533 } |
536 | 534 |
537 } // namespace device | 535 } // namespace device |
OLD | NEW |