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_TEST_SERIAL_IO_HANDLER_H_
6 #define DEVICE_SERIAL_TEST_SERIAL_IO_HANDLER_H_
10 #include "base/callback.h"
11 #include "device/serial/serial.mojom.h"
12 #include "device/serial/serial_io_handler.h"
16 class TestSerialIoHandler
: public SerialIoHandler
{
18 TestSerialIoHandler();
20 static scoped_refptr
<SerialIoHandler
> Create();
22 // SerialIoHandler overrides.
23 void Open(const std::string
& port
,
24 const serial::ConnectionOptions
& options
,
25 const OpenCompleteCallback
& callback
) override
;
26 void ReadImpl() override
;
27 void CancelReadImpl() override
;
28 void WriteImpl() override
;
29 void CancelWriteImpl() override
;
30 bool ConfigurePortImpl() override
;
31 serial::DeviceControlSignalsPtr
GetControlSignals() const override
;
32 serial::ConnectionInfoPtr
GetPortInfo() const override
;
33 bool Flush() const override
;
34 bool SetControlSignals(const serial::HostControlSignals
& signals
) override
;
35 bool SetBreak() override
;
36 bool ClearBreak() override
;
38 serial::ConnectionInfo
* connection_info() { return &info_
; }
39 serial::DeviceControlSignals
* device_control_signals() {
40 return &device_control_signals_
;
42 bool dtr() { return dtr_
; }
43 bool rts() { return rts_
; }
44 int flushes() { return flushes_
; }
45 // This callback will be called when this IoHandler processes its next write,
46 // instead of the normal behavior of echoing the data to reads.
47 void set_send_callback(const base::Closure
& callback
) {
48 send_callback_
= callback
;
52 ~TestSerialIoHandler() override
;
56 serial::ConnectionInfo info_
;
57 serial::DeviceControlSignals device_control_signals_
;
62 base::Closure send_callback_
;
64 DISALLOW_COPY_AND_ASSIGN(TestSerialIoHandler
);
69 #endif // DEVICE_SERIAL_TEST_SERIAL_IO_HANDLER_H_