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_RECEIVER_H_ | 5 #ifndef DEVICE_SERIAL_DATA_RECEIVER_H_ |
6 #define DEVICE_SERIAL_DATA_RECEIVER_H_ | 6 #define DEVICE_SERIAL_DATA_RECEIVER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 public serial::DataSourceClient, | 22 public serial::DataSourceClient, |
23 public mojo::ErrorHandler { | 23 public mojo::ErrorHandler { |
24 public: | 24 public: |
25 typedef base::Callback<void(scoped_ptr<ReadOnlyBuffer>)> ReceiveDataCallback; | 25 typedef base::Callback<void(scoped_ptr<ReadOnlyBuffer>)> ReceiveDataCallback; |
26 typedef base::Callback<void(int32_t error)> ReceiveErrorCallback; | 26 typedef base::Callback<void(int32_t error)> ReceiveErrorCallback; |
27 | 27 |
28 // Constructs a DataReceiver to receive data from |source|, using a buffer | 28 // Constructs a DataReceiver to receive data from |source|, using a buffer |
29 // size of |buffer_size|, with connection errors reported as | 29 // size of |buffer_size|, with connection errors reported as |
30 // |fatal_error_value|. | 30 // |fatal_error_value|. |
31 DataReceiver(mojo::InterfacePtr<serial::DataSource> source, | 31 DataReceiver(mojo::InterfacePtr<serial::DataSource> source, |
| 32 mojo::InterfaceRequest<serial::DataSourceClient> client, |
32 uint32_t buffer_size, | 33 uint32_t buffer_size, |
33 int32_t fatal_error_value); | 34 int32_t fatal_error_value); |
34 | 35 |
35 // Begins a receive operation. If this returns true, exactly one of |callback| | 36 // Begins a receive operation. If this returns true, exactly one of |callback| |
36 // and |error_callback| will eventually be called. If there is already a | 37 // and |error_callback| will eventually be called. If there is already a |
37 // receive in progress or there has been a connection error, this will have no | 38 // receive in progress or there has been a connection error, this will have no |
38 // effect and return false. | 39 // effect and return false. |
39 bool Receive(const ReceiveDataCallback& callback, | 40 bool Receive(const ReceiveDataCallback& callback, |
40 const ReceiveErrorCallback& error_callback); | 41 const ReceiveErrorCallback& error_callback); |
41 | 42 |
(...skipping 23 matching lines...) Expand all Loading... |
65 // |waiter_| is used to wait until it is ready. If an error occurs in reading | 66 // |waiter_| is used to wait until it is ready. If an error occurs in reading |
66 // |handle_|, ShutDown() is called. | 67 // |handle_|, ShutDown() is called. |
67 void ReceiveInternal(); | 68 void ReceiveInternal(); |
68 | 69 |
69 // Called when we encounter a fatal error. If a receive is in progress, | 70 // Called when we encounter a fatal error. If a receive is in progress, |
70 // |fatal_error_value_| will be reported to the user. | 71 // |fatal_error_value_| will be reported to the user. |
71 void ShutDown(); | 72 void ShutDown(); |
72 | 73 |
73 // The control connection to the data source. | 74 // The control connection to the data source. |
74 mojo::InterfacePtr<serial::DataSource> source_; | 75 mojo::InterfacePtr<serial::DataSource> source_; |
| 76 mojo::Binding<serial::DataSourceClient> client_; |
75 | 77 |
76 // The error value to report in the event of a fatal error. | 78 // The error value to report in the event of a fatal error. |
77 const int32_t fatal_error_value_; | 79 const int32_t fatal_error_value_; |
78 | 80 |
79 // Whether we have encountered a fatal error and shut down. | 81 // Whether we have encountered a fatal error and shut down. |
80 bool shut_down_; | 82 bool shut_down_; |
81 | 83 |
82 // The current pending receive operation if there is one. | 84 // The current pending receive operation if there is one. |
83 scoped_ptr<PendingReceive> pending_receive_; | 85 scoped_ptr<PendingReceive> pending_receive_; |
84 | 86 |
85 // The queue of pending data frames (data or an error) received from the | 87 // The queue of pending data frames (data or an error) received from the |
86 // DataSource. | 88 // DataSource. |
87 std::queue<linked_ptr<DataFrame>> pending_data_frames_; | 89 std::queue<linked_ptr<DataFrame>> pending_data_frames_; |
88 | 90 |
89 base::WeakPtrFactory<DataReceiver> weak_factory_; | 91 base::WeakPtrFactory<DataReceiver> weak_factory_; |
90 | 92 |
91 DISALLOW_COPY_AND_ASSIGN(DataReceiver); | 93 DISALLOW_COPY_AND_ASSIGN(DataReceiver); |
92 }; | 94 }; |
93 | 95 |
94 } // namespace device | 96 } // namespace device |
95 | 97 |
96 #endif // DEVICE_SERIAL_DATA_RECEIVER_H_ | 98 #endif // DEVICE_SERIAL_DATA_RECEIVER_H_ |
OLD | NEW |