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 #include "device/serial/data_receiver.h" | 5 #include "device/serial/data_receiver.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // The offset within |data| at which the next read should begin. | 100 // The offset within |data| at which the next read should begin. |
101 uint32_t offset; | 101 uint32_t offset; |
102 | 102 |
103 // The value of the error that occurred. | 103 // The value of the error that occurred. |
104 const int32_t error; | 104 const int32_t error; |
105 | 105 |
106 // Whether the error has been dispatched to the user. | 106 // Whether the error has been dispatched to the user. |
107 bool dispatched; | 107 bool dispatched; |
108 }; | 108 }; |
109 | 109 |
110 DataReceiver::DataReceiver(mojo::InterfacePtr<serial::DataSource> source, | 110 DataReceiver::DataReceiver( |
111 uint32_t buffer_size, | 111 mojo::InterfacePtr<serial::DataSource> source, |
112 int32_t fatal_error_value) | 112 mojo::InterfaceRequest<serial::DataSourceClient> client, |
| 113 uint32_t buffer_size, |
| 114 int32_t fatal_error_value) |
113 : source_(source.Pass()), | 115 : source_(source.Pass()), |
| 116 client_(this, client.Pass()), |
114 fatal_error_value_(fatal_error_value), | 117 fatal_error_value_(fatal_error_value), |
115 shut_down_(false), | 118 shut_down_(false), |
116 weak_factory_(this) { | 119 weak_factory_(this) { |
117 source_.set_client(this); | |
118 source_.set_error_handler(this); | 120 source_.set_error_handler(this); |
119 source_->Init(buffer_size); | 121 source_->Init(buffer_size); |
| 122 client_.set_error_handler(this); |
120 } | 123 } |
121 | 124 |
122 bool DataReceiver::Receive(const ReceiveDataCallback& callback, | 125 bool DataReceiver::Receive(const ReceiveDataCallback& callback, |
123 const ReceiveErrorCallback& error_callback) { | 126 const ReceiveErrorCallback& error_callback) { |
124 DCHECK(!callback.is_null() && !error_callback.is_null()); | 127 DCHECK(!callback.is_null() && !error_callback.is_null()); |
125 if (pending_receive_ || shut_down_) | 128 if (pending_receive_ || shut_down_) |
126 return false; | 129 return false; |
127 // When the DataSource encounters an error, it pauses transmission. When the | 130 // When the DataSource encounters an error, it pauses transmission. When the |
128 // user starts a new receive following notification of the error (via | 131 // user starts a new receive following notification of the error (via |
129 // |error_callback| of the previous Receive call) of the error we can tell the | 132 // |error_callback| of the previous Receive call) of the error we can tell the |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 buffer_size_ = 0; | 279 buffer_size_ = 0; |
277 } | 280 } |
278 | 281 |
279 void DataReceiver::PendingReceive::Buffer::DoneWithError( | 282 void DataReceiver::PendingReceive::Buffer::DoneWithError( |
280 uint32_t bytes_consumed, | 283 uint32_t bytes_consumed, |
281 int32_t error) { | 284 int32_t error) { |
282 Done(bytes_consumed); | 285 Done(bytes_consumed); |
283 } | 286 } |
284 | 287 |
285 } // namespace device | 288 } // namespace device |
OLD | NEW |