| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <queue> | 11 #include <queue> |
| 11 | 12 |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "device/serial/buffer.h" | 18 #include "device/serial/buffer.h" |
| 18 #include "device/serial/data_stream.mojom.h" | 19 #include "device/serial/data_stream.mojom.h" |
| 19 #include "mojo/public/cpp/bindings/binding.h" | 20 #include "mojo/public/cpp/bindings/binding.h" |
| 20 #include "mojo/public/cpp/system/data_pipe.h" | 21 #include "mojo/public/cpp/system/data_pipe.h" |
| 21 | 22 |
| 22 namespace device { | 23 namespace device { |
| 23 | 24 |
| 24 // A DataReceiver receives data from a DataSource. | 25 // A DataReceiver receives data from a DataSource. |
| 25 class DataReceiver : public base::RefCounted<DataReceiver>, | 26 class DataReceiver : public base::RefCounted<DataReceiver>, |
| 26 public serial::DataSourceClient { | 27 public serial::DataSourceClient { |
| 27 public: | 28 public: |
| 28 typedef base::Callback<void(scoped_ptr<ReadOnlyBuffer>)> ReceiveDataCallback; | 29 typedef base::Callback<void(std::unique_ptr<ReadOnlyBuffer>)> |
| 30 ReceiveDataCallback; |
| 29 typedef base::Callback<void(int32_t error)> ReceiveErrorCallback; | 31 typedef base::Callback<void(int32_t error)> ReceiveErrorCallback; |
| 30 | 32 |
| 31 // Constructs a DataReceiver to receive data from |source|, using a buffer | 33 // Constructs a DataReceiver to receive data from |source|, using a buffer |
| 32 // size of |buffer_size|, with connection errors reported as | 34 // size of |buffer_size|, with connection errors reported as |
| 33 // |fatal_error_value|. | 35 // |fatal_error_value|. |
| 34 DataReceiver(mojo::InterfacePtr<serial::DataSource> source, | 36 DataReceiver(mojo::InterfacePtr<serial::DataSource> source, |
| 35 mojo::InterfaceRequest<serial::DataSourceClient> client, | 37 mojo::InterfaceRequest<serial::DataSourceClient> client, |
| 36 uint32_t buffer_size, | 38 uint32_t buffer_size, |
| 37 int32_t fatal_error_value); | 39 int32_t fatal_error_value); |
| 38 | 40 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 mojo::InterfacePtr<serial::DataSource> source_; | 80 mojo::InterfacePtr<serial::DataSource> source_; |
| 79 mojo::Binding<serial::DataSourceClient> client_; | 81 mojo::Binding<serial::DataSourceClient> client_; |
| 80 | 82 |
| 81 // The error value to report in the event of a fatal error. | 83 // The error value to report in the event of a fatal error. |
| 82 const int32_t fatal_error_value_; | 84 const int32_t fatal_error_value_; |
| 83 | 85 |
| 84 // Whether we have encountered a fatal error and shut down. | 86 // Whether we have encountered a fatal error and shut down. |
| 85 bool shut_down_; | 87 bool shut_down_; |
| 86 | 88 |
| 87 // The current pending receive operation if there is one. | 89 // The current pending receive operation if there is one. |
| 88 scoped_ptr<PendingReceive> pending_receive_; | 90 std::unique_ptr<PendingReceive> pending_receive_; |
| 89 | 91 |
| 90 // The queue of pending data frames (data or an error) received from the | 92 // The queue of pending data frames (data or an error) received from the |
| 91 // DataSource. | 93 // DataSource. |
| 92 std::queue<linked_ptr<DataFrame>> pending_data_frames_; | 94 std::queue<linked_ptr<DataFrame>> pending_data_frames_; |
| 93 | 95 |
| 94 base::WeakPtrFactory<DataReceiver> weak_factory_; | 96 base::WeakPtrFactory<DataReceiver> weak_factory_; |
| 95 | 97 |
| 96 DISALLOW_COPY_AND_ASSIGN(DataReceiver); | 98 DISALLOW_COPY_AND_ASSIGN(DataReceiver); |
| 97 }; | 99 }; |
| 98 | 100 |
| 99 } // namespace device | 101 } // namespace device |
| 100 | 102 |
| 101 #endif // DEVICE_SERIAL_DATA_RECEIVER_H_ | 103 #endif // DEVICE_SERIAL_DATA_RECEIVER_H_ |
| OLD | NEW |