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.
5 #include "remoting/protocol/host_control_dispatcher.h"
7 #include "base/callback_helpers.h"
8 #include "base/message_loop/message_loop_proxy.h"
9 #include "net/socket/stream_socket.h"
10 #include "remoting/base/constants.h"
11 #include "remoting/proto/control.pb.h"
12 #include "remoting/proto/internal.pb.h"
13 #include "remoting/protocol/clipboard_stub.h"
14 #include "remoting/protocol/host_stub.h"
15 #include "remoting/protocol/message_serialization.h"
20 HostControlDispatcher::HostControlDispatcher()
21 : ChannelDispatcherBase(kControlChannelName
),
22 clipboard_stub_(nullptr),
24 parser_(base::Bind(&HostControlDispatcher::OnMessageReceived
,
25 base::Unretained(this)),
29 HostControlDispatcher::~HostControlDispatcher() {
32 void HostControlDispatcher::SetCapabilities(
33 const Capabilities
& capabilities
) {
34 ControlMessage message
;
35 message
.mutable_capabilities()->CopyFrom(capabilities
);
36 writer()->Write(SerializeAndFrameMessage(message
), base::Closure());
39 void HostControlDispatcher::SetPairingResponse(
40 const PairingResponse
& pairing_response
) {
41 ControlMessage message
;
42 message
.mutable_pairing_response()->CopyFrom(pairing_response
);
43 writer()->Write(SerializeAndFrameMessage(message
), base::Closure());
46 void HostControlDispatcher::DeliverHostMessage(
47 const ExtensionMessage
& message
) {
48 ControlMessage control_message
;
49 control_message
.mutable_extension_message()->CopyFrom(message
);
50 writer()->Write(SerializeAndFrameMessage(control_message
), base::Closure());
53 void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent
& event
) {
54 ControlMessage message
;
55 message
.mutable_clipboard_event()->CopyFrom(event
);
56 writer()->Write(SerializeAndFrameMessage(message
), base::Closure());
59 void HostControlDispatcher::SetCursorShape(
60 const CursorShapeInfo
& cursor_shape
) {
61 ControlMessage message
;
62 message
.mutable_cursor_shape()->CopyFrom(cursor_shape
);
63 writer()->Write(SerializeAndFrameMessage(message
), base::Closure());
66 void HostControlDispatcher::OnMessageReceived(
67 scoped_ptr
<ControlMessage
> message
, const base::Closure
& done_task
) {
68 DCHECK(clipboard_stub_
);
71 base::ScopedClosureRunner
done_runner(done_task
);
73 if (message
->has_clipboard_event()) {
74 clipboard_stub_
->InjectClipboardEvent(message
->clipboard_event());
75 } else if (message
->has_client_resolution()) {
76 host_stub_
->NotifyClientResolution(message
->client_resolution());
77 } else if (message
->has_video_control()) {
78 host_stub_
->ControlVideo(message
->video_control());
79 } else if (message
->has_audio_control()) {
80 host_stub_
->ControlAudio(message
->audio_control());
81 } else if (message
->has_capabilities()) {
82 host_stub_
->SetCapabilities(message
->capabilities());
83 } else if (message
->has_pairing_request()) {
84 host_stub_
->RequestPairing(message
->pairing_request());
85 } else if (message
->has_extension_message()) {
86 host_stub_
->DeliverClientMessage(message
->extension_message());
88 LOG(WARNING
) << "Unknown control message received.";
92 } // namespace protocol
93 } // namespace remoting