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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 16 matching lines...) Expand all Loading... |
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 OnBytesRead(bool success, | 37 virtual void OnMessageRead(bool success, |
38 BattOrMessageType type, | 38 BattOrMessageType type, |
39 scoped_ptr<std::vector<char>> bytes) = 0; | 39 scoped_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; |
50 // Closes the serial connection and releases any handles being held. | 50 // Closes the serial connection and releases any handles being held. |
51 virtual void Close() = 0; | 51 virtual void Close() = 0; |
52 | 52 |
53 // Sends the specified buffer over the serial connection and calls the | 53 // Sends the specified buffer over the serial connection and calls the |
54 // listener's OnBytesSent() when complete. Note that bytes_to_send should not | 54 // listener's OnBytesSent() when complete. Note that bytes_to_send should not |
55 // include the start, end, type, or escape bytes required by the BattOr | 55 // include the start, end, type, or escape bytes required by the BattOr |
56 // protocol. | 56 // protocol. |
57 virtual void SendBytes(BattOrMessageType type, | 57 virtual void SendBytes(BattOrMessageType type, |
58 const void* buffer, | 58 const void* buffer, |
59 size_t bytes_to_send) = 0; | 59 size_t bytes_to_send) = 0; |
60 | 60 |
61 // Reads the specified number of bytes from the serial connection and calls | 61 // Gets the next message available from the serial connection, reading the |
62 // the listener's OnBytesRead() when complete. Note that the number of bytes | 62 // correct number of bytes based on the specified message type, and calls the |
63 // requested should not include the start, end, or type bytes required by the | 63 // listener's OnMessageRead() when complete. |
64 // BattOr protocol, and that this method may issue multiple read read requests | 64 virtual void ReadMessage(BattOrMessageType type) = 0; |
65 // if the message contains escape characters. | |
66 virtual void ReadBytes(size_t bytes_to_read) = 0; | |
67 | 65 |
68 // Flushes the serial connection to the BattOr. | 66 // Flushes the serial connection to the BattOr. |
69 virtual void Flush() = 0; | 67 virtual void Flush() = 0; |
70 | 68 |
71 protected: | 69 protected: |
72 // The listener receiving the results of the commands being executed. | 70 // The listener receiving the results of the commands being executed. |
73 Listener* listener_; | 71 Listener* listener_; |
74 | 72 |
75 private: | 73 private: |
76 DISALLOW_COPY_AND_ASSIGN(BattOrConnection); | 74 DISALLOW_COPY_AND_ASSIGN(BattOrConnection); |
77 }; | 75 }; |
78 | 76 |
79 } // namespace battor | 77 } // namespace battor |
80 | 78 |
81 #endif // TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_H_ | 79 #endif // TOOLS_BATTOR_AGENT_BATTOR_CONNECTION_H_ |
OLD | NEW |