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 "device/serial/serial_io_handler.h"
13 class SerialIoHandlerPosix
: public SerialIoHandler
,
14 public base::MessageLoopForIO::Watcher
{
16 // SerialIoHandler impl.
17 void ReadImpl() override
;
18 void WriteImpl() override
;
19 void CancelReadImpl() override
;
20 void CancelWriteImpl() override
;
21 bool ConfigurePortImpl() override
;
22 bool Flush() const override
;
23 serial::DeviceControlSignalsPtr
GetControlSignals() const override
;
24 bool SetControlSignals(
25 const serial::HostControlSignals
& control_signals
) override
;
26 serial::ConnectionInfoPtr
GetPortInfo() const override
;
28 const std::string
& port
,
29 scoped_refptr
<base::MessageLoopProxy
> file_message_loop
,
30 scoped_refptr
<base::MessageLoopProxy
> ui_message_loop
) override
;
33 friend class SerialIoHandler
;
36 scoped_refptr
<base::MessageLoopProxy
> file_thread_message_loop
,
37 scoped_refptr
<base::MessageLoopProxy
> ui_thread_message_loop
);
38 ~SerialIoHandlerPosix() override
;
40 // base::MessageLoopForIO::Watcher implementation.
41 void OnFileCanWriteWithoutBlocking(int fd
) override
;
42 void OnFileCanReadWithoutBlocking(int fd
) override
;
44 void EnsureWatchingReads();
45 void EnsureWatchingWrites();
47 base::MessageLoopForIO::FileDescriptorWatcher file_read_watcher_
;
48 base::MessageLoopForIO::FileDescriptorWatcher file_write_watcher_
;
50 // Flags indicating if the message loop is watching the device for IO events.
51 bool is_watching_reads_
;
52 bool is_watching_writes_
;
54 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix
);
59 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_