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_PROTOCOL_CLIENT_MESSAGE_DISPATCHER_H_ | 5 #ifndef REMOTING_PROTOCOL_CLIENT_MESSAGE_DISPATCHER_H_ |
6 #define REMOTING_PROTOCOL_CLIENT_MESSAGE_DISPATCHER_H_ | 6 #define REMOTING_PROTOCOL_CLIENT_MESSAGE_DISPATCHER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "remoting/protocol/message_reader.h" |
11 | 12 |
12 namespace remoting { | 13 namespace remoting { |
13 | 14 |
14 class EventMessage; | 15 class EventMessage; |
15 | 16 |
16 namespace protocol { | 17 namespace protocol { |
17 | 18 |
18 class ClientStub; | 19 class ClientStub; |
19 class ControlMessage; | 20 class ControlMessage; |
20 class InputStub; | |
21 class MessageReader; | |
22 class Session; | 21 class Session; |
23 | 22 |
24 // A message dispatcher used to listen for messages received in | 23 // A message dispatcher used to listen for messages received in |
25 // protocol::Session. It dispatches messages to the corresponding | 24 // protocol::Session. It dispatches messages to the corresponding |
26 // handler. | 25 // handler. |
27 // | 26 // |
28 // Internally it contains an EventStreamReader that decodes data on | 27 // Internally it contains an EventStreamReader that decodes data on |
29 // communications channels into protocol buffer messages. | 28 // communications channels into protocol buffer messages. |
30 // EventStreamReader is registered with protocol::Session given to it. | 29 // EventStreamReader is registered with protocol::Session given to it. |
31 // | 30 // |
32 // Object of this class is owned by ConnectionToHost. | 31 // Object of this class is owned by ConnectionToHost. |
33 class ClientMessageDispatcher { | 32 class ClientMessageDispatcher { |
34 public: | 33 public: |
35 // Construct a message dispatcher. | 34 // Construct a message dispatcher. |
36 ClientMessageDispatcher(); | 35 ClientMessageDispatcher(); |
37 virtual ~ClientMessageDispatcher(); | 36 virtual ~ClientMessageDispatcher(); |
38 | 37 |
39 // Initialize the message dispatcher with the given connection and | 38 // Initialize the message dispatcher with the given connection and |
40 // message handlers. | 39 // message handlers. |
41 void Initialize(protocol::Session* session, ClientStub* client_stub); | 40 void Initialize(protocol::Session* session, ClientStub* client_stub); |
42 | 41 |
43 private: | 42 private: |
44 void OnControlMessageReceived(ControlMessage* message); | 43 void OnControlMessageReceived(ControlMessage* message); |
45 | 44 |
46 // MessageReader that runs on the control channel. It runs a loop | 45 // MessageReader that runs on the control channel. It runs a loop |
47 // that parses data on the channel and then calls the corresponding handler | 46 // that parses data on the channel and then calls the corresponding handler |
48 // in this class. | 47 // in this class. |
49 scoped_ptr<MessageReader> control_message_reader_; | 48 scoped_ptr<ProtobufMessageReader<ControlMessage> > control_message_reader_; |
50 | 49 |
51 // Stubs for client and input. These objects are not owned. | 50 // Stubs for client and input. These objects are not owned. |
52 // They are called on the thread there data is received, i.e. jingle thread. | 51 // They are called on the thread there data is received, i.e. jingle thread. |
53 ClientStub* client_stub_; | 52 ClientStub* client_stub_; |
54 | 53 |
55 DISALLOW_COPY_AND_ASSIGN(ClientMessageDispatcher); | 54 DISALLOW_COPY_AND_ASSIGN(ClientMessageDispatcher); |
56 }; | 55 }; |
57 | 56 |
58 } // namespace protocol | 57 } // namespace protocol |
59 } // namespace remoting | 58 } // namespace remoting |
60 | 59 |
61 #endif // REMOTING_PROTOCOL_CLIENT_MESSAGE_DISPATCHER_H_ | 60 #endif // REMOTING_PROTOCOL_CLIENT_MESSAGE_DISPATCHER_H_ |
OLD | NEW |