Index: components/pairing/proto_decoder.h |
diff --git a/components/pairing/proto_decoder.h b/components/pairing/proto_decoder.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..73a70594498afda5c0cd1d7417a067b6966228a3 |
--- /dev/null |
+++ b/components/pairing/proto_decoder.h |
@@ -0,0 +1,84 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_PAIRING_PROTO_DECODER_H_ |
+#define COMPONENTS_PAIRING_PROTO_DECODER_H_ |
+ |
+#include <deque> |
+ |
+#include "base/logging.h" |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+ |
+namespace net { |
+class IOBuffer; |
+} |
+ |
+namespace pairing_api { |
+class CompleteSetup; |
+class ConfigureHost; |
+class Error; |
+class HostStatus; |
+class PairDevices; |
+} // namespace pairing_api |
+ |
+namespace pairing_chromeos { |
+ |
+class MessageBuffer; |
+ |
+// A ProtoDecoder collects data from a series of IOBuffers and decodes Proto |
+// buffers from the data. The decoded messages are then forwarded to an |
+// observer. |
+class ProtoDecoder { |
+ public: |
+ class Observer { |
+ public: |
+ virtual void OnHostStatusMessage( |
achuithb
2014/08/11 22:04:31
Please add a public virtual dtor with an empty bod
Zachary Kuznia
2014/08/11 23:40:29
Done.
|
+ const pairing_api::HostStatus& message) = 0; |
+ virtual void OnConfigureHostMessage( |
+ const pairing_api::ConfigureHost& message) = 0; |
+ virtual void OnPairDevicesMessage( |
+ const pairing_api::PairDevices& message) = 0; |
+ virtual void OnCompleteSetupMessage( |
+ const pairing_api::CompleteSetup& message) = 0; |
+ virtual void OnErrorMessage( |
+ const pairing_api::Error& message) = 0; |
+ }; |
+ |
+ explicit ProtoDecoder(Observer* observer); |
+ ~ProtoDecoder(); |
+ |
+ // Decode the data from an io_buffer, and send out events for any complete |
achuithb
2014/08/11 22:04:31
Decodes ..., and sends
Zachary Kuznia
2014/08/11 23:40:29
Done.
|
+ // messages. |
+ bool DecodeIOBuffer(int size, scoped_refptr<net::IOBuffer> io_buffer); |
achuithb
2014/08/11 22:04:31
consider using a typedef for scoped_refptr<net::IO
Zachary Kuznia
2014/08/11 23:40:29
Done.
|
+ |
+ // Convenience functions for serializing messages into an IOBuffer. |
+ static scoped_refptr<net::IOBuffer> SendHostStatus( |
+ const pairing_api::HostStatus& message, int* size); |
+ static scoped_refptr<net::IOBuffer> SendConfigureHost( |
+ const pairing_api::ConfigureHost& message, int* size); |
+ static scoped_refptr<net::IOBuffer> SendPairDevices( |
+ const pairing_api::PairDevices& message, int* size); |
+ static scoped_refptr<net::IOBuffer> SendCompleteSetup( |
+ const pairing_api::CompleteSetup& message, int* size); |
+ static scoped_refptr<net::IOBuffer> SendError( |
+ const pairing_api::Error& message, int* size); |
+ |
+ private: |
+ static scoped_refptr<net::IOBuffer> SendMessage(uint8_t message_type, |
+ const std::string& message, |
+ int* size); |
+ |
+ Observer* observer_; |
+ scoped_ptr<MessageBuffer> message_buffer_; |
achuithb
2014/08/11 22:04:31
Why not just have a MessageBuffer member:
MessageB
Zachary Kuznia
2014/08/11 23:40:29
Done.
|
+ int next_message_type_; |
+ int next_message_size_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ProtoDecoder); |
+}; |
+ |
+} // namespace pairing_chromeos |
+ |
+#endif // COMPONENTS_PAIRING_PROTO_DECODER_H_ |