OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 REMOTING_BASE_PROTOCOL_DECODER_H_ | 5 #ifndef REMOTING_BASE_PROTOCOL_DECODER_H_ |
6 #define REMOTING_BASE_PROTOCOL_DECODER_H_ | 6 #define REMOTING_BASE_PROTOCOL_DECODER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <list> |
10 | 10 |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "google/protobuf/message_lite.h" | 12 #include "google/protobuf/message_lite.h" |
13 #include "media/base/data_buffer.h" | 13 #include "media/base/data_buffer.h" |
14 #include "remoting/base/protocol/chromotocol.pb.h" | 14 #include "remoting/base/protocol/chromotocol.pb.h" |
15 | 15 |
16 namespace remoting { | 16 namespace remoting { |
17 | 17 |
18 typedef std::vector<ChromotingHostMessage*> HostMessageList; | 18 typedef std::list<ChromotingHostMessage*> HostMessageList; |
19 typedef std::vector<ChromotingClientMessage*> ClientMessageList; | 19 typedef std::list<ChromotingClientMessage*> ClientMessageList; |
20 | 20 |
21 // A protocol decoder is used to decode data transmitted in the chromoting | 21 // A protocol decoder is used to decode data transmitted in the chromoting |
22 // network. | 22 // network. |
23 // TODO(hclam): Defines the interface and implement methods. | 23 // TODO(hclam): Defines the interface and implement methods. |
24 class ProtocolDecoder { | 24 class ProtocolDecoder { |
25 public: | 25 public: |
26 ProtocolDecoder(); | 26 ProtocolDecoder(); |
27 | 27 |
28 virtual ~ProtocolDecoder() {} | 28 virtual ~ProtocolDecoder() {} |
29 | 29 |
30 // Parse data received from network into ClientMessages. Ownership of |data| | 30 // Parse data received from network into ClientMessages. Ownership of |data| |
31 // is passed to this object and output is written to |messages|. | 31 // is passed to this object and output is written to |messages|. |
32 virtual void ParseClientMessages(scoped_refptr<media::DataBuffer> data, | 32 virtual void ParseClientMessages(scoped_refptr<media::DataBuffer> data, |
33 ClientMessageList* messages); | 33 ClientMessageList* messages); |
34 | 34 |
35 // Parse data received from network into HostMessages. Ownership of |data| | 35 // Parse data received from network into HostMessages. Ownership of |data| |
36 // is passed to this object and output is written to |messages|. | 36 // is passed to this object and output is written to |messages|. |
37 virtual void ParseHostMessages(scoped_refptr<media::DataBuffer> data, | 37 virtual void ParseHostMessages(scoped_refptr<media::DataBuffer> data, |
38 HostMessageList* messages); | 38 HostMessageList* messages); |
39 | 39 |
40 private: | 40 private: |
41 // A private method used to parse data received from network into protocol | 41 // A private method used to parse data received from network into protocol |
42 // buffers. | 42 // buffers. |
43 template <typename T> | 43 template <typename T> |
44 void ParseMessages(scoped_refptr<media::DataBuffer> data, | 44 void ParseMessages(scoped_refptr<media::DataBuffer> data, |
45 std::vector<T*>* messages); | 45 std::list<T*>* messages); |
46 | 46 |
47 // Parse one message from |data_list_|. Return true if sucessful. | 47 // Parse one message from |data_list_|. Return true if sucessful. |
48 template <typename T> | 48 template <typename T> |
49 bool ParseOneMessage(T** messages); | 49 bool ParseOneMessage(T** messages); |
50 | 50 |
51 // A utility method to read payload size of the protocol buffer from the | 51 // A utility method to read payload size of the protocol buffer from the |
52 // data list. Return false if we don't have enough data. | 52 // data list. Return false if we don't have enough data. |
53 bool GetPayloadSize(int* size); | 53 bool GetPayloadSize(int* size); |
54 | 54 |
55 typedef std::deque<scoped_refptr<media::DataBuffer> > DataList; | 55 typedef std::deque<scoped_refptr<media::DataBuffer> > DataList; |
56 DataList data_list_; | 56 DataList data_list_; |
57 size_t last_read_position_; | 57 size_t last_read_position_; |
58 | 58 |
59 // Count the number of bytes in |data_list_| not read. | 59 // Count the number of bytes in |data_list_| not read. |
60 size_t available_bytes_; | 60 size_t available_bytes_; |
61 | 61 |
62 // Stores the size of the next payload if known. | 62 // Stores the size of the next payload if known. |
63 size_t next_payload_; | 63 size_t next_payload_; |
64 | 64 |
65 // True if the size of the next payload is known. After one payload is read, | 65 // True if the size of the next payload is known. After one payload is read, |
66 // this is reset to false. | 66 // this is reset to false. |
67 bool next_payload_known_; | 67 bool next_payload_known_; |
68 }; | 68 }; |
69 | 69 |
70 } // namespace remoting | 70 } // namespace remoting |
71 | 71 |
72 #endif // REMOTING_BASE_PROTOCOL_DECODER_H_ | 72 #endif // REMOTING_BASE_PROTOCOL_DECODER_H_ |
OLD | NEW |