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
3 // found in the LICENSE file.
5 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
8 #include "base/message_loop/message_loop.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "device/serial/serial_io_handler.h"
15 class SerialIoHandlerPosix
: public SerialIoHandler
,
16 public base::MessageLoopForIO::Watcher
{
18 // SerialIoHandler impl.
19 void ReadImpl() override
;
20 void WriteImpl() override
;
21 void CancelReadImpl() override
;
22 void CancelWriteImpl() override
;
23 bool ConfigurePortImpl() override
;
24 bool Flush() const override
;
25 serial::DeviceControlSignalsPtr
GetControlSignals() const override
;
26 bool SetControlSignals(
27 const serial::HostControlSignals
& control_signals
) override
;
28 serial::ConnectionInfoPtr
GetPortInfo() const override
;
29 bool SetBreak() override
;
30 bool ClearBreak() override
;
32 const std::string
& port
,
33 scoped_refptr
<base::SingleThreadTaskRunner
> file_task_runner
,
34 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
) override
;
37 friend class SerialIoHandler
;
40 scoped_refptr
<base::SingleThreadTaskRunner
> file_thread_task_runner
,
41 scoped_refptr
<base::SingleThreadTaskRunner
> ui_thread_task_runner
);
42 ~SerialIoHandlerPosix() override
;
44 // base::MessageLoopForIO::Watcher implementation.
45 void OnFileCanWriteWithoutBlocking(int fd
) override
;
46 void OnFileCanReadWithoutBlocking(int fd
) override
;
48 void EnsureWatchingReads();
49 void EnsureWatchingWrites();
51 base::MessageLoopForIO::FileDescriptorWatcher file_read_watcher_
;
52 base::MessageLoopForIO::FileDescriptorWatcher file_write_watcher_
;
54 // Flags indicating if the message loop is watching the device for IO events.
55 bool is_watching_reads_
;
56 bool is_watching_writes_
;
58 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix
);
63 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_