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
;
36 serial::ConnectionInfo
* connection_info() { return &info_
; }
37 serial::DeviceControlSignals
* device_control_signals() {
38 return &device_control_signals_
;
40 bool dtr() { return dtr_
; }
41 bool rts() { return rts_
; }
42 int flushes() { return flushes_
; }
43 // This callback will be called when this IoHandler processes its next write,
44 // instead of the normal behavior of echoing the data to reads.
45 void set_send_callback(const base::Closure
& callback
) {
46 send_callback_
= callback
;
50 ~TestSerialIoHandler() override
;
54 serial::ConnectionInfo info_
;
55 serial::DeviceControlSignals device_control_signals_
;
60 base::Closure send_callback_
;
62 DISALLOW_COPY_AND_ASSIGN(TestSerialIoHandler
);
67 #endif // DEVICE_SERIAL_TEST_SERIAL_IO_HANDLER_H_