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 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 5 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 virtual serial::ConnectionInfoPtr GetPortInfo() const = 0; | 98 virtual serial::ConnectionInfoPtr GetPortInfo() const = 0; |
99 | 99 |
100 // Initiates a BREAK signal. Places the transmission line in a break state | 100 // Initiates a BREAK signal. Places the transmission line in a break state |
101 // until the |ClearBreak| is called. | 101 // until the |ClearBreak| is called. |
102 virtual bool SetBreak() = 0; | 102 virtual bool SetBreak() = 0; |
103 | 103 |
104 // Terminates the BREAK signal. Places the transmission line in a nonbreak | 104 // Terminates the BREAK signal. Places the transmission line in a nonbreak |
105 // state. | 105 // state. |
106 virtual bool ClearBreak() = 0; | 106 virtual bool ClearBreak() = 0; |
107 | 107 |
| 108 void set_port(const std::string& port) { port_ = port; } |
| 109 |
108 protected: | 110 protected: |
109 explicit SerialIoHandler( | 111 explicit SerialIoHandler( |
110 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 112 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
111 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); | 113 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); |
112 virtual ~SerialIoHandler(); | 114 virtual ~SerialIoHandler(); |
113 | 115 |
114 // Performs a platform-specific read operation. This must guarantee that | 116 // Performs a platform-specific read operation. This must guarantee that |
115 // ReadCompleted is called when the underlying async operation is completed | 117 // ReadCompleted is called when the underlying async operation is completed |
116 // or the SerialIoHandler instance will leak. | 118 // or the SerialIoHandler instance will leak. |
117 // NOTE: Implementations of ReadImpl should never call ReadCompleted directly. | 119 // NOTE: Implementations of ReadImpl should never call ReadCompleted directly. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 185 |
184 serial::SendError write_cancel_reason() const { return write_cancel_reason_; } | 186 serial::SendError write_cancel_reason() const { return write_cancel_reason_; } |
185 | 187 |
186 bool write_canceled() const { return write_canceled_; } | 188 bool write_canceled() const { return write_canceled_; } |
187 | 189 |
188 const serial::ConnectionOptions& options() const { return options_; } | 190 const serial::ConnectionOptions& options() const { return options_; } |
189 | 191 |
190 // Possibly fixes up a serial port path name in a platform-specific manner. | 192 // Possibly fixes up a serial port path name in a platform-specific manner. |
191 static std::string MaybeFixUpPortName(const std::string& port_name); | 193 static std::string MaybeFixUpPortName(const std::string& port_name); |
192 | 194 |
| 195 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; |
| 196 // On Chrome OS, PermissionBrokerClient should be called on the UI thread. |
| 197 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; |
| 198 |
| 199 std::string port_; |
| 200 |
193 private: | 201 private: |
194 friend class base::RefCounted<SerialIoHandler>; | 202 friend class base::RefCounted<SerialIoHandler>; |
195 | 203 |
196 void MergeConnectionOptions(const serial::ConnectionOptions& options); | 204 void MergeConnectionOptions(const serial::ConnectionOptions& options); |
197 | 205 |
198 // Continues an Open operation on the FILE thread. | 206 // Continues an Open operation on the FILE thread. |
199 void StartOpen(const std::string& port, | 207 void StartOpen(const std::string& port, |
200 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); | 208 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
201 | 209 |
202 // Finalizes an Open operation (continued from StartOpen) on the IO thread. | 210 // Finalizes an Open operation (continued from StartOpen) on the IO thread. |
(...skipping 15 matching lines...) Expand all Loading... |
218 serial::ReceiveError read_cancel_reason_; | 226 serial::ReceiveError read_cancel_reason_; |
219 bool read_canceled_; | 227 bool read_canceled_; |
220 | 228 |
221 scoped_ptr<ReadOnlyBuffer> pending_write_buffer_; | 229 scoped_ptr<ReadOnlyBuffer> pending_write_buffer_; |
222 serial::SendError write_cancel_reason_; | 230 serial::SendError write_cancel_reason_; |
223 bool write_canceled_; | 231 bool write_canceled_; |
224 | 232 |
225 // Callback to handle the completion of a pending Open() request. | 233 // Callback to handle the completion of a pending Open() request. |
226 OpenCompleteCallback open_complete_; | 234 OpenCompleteCallback open_complete_; |
227 | 235 |
228 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; | |
229 // On Chrome OS, PermissionBrokerClient should be called on the UI thread. | |
230 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; | |
231 | |
232 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); | 236 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); |
233 }; | 237 }; |
234 | 238 |
235 } // namespace device | 239 } // namespace device |
236 | 240 |
237 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 241 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
OLD | NEW |