Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: tools/battor_agent/battor_connection.cc

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "tools/battor_agent/battor_connection.h" 5 #include "tools/battor_agent/battor_connection.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "device/serial/buffer.h" 9 #include "device/serial/buffer.h"
10 #include "device/serial/serial_io_handler.h" 10 #include "device/serial/serial_io_handler.h"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 12
13 using std::vector; 13 using std::vector;
14 14
15 namespace battor { 15 namespace battor {
16 16
17 namespace { 17 namespace {
18 18
19 // Serial configuration parameters for the BattOr. 19 // Serial configuration parameters for the BattOr.
20 const uint32_t kBattOrBitrate = 2000000; 20 const uint32_t kBattOrBitrate = 2000000;
21 const device::serial::DataBits kBattOrDataBits = 21 const device::serial::DataBits kBattOrDataBits =
22 device::serial::DATA_BITS_EIGHT; 22 device::serial::DataBits::EIGHT;
23 const device::serial::ParityBit kBattOrParityBit = 23 const device::serial::ParityBit kBattOrParityBit =
24 device::serial::PARITY_BIT_NONE; 24 device::serial::ParityBit::NONE;
25 const device::serial::StopBits kBattOrStopBit = device::serial::STOP_BITS_ONE; 25 const device::serial::StopBits kBattOrStopBit = device::serial::StopBits::ONE;
26 const bool kBattOrCtsFlowControl = true; 26 const bool kBattOrCtsFlowControl = true;
27 const bool kBattOrHasCtsFlowControl = true; 27 const bool kBattOrHasCtsFlowControl = true;
28 const uint32_t kMaxMessageSize = 50000; 28 const uint32_t kMaxMessageSize = 50000;
29 29
30 // MessageHealth describes the possible healthiness states that a partially 30 // MessageHealth describes the possible healthiness states that a partially
31 // received message could be in. 31 // received message could be in.
32 enum class MessageHealth { 32 enum class MessageHealth {
33 INVALID, 33 INVALID,
34 INCOMPLETE, 34 INCOMPLETE,
35 COMPLETE, 35 COMPLETE,
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 base::Bind(&BattOrConnection::OnBytesRead, AsWeakPtr()); 221 base::Bind(&BattOrConnection::OnBytesRead, AsWeakPtr());
222 222
223 pending_read_length_ = bytes_to_read; 223 pending_read_length_ = bytes_to_read;
224 io_handler_->Read(make_scoped_ptr(new device::ReceiveBuffer( 224 io_handler_->Read(make_scoped_ptr(new device::ReceiveBuffer(
225 last_read_buffer_, bytes_to_read, on_receive_buffer_filled))); 225 last_read_buffer_, bytes_to_read, on_receive_buffer_filled)));
226 } 226 }
227 227
228 void BattOrConnection::OnBytesRead(int bytes_read, 228 void BattOrConnection::OnBytesRead(int bytes_read,
229 device::serial::ReceiveError error) { 229 device::serial::ReceiveError error) {
230 if ((static_cast<size_t>(bytes_read) < pending_read_length_) || 230 if ((static_cast<size_t>(bytes_read) < pending_read_length_) ||
231 (error != device::serial::RECEIVE_ERROR_NONE)) { 231 (error != device::serial::ReceiveError::NONE)) {
232 listener_->OnBytesRead(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); 232 listener_->OnBytesRead(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr);
233 return; 233 return;
234 } 234 }
235 235
236 pending_read_buffer_->insert(pending_read_buffer_->end(), 236 pending_read_buffer_->insert(pending_read_buffer_->end(),
237 last_read_buffer_->data(), 237 last_read_buffer_->data(),
238 last_read_buffer_->data() + bytes_read); 238 last_read_buffer_->data() + bytes_read);
239 239
240 scoped_ptr<vector<char>> parsed_content(new vector<char>()); 240 scoped_ptr<vector<char>> parsed_content(new vector<char>());
241 MessageHealth health; 241 MessageHealth health;
(...skipping 26 matching lines...) Expand all
268 // If everything is valid and we didn't see any escape bytes, then we should 268 // If everything is valid and we didn't see any escape bytes, then we should
269 // have the whole message. If we don't, the message was malformed. 269 // have the whole message. If we don't, the message was malformed.
270 listener_->OnBytesRead(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); 270 listener_->OnBytesRead(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr);
271 271
272 // If we've gotten this far, we've received the whole, well-formed message. 272 // If we've gotten this far, we've received the whole, well-formed message.
273 listener_->OnBytesRead(true, type, std::move(parsed_content)); 273 listener_->OnBytesRead(true, type, std::move(parsed_content));
274 } 274 }
275 275
276 void BattOrConnection::OnBytesSent(int bytes_sent, 276 void BattOrConnection::OnBytesSent(int bytes_sent,
277 device::serial::SendError error) { 277 device::serial::SendError error) {
278 bool success = (error == device::serial::SEND_ERROR_NONE) && 278 bool success = (error == device::serial::SendError::NONE) &&
279 (pending_write_length_ == static_cast<size_t>(bytes_sent)); 279 (pending_write_length_ == static_cast<size_t>(bytes_sent));
280 listener_->OnBytesSent(success); 280 listener_->OnBytesSent(success);
281 } 281 }
282 282
283 } // namespace battor 283 } // namespace battor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698