| 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 #ifndef TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_IMPL_H_ | 5 #ifndef TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_IMPL_H_ |
| 6 #define TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_IMPL_H_ | 6 #define TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_IMPL_H_ |
| 7 | 7 |
| 8 #include <fstream> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "device/serial/serial.mojom.h" | 15 #include "device/serial/serial.mojom.h" |
| 15 #include "tools/battor_agent/battor_connection.h" | 16 #include "tools/battor_agent/battor_connection.h" |
| 16 #include "tools/battor_agent/battor_error.h" | 17 #include "tools/battor_agent/battor_error.h" |
| 17 #include "tools/battor_agent/battor_protocol_types.h" | 18 #include "tools/battor_agent/battor_protocol_types.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 std::unique_ptr<std::vector<char>> data); | 69 std::unique_ptr<std::vector<char>> data); |
| 69 | 70 |
| 70 // Pulls off the next complete message from already_read_buffer_, returning | 71 // Pulls off the next complete message from already_read_buffer_, returning |
| 71 // its type and contents (via out parameters) and whether a complete message | 72 // its type and contents (via out parameters) and whether a complete message |
| 72 // was able to be read (via the return value). | 73 // was able to be read (via the return value). |
| 73 bool ParseMessage(BattOrMessageType* type, std::vector<char>* data); | 74 bool ParseMessage(BattOrMessageType* type, std::vector<char>* data); |
| 74 | 75 |
| 75 // Internal callback for when bytes are sent. | 76 // Internal callback for when bytes are sent. |
| 76 void OnBytesSent(int bytes_sent, device::serial::SendError error); | 77 void OnBytesSent(int bytes_sent, device::serial::SendError error); |
| 77 | 78 |
| 79 // Appends |str| to the serial log file if it exists. |
| 80 void LogSerial(const std::string& str); |
| 81 |
| 78 // The path of the BattOr. | 82 // The path of the BattOr. |
| 79 std::string path_; | 83 std::string path_; |
| 80 | 84 |
| 81 // All bytes that have already been read from the serial stream, but have not | 85 // All bytes that have already been read from the serial stream, but have not |
| 82 // yet been given to the listener as a complete message. | 86 // yet been given to the listener as a complete message. |
| 83 std::vector<char> already_read_buffer_; | 87 std::vector<char> already_read_buffer_; |
| 84 // The bytes that were read in the pending read. | 88 // The bytes that were read in the pending read. |
| 85 scoped_refptr<net::IOBuffer> pending_read_buffer_; | 89 scoped_refptr<net::IOBuffer> pending_read_buffer_; |
| 86 // The type of message we're looking for in the pending read. | 90 // The type of message we're looking for in the pending read. |
| 87 BattOrMessageType pending_read_message_type_; | 91 BattOrMessageType pending_read_message_type_; |
| 88 | 92 |
| 89 // The total number of bytes that we're expecting to send. | 93 // The total number of bytes that we're expecting to send. |
| 90 size_t pending_write_length_; | 94 size_t pending_write_length_; |
| 91 | 95 |
| 92 // Threads needed for serial communication. | 96 // Threads needed for serial communication. |
| 93 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; | 97 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; |
| 94 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; | 98 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; |
| 95 | 99 |
| 100 std::fstream serial_log_; |
| 101 |
| 96 DISALLOW_COPY_AND_ASSIGN(BattOrConnectionImpl); | 102 DISALLOW_COPY_AND_ASSIGN(BattOrConnectionImpl); |
| 97 }; | 103 }; |
| 98 | 104 |
| 99 } // namespace battor | 105 } // namespace battor |
| 100 | 106 |
| 101 #endif // TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_IMPL_H_ | 107 #endif // TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_IMPL_H_ |
| OLD | NEW |