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( | 110 DataReceiver::DataReceiver(mojo::InterfacePtr<serial::DataSource> source, |
111 mojo::InterfacePtr<serial::DataSource> source, | 111 uint32_t buffer_size, |
112 mojo::InterfaceRequest<serial::DataSourceClient> client, | 112 int32_t fatal_error_value) |
113 uint32_t buffer_size, | |
114 int32_t fatal_error_value) | |
115 : source_(source.Pass()), | 113 : source_(source.Pass()), |
116 client_(this, client.Pass()), | |
117 fatal_error_value_(fatal_error_value), | 114 fatal_error_value_(fatal_error_value), |
118 shut_down_(false), | 115 shut_down_(false), |
119 weak_factory_(this) { | 116 weak_factory_(this) { |
| 117 source_.set_client(this); |
120 source_.set_error_handler(this); | 118 source_.set_error_handler(this); |
121 source_->Init(buffer_size); | 119 source_->Init(buffer_size); |
122 client_.set_error_handler(this); | |
123 } | 120 } |
124 | 121 |
125 bool DataReceiver::Receive(const ReceiveDataCallback& callback, | 122 bool DataReceiver::Receive(const ReceiveDataCallback& callback, |
126 const ReceiveErrorCallback& error_callback) { | 123 const ReceiveErrorCallback& error_callback) { |
127 DCHECK(!callback.is_null() && !error_callback.is_null()); | 124 DCHECK(!callback.is_null() && !error_callback.is_null()); |
128 if (pending_receive_ || shut_down_) | 125 if (pending_receive_ || shut_down_) |
129 return false; | 126 return false; |
130 // When the DataSource encounters an error, it pauses transmission. When the | 127 // When the DataSource encounters an error, it pauses transmission. When the |
131 // user starts a new receive following notification of the error (via | 128 // user starts a new receive following notification of the error (via |
132 // |error_callback| of the previous Receive call) of the error we can tell the | 129 // |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... |
279 buffer_size_ = 0; | 276 buffer_size_ = 0; |
280 } | 277 } |
281 | 278 |
282 void DataReceiver::PendingReceive::Buffer::DoneWithError( | 279 void DataReceiver::PendingReceive::Buffer::DoneWithError( |
283 uint32_t bytes_consumed, | 280 uint32_t bytes_consumed, |
284 int32_t error) { | 281 int32_t error) { |
285 Done(bytes_consumed); | 282 Done(bytes_consumed); |
286 } | 283 } |
287 | 284 |
288 } // namespace device | 285 } // namespace device |
OLD | NEW |