Skip to content

Commit

Permalink
HostMessageDispatcher to dispatch messages received on a chromoting c…
Browse files Browse the repository at this point in the history
…onnection

Adding HostMessageDispatcher to be used by ChromotingHost.

BUG=None
TEST=None

Review URL: http://codereview.chromium.org/3852002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63111 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hclam@chromium.org committed Oct 19, 2010
1 parent 0d7dad6 commit 94b2c17
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 3 deletions.
22 changes: 21 additions & 1 deletion remoting/proto/control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ option optimize_for = LITE_RUNTIME;

package remoting;

// TODO(hclam): Define control messages.
message SuggestScreenResolutionRequest {
required int32 width = 1;
required int32 height = 2;
};

// Represents a control message that sent from the client to the host.
// This message is transmitted on the control channel.
message ClientControlMessage {
optional SuggestScreenResolutionRequest suggestScreenResolutionRequest = 1;
}

message SetScreenResolutionRequest {
required int32 width = 1;
required int32 height = 2;
};

// Represents a control message that sent from host to the client.
// This message is transmitted on the control channel.
message HostControlMessage {
optional SetScreenResolutionRequest setScreenResolutionRequest = 1;
}
36 changes: 36 additions & 0 deletions remoting/proto/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,39 @@ message MouseDownEvent {
message MouseUpEvent {
required MouseButton button = 1;
}

// Defines a mouse event message on the event channel.
message MouseEvent {
// Mouse position information.
optional int32 mouse_x = 1;
optional int32 mouse_y = 2;

// Mouse wheel information.
optional int32 wheel_offset_x = 3;
optional int32 wheel_offset_y = 4;

// Mouse button information.
optional MouseButton button = 5;
optional bool button_down = 6;
}

// Defines an event message on the event channel.
message Event {
required int32 timestamp = 1; // Client timestamp for event
optional bool dummy = 2; // Is this a dummy event?

optional KeyEvent key = 3;
optional MouseEvent mouse = 4;
}

// Defines the message that is sent from client to host.
// Only one of the optional messages should be present.
message ClientEventMessage {
repeated Event events = 1;
}

// Defines the message that is sent from host to client.
// Only one of the optional messages should be present.
message HostEventMessage {
// TODO(hclam): Define the message.
}
1 change: 0 additions & 1 deletion remoting/proto/internal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ message ChromotingHostMessage {
optional BeginUpdateStreamMessage begin_update_stream = 2;
optional EndUpdateStreamMessage end_update_stream = 3;
optional UpdateStreamPacketMessage update_stream_packet = 4;

optional RectangleUpdatePacket rectangle_update = 5;
}

Expand Down
27 changes: 27 additions & 0 deletions remoting/protocol/host_control_message_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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_CONTROL_MESSAGE_HANDLER_H_
#define REMOTING_PROTOCOL_HOST_CONTROL_MESSAGE_HANDLER_H_

#include "remoting/proto/control.pb.h"

class Task;

namespace remoting {

// The interface for handling control messages sent to the host.
// For all methods of this interface. |task| needs to be called when
// receiver is done processing the event.
class HostControlMessageHandler {
public:
virtual ~HostControlMessageHandler() {}

virtual void OnSuggestScreenResolutionRequest(
const SuggestScreenResolutionRequest& request, Task* task) = 0;
};

} // namespace remoting

#endif // REMOTING_PROTOCOL_HOST_CONTROL_MESSAGE_HANDLER_H_
30 changes: 30 additions & 0 deletions remoting/protocol/host_event_message_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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_EVENT_MESSAGE_HANDLER_H_
#define REMOTING_PROTOCOL_HOST_EVENT_MESSAGE_HANDLER_H_

#include "base/basictypes.h"
#include "remoting/proto/event.pb.h"

class Task;

namespace remoting {

// The interface for handling event messages sent to the host.
// For all methods of this interface. |task| needs to be called when
// receiver is done processing the event.
class HostEventMessageHandler {
public:
virtual ~HostEventMessageHandler() {}

virtual void OnKeyEvent(int32 timestamp,
const KeyEvent& event, Task* task) = 0;
virtual void OnMouseEvent(int32 timestamp, const MouseEvent& event,
Task* task) = 0;
};

} // namespace remoting

#endif // REMOTING_PROTOCOL_HOST_EVENT_MESSAGE_HANDLER_H_
28 changes: 28 additions & 0 deletions remoting/protocol/host_message_dispatcher.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 "base/message_loop_proxy.h"
#include "remoting/proto/control.pb.h"
#include "remoting/proto/event.pb.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/stream_reader.h"

namespace remoting {

HostMessageDispatcher::HostMessageDispatcher(
base::MessageLoopProxy* message_loop_proxy,
ChromotingConnection* connection,
HostControlMessageHandler* control_message_handler,
HostEventMessageHandler* event_message_handler)
: message_loop_proxy_(message_loop_proxy),
control_message_handler_(control_message_handler),
event_message_handler_(event_message_handler) {
}

HostMessageDispatcher::~HostMessageDispatcher() {
}

} // namespace remoting
73 changes: 73 additions & 0 deletions remoting/protocol/host_message_dispatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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"

namespace base {
class MessageLoopProxy;
} // namespace base

namespace remoting {

class ChromotingClientMessage;
class ChromotingConnection;
class EventsStreamReader;
class HostControlMessageHandler;
class HostEventMessageHandler;

// A message dispatcher used to listen for messages received in
// ChromotingConnection. It dispatches messages to the corresponding
// handler.
//
// Internally it contains an EventsStreamReader that decodes data on
// communications channels into protocol buffer messages.
// EventStreamReader is registered with ChromotingConnection given to it.
//
// Object of this class is owned by ChromotingHost to dispatch messages
// to itself.
class HostMessageDispatcher {
public:
// Construct a message dispatcher that dispatches messages received
// in ChromotingConnection.
HostMessageDispatcher(base::MessageLoopProxy* message_loop_proxy,
ChromotingConnection* connection,
HostControlMessageHandler* control_message_handler,
HostEventMessageHandler* event_message_handler);

virtual ~HostMessageDispatcher();

private:
// This method is called by |control_channel_reader_| when a control
// message is received.
void OnControlMessageReceived(ChromotingClientMessage* message);

// This method is called by |event_channel_reader_| when a event
// message is received.
void OnEventMessageReceived(ChromotingClientMessage* message);

// Message loop to dispatch the messages.
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;

// EventsStreamReader that runs on the control channel. It runs a loop
// that parses data on the channel and then delegate the message to this
// class.
scoped_ptr<EventsStreamReader> control_channel_reader_;

// EventsStreamReader that runs on the event channel.
scoped_ptr<EventsStreamReader> event_channel_reader_;

// Event handlers for control channel and event channel respectively.
// Method calls to these objects are made on the message loop given.
scoped_ptr<HostControlMessageHandler> control_message_handler_;
scoped_ptr<HostEventMessageHandler> event_message_handler_;
};

} // namespace remoting

#endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_
2 changes: 1 addition & 1 deletion remoting/protocol/stream_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class EventsStreamReader : public StreamReaderBase {
DISALLOW_COPY_AND_ASSIGN(EventsStreamReader);
};

class VideoStreamReader : public StreamReaderBase {
class VideoStreamReader : public StreamReaderBase {
public:
VideoStreamReader();
~VideoStreamReader();
Expand Down
4 changes: 4 additions & 0 deletions remoting/remoting.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@
'protocol/buffered_socket_writer.h',
'protocol/chromoting_connection.h',
'protocol/chromoting_server.h',
'protocol/host_message_dispatcher.cc',
'protocol/host_message_dispatcher.h',
'protocol/host_control_message_handler.h',
'protocol/host_event_message_handler.h',
'protocol/jingle_chromoting_connection.cc',
'protocol/jingle_chromoting_connection.h',
'protocol/jingle_chromoting_server.cc',
Expand Down

0 comments on commit 94b2c17

Please sign in to comment.