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