| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "device/serial/buffer.h" | 20 #include "device/serial/buffer.h" |
| 21 #include "device/serial/serial.mojom.h" | 21 #include "device/serial/serial.mojom.h" |
| 22 | 22 |
| 23 namespace dbus { | |
| 24 class FileDescriptor; | |
| 25 } | |
| 26 | |
| 27 namespace device { | 23 namespace device { |
| 28 | 24 |
| 29 // Provides a simplified interface for performing asynchronous I/O on serial | 25 // Provides a simplified interface for performing asynchronous I/O on serial |
| 30 // devices by hiding platform-specific MessageLoop interfaces. Pending I/O | 26 // devices by hiding platform-specific MessageLoop interfaces. Pending I/O |
| 31 // 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 |
| 32 // doesn't disappear out from under the OS. | 28 // doesn't disappear out from under the OS. |
| 33 class SerialIoHandler : public base::NonThreadSafe, | 29 class SerialIoHandler : public base::NonThreadSafe, |
| 34 public base::RefCounted<SerialIoHandler> { | 30 public base::RefCounted<SerialIoHandler> { |
| 35 public: | 31 public: |
| 36 // Constructs an instance of some platform-specific subclass. | 32 // Constructs an instance of some platform-specific subclass. |
| 37 static scoped_refptr<SerialIoHandler> Create( | 33 static scoped_refptr<SerialIoHandler> Create( |
| 38 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 34 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 39 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); | 35 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); |
| 40 | 36 |
| 41 typedef base::Callback<void(bool success)> OpenCompleteCallback; | 37 typedef base::Callback<void(bool success)> OpenCompleteCallback; |
| 42 | 38 |
| 43 // Initiates an asynchronous Open of the device. | 39 // Initiates an asynchronous Open of the device. |
| 44 virtual void Open(const std::string& port, | 40 virtual void Open(const std::string& port, |
| 45 const serial::ConnectionOptions& options, | 41 const serial::ConnectionOptions& options, |
| 46 const OpenCompleteCallback& callback); | 42 const OpenCompleteCallback& callback); |
| 47 | 43 |
| 48 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
| 49 // Signals that the port has been opened. | 45 // Signals that the port has been opened. |
| 50 void OnPathOpened( | 46 void OnPathOpened( |
| 51 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | |
| 52 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 47 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 53 dbus::FileDescriptor fd); | 48 base::ScopedFD fd); |
| 54 | 49 |
| 55 // Signals that the permission broker failed to open the port. | 50 // Signals that the permission broker failed to open the port. |
| 56 void OnPathOpenError( | 51 void OnPathOpenError( |
| 57 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 52 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 58 const std::string& error_name, | 53 const std::string& error_name, |
| 59 const std::string& error_message); | 54 const std::string& error_message); |
| 60 | 55 |
| 61 // Validates the file descriptor provided by the permission broker. | |
| 62 void ValidateOpenPort( | |
| 63 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | |
| 64 dbus::FileDescriptor fd); | |
| 65 | |
| 66 // Reports the open error from the permission broker. | 56 // Reports the open error from the permission broker. |
| 67 void ReportPathOpenError(const std::string& error_name, | 57 void ReportPathOpenError(const std::string& error_name, |
| 68 const std::string& error_message); | 58 const std::string& error_message); |
| 69 #endif // defined(OS_CHROMEOS) | 59 #endif // defined(OS_CHROMEOS) |
| 70 | 60 |
| 71 // Performs an async Read operation. Behavior is undefined if this is called | 61 // Performs an async Read operation. Behavior is undefined if this is called |
| 72 // while a Read is already pending. Otherwise, the Done or DoneWithError | 62 // while a Read is already pending. Otherwise, the Done or DoneWithError |
| 73 // method on |buffer| will eventually be called with a result. | 63 // method on |buffer| will eventually be called with a result. |
| 74 void Read(std::unique_ptr<WritableBuffer> buffer); | 64 void Read(std::unique_ptr<WritableBuffer> buffer); |
| 75 | 65 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; | 246 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; |
| 257 | 247 |
| 258 std::string port_; | 248 std::string port_; |
| 259 | 249 |
| 260 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); | 250 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); |
| 261 }; | 251 }; |
| 262 | 252 |
| 263 } // namespace device | 253 } // namespace device |
| 264 | 254 |
| 265 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 255 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
| OLD | NEW |