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 #include "device/serial/test_serial_io_handler.h"
8 #include "device/serial/serial.mojom.h"
12 TestSerialIoHandler::TestSerialIoHandler()
13 : SerialIoHandler(NULL
),
20 scoped_refptr
<SerialIoHandler
> TestSerialIoHandler::Create() {
21 return scoped_refptr
<SerialIoHandler
>(new TestSerialIoHandler
);
24 void TestSerialIoHandler::Open(const std::string
& port
,
25 const OpenCompleteCallback
& callback
) {
31 bool TestSerialIoHandler::ConfigurePort(
32 const serial::ConnectionOptions
& options
) {
34 info_
.bitrate
= options
.bitrate
;
35 if (options
.data_bits
!= serial::DATA_BITS_NONE
)
36 info_
.data_bits
= options
.data_bits
;
37 if (options
.parity_bit
!= serial::PARITY_BIT_NONE
)
38 info_
.parity_bit
= options
.parity_bit
;
39 if (options
.stop_bits
!= serial::STOP_BITS_NONE
)
40 info_
.stop_bits
= options
.stop_bits
;
41 if (options
.has_cts_flow_control
)
42 info_
.cts_flow_control
= options
.cts_flow_control
;
46 void TestSerialIoHandler::ReadImpl() {
49 void TestSerialIoHandler::CancelReadImpl() {
50 QueueReadCompleted(0, read_cancel_reason());
53 void TestSerialIoHandler::WriteImpl() {
54 DCHECK(pending_read_buffer());
55 DCHECK_LE(pending_write_buffer_len(), pending_read_buffer_len());
56 memcpy(pending_read_buffer()->data(),
57 pending_write_buffer()->data(),
58 pending_write_buffer_len());
59 QueueReadCompleted(pending_write_buffer_len(), serial::RECEIVE_ERROR_NONE
);
60 QueueWriteCompleted(pending_write_buffer_len(), serial::SEND_ERROR_NONE
);
63 void TestSerialIoHandler::CancelWriteImpl() {
64 QueueWriteCompleted(0, write_cancel_reason());
67 serial::DeviceControlSignalsPtr
TestSerialIoHandler::GetControlSignals() const {
68 serial::DeviceControlSignalsPtr
signals(serial::DeviceControlSignals::New());
69 *signals
= device_control_signals_
;
70 return signals
.Pass();
73 serial::ConnectionInfoPtr
TestSerialIoHandler::GetPortInfo() const {
74 serial::ConnectionInfoPtr
info(serial::ConnectionInfo::New());
79 bool TestSerialIoHandler::Flush() const {
84 bool TestSerialIoHandler::SetControlSignals(
85 const serial::HostControlSignals
& signals
) {
93 TestSerialIoHandler::~TestSerialIoHandler() {