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 Flush() const override
;
22 serial::DeviceControlSignalsPtr
GetControlSignals() const override
;
23 bool SetControlSignals(
24 const serial::HostControlSignals
& control_signals
) override
;
25 bool ConfigurePort(const serial::ConnectionOptions
& options
) 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
;
31 bool PostOpen() override
;
34 friend class SerialIoHandler
;
37 scoped_refptr
<base::MessageLoopProxy
> file_thread_message_loop
,
38 scoped_refptr
<base::MessageLoopProxy
> ui_thread_message_loop
);
39 ~SerialIoHandlerPosix() override
;
41 // base::MessageLoopForIO::Watcher implementation.
42 void OnFileCanWriteWithoutBlocking(int fd
) override
;
43 void OnFileCanReadWithoutBlocking(int fd
) override
;
45 void EnsureWatchingReads();
46 void EnsureWatchingWrites();
48 base::MessageLoopForIO::FileDescriptorWatcher file_read_watcher_
;
49 base::MessageLoopForIO::FileDescriptorWatcher file_write_watcher_
;
51 // Flags indicating if the message loop is watching the device for IO events.
52 bool is_watching_reads_
;
53 bool is_watching_writes_
;
55 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix
);
60 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_