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_SINK_RECEIVER_H_ | 5 #ifndef DEVICE_SERIAL_DATA_SINK_RECEIVER_H_ |
6 #define DEVICE_SERIAL_DATA_SINK_RECEIVER_H_ | 6 #define DEVICE_SERIAL_DATA_SINK_RECEIVER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "device/serial/buffer.h" | 14 #include "device/serial/buffer.h" |
15 #include "device/serial/data_stream.mojom.h" | 15 #include "device/serial/data_stream.mojom.h" |
16 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" | 16 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" |
17 | 17 |
18 namespace device { | 18 namespace device { |
19 | 19 |
20 class DataSinkReceiver : public base::RefCounted<DataSinkReceiver>, | 20 class DataSinkReceiver : public base::RefCounted<DataSinkReceiver>, |
21 public serial::DataSink, | 21 public serial::DataSink { |
22 public mojo::ErrorHandler { | |
23 public: | 22 public: |
24 typedef base::Callback<void(scoped_ptr<ReadOnlyBuffer>)> ReadyCallback; | 23 typedef base::Callback<void(scoped_ptr<ReadOnlyBuffer>)> ReadyCallback; |
25 typedef base::Callback<void(int32_t error)> CancelCallback; | 24 typedef base::Callback<void(int32_t error)> CancelCallback; |
26 typedef base::Callback<void()> ErrorCallback; | 25 typedef base::Callback<void()> ErrorCallback; |
27 | 26 |
28 // Constructs a DataSinkReceiver. Whenever the pipe is ready for reading, the | 27 // Constructs a DataSinkReceiver. Whenever the pipe is ready for reading, the |
29 // |ready_callback| will be called with the ReadOnlyBuffer to read. | 28 // |ready_callback| will be called with the ReadOnlyBuffer to read. |
30 // |ready_callback| will not be called again until the previous ReadOnlyBuffer | 29 // |ready_callback| will not be called again until the previous ReadOnlyBuffer |
31 // is destroyed. If a connection error occurs, |error_callback| will be called | 30 // is destroyed. If a connection error occurs, |error_callback| will be called |
32 // and the DataSinkReceiver will act as if ShutDown() had been called. If | 31 // and the DataSinkReceiver will act as if ShutDown() had been called. If |
(...skipping 14 matching lines...) Expand all Loading... |
47 friend class base::RefCounted<DataSinkReceiver>; | 46 friend class base::RefCounted<DataSinkReceiver>; |
48 | 47 |
49 ~DataSinkReceiver() override; | 48 ~DataSinkReceiver() override; |
50 | 49 |
51 // mojo::InterfaceImpl<serial::DataSink> overrides. | 50 // mojo::InterfaceImpl<serial::DataSink> overrides. |
52 void Cancel(int32_t error) override; | 51 void Cancel(int32_t error) override; |
53 void OnData(mojo::Array<uint8_t> data, | 52 void OnData(mojo::Array<uint8_t> data, |
54 const mojo::Callback<void(uint32_t, int32_t)>& callback) override; | 53 const mojo::Callback<void(uint32_t, int32_t)>& callback) override; |
55 void ClearError() override; | 54 void ClearError() override; |
56 | 55 |
57 void OnConnectionError() override; | 56 void OnConnectionError(); |
58 | 57 |
59 // Dispatches data to |ready_callback_|. | 58 // Dispatches data to |ready_callback_|. |
60 void RunReadyCallback(); | 59 void RunReadyCallback(); |
61 | 60 |
62 // Reports a successful read of |bytes_read|. | 61 // Reports a successful read of |bytes_read|. |
63 void Done(uint32_t bytes_read); | 62 void Done(uint32_t bytes_read); |
64 | 63 |
65 // Reports a partially successful or unsuccessful read of |bytes_read| | 64 // Reports a partially successful or unsuccessful read of |bytes_read| |
66 // with an error of |error|. | 65 // with an error of |error|. |
67 void DoneWithError(uint32_t bytes_read, int32_t error); | 66 void DoneWithError(uint32_t bytes_read, int32_t error); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 bool shut_down_; | 100 bool shut_down_; |
102 | 101 |
103 base::WeakPtrFactory<DataSinkReceiver> weak_factory_; | 102 base::WeakPtrFactory<DataSinkReceiver> weak_factory_; |
104 | 103 |
105 DISALLOW_COPY_AND_ASSIGN(DataSinkReceiver); | 104 DISALLOW_COPY_AND_ASSIGN(DataSinkReceiver); |
106 }; | 105 }; |
107 | 106 |
108 } // namespace device | 107 } // namespace device |
109 | 108 |
110 #endif // DEVICE_SERIAL_DATA_SINK_RECEIVER_H_ | 109 #endif // DEVICE_SERIAL_DATA_SINK_RECEIVER_H_ |
OLD | NEW |