Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: tools/battor_agent/battor_connection_impl.h

Issue 1567683002: Makes the BattOrConnection read messages instead of bytes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/battor_agent/battor_connection.h ('k') | tools/battor_agent/battor_connection_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/battor_agent/battor_connection_impl.h
diff --git a/tools/battor_agent/battor_connection_impl.h b/tools/battor_agent/battor_connection_impl.h
index f13acb9291e2a2c1cffeed60d57c4f9016bbf77f..893ef0ffb7b6bc5ad4e0925f0185cd01440dd653 100644
--- a/tools/battor_agent/battor_connection_impl.h
+++ b/tools/battor_agent/battor_connection_impl.h
@@ -42,7 +42,7 @@ class BattOrConnectionImpl
void SendBytes(BattOrMessageType type,
const void* buffer,
size_t bytes_to_send) override;
- void ReadBytes(size_t bytes_to_read) override;
+ void ReadMessage(BattOrMessageType type) override;
void Flush() override;
protected:
@@ -57,30 +57,34 @@ class BattOrConnectionImpl
// Reads the specified number of additional bytes and adds them to the pending
// read buffer.
- void ReadMoreBytes(size_t bytes_to_read);
+ void BeginReadBytes(size_t bytes_to_read);
// Internal callback for when bytes are read. This method may trigger
// additional reads if any newly read bytes are escape bytes.
void OnBytesRead(int bytes_read, device::serial::ReceiveError error);
+ void EndReadBytes(bool success,
+ BattOrMessageType type,
+ scoped_ptr<std::vector<char>> data);
+
+ // Pulls off the next complete message from already_read_buffer_, returning
+ // its type and contents (via out parameters) and whether a complete message
+ // was able to be read (via the return value).
+ bool ParseMessage(BattOrMessageType* type, std::vector<char>* data);
+
// Internal callback for when bytes are sent.
void OnBytesSent(int bytes_sent, device::serial::SendError error);
// The path of the BattOr.
std::string path_;
- // All bytes that have been read since the user requested a read. If multiple
- // reads are required due to the presence of escape bytes,
- // pending_read_buffer_ grows with each read.
- scoped_ptr<std::vector<char>> pending_read_buffer_;
- // The bytes that were read in just the last read. If multiple reads are
- // required due to the presence of escape bytes, last_read_buffer_ only
- // contains the results of the last read.
- scoped_refptr<net::IOBuffer> last_read_buffer_;
- // The number of bytes that we requested in the last read.
- size_t pending_read_length_;
- // The number of escape bytes that have already been read.
- size_t pending_read_escape_byte_count_;
+ // All bytes that have already been read from the serial stream, but have not
+ // yet been given to the listener as a complete message.
+ std::vector<char> already_read_buffer_;
+ // The bytes that were read in the pending read.
+ scoped_refptr<net::IOBuffer> pending_read_buffer_;
+ // The type of message we're looking for in the pending read.
+ BattOrMessageType pending_read_message_type_;
// The total number of bytes that we're expecting to send.
size_t pending_write_length_;
« no previous file with comments | « tools/battor_agent/battor_connection.h ('k') | tools/battor_agent/battor_connection_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698