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

Unified Diff: device/serial/data_source_sender.h

Issue 437933002: Add data pipe wrappers to be used to implement serial receive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serial-buffer
Patch Set: address comments 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
Index: device/serial/data_source_sender.h
diff --git a/device/serial/data_source_sender.h b/device/serial/data_source_sender.h
new file mode 100644
index 0000000000000000000000000000000000000000..31505c1763a8098a60a95cf7b8a9cd18f3a5e0a0
--- /dev/null
+++ b/device/serial/data_source_sender.h
@@ -0,0 +1,70 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_SERIAL_DATA_SOURCE_SENDER_H_
+#define DEVICE_SERIAL_DATA_SOURCE_SENDER_H_
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "device/serial/buffer.h"
+#include "device/serial/data_stream.mojom.h"
+#include "mojo/public/cpp/system/data_pipe.h"
+
+namespace device {
+
+class AsyncWaiter;
+
+// A DataSourceSender is an interface between a source of data and a data pipe.
+class DataSourceSender : public base::RefCounted<DataSourceSender>,
+ public mojo::InterfaceImpl<serial::DataSource> {
+ public:
+ typedef base::Callback<void(scoped_ptr<WritableBuffer>)> ReadyCallback;
+ typedef base::Callback<void()> ErrorCallback;
+
+ // Constructs a DataSourceSender. Whenever the pipe is ready for writing, the
+ // |ready_callback| will be called with the WritableBuffer to be filled.
+ // |ready_callback| will not be called again until the previous WritableBuffer
+ // is destroyed. If a connection error occurs, |error_callback| will be
+ // called and the DataSourceSender will act as if ShutDown() had been called.
+ DataSourceSender(const ReadyCallback& ready_callback,
+ const ErrorCallback& error_callback);
+
+ // Shuts down this DataSourceSender. After shut down, |ready_callback| and
+ // |error_callback| will never be called.
+ void ShutDown();
+
+ private:
+ friend class base::RefCounted<DataSourceSender>;
+ class PendingSend;
+
+ virtual ~DataSourceSender();
+
+ // mojo::InterfaceImpl<serial::DataSourceSender> overrides.
+ virtual void Init(mojo::ScopedDataPipeProducerHandle handle) OVERRIDE;
+ virtual void Resume() OVERRIDE;
+ virtual void OnConnectionError() OVERRIDE;
+
+ void StartWaiting();
+ void OnDoneWaiting(MojoResult result);
+
+ void Done(uint32_t bytes_produced);
+ void DoneWithError(uint32_t bytes_produced, int32_t error);
+ void DoneInternal(uint32_t bytes_produced);
+ bool HandleMojoResult(MojoResult result);
+ void DispatchFatalError();
+
+ mojo::ScopedDataPipeProducerHandle handle_;
+ const ReadyCallback ready_callback_;
+ const ErrorCallback error_callback_;
+ scoped_ptr<PendingSend> send_;
+ scoped_ptr<AsyncWaiter> waiter_;
+ uint32_t bytes_sent_;
+ bool shut_down_;
+
+ DISALLOW_COPY_AND_ASSIGN(DataSourceSender);
+};
+
+} // namespace device
+
+#endif // DEVICE_SERIAL_DATA_SOURCE_SENDER_H_

Powered by Google App Engine
This is Rietveld 408576698