| 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 13 matching lines...) Expand all Loading... |
| 24 public: | 24 public: |
| 25 // Constructs an instance of some platform-specific subclass. | 25 // Constructs an instance of some platform-specific subclass. |
| 26 static scoped_refptr<SerialIoHandler> Create( | 26 static scoped_refptr<SerialIoHandler> Create( |
| 27 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop, | 27 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop, |
| 28 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop); | 28 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop); |
| 29 | 29 |
| 30 typedef base::Callback<void(bool success)> OpenCompleteCallback; | 30 typedef base::Callback<void(bool success)> OpenCompleteCallback; |
| 31 | 31 |
| 32 // Initiates an asynchronous Open of the device. | 32 // Initiates an asynchronous Open of the device. |
| 33 virtual void Open(const std::string& port, | 33 virtual void Open(const std::string& port, |
| 34 const serial::ConnectionOptions& options, |
| 34 const OpenCompleteCallback& callback); | 35 const OpenCompleteCallback& callback); |
| 35 | 36 |
| 36 // Signals that the access request for |port| is complete. | 37 // Signals that the access request for |port| is complete. |
| 37 void OnRequestAccessComplete(const std::string& port, bool success); | 38 void OnRequestAccessComplete(const std::string& port, bool success); |
| 38 | 39 |
| 39 // Performs an async Read operation. Behavior is undefined if this is called | 40 // Performs an async Read operation. Behavior is undefined if this is called |
| 40 // while a Read is already pending. Otherwise, the Done or DoneWithError | 41 // while a Read is already pending. Otherwise, the Done or DoneWithError |
| 41 // method on |buffer| will eventually be called with a result. | 42 // method on |buffer| will eventually be called with a result. |
| 42 void Read(scoped_ptr<WritableBuffer> buffer); | 43 void Read(scoped_ptr<WritableBuffer> buffer); |
| 43 | 44 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 67 virtual serial::DeviceControlSignalsPtr GetControlSignals() const = 0; | 68 virtual serial::DeviceControlSignalsPtr GetControlSignals() const = 0; |
| 68 | 69 |
| 69 // Sets one or more control signals (DTR and/or RTS). Returns |true| iff | 70 // Sets one or more control signals (DTR and/or RTS). Returns |true| iff |
| 70 // the signals were successfully set. Unininitialized flags in the | 71 // the signals were successfully set. Unininitialized flags in the |
| 71 // HostControlSignals structure are left unchanged. | 72 // HostControlSignals structure are left unchanged. |
| 72 virtual bool SetControlSignals( | 73 virtual bool SetControlSignals( |
| 73 const serial::HostControlSignals& control_signals) = 0; | 74 const serial::HostControlSignals& control_signals) = 0; |
| 74 | 75 |
| 75 // Performs platform-specific port configuration. Returns |true| iff | 76 // Performs platform-specific port configuration. Returns |true| iff |
| 76 // configuration was successful. | 77 // configuration was successful. |
| 77 virtual bool ConfigurePort(const serial::ConnectionOptions& options) = 0; | 78 bool ConfigurePort(const serial::ConnectionOptions& options); |
| 78 | 79 |
| 79 // Performs a platform-specific port configuration query. Fills values in an | 80 // Performs a platform-specific port configuration query. Fills values in an |
| 80 // existing ConnectionInfo. Returns |true| iff port configuration was | 81 // existing ConnectionInfo. Returns |true| iff port configuration was |
| 81 // successfully retrieved. | 82 // successfully retrieved. |
| 82 virtual serial::ConnectionInfoPtr GetPortInfo() const = 0; | 83 virtual serial::ConnectionInfoPtr GetPortInfo() const = 0; |
| 83 | 84 |
| 84 protected: | 85 protected: |
| 85 explicit SerialIoHandler( | 86 explicit SerialIoHandler( |
| 86 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop, | 87 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop, |
| 87 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop); | 88 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 // NOTE: Implementations of WriteImpl should never call WriteCompleted | 101 // NOTE: Implementations of WriteImpl should never call WriteCompleted |
| 101 // directly. Use QueueWriteCompleted instead to avoid reentrancy. | 102 // directly. Use QueueWriteCompleted instead to avoid reentrancy. |
| 102 virtual void WriteImpl() = 0; | 103 virtual void WriteImpl() = 0; |
| 103 | 104 |
| 104 // Platform-specific read cancelation. | 105 // Platform-specific read cancelation. |
| 105 virtual void CancelReadImpl() = 0; | 106 virtual void CancelReadImpl() = 0; |
| 106 | 107 |
| 107 // Platform-specific write cancelation. | 108 // Platform-specific write cancelation. |
| 108 virtual void CancelWriteImpl() = 0; | 109 virtual void CancelWriteImpl() = 0; |
| 109 | 110 |
| 111 // Platform-specific port configuration applies options_ to the device. |
| 112 virtual bool ConfigurePortImpl() = 0; |
| 113 |
| 110 // Requests access to the underlying serial device, if needed. | 114 // Requests access to the underlying serial device, if needed. |
| 111 virtual void RequestAccess( | 115 virtual void RequestAccess( |
| 112 const std::string& port, | 116 const std::string& port, |
| 113 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 117 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| 114 scoped_refptr<base::MessageLoopProxy> ui_message_loop); | 118 scoped_refptr<base::MessageLoopProxy> ui_message_loop); |
| 115 | 119 |
| 116 // Performs platform-specific, one-time port configuration on open. | 120 // Performs platform-specific, one-time port configuration on open. |
| 117 virtual bool PostOpen(); | 121 virtual bool PostOpen(); |
| 118 | 122 |
| 119 // Called by the implementation to signal that the active read has completed. | 123 // Called by the implementation to signal that the active read has completed. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 161 } |
| 158 | 162 |
| 159 uint32_t pending_write_buffer_len() const { | 163 uint32_t pending_write_buffer_len() const { |
| 160 return pending_write_buffer_ ? pending_write_buffer_->GetSize() : 0; | 164 return pending_write_buffer_ ? pending_write_buffer_->GetSize() : 0; |
| 161 } | 165 } |
| 162 | 166 |
| 163 serial::SendError write_cancel_reason() const { return write_cancel_reason_; } | 167 serial::SendError write_cancel_reason() const { return write_cancel_reason_; } |
| 164 | 168 |
| 165 bool write_canceled() const { return write_canceled_; } | 169 bool write_canceled() const { return write_canceled_; } |
| 166 | 170 |
| 171 const serial::ConnectionOptions& options() const { return options_; } |
| 172 |
| 167 // Possibly fixes up a serial port path name in a platform-specific manner. | 173 // Possibly fixes up a serial port path name in a platform-specific manner. |
| 168 static std::string MaybeFixUpPortName(const std::string& port_name); | 174 static std::string MaybeFixUpPortName(const std::string& port_name); |
| 169 | 175 |
| 170 private: | 176 private: |
| 171 friend class base::RefCounted<SerialIoHandler>; | 177 friend class base::RefCounted<SerialIoHandler>; |
| 172 | 178 |
| 179 void MergeConnectionOptions(const serial::ConnectionOptions& options); |
| 180 |
| 173 // Continues an Open operation on the FILE thread. | 181 // Continues an Open operation on the FILE thread. |
| 174 void StartOpen(const std::string& port, | 182 void StartOpen(const std::string& port, |
| 175 scoped_refptr<base::MessageLoopProxy> io_message_loop); | 183 scoped_refptr<base::MessageLoopProxy> io_message_loop); |
| 176 | 184 |
| 177 // Finalizes an Open operation (continued from StartOpen) on the IO thread. | 185 // Finalizes an Open operation (continued from StartOpen) on the IO thread. |
| 178 void FinishOpen(base::File file); | 186 void FinishOpen(base::File file); |
| 179 | 187 |
| 180 void Close(); | 188 void Close(); |
| 181 | 189 |
| 182 // Continues a Close operation on the FILE thread. | 190 // Continues a Close operation on the FILE thread. |
| 183 static void DoClose(base::File port); | 191 static void DoClose(base::File port); |
| 184 | 192 |
| 185 // File for the opened serial device. This value is only modified from the IO | 193 // File for the opened serial device. This value is only modified from the IO |
| 186 // thread. | 194 // thread. |
| 187 base::File file_; | 195 base::File file_; |
| 188 | 196 |
| 197 // Currently applied connection options. |
| 198 serial::ConnectionOptions options_; |
| 199 |
| 189 scoped_ptr<WritableBuffer> pending_read_buffer_; | 200 scoped_ptr<WritableBuffer> pending_read_buffer_; |
| 190 serial::ReceiveError read_cancel_reason_; | 201 serial::ReceiveError read_cancel_reason_; |
| 191 bool read_canceled_; | 202 bool read_canceled_; |
| 192 | 203 |
| 193 scoped_ptr<ReadOnlyBuffer> pending_write_buffer_; | 204 scoped_ptr<ReadOnlyBuffer> pending_write_buffer_; |
| 194 serial::SendError write_cancel_reason_; | 205 serial::SendError write_cancel_reason_; |
| 195 bool write_canceled_; | 206 bool write_canceled_; |
| 196 | 207 |
| 197 // Callback to handle the completion of a pending Open() request. | 208 // Callback to handle the completion of a pending Open() request. |
| 198 OpenCompleteCallback open_complete_; | 209 OpenCompleteCallback open_complete_; |
| 199 | 210 |
| 200 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop_; | 211 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop_; |
| 201 // On Chrome OS, PermissionBrokerClient should be called on the UI thread. | 212 // On Chrome OS, PermissionBrokerClient should be called on the UI thread. |
| 202 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop_; | 213 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop_; |
| 203 | 214 |
| 204 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); | 215 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); |
| 205 }; | 216 }; |
| 206 | 217 |
| 207 } // namespace device | 218 } // namespace device |
| 208 | 219 |
| 209 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 220 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
| OLD | NEW |