summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/host_event_dispatcher.h
blob: e5d1a46313aa8319829dba96028002f61286f583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_PROTOCOL_HOST_EVENT_DISPATCHER_H_
#define REMOTING_PROTOCOL_HOST_EVENT_DISPATCHER_H_

#include "remoting/protocol/channel_dispatcher_base.h"
#include "remoting/protocol/message_reader.h"

namespace remoting {
namespace protocol {

class EventMessage;
class InputStub;

// HostEventDispatcher dispatches incoming messages on the event
// channel to InputStub.
class HostEventDispatcher : public ChannelDispatcherBase {
 public:
  typedef base::Callback<void(int64)> SequenceNumberCallback;

  HostEventDispatcher();
  virtual ~HostEventDispatcher();

  // Set InputStub that will be called for each incoming input
  // message. Doesn't take ownership of |input_stub|. It must outlive
  // the dispatcher.
  void set_input_stub(InputStub* input_stub) { input_stub_ = input_stub; }

  // Set callback to notify of each message's sequence number. The
  // callback cannot tear down this object.
  void set_sequence_number_callback(const SequenceNumberCallback& value) {
    sequence_number_callback_ = value;
  }

 protected:
  // ChannelDispatcherBase overrides.
  virtual void OnInitialized() OVERRIDE;

 private:
  void OnMessageReceived(scoped_ptr<EventMessage> message,
                         const base::Closure& done_task);

  InputStub* input_stub_;
  SequenceNumberCallback sequence_number_callback_;

  ProtobufMessageReader<EventMessage> reader_;

  DISALLOW_COPY_AND_ASSIGN(HostEventDispatcher);
};

}  // namespace protocol
}  // namespace remoting

#endif  // REMOTING_PROTOCOL_HOST_EVENT_DISPATCHER_H_