blob: 6830981a38ec71992b65e65c8310efefe5fcb58c [file] [log] [blame]
[email protected]e265ad72012-03-16 17:28:031// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]409ac612011-11-18 04:05:572// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "remoting/protocol/client_control_dispatcher.h"
6
[email protected]c6944272012-01-06 22:12:287#include "base/bind_helpers.h"
8#include "base/callback.h"
[email protected]409ac612011-11-18 04:05:579#include "base/message_loop_proxy.h"
[email protected]2e8b52c2011-11-22 00:07:1310#include "net/socket/stream_socket.h"
11#include "remoting/base/constants.h"
[email protected]409ac612011-11-18 04:05:5712#include "remoting/proto/control.pb.h"
[email protected]409ac612011-11-18 04:05:5713#include "remoting/proto/internal.pb.h"
14#include "remoting/protocol/client_stub.h"
[email protected]e265ad72012-03-16 17:28:0315#include "remoting/protocol/util.h"
[email protected]409ac612011-11-18 04:05:5716
17namespace remoting {
18namespace protocol {
19
20ClientControlDispatcher::ClientControlDispatcher()
[email protected]2e8b52c2011-11-22 00:07:1321 : ChannelDispatcherBase(kControlChannelName),
22 client_stub_(NULL),
[email protected]a3464dca2012-05-24 01:27:0923 clipboard_stub_(NULL) {
[email protected]409ac612011-11-18 04:05:5724}
25
26ClientControlDispatcher::~ClientControlDispatcher() {
[email protected]a3464dca2012-05-24 01:27:0927 writer_.Close();
[email protected]409ac612011-11-18 04:05:5728}
29
[email protected]2e8b52c2011-11-22 00:07:1330void ClientControlDispatcher::OnInitialized() {
[email protected]409ac612011-11-18 04:05:5731 // TODO(garykac): Set write failed callback.
[email protected]a3464dca2012-05-24 01:27:0932 writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback());
[email protected]2e8b52c2011-11-22 00:07:1333 reader_.Init(channel(), base::Bind(
[email protected]409ac612011-11-18 04:05:5734 &ClientControlDispatcher::OnMessageReceived, base::Unretained(this)));
35}
36
[email protected]e265ad72012-03-16 17:28:0337void ClientControlDispatcher::InjectClipboardEvent(
38 const ClipboardEvent& event) {
39 ControlMessage message;
40 message.mutable_clipboard_event()->CopyFrom(event);
[email protected]a3464dca2012-05-24 01:27:0941 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
[email protected]e265ad72012-03-16 17:28:0342}
43
[email protected]48a8ca32013-02-13 04:31:0144void ClientControlDispatcher::NotifyClientResolution(
45 const ClientResolution& resolution) {
[email protected]f2b9cf32012-04-27 00:13:4346 ControlMessage message;
[email protected]48a8ca32013-02-13 04:31:0147 message.mutable_client_resolution()->CopyFrom(resolution);
[email protected]a3464dca2012-05-24 01:27:0948 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
[email protected]f2b9cf32012-04-27 00:13:4349}
50
[email protected]50d71c72012-05-03 01:28:5551void ClientControlDispatcher::ControlVideo(const VideoControl& video_control) {
52 ControlMessage message;
53 message.mutable_video_control()->CopyFrom(video_control);
[email protected]a3464dca2012-05-24 01:27:0954 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
[email protected]50d71c72012-05-03 01:28:5555}
56
[email protected]f458bed2012-10-18 03:27:5957void ClientControlDispatcher::ControlAudio(const AudioControl& audio_control) {
58 ControlMessage message;
59 message.mutable_audio_control()->CopyFrom(audio_control);
60 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
61}
62
[email protected]409ac612011-11-18 04:05:5763void ClientControlDispatcher::OnMessageReceived(
[email protected]9302fce2012-03-28 03:57:5764 scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
[email protected]409ac612011-11-18 04:05:5765 DCHECK(client_stub_);
[email protected]ba6d1c2d2012-03-31 01:28:3866 DCHECK(clipboard_stub_);
[email protected]409ac612011-11-18 04:05:5767 base::ScopedClosureRunner done_runner(done_task);
[email protected]ba6d1c2d2012-03-31 01:28:3868
69 if (message->has_clipboard_event()) {
70 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
[email protected]d65e15bd2012-06-02 22:16:4171 } else if (message->has_cursor_shape()) {
72 client_stub_->SetCursorShape(message->cursor_shape());
[email protected]ba6d1c2d2012-03-31 01:28:3873 } else {
74 LOG(WARNING) << "Unknown control message received.";
75 }
[email protected]409ac612011-11-18 04:05:5776}
77
78} // namespace protocol
79} // namespace remoting