| OLD | NEW |
| 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_impl.h" | 5 #include "tools/battor_agent/battor_connection_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 is_read_complete_ = false; | 71 is_read_complete_ = false; |
| 72 connection_->ReadMessage(type); | 72 connection_->ReadMessage(type); |
| 73 task_runner_->RunUntilIdle(); | 73 task_runner_->RunUntilIdle(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Reads the specified number of bytes directly from the serial connection. | 76 // Reads the specified number of bytes directly from the serial connection. |
| 77 scoped_refptr<net::IOBuffer> ReadMessageRaw(int bytes_to_read) { | 77 scoped_refptr<net::IOBuffer> ReadMessageRaw(int bytes_to_read) { |
| 78 scoped_refptr<net::IOBuffer> buffer( | 78 scoped_refptr<net::IOBuffer> buffer( |
| 79 new net::IOBuffer((size_t)bytes_to_read)); | 79 new net::IOBuffer((size_t)bytes_to_read)); |
| 80 | 80 |
| 81 connection_->GetIoHandler()->Read( | 81 connection_->GetIoHandler()->Read(base::MakeUnique<device::ReceiveBuffer>( |
| 82 base::WrapUnique(new device::ReceiveBuffer( | 82 buffer, bytes_to_read, base::Bind(&NullReadCallback))); |
| 83 buffer, bytes_to_read, base::Bind(&NullReadCallback)))); | |
| 84 task_runner_->RunUntilIdle(); | 83 task_runner_->RunUntilIdle(); |
| 85 | 84 |
| 86 return buffer; | 85 return buffer; |
| 87 } | 86 } |
| 88 | 87 |
| 89 void SendControlMessage(BattOrControlMessageType type, | 88 void SendControlMessage(BattOrControlMessageType type, |
| 90 uint16_t param1, | 89 uint16_t param1, |
| 91 uint16_t param2) { | 90 uint16_t param2) { |
| 92 BattOrControlMessage msg{type, param1, param2}; | 91 BattOrControlMessage msg{type, param1, param2}; |
| 93 connection_->SendBytes(BATTOR_MESSAGE_TYPE_CONTROL, | 92 connection_->SendBytes(BATTOR_MESSAGE_TYPE_CONTROL, |
| 94 reinterpret_cast<char*>(&msg), sizeof(msg)); | 93 reinterpret_cast<char*>(&msg), sizeof(msg)); |
| 95 task_runner_->RunUntilIdle(); | 94 task_runner_->RunUntilIdle(); |
| 96 } | 95 } |
| 97 | 96 |
| 98 // Writes the specified bytes directly to the serial connection. | 97 // Writes the specified bytes directly to the serial connection. |
| 99 void SendBytesRaw(const char* data, uint16_t bytes_to_send) { | 98 void SendBytesRaw(const char* data, uint16_t bytes_to_send) { |
| 100 std::vector<char> data_vector(data, data + bytes_to_send); | 99 std::vector<char> data_vector(data, data + bytes_to_send); |
| 101 connection_->GetIoHandler()->Write(base::WrapUnique( | 100 connection_->GetIoHandler()->Write(base::MakeUnique<device::SendBuffer>( |
| 102 new device::SendBuffer(data_vector, base::Bind(&NullWriteCallback)))); | 101 data_vector, base::Bind(&NullWriteCallback))); |
| 103 task_runner_->RunUntilIdle(); | 102 task_runner_->RunUntilIdle(); |
| 104 } | 103 } |
| 105 | 104 |
| 106 bool GetOpenSuccess() { return open_success_; } | 105 bool GetOpenSuccess() { return open_success_; } |
| 107 bool GetSendSuccess() { return send_success_; } | 106 bool GetSendSuccess() { return send_success_; } |
| 108 bool IsReadComplete() { return is_read_complete_; } | 107 bool IsReadComplete() { return is_read_complete_; } |
| 109 bool GetReadSuccess() { return read_success_; } | 108 bool GetReadSuccess() { return read_success_; } |
| 110 BattOrMessageType GetReadType() { return read_type_; } | 109 BattOrMessageType GetReadType() { return read_type_; } |
| 111 std::vector<char>* GetReadMessage() { return read_bytes_.get(); } | 110 std::vector<char>* GetReadMessage() { return read_bytes_.get(); } |
| 112 | 111 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 BATTOR_CONTROL_BYTE_END, | 390 BATTOR_CONTROL_BYTE_END, |
| 392 }; | 391 }; |
| 393 SendBytesRaw(data, 3); | 392 SendBytesRaw(data, 3); |
| 394 ReadMessage(BATTOR_MESSAGE_TYPE_PRINT); | 393 ReadMessage(BATTOR_MESSAGE_TYPE_PRINT); |
| 395 | 394 |
| 396 ASSERT_TRUE(IsReadComplete()); | 395 ASSERT_TRUE(IsReadComplete()); |
| 397 ASSERT_FALSE(GetReadSuccess()); | 396 ASSERT_FALSE(GetReadSuccess()); |
| 398 } | 397 } |
| 399 | 398 |
| 400 } // namespace battor | 399 } // namespace battor |
| OLD | NEW |