blob: cd95b264be2d25eeb4cd28d9f9c9efad9f53418f (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright (c) 2010 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_MESSAGE_DISPATCHER_H_
#define REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_
#include "base/basictypes.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
namespace remoting {
class EventMessage;
class MessageReader;
namespace protocol {
class ControlMessage;
class HostStub;
class InputStub;
class Session;
// A message dispatcher used to listen for messages received in
// protocol::Session. It dispatches messages to the corresponding
// handler.
//
// Internally it contains an EventStreamReader that decodes data on
// communications channels into protocol buffer messages.
// EventStreamReader is registered with protocol::Session given to it.
//
// Object of this class is owned by ChromotingHost to dispatch messages
// to itself.
class HostMessageDispatcher :
public base::RefCountedThreadSafe<HostMessageDispatcher> {
public:
// Construct a message dispatcher.
HostMessageDispatcher();
virtual ~HostMessageDispatcher();
// Initialize the message dispatcher with the given connection and
// message handlers.
// Return true if initalization was successful.
bool Initialize(protocol::Session* session,
HostStub* host_stub, InputStub* input_stub);
private:
// This method is called by |control_channel_reader_| when a control
// message is received.
void OnControlMessageReceived(ControlMessage* message);
// This method is called by |event_channel_reader_| when a event
// message is received.
void OnEventMessageReceived(EventMessage* message);
// MessageReader that runs on the control channel. It runs a loop
// that parses data on the channel and then delegates the message to this
// class.
scoped_ptr<MessageReader> control_message_reader_;
// MessageReader that runs on the event channel.
scoped_ptr<MessageReader> event_message_reader_;
// Stubs for host and input. These objects are not owned.
// They are called on the thread there data is received, i.e. jingle thread.
HostStub* host_stub_;
InputStub* input_stub_;
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_
|