| 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_HOST_MESSAGE_DISPATCHER_H_ | 5 #ifndef REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ |
| 6 #define REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ | 6 #define REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 | 14 |
| 15 class ChromotocolConnection; | |
| 16 class EventMessage; | 15 class EventMessage; |
| 17 class MessageReader; | 16 class MessageReader; |
| 18 | 17 |
| 19 namespace protocol { | 18 namespace protocol { |
| 20 | 19 |
| 21 class ControlMessage; | 20 class ControlMessage; |
| 22 class HostStub; | 21 class HostStub; |
| 23 class InputStub; | 22 class InputStub; |
| 23 class Session; |
| 24 | 24 |
| 25 // A message dispatcher used to listen for messages received in | 25 // A message dispatcher used to listen for messages received in |
| 26 // ChromotocolConnection. It dispatches messages to the corresponding | 26 // protocol::Session. It dispatches messages to the corresponding |
| 27 // handler. | 27 // handler. |
| 28 // | 28 // |
| 29 // Internally it contains an EventStreamReader that decodes data on | 29 // Internally it contains an EventStreamReader that decodes data on |
| 30 // communications channels into protocol buffer messages. | 30 // communications channels into protocol buffer messages. |
| 31 // EventStreamReader is registered with ChromotocolConnection given to it. | 31 // EventStreamReader is registered with protocol::Session given to it. |
| 32 // | 32 // |
| 33 // Object of this class is owned by ChromotingHost to dispatch messages | 33 // Object of this class is owned by ChromotingHost to dispatch messages |
| 34 // to itself. | 34 // to itself. |
| 35 class HostMessageDispatcher : | 35 class HostMessageDispatcher : |
| 36 public base::RefCountedThreadSafe<HostMessageDispatcher> { | 36 public base::RefCountedThreadSafe<HostMessageDispatcher> { |
| 37 public: | 37 public: |
| 38 // Construct a message dispatcher. | 38 // Construct a message dispatcher. |
| 39 HostMessageDispatcher(); | 39 HostMessageDispatcher(); |
| 40 virtual ~HostMessageDispatcher(); | 40 virtual ~HostMessageDispatcher(); |
| 41 | 41 |
| 42 // Initialize the message dispatcher with the given connection and | 42 // Initialize the message dispatcher with the given connection and |
| 43 // message handlers. | 43 // message handlers. |
| 44 // Return true if initalization was successful. | 44 // Return true if initalization was successful. |
| 45 bool Initialize(ChromotocolConnection* connection, | 45 bool Initialize(protocol::Session* session, |
| 46 HostStub* host_stub, InputStub* input_stub); | 46 HostStub* host_stub, InputStub* input_stub); |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 // This method is called by |control_channel_reader_| when a control | 49 // This method is called by |control_channel_reader_| when a control |
| 50 // message is received. | 50 // message is received. |
| 51 void OnControlMessageReceived(ControlMessage* message); | 51 void OnControlMessageReceived(ControlMessage* message); |
| 52 | 52 |
| 53 // This method is called by |event_channel_reader_| when a event | 53 // This method is called by |event_channel_reader_| when a event |
| 54 // message is received. | 54 // message is received. |
| 55 void OnEventMessageReceived(EventMessage* message); | 55 void OnEventMessageReceived(EventMessage* message); |
| 56 | 56 |
| 57 // MessageReader that runs on the control channel. It runs a loop | 57 // MessageReader that runs on the control channel. It runs a loop |
| 58 // that parses data on the channel and then delegates the message to this | 58 // that parses data on the channel and then delegates the message to this |
| 59 // class. | 59 // class. |
| 60 scoped_ptr<MessageReader> control_message_reader_; | 60 scoped_ptr<MessageReader> control_message_reader_; |
| 61 | 61 |
| 62 // MessageReader that runs on the event channel. | 62 // MessageReader that runs on the event channel. |
| 63 scoped_ptr<MessageReader> event_message_reader_; | 63 scoped_ptr<MessageReader> event_message_reader_; |
| 64 | 64 |
| 65 // Stubs for host and input. These objects are not owned. | 65 // Stubs for host and input. These objects are not owned. |
| 66 // They are called on the thread there data is received, i.e. jingle thread. | 66 // They are called on the thread there data is received, i.e. jingle thread. |
| 67 HostStub* host_stub_; | 67 HostStub* host_stub_; |
| 68 InputStub* input_stub_; | 68 InputStub* input_stub_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 } // namespace protocol | 71 } // namespace protocol |
| 72 } // namespace remoting | 72 } // namespace remoting |
| 73 | 73 |
| 74 #endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ | 74 #endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ |
| OLD | NEW |