| 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_H_ | 5 #ifndef TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_H_ |
| 6 #define TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_H_ | 6 #define TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "tools/battor_agent/battor_protocol_types.h" | 13 #include "tools/battor_agent/battor_protocol_types.h" |
| 14 | 14 |
| 15 namespace battor { | 15 namespace battor { |
| 16 | 16 |
| 17 // A BattOrConnection is a wrapper around the serial connection to the BattOr | 17 // A BattOrConnection is a wrapper around the serial connection to the BattOr |
| 18 // that handles conversion of a message to and from the byte-level BattOr | 18 // that handles conversion of a message to and from the byte-level BattOr |
| 19 // protocol. | 19 // protocol. |
| 20 // | 20 // |
| 21 // At a high-level, all BattOr messages consist of: | 21 // At a high-level, all BattOr messages consist of: |
| 22 // | 22 // |
| 23 // 0x00 (1 byte start marker) | 23 // 0x00 (1 byte start marker) |
| 24 // uint8_t (1 byte header indicating the message type) | 24 // uint8_t (1 byte header indicating the message type) |
| 25 // data (message data, with 0x00s and 0x01s escaped with 0x02) | 25 // data (message data, with 0x00s and 0x01s escaped with 0x02) |
| 26 // 0x01 (1 byte end marker) | 26 // 0x01 (1 byte end marker) |
| 27 // | 27 // |
| 28 // For a more in-depth description of the protocol, see http://bit.ly/1NvNVc3. | 28 // For a more in-depth description of the protocol, see http://bit.ly/1NvNVc3. |
| 29 class BattOrConnection { | 29 class BattOrConnection { |
| 30 public: | 30 public: |
| 31 // The listener interface that must be implemented in order to interact with | 31 // The listener interface that must be implemented in order to interact with |
| 32 // the BattOrConnection. | 32 // the BattOrConnection. |
| 33 class Listener { | 33 class Listener { |
| 34 public: | 34 public: |
| 35 virtual void OnConnectionOpened(bool success) = 0; | 35 virtual void OnConnectionOpened(bool success) = 0; |
| 36 virtual void OnBytesSent(bool success) = 0; | 36 virtual void OnBytesSent(bool success) = 0; |
| 37 virtual void OnMessageRead(bool success, | 37 virtual void OnMessageRead(bool success, |
| 38 BattOrMessageType type, | 38 BattOrMessageType type, |
| 39 scoped_ptr<std::vector<char>> bytes) = 0; | 39 std::unique_ptr<std::vector<char>> bytes) = 0; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 BattOrConnection(Listener* listener); | 42 BattOrConnection(Listener* listener); |
| 43 virtual ~BattOrConnection() = 0; | 43 virtual ~BattOrConnection() = 0; |
| 44 | 44 |
| 45 // Initializes the serial connection and calls the listener's | 45 // Initializes the serial connection and calls the listener's |
| 46 // OnConnectionOpened() when complete. This function must be called before | 46 // OnConnectionOpened() when complete. This function must be called before |
| 47 // using the BattOrConnection. If the connection is already open, calling this | 47 // using the BattOrConnection. If the connection is already open, calling this |
| 48 // method immediately calls the listener's OnConnectionOpened method. | 48 // method immediately calls the listener's OnConnectionOpened method. |
| 49 virtual void Open() = 0; | 49 virtual void Open() = 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 70 // The listener receiving the results of the commands being executed. | 70 // The listener receiving the results of the commands being executed. |
| 71 Listener* listener_; | 71 Listener* listener_; |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(BattOrConnection); | 74 DISALLOW_COPY_AND_ASSIGN(BattOrConnection); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 } // namespace battor | 77 } // namespace battor |
| 78 | 78 |
| 79 #endif // TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_H_ | 79 #endif // TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_H_ |
| OLD | NEW |