| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EVENT_DISPATCHER_H_ | 5 #ifndef REMOTING_PROTOCOL_HOST_EVENT_DISPATCHER_H_ |
| 6 #define REMOTING_PROTOCOL_HOST_EVENT_DISPATCHER_H_ | 6 #define REMOTING_PROTOCOL_HOST_EVENT_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "remoting/protocol/channel_dispatcher_base.h" |
| 9 #include "remoting/protocol/message_reader.h" | 9 #include "remoting/protocol/message_reader.h" |
| 10 | 10 |
| 11 namespace remoting { | 11 namespace remoting { |
| 12 namespace protocol { | 12 namespace protocol { |
| 13 | 13 |
| 14 class EventMessage; | 14 class EventMessage; |
| 15 class InputStub; | 15 class InputStub; |
| 16 class Session; | |
| 17 | 16 |
| 18 // HostEventDispatcher dispatches incoming messages on the event | 17 // HostEventDispatcher dispatches incoming messages on the event |
| 19 // channel to InputStub. | 18 // channel to InputStub. |
| 20 class HostEventDispatcher { | 19 class HostEventDispatcher : public ChannelDispatcherBase { |
| 21 public: | 20 public: |
| 22 typedef base::Callback<void(int64)> SequenceNumberCallback; | 21 typedef base::Callback<void(int64)> SequenceNumberCallback; |
| 23 | 22 |
| 24 HostEventDispatcher(); | 23 HostEventDispatcher(); |
| 25 virtual ~HostEventDispatcher(); | 24 virtual ~HostEventDispatcher(); |
| 26 | 25 |
| 27 // Initialize the event channel and the dispatcher for the | |
| 28 // |session|. Caller retains ownership of |session|. | |
| 29 void Init(Session* session); | |
| 30 | |
| 31 // Set InputStub that will be called for each incoming input | 26 // Set InputStub that will be called for each incoming input |
| 32 // message. Doesn't take ownership of |input_stub|. It must outlive | 27 // message. Doesn't take ownership of |input_stub|. It must outlive |
| 33 // the dispatcher. | 28 // the dispatcher. |
| 34 void set_input_stub(InputStub* input_stub) { input_stub_ = input_stub; } | 29 void set_input_stub(InputStub* input_stub) { input_stub_ = input_stub; } |
| 35 | 30 |
| 36 // Set callback to notify of each message's sequence number. The | 31 // Set callback to notify of each message's sequence number. The |
| 37 // callback cannot tear down this object. | 32 // callback cannot tear down this object. |
| 38 void set_sequence_number_callback(const SequenceNumberCallback& value) { | 33 void set_sequence_number_callback(const SequenceNumberCallback& value) { |
| 39 sequence_number_callback_ = value; | 34 sequence_number_callback_ = value; |
| 40 } | 35 } |
| 41 | 36 |
| 37 protected: |
| 38 // ChannelDispatcherBase overrides. |
| 39 virtual void OnInitialized() OVERRIDE; |
| 40 |
| 42 private: | 41 private: |
| 43 // This method is called by |reader_| when a message is received. | |
| 44 void OnMessageReceived(EventMessage* message, | 42 void OnMessageReceived(EventMessage* message, |
| 45 const base::Closure& done_task); | 43 const base::Closure& done_task); |
| 46 | 44 |
| 47 InputStub* input_stub_; | 45 InputStub* input_stub_; |
| 48 SequenceNumberCallback sequence_number_callback_; | 46 SequenceNumberCallback sequence_number_callback_; |
| 49 | 47 |
| 50 ProtobufMessageReader<EventMessage> reader_; | 48 ProtobufMessageReader<EventMessage> reader_; |
| 51 | 49 |
| 52 DISALLOW_COPY_AND_ASSIGN(HostEventDispatcher); | 50 DISALLOW_COPY_AND_ASSIGN(HostEventDispatcher); |
| 53 }; | 51 }; |
| 54 | 52 |
| 55 } // namespace protocol | 53 } // namespace protocol |
| 56 } // namespace remoting | 54 } // namespace remoting |
| 57 | 55 |
| 58 #endif // REMOTING_PROTOCOL_HOST_EVENT_DISPATCHER_H_ | 56 #endif // REMOTING_PROTOCOL_HOST_EVENT_DISPATCHER_H_ |
| OLD | NEW |