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

Unified 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, 4 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/serial/serial_connection.cc
diff --git a/device/serial/serial_connection.cc b/device/serial/serial_connection.cc
index c59aad205f5e223fd26731d099e99cc79d766df9..0d3e4171c84b64a74c2f9807322448548ecff5bd 100644
--- a/device/serial/serial_connection.cc
+++ b/device/serial/serial_connection.cc
@@ -4,15 +4,38 @@
#include "device/serial/serial_connection.h"
+#include "base/bind.h"
+#include "device/serial/buffer.h"
+#include "device/serial/data_sink_receiver.h"
+#include "device/serial/data_source_sender.h"
#include "device/serial/serial_io_handler.h"
namespace device {
-SerialConnection::SerialConnection(scoped_refptr<SerialIoHandler> io_handler)
+SerialConnection::SerialConnection(
+ scoped_refptr<SerialIoHandler> io_handler,
+ mojo::InterfaceRequest<serial::DataSink> sink,
+ mojo::InterfaceRequest<serial::DataSource> source)
: io_handler_(io_handler) {
+ receiver_ = mojo::WeakBindToRequest(
+ new DataSinkReceiver(base::Bind(&SerialConnection::OnSendPipeReady,
+ base::Unretained(this)),
+ base::Bind(&SerialConnection::OnSendCancelled,
+ base::Unretained(this)),
+ base::Bind(base::DoNothing)),
+ &sink);
+ sender_ = mojo::WeakBindToRequest(
+ new DataSourceSender(base::Bind(&SerialConnection::OnReceivePipeReady,
+ base::Unretained(this)),
+ base::Bind(base::DoNothing)),
+ &source);
}
SerialConnection::~SerialConnection() {
+ receiver_->ShutDown();
+ sender_->ShutDown();
+ io_handler_->CancelRead(serial::RECEIVE_ERROR_DISCONNECTED);
+ io_handler_->CancelWrite(serial::SEND_ERROR_DISCONNECTED);
}
void SerialConnection::GetInfo(
@@ -41,4 +64,16 @@ void SerialConnection::Flush(const mojo::Callback<void(bool)>& callback) {
callback.Run(io_handler_->Flush());
}
+void SerialConnection::OnSendCancelled(int32_t error) {
+ io_handler_->CancelWrite(static_cast<serial::SendError>(error));
+}
+
+void SerialConnection::OnSendPipeReady(scoped_ptr<ReadOnlyBuffer> buffer) {
+ io_handler_->Write(buffer.Pass());
+}
+
+void SerialConnection::OnReceivePipeReady(scoped_ptr<WritableBuffer> buffer) {
+ io_handler_->Read(buffer.Pass());
+}
+
} // namespace device
« 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