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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 12 matching lines...) Expand all Loading... |
23 namespace device { | 23 namespace device { |
24 | 24 |
25 // Provides a simplified interface for performing asynchronous I/O on serial | 25 // Provides a simplified interface for performing asynchronous I/O on serial |
26 // devices by hiding platform-specific MessageLoop interfaces. Pending I/O | 26 // devices by hiding platform-specific MessageLoop interfaces. Pending I/O |
27 // operations hold a reference to this object until completion so that memory | 27 // operations hold a reference to this object until completion so that memory |
28 // doesn't disappear out from under the OS. | 28 // doesn't disappear out from under the OS. |
29 class SerialIoHandler : public base::RefCounted<SerialIoHandler> { | 29 class SerialIoHandler : public base::RefCounted<SerialIoHandler> { |
30 public: | 30 public: |
31 // Constructs an instance of some platform-specific subclass. | 31 // Constructs an instance of some platform-specific subclass. |
32 static scoped_refptr<SerialIoHandler> Create( | 32 static scoped_refptr<SerialIoHandler> Create( |
33 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | |
34 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); | 33 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); |
35 | 34 |
36 typedef base::Callback<void(bool success)> OpenCompleteCallback; | 35 typedef base::Callback<void(bool success)> OpenCompleteCallback; |
37 | 36 |
38 // Initiates an asynchronous Open of the device. | 37 // Initiates an asynchronous Open of the device. |
39 virtual void Open(const std::string& port, | 38 virtual void Open(const std::string& port, |
40 const serial::ConnectionOptions& options, | 39 const serial::ConnectionOptions& options, |
41 const OpenCompleteCallback& callback); | 40 const OpenCompleteCallback& callback); |
42 | 41 |
43 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Initiates a BREAK signal. Places the transmission line in a break state | 104 // Initiates a BREAK signal. Places the transmission line in a break state |
106 // until the |ClearBreak| is called. | 105 // until the |ClearBreak| is called. |
107 virtual bool SetBreak() = 0; | 106 virtual bool SetBreak() = 0; |
108 | 107 |
109 // Terminates the BREAK signal. Places the transmission line in a nonbreak | 108 // Terminates the BREAK signal. Places the transmission line in a nonbreak |
110 // state. | 109 // state. |
111 virtual bool ClearBreak() = 0; | 110 virtual bool ClearBreak() = 0; |
112 | 111 |
113 protected: | 112 protected: |
114 explicit SerialIoHandler( | 113 explicit SerialIoHandler( |
115 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | |
116 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); | 114 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); |
117 virtual ~SerialIoHandler(); | 115 virtual ~SerialIoHandler(); |
118 | 116 |
119 // Performs a platform-specific read operation. This must guarantee that | 117 // Performs a platform-specific read operation. This must guarantee that |
120 // ReadCompleted is called when the underlying async operation is completed | 118 // ReadCompleted is called when the underlying async operation is completed |
121 // or the SerialIoHandler instance will leak. | 119 // or the SerialIoHandler instance will leak. |
122 // NOTE: Implementations of ReadImpl should never call ReadCompleted directly. | 120 // NOTE: Implementations of ReadImpl should never call ReadCompleted directly. |
123 // Use QueueReadCompleted instead to avoid reentrancy. | 121 // Use QueueReadCompleted instead to avoid reentrancy. |
124 virtual void ReadImpl() = 0; | 122 virtual void ReadImpl() = 0; |
125 | 123 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 186 |
189 serial::SendError write_cancel_reason() const { return write_cancel_reason_; } | 187 serial::SendError write_cancel_reason() const { return write_cancel_reason_; } |
190 | 188 |
191 bool write_canceled() const { return write_canceled_; } | 189 bool write_canceled() const { return write_canceled_; } |
192 | 190 |
193 const serial::ConnectionOptions& options() const { return options_; } | 191 const serial::ConnectionOptions& options() const { return options_; } |
194 | 192 |
195 // Possibly fixes up a serial port path name in a platform-specific manner. | 193 // Possibly fixes up a serial port path name in a platform-specific manner. |
196 static std::string MaybeFixUpPortName(const std::string& port_name); | 194 static std::string MaybeFixUpPortName(const std::string& port_name); |
197 | 195 |
198 base::SingleThreadTaskRunner* file_thread_task_runner() const { | |
199 return file_thread_task_runner_.get(); | |
200 } | |
201 | |
202 base::SingleThreadTaskRunner* ui_thread_task_runner() const { | 196 base::SingleThreadTaskRunner* ui_thread_task_runner() const { |
203 return ui_thread_task_runner_.get(); | 197 return ui_thread_task_runner_.get(); |
204 } | 198 } |
205 | 199 |
206 const std::string& port() const { return port_; } | 200 const std::string& port() const { return port_; } |
207 | 201 |
208 SEQUENCE_CHECKER(sequence_checker_); | 202 SEQUENCE_CHECKER(sequence_checker_); |
209 | 203 |
210 private: | 204 private: |
211 friend class base::RefCounted<SerialIoHandler>; | 205 friend class base::RefCounted<SerialIoHandler>; |
(...skipping 23 matching lines...) Expand all Loading... |
235 serial::ReceiveError read_cancel_reason_; | 229 serial::ReceiveError read_cancel_reason_; |
236 bool read_canceled_; | 230 bool read_canceled_; |
237 | 231 |
238 std::unique_ptr<ReadOnlyBuffer> pending_write_buffer_; | 232 std::unique_ptr<ReadOnlyBuffer> pending_write_buffer_; |
239 serial::SendError write_cancel_reason_; | 233 serial::SendError write_cancel_reason_; |
240 bool write_canceled_; | 234 bool write_canceled_; |
241 | 235 |
242 // Callback to handle the completion of a pending Open() request. | 236 // Callback to handle the completion of a pending Open() request. |
243 OpenCompleteCallback open_complete_; | 237 OpenCompleteCallback open_complete_; |
244 | 238 |
245 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; | |
246 // On Chrome OS, PermissionBrokerClient should be called on the UI thread. | 239 // On Chrome OS, PermissionBrokerClient should be called on the UI thread. |
247 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; | 240 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; |
248 | 241 |
249 std::string port_; | 242 std::string port_; |
250 | 243 |
251 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); | 244 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); |
252 }; | 245 }; |
253 | 246 |
254 } // namespace device | 247 } // namespace device |
255 | 248 |
256 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 249 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
OLD | NEW |