OLD | NEW |
---|---|
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 #ifndef DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ | 5 #ifndef DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ |
6 #define DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ | 6 #define DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "device/serial/buffer.h" | 13 #include "device/serial/buffer.h" |
14 #include "device/serial/data_stream.mojom.h" | 14 #include "device/serial/data_stream.mojom.h" |
15 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" | 15 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" |
16 | 16 |
17 namespace device { | 17 namespace device { |
18 | 18 |
19 // A DataSourceSender is an interface between a source of data and a | 19 // A DataSourceSender is an interface between a source of data and a |
20 // DataSourceClient. | 20 // DataSourceClient. |
21 class DataSourceSender : public base::RefCounted<DataSourceSender>, | 21 class DataSourceSender : public base::RefCounted<DataSourceSender>, |
22 public serial::DataSource, | 22 public serial::DataSource { |
23 public mojo::ErrorHandler { | |
24 public: | 23 public: |
25 typedef base::Callback<void(scoped_ptr<WritableBuffer>)> ReadyCallback; | 24 typedef base::Callback<void(scoped_ptr<WritableBuffer>)> ReadyCallback; |
26 typedef base::Callback<void()> ErrorCallback; | 25 typedef base::Callback<void()> ErrorCallback; |
27 | 26 |
28 // Constructs a DataSourceSender. Whenever the pipe is ready for writing, the | 27 // Constructs a DataSourceSender. Whenever the pipe is ready for writing, the |
29 // |ready_callback| will be called with the WritableBuffer to be filled. | 28 // |ready_callback| will be called with the WritableBuffer to be filled. |
30 // |ready_callback| will not be called again until the previous WritableBuffer | 29 // |ready_callback| will not be called again until the previous WritableBuffer |
31 // is destroyed. If a connection error occurs, |error_callback| will be | 30 // is destroyed. If a connection error occurs, |error_callback| will be |
32 // called and the DataSourceSender will act as if ShutDown() had been called. | 31 // called and the DataSourceSender will act as if ShutDown() had been called. |
33 DataSourceSender(mojo::InterfaceRequest<serial::DataSource> source, | 32 DataSourceSender(mojo::InterfaceRequest<serial::DataSource> source, |
34 mojo::InterfacePtr<serial::DataSourceClient> client, | 33 mojo::InterfacePtr<serial::DataSourceClient> client, |
35 const ReadyCallback& ready_callback, | 34 const ReadyCallback& ready_callback, |
36 const ErrorCallback& error_callback); | 35 const ErrorCallback& error_callback); |
37 | 36 |
38 // Shuts down this DataSourceSender. After shut down, |ready_callback| and | 37 // Shuts down this DataSourceSender. After shut down, |ready_callback| and |
39 // |error_callback| will never be called. | 38 // |error_callback| will never be called. |
40 void ShutDown(); | 39 void ShutDown(); |
41 | 40 |
42 private: | 41 private: |
43 friend class base::RefCounted<DataSourceSender>; | 42 friend class base::RefCounted<DataSourceSender>; |
44 class PendingSend; | 43 class PendingSend; |
45 | 44 |
46 ~DataSourceSender() override; | 45 ~DataSourceSender() override; |
47 | 46 |
48 // mojo::InterfaceImpl<serial::DataSourceSender> overrides. | 47 // mojo::InterfaceImpl<serial::DataSourceSender> overrides. |
49 void Init(uint32_t buffer_size) override; | 48 void Init(uint32_t buffer_size) override; |
50 void Resume() override; | 49 void Resume() override; |
51 void ReportBytesReceived(uint32_t bytes_sent) override; | 50 void ReportBytesReceived(uint32_t bytes_sent) override; |
52 // Invoked in the event of a connection error. Calls DispatchFatalError(). | 51 // mojo error handler |
Reilly Grant (use Gerrit)
2015/07/06 23:03:14
Can you preserve "Calls DispatchFatalError()."?
tanay.c
2015/07/07 05:29:12
Done. PTAL.
| |
53 void OnConnectionError() override; | 52 void OnConnectionError(); |
54 | 53 |
55 // Gets more data to send to the DataSourceClient. | 54 // Gets more data to send to the DataSourceClient. |
56 void GetMoreData(); | 55 void GetMoreData(); |
57 | 56 |
58 // Invoked to pass |data| obtained in response to |ready_callback_|. | 57 // Invoked to pass |data| obtained in response to |ready_callback_|. |
59 void Done(const std::vector<char>& data); | 58 void Done(const std::vector<char>& data); |
60 | 59 |
61 // Invoked to pass |data| and |error| obtained in response to | 60 // Invoked to pass |data| and |error| obtained in response to |
62 // |ready_callback_|. | 61 // |ready_callback_|. |
63 void DoneWithError(const std::vector<char>& data, int32_t error); | 62 void DoneWithError(const std::vector<char>& data, int32_t error); |
(...skipping 26 matching lines...) Expand all Loading... | |
90 bool shut_down_; | 89 bool shut_down_; |
91 | 90 |
92 base::WeakPtrFactory<DataSourceSender> weak_factory_; | 91 base::WeakPtrFactory<DataSourceSender> weak_factory_; |
93 | 92 |
94 DISALLOW_COPY_AND_ASSIGN(DataSourceSender); | 93 DISALLOW_COPY_AND_ASSIGN(DataSourceSender); |
95 }; | 94 }; |
96 | 95 |
97 } // namespace device | 96 } // namespace device |
98 | 97 |
99 #endif // DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ | 98 #endif // DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ |
OLD | NEW |