Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: device/serial/serial_connection.cc

Issue 488363002: Implement the host side of serial connection I/O on data pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win x64 build Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/serial/serial_connection.h ('k') | device/serial/serial_connection_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/serial/serial_connection.h" 5 #include "device/serial/serial_connection.h"
6 6
7 #include "base/bind.h"
8 #include "device/serial/buffer.h"
9 #include "device/serial/data_sink_receiver.h"
10 #include "device/serial/data_source_sender.h"
7 #include "device/serial/serial_io_handler.h" 11 #include "device/serial/serial_io_handler.h"
8 12
9 namespace device { 13 namespace device {
10 14
11 SerialConnection::SerialConnection(scoped_refptr<SerialIoHandler> io_handler) 15 SerialConnection::SerialConnection(
16 scoped_refptr<SerialIoHandler> io_handler,
17 mojo::InterfaceRequest<serial::DataSink> sink,
18 mojo::InterfaceRequest<serial::DataSource> source)
12 : io_handler_(io_handler) { 19 : io_handler_(io_handler) {
20 receiver_ = mojo::WeakBindToRequest(
21 new DataSinkReceiver(base::Bind(&SerialConnection::OnSendPipeReady,
22 base::Unretained(this)),
23 base::Bind(&SerialConnection::OnSendCancelled,
24 base::Unretained(this)),
25 base::Bind(base::DoNothing)),
26 &sink);
27 sender_ = mojo::WeakBindToRequest(
28 new DataSourceSender(base::Bind(&SerialConnection::OnReceivePipeReady,
29 base::Unretained(this)),
30 base::Bind(base::DoNothing)),
31 &source);
13 } 32 }
14 33
15 SerialConnection::~SerialConnection() { 34 SerialConnection::~SerialConnection() {
35 receiver_->ShutDown();
36 sender_->ShutDown();
37 io_handler_->CancelRead(serial::RECEIVE_ERROR_DISCONNECTED);
38 io_handler_->CancelWrite(serial::SEND_ERROR_DISCONNECTED);
16 } 39 }
17 40
18 void SerialConnection::GetInfo( 41 void SerialConnection::GetInfo(
19 const mojo::Callback<void(serial::ConnectionInfoPtr)>& callback) { 42 const mojo::Callback<void(serial::ConnectionInfoPtr)>& callback) {
20 callback.Run(io_handler_->GetPortInfo()); 43 callback.Run(io_handler_->GetPortInfo());
21 } 44 }
22 45
23 void SerialConnection::SetOptions(serial::ConnectionOptionsPtr options, 46 void SerialConnection::SetOptions(serial::ConnectionOptionsPtr options,
24 const mojo::Callback<void(bool)>& callback) { 47 const mojo::Callback<void(bool)>& callback) {
25 callback.Run(io_handler_->ConfigurePort(*options)); 48 callback.Run(io_handler_->ConfigurePort(*options));
26 io_handler_->CancelRead(device::serial::RECEIVE_ERROR_NONE); 49 io_handler_->CancelRead(device::serial::RECEIVE_ERROR_NONE);
27 } 50 }
28 51
29 void SerialConnection::SetControlSignals( 52 void SerialConnection::SetControlSignals(
30 serial::HostControlSignalsPtr signals, 53 serial::HostControlSignalsPtr signals,
31 const mojo::Callback<void(bool)>& callback) { 54 const mojo::Callback<void(bool)>& callback) {
32 callback.Run(io_handler_->SetControlSignals(*signals)); 55 callback.Run(io_handler_->SetControlSignals(*signals));
33 } 56 }
34 57
35 void SerialConnection::GetControlSignals( 58 void SerialConnection::GetControlSignals(
36 const mojo::Callback<void(serial::DeviceControlSignalsPtr)>& callback) { 59 const mojo::Callback<void(serial::DeviceControlSignalsPtr)>& callback) {
37 callback.Run(io_handler_->GetControlSignals()); 60 callback.Run(io_handler_->GetControlSignals());
38 } 61 }
39 62
40 void SerialConnection::Flush(const mojo::Callback<void(bool)>& callback) { 63 void SerialConnection::Flush(const mojo::Callback<void(bool)>& callback) {
41 callback.Run(io_handler_->Flush()); 64 callback.Run(io_handler_->Flush());
42 } 65 }
43 66
67 void SerialConnection::OnSendCancelled(int32_t error) {
68 io_handler_->CancelWrite(static_cast<serial::SendError>(error));
69 }
70
71 void SerialConnection::OnSendPipeReady(scoped_ptr<ReadOnlyBuffer> buffer) {
72 io_handler_->Write(buffer.Pass());
73 }
74
75 void SerialConnection::OnReceivePipeReady(scoped_ptr<WritableBuffer> buffer) {
76 io_handler_->Read(buffer.Pass());
77 }
78
44 } // namespace device 79 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_connection.h ('k') | device/serial/serial_connection_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698