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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "device/serial/serial_io_handler_win.h" | 7 #include "device/serial/serial_io_handler_win.h" |
8 | 8 |
9 namespace device { | 9 namespace device { |
10 | 10 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 return serial::STOP_BITS_TWO; | 126 return serial::STOP_BITS_TWO; |
127 case ONESTOPBIT: | 127 case ONESTOPBIT: |
128 default: | 128 default: |
129 return serial::STOP_BITS_ONE; | 129 return serial::STOP_BITS_ONE; |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 } // namespace | 133 } // namespace |
134 | 134 |
135 // static | 135 // static |
136 scoped_refptr<SerialIoHandler> SerialIoHandler::Create() { | 136 scoped_refptr<SerialIoHandler> SerialIoHandler::Create( |
137 return new SerialIoHandlerWin(); | 137 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop) { |
| 138 return new SerialIoHandlerWin(file_thread_message_loop); |
138 } | 139 } |
139 | 140 |
140 bool SerialIoHandlerWin::PostOpen() { | 141 bool SerialIoHandlerWin::PostOpen() { |
141 DCHECK(!comm_context_); | 142 DCHECK(!comm_context_); |
142 DCHECK(!read_context_); | 143 DCHECK(!read_context_); |
143 DCHECK(!write_context_); | 144 DCHECK(!write_context_); |
144 | 145 |
145 base::MessageLoopForIO::current()->RegisterIOHandler(file().GetPlatformFile(), | 146 base::MessageLoopForIO::current()->RegisterIOHandler(file().GetPlatformFile(), |
146 this); | 147 this); |
147 | 148 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 DCHECK(file().IsValid()); | 231 DCHECK(file().IsValid()); |
231 ::CancelIo(file().GetPlatformFile()); | 232 ::CancelIo(file().GetPlatformFile()); |
232 } | 233 } |
233 | 234 |
234 void SerialIoHandlerWin::CancelWriteImpl() { | 235 void SerialIoHandlerWin::CancelWriteImpl() { |
235 DCHECK(CalledOnValidThread()); | 236 DCHECK(CalledOnValidThread()); |
236 DCHECK(file().IsValid()); | 237 DCHECK(file().IsValid()); |
237 ::CancelIo(file().GetPlatformFile()); | 238 ::CancelIo(file().GetPlatformFile()); |
238 } | 239 } |
239 | 240 |
240 SerialIoHandlerWin::SerialIoHandlerWin() | 241 SerialIoHandlerWin::SerialIoHandlerWin( |
241 : event_mask_(0), is_comm_pending_(false) { | 242 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop) |
| 243 : SerialIoHandler(file_thread_message_loop), |
| 244 event_mask_(0), |
| 245 is_comm_pending_(false) { |
242 } | 246 } |
243 | 247 |
244 SerialIoHandlerWin::~SerialIoHandlerWin() { | 248 SerialIoHandlerWin::~SerialIoHandlerWin() { |
245 } | 249 } |
246 | 250 |
247 void SerialIoHandlerWin::OnIOCompleted( | 251 void SerialIoHandlerWin::OnIOCompleted( |
248 base::MessageLoopForIO::IOContext* context, | 252 base::MessageLoopForIO::IOContext* context, |
249 DWORD bytes_transferred, | 253 DWORD bytes_transferred, |
250 DWORD error) { | 254 DWORD error) { |
251 DCHECK(CalledOnValidThread()); | 255 DCHECK(CalledOnValidThread()); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 376 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
373 // For COM numbers less than 9, CreateFile is called with a string such as | 377 // For COM numbers less than 9, CreateFile is called with a string such as |
374 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. | 378 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. |
375 if (port_name.length() > std::string("COM9").length()) | 379 if (port_name.length() > std::string("COM9").length()) |
376 return std::string("\\\\.\\").append(port_name); | 380 return std::string("\\\\.\\").append(port_name); |
377 | 381 |
378 return port_name; | 382 return port_name; |
379 } | 383 } |
380 | 384 |
381 } // namespace device | 385 } // namespace device |
OLD | NEW |