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