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 "base/numerics/safe_conversions.h" | 5 #include "base/numerics/safe_conversions.h" |
6 #include "base/stl_util.h" | |
7 #include "device/serial/buffer.h" | 6 #include "device/serial/buffer.h" |
8 #include "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
9 | 8 |
10 namespace device { | 9 namespace device { |
11 | 10 |
12 ReadOnlyBuffer::~ReadOnlyBuffer() { | 11 ReadOnlyBuffer::~ReadOnlyBuffer() { |
13 } | 12 } |
14 | 13 |
15 WritableBuffer::~WritableBuffer() { | 14 WritableBuffer::~WritableBuffer() { |
16 } | 15 } |
17 | 16 |
18 SendBuffer::SendBuffer( | 17 SendBuffer::SendBuffer( |
19 const std::vector<char>& data, | 18 const std::vector<char>& data, |
20 const base::Callback<void(int, device::serial::SendError)>& callback) | 19 const base::Callback<void(int, device::serial::SendError)>& callback) |
21 : data_(data), callback_(callback) {} | 20 : data_(data), callback_(callback) {} |
22 | 21 |
23 SendBuffer::~SendBuffer() {} | 22 SendBuffer::~SendBuffer() {} |
24 | 23 |
25 const char* SendBuffer::GetData() { | 24 const char* SendBuffer::GetData() { |
26 return vector_as_array(&data_); | 25 return data_.data(); |
27 } | 26 } |
28 | 27 |
29 uint32_t SendBuffer::GetSize() { | 28 uint32_t SendBuffer::GetSize() { |
30 return base::checked_cast<uint32_t>(data_.size()); | 29 return base::checked_cast<uint32_t>(data_.size()); |
31 } | 30 } |
32 | 31 |
33 void SendBuffer::Done(uint32_t bytes_read) { | 32 void SendBuffer::Done(uint32_t bytes_read) { |
34 callback_.Run(bytes_read, device::serial::SEND_ERROR_NONE); | 33 callback_.Run(bytes_read, device::serial::SEND_ERROR_NONE); |
35 } | 34 } |
36 | 35 |
(...skipping 20 matching lines...) Expand all Loading... |
57 void ReceiveBuffer::Done(uint32_t bytes_written) { | 56 void ReceiveBuffer::Done(uint32_t bytes_written) { |
58 callback_.Run(bytes_written, device::serial::RECEIVE_ERROR_NONE); | 57 callback_.Run(bytes_written, device::serial::RECEIVE_ERROR_NONE); |
59 } | 58 } |
60 | 59 |
61 void ReceiveBuffer::DoneWithError(uint32_t bytes_written, int32_t error) { | 60 void ReceiveBuffer::DoneWithError(uint32_t bytes_written, int32_t error) { |
62 callback_.Run(bytes_written, | 61 callback_.Run(bytes_written, |
63 static_cast<device::serial::ReceiveError>(error)); | 62 static_cast<device::serial::ReceiveError>(error)); |
64 } | 63 } |
65 | 64 |
66 } // namespace device | 65 } // namespace device |
OLD | NEW |