blob: 0c44cc2ee0b10564225eb80bd3112afd6f7bbf45 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// 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.
#include "remoting/protocol/host_control_dispatcher.h"
#include "base/message_loop_proxy.h"
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "remoting/proto/control.pb.h"
#include "remoting/proto/internal.pb.h"
#include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/host_stub.h"
#include "remoting/protocol/util.h"
namespace remoting {
namespace protocol {
HostControlDispatcher::HostControlDispatcher()
: ChannelDispatcherBase(kControlChannelName),
clipboard_stub_(NULL),
host_stub_(NULL) {
}
HostControlDispatcher::~HostControlDispatcher() {
writer_.Close();
}
void HostControlDispatcher::OnInitialized() {
reader_.Init(channel(), base::Bind(
&HostControlDispatcher::OnMessageReceived, base::Unretained(this)));
writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback());
}
void HostControlDispatcher::SetCapabilities(
const Capabilities& capabilities) {
ControlMessage message;
message.mutable_capabilities()->CopyFrom(capabilities);
writer_.Write(SerializeAndFrameMessage(message), base::Closure());
}
void HostControlDispatcher::SetPairingResponse(
const PairingResponse& pairing_response) {
ControlMessage message;
message.mutable_pairing_response()->CopyFrom(pairing_response);
writer_.Write(SerializeAndFrameMessage(message), base::Closure());
}
void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
ControlMessage message;
message.mutable_clipboard_event()->CopyFrom(event);
writer_.Write(SerializeAndFrameMessage(message), base::Closure());
}
void HostControlDispatcher::SetCursorShape(
const CursorShapeInfo& cursor_shape) {
ControlMessage message;
message.mutable_cursor_shape()->CopyFrom(cursor_shape);
writer_.Write(SerializeAndFrameMessage(message), base::Closure());
}
void HostControlDispatcher::OnMessageReceived(
scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
DCHECK(clipboard_stub_);
DCHECK(host_stub_);
base::ScopedClosureRunner done_runner(done_task);
if (message->has_clipboard_event()) {
clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
} else if (message->has_client_resolution()) {
host_stub_->NotifyClientResolution(message->client_resolution());
} else if (message->has_video_control()) {
host_stub_->ControlVideo(message->video_control());
} else if (message->has_audio_control()) {
host_stub_->ControlAudio(message->audio_control());
} else if (message->has_capabilities()) {
host_stub_->SetCapabilities(message->capabilities());
} else if (message->has_pairing_request()) {
host_stub_->RequestPairing(message->pairing_request());
} else {
LOG(WARNING) << "Unknown control message received.";
}
}
} // namespace protocol
} // namespace remoting
|