summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/host_message_dispatcher.cc
blob: 148dccf613b4106943a9f060083974c80d237e36 (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
// 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.

#include "net/base/io_buffer.h"
#include "remoting/base/multiple_array_input_stream.h"
#include "remoting/proto/control.pb.h"
#include "remoting/proto/event.pb.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/chromotocol_connection.h"
#include "remoting/protocol/host_message_dispatcher.h"
#include "remoting/protocol/host_control_message_handler.h"
#include "remoting/protocol/host_event_message_handler.h"
#include "remoting/protocol/message_reader.h"

namespace remoting {

HostMessageDispatcher::HostMessageDispatcher() {
}

HostMessageDispatcher::~HostMessageDispatcher() {
}

bool HostMessageDispatcher::Initialize(
    ChromotocolConnection* connection,
    HostControlMessageHandler* control_message_handler,
    HostEventMessageHandler* event_message_handler) {
  if (!connection || !control_message_handler || !event_message_handler ||
      !connection->event_channel() || !connection->control_channel()) {
    return false;
  }

  control_message_reader_.reset(new MessageReader());
  event_message_reader_.reset(new MessageReader());
  control_message_handler_.reset(control_message_handler);
  event_message_handler_.reset(event_message_handler);

  // Initialize the readers on the sockets provided by channels.
  event_message_reader_->Init<ClientEventMessage>(
      connection->event_channel(),
      NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived));
  control_message_reader_->Init<ClientControlMessage>(
      connection->control_channel(),
      NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived));
  return true;
}

void HostMessageDispatcher::OnControlMessageReceived(
    ClientControlMessage* message) {
  scoped_refptr<RefCountedMessage<ClientControlMessage> > ref_msg(
      new RefCountedMessage<ClientControlMessage>(message));
  if (message->has_suggest_screen_resolution_request()) {
    control_message_handler_->OnSuggestScreenResolutionRequest(
        message->suggest_screen_resolution_request(),
        NewRunnableFunction(
            &DeleteMessage<RefCountedMessage<ClientControlMessage> >,
            ref_msg));
  }
}

void HostMessageDispatcher::OnEventMessageReceived(
    ClientEventMessage* message) {
  // TODO(hclam): Implement.
}

}  // namespace remoting