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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef DEVICE_SERIAL_DATA_SOURCE_SENDER_H_
6 #define DEVICE_SERIAL_DATA_SOURCE_SENDER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "device/serial/buffer.h"
11 #include "device/serial/data_stream.mojom.h"
12 #include "mojo/public/cpp/system/data_pipe.h"
13
14 namespace device {
15
16 class AsyncWaiter;
17
18 // A DataSourceSender is an interface between a source of data and a data pipe.
19 class DataSourceSender : public base::RefCounted<DataSourceSender>,
20 public mojo::InterfaceImpl<serial::DataSource> {
21 public:
22 typedef base::Callback<void(scoped_ptr<WritableBuffer>)> ReadyCallback;
23 typedef base::Callback<void()> ErrorCallback;
24
25 // Constructs a DataSourceSender. Whenever the pipe is ready for writing, the
26 // |ready_callback| will be called with the WritableBuffer to be filled.
27 // |ready_callback| will not be called again until the previous WritableBuffer
28 // is destroyed. If a connection error occurs, |error_callback| will be
29 // called and the DataSourceSender will act as if ShutDown() had been called.
30 DataSourceSender(const ReadyCallback& ready_callback,
31 const ErrorCallback& error_callback);
32
33 // Shuts down this DataSourceSender. After shut down, |ready_callback| and
34 // |error_callback| will never be called.
35 void ShutDown();
36
37 private:
38 friend class base::RefCounted<DataSourceSender>;
39 class PendingSend;
40
41 virtual ~DataSourceSender();
42
43 // mojo::InterfaceImpl<serial::DataSourceSender> overrides.
44 virtual void Init(mojo::ScopedDataPipeProducerHandle handle) OVERRIDE;
45 virtual void Resume() OVERRIDE;
46 virtual void OnConnectionError() OVERRIDE;
47
48 void StartWaiting();
49 void OnDoneWaiting(MojoResult result);
50
51 void Done(uint32_t bytes_written);
52 void DoneWithError(uint32_t bytes_written, int32_t error);
53 void DoneInternal(uint32_t bytes_written);
54 void DispatchFatalError();
55
56 mojo::ScopedDataPipeProducerHandle handle_;
57 ReadyCallback ready_callback_;
58 ErrorCallback error_callback_;
59 scoped_ptr<PendingSend> pending_send_;
60 scoped_ptr<AsyncWaiter> waiter_;
61 uint32_t bytes_sent_;
62 bool shut_down_;
63
64 DISALLOW_COPY_AND_ASSIGN(DataSourceSender);
65 };
66
67 } // namespace device
68
69 #endif // DEVICE_SERIAL_DATA_SOURCE_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698