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/test_serial_io_handler.h" | 5 #include "device/serial/test_serial_io_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 27 matching lines...) Expand all Loading... |
38 void TestSerialIoHandler::ReadImpl() { | 38 void TestSerialIoHandler::ReadImpl() { |
39 if (!pending_read_buffer()) | 39 if (!pending_read_buffer()) |
40 return; | 40 return; |
41 if (buffer_.empty()) | 41 if (buffer_.empty()) |
42 return; | 42 return; |
43 | 43 |
44 size_t num_bytes = | 44 size_t num_bytes = |
45 std::min(buffer_.size(), static_cast<size_t>(pending_read_buffer_len())); | 45 std::min(buffer_.size(), static_cast<size_t>(pending_read_buffer_len())); |
46 memcpy(pending_read_buffer(), buffer_.c_str(), num_bytes); | 46 memcpy(pending_read_buffer(), buffer_.c_str(), num_bytes); |
47 buffer_ = buffer_.substr(num_bytes); | 47 buffer_ = buffer_.substr(num_bytes); |
48 ReadCompleted(static_cast<uint32_t>(num_bytes), serial::RECEIVE_ERROR_NONE); | 48 ReadCompleted(static_cast<uint32_t>(num_bytes), serial::ReceiveError::NONE); |
49 } | 49 } |
50 | 50 |
51 void TestSerialIoHandler::CancelReadImpl() { | 51 void TestSerialIoHandler::CancelReadImpl() { |
52 ReadCompleted(0, read_cancel_reason()); | 52 ReadCompleted(0, read_cancel_reason()); |
53 } | 53 } |
54 | 54 |
55 void TestSerialIoHandler::WriteImpl() { | 55 void TestSerialIoHandler::WriteImpl() { |
56 if (!send_callback_.is_null()) { | 56 if (!send_callback_.is_null()) { |
57 base::Closure callback = send_callback_; | 57 base::Closure callback = send_callback_; |
58 send_callback_.Reset(); | 58 send_callback_.Reset(); |
59 callback.Run(); | 59 callback.Run(); |
60 return; | 60 return; |
61 } | 61 } |
62 buffer_ += std::string(pending_write_buffer(), pending_write_buffer_len()); | 62 buffer_ += std::string(pending_write_buffer(), pending_write_buffer_len()); |
63 WriteCompleted(pending_write_buffer_len(), serial::SEND_ERROR_NONE); | 63 WriteCompleted(pending_write_buffer_len(), serial::SendError::NONE); |
64 if (pending_read_buffer()) | 64 if (pending_read_buffer()) |
65 ReadImpl(); | 65 ReadImpl(); |
66 } | 66 } |
67 | 67 |
68 void TestSerialIoHandler::CancelWriteImpl() { | 68 void TestSerialIoHandler::CancelWriteImpl() { |
69 WriteCompleted(0, write_cancel_reason()); | 69 WriteCompleted(0, write_cancel_reason()); |
70 } | 70 } |
71 | 71 |
72 bool TestSerialIoHandler::ConfigurePortImpl() { | 72 bool TestSerialIoHandler::ConfigurePortImpl() { |
73 info_.bitrate = options().bitrate; | 73 info_.bitrate = options().bitrate; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 | 110 |
111 bool TestSerialIoHandler::ClearBreak() { | 111 bool TestSerialIoHandler::ClearBreak() { |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 TestSerialIoHandler::~TestSerialIoHandler() { | 115 TestSerialIoHandler::~TestSerialIoHandler() { |
116 } | 116 } |
117 | 117 |
118 } // namespace device | 118 } // namespace device |
OLD | NEW |