diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 21:42:25 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 21:42:25 +0000 |
commit | 5e240672f29d5371b193ca641bab85e8fcc72e7e (patch) | |
tree | 3e6b99b8ba30155099c63fcc00bb35cd83d1ecde | |
parent | b92699afc8e0c70dfa9ed198786cba63d38fd5b2 (diff) | |
download | chromium_src-5e240672f29d5371b193ca641bab85e8fcc72e7e.zip chromium_src-5e240672f29d5371b193ca641bab85e8fcc72e7e.tar.gz chromium_src-5e240672f29d5371b193ca641bab85e8fcc72e7e.tar.bz2 |
Stub classes for Chromoting and use them in HostMessageDispatcher.
(Landing http://http://codereview.chromium.org/4167011 for hclam)
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/4336001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64818 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | remoting/proto/control.proto | 21 | ||||
-rw-r--r-- | remoting/proto/event.proto | 13 | ||||
-rw-r--r-- | remoting/proto/internal.proto | 1 | ||||
-rw-r--r-- | remoting/protocol/client_stub.h | 37 | ||||
-rw-r--r-- | remoting/protocol/host_control_message_handler.h | 27 | ||||
-rw-r--r-- | remoting/protocol/host_event_message_handler.h | 30 | ||||
-rw-r--r-- | remoting/protocol/host_message_dispatcher.cc | 68 | ||||
-rw-r--r-- | remoting/protocol/host_message_dispatcher.h | 46 | ||||
-rw-r--r-- | remoting/protocol/host_stub.h | 36 | ||||
-rw-r--r-- | remoting/protocol/input_stub.h | 37 |
10 files changed, 184 insertions, 132 deletions
diff --git a/remoting/proto/control.proto b/remoting/proto/control.proto index 99b5d37..6e40658 100644 --- a/remoting/proto/control.proto +++ b/remoting/proto/control.proto @@ -8,26 +8,21 @@ syntax = "proto2"; option optimize_for = LITE_RUNTIME; -package remoting; +package remoting.protocol; -message SuggestScreenResolutionRequest { +// TODO(hclam): Isolate rectangle from these two messages. +message SuggestResolutionRequest { 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 suggest_screen_resolution_request = 1; -} - -message SetScreenResolutionRequest { +message NotifyResolutionRequest { 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 set_screen_resolution_request = 1; +// Represents a message being sent on the control channel. +message ControlMessage { + optional SuggestResolutionRequest suggest_resolution = 1; + optional NotifyResolutionRequest notify_resolution = 2; } diff --git a/remoting/proto/event.proto b/remoting/proto/event.proto index 2526d78..1f14c9dc 100644 --- a/remoting/proto/event.proto +++ b/remoting/proto/event.proto @@ -90,14 +90,7 @@ message Event { 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. +// Message sent in the event channel. +message EventMessage { + repeated Event event = 1; } diff --git a/remoting/proto/internal.proto b/remoting/proto/internal.proto index 3319420..fbe3181 100644 --- a/remoting/proto/internal.proto +++ b/remoting/proto/internal.proto @@ -6,7 +6,6 @@ syntax = "proto2"; -import "control.proto"; import "event.proto"; import "video.proto"; diff --git a/remoting/protocol/client_stub.h b/remoting/protocol/client_stub.h new file mode 100644 index 0000000..8873a13 --- /dev/null +++ b/remoting/protocol/client_stub.h @@ -0,0 +1,37 @@ +// 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. + +// Interface of a client that receives commands from a Chromoting host. +// +// This interface is responsible for a subset of control messages sent to +// the Chromoting client. + +#ifndef REMOTING_PROTOCOL_CLIENT_STUB_H_ +#define REMOTING_PROTOCOL_CLIENT_STUB_H_ + +#include "base/basictypes.h" + +class Task; + +namespace remoting { +namespace protocol { + +class NotifyScreenResolution; + +class ClientStub { + public: + ClientStub() {} + virtual ~ClientStub() {} + + virtual void NotifyScreenResolution(const NotifyScreenResolution& msg, + Task* done) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(ClientStub); +}; + +} // namespace protocol +} // namespace remoting + +#endif // REMOTING_PROTOCOL_CLIENT_STUB_H_ diff --git a/remoting/protocol/host_control_message_handler.h b/remoting/protocol/host_control_message_handler.h deleted file mode 100644 index 8bb60cd..0000000 --- a/remoting/protocol/host_control_message_handler.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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_ diff --git a/remoting/protocol/host_event_message_handler.h b/remoting/protocol/host_event_message_handler.h deleted file mode 100644 index 0d01357..0000000 --- a/remoting/protocol/host_event_message_handler.h +++ /dev/null @@ -1,30 +0,0 @@ -// 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_ diff --git a/remoting/protocol/host_message_dispatcher.cc b/remoting/protocol/host_message_dispatcher.cc index 148dccf..5406813 100644 --- a/remoting/protocol/host_message_dispatcher.cc +++ b/remoting/protocol/host_message_dispatcher.cc @@ -9,13 +9,43 @@ #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/host_stub.h" +#include "remoting/protocol/input_stub.h" #include "remoting/protocol/message_reader.h" +namespace { + +// A single protobuf can contain multiple messages that will be handled by +// different message handlers. We use this wrapper to ensure that the +// protobuf is only deleted after all the handlers have finished executing. +template <typename T> +class RefCountedMessage : public base::RefCounted<RefCountedMessage<T> > { + public: + RefCountedMessage(T* message) : message_(message) { } + + T* message() { return message_.get(); } + + private: + scoped_ptr<T> message_; +}; + +// Dummy methods to destroy messages. +template <class T> +static void DeleteMessage(scoped_refptr<T> message) { } + +template <class T> +static Task* NewDeleteTask(scoped_refptr<T> message) { + return NewRunnableFunction(&DeleteMessage<T>, message); +} + +} // namespace + namespace remoting { +namespace protocol { -HostMessageDispatcher::HostMessageDispatcher() { +HostMessageDispatcher::HostMessageDispatcher() : + host_stub_(NULL), + input_stub_(NULL) { } HostMessageDispatcher::~HostMessageDispatcher() { @@ -23,44 +53,40 @@ HostMessageDispatcher::~HostMessageDispatcher() { bool HostMessageDispatcher::Initialize( ChromotocolConnection* connection, - HostControlMessageHandler* control_message_handler, - HostEventMessageHandler* event_message_handler) { - if (!connection || !control_message_handler || !event_message_handler || + HostStub* host_stub, InputStub* input_stub) { + if (!connection || !host_stub || !input_stub || !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); + host_stub_ = host_stub; + input_stub_ = input_stub; // Initialize the readers on the sockets provided by channels. - event_message_reader_->Init<ClientEventMessage>( + event_message_reader_->Init<EventMessage>( connection->event_channel(), NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); - control_message_reader_->Init<ClientControlMessage>( + control_message_reader_->Init<ControlMessage>( 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::OnControlMessageReceived(ControlMessage* message) { + scoped_refptr<RefCountedMessage<ControlMessage> > ref_msg = + new RefCountedMessage<ControlMessage>(message); + if (message->has_suggest_resolution()) { + host_stub_->SuggestResolution( + message->suggest_resolution(), NewDeleteTask(ref_msg)); } } void HostMessageDispatcher::OnEventMessageReceived( - ClientEventMessage* message) { + EventMessage* message) { // TODO(hclam): Implement. } +} // namespace protocol } // namespace remoting diff --git a/remoting/protocol/host_message_dispatcher.h b/remoting/protocol/host_message_dispatcher.h index 23dc55a..7357723 100644 --- a/remoting/protocol/host_message_dispatcher.h +++ b/remoting/protocol/host_message_dispatcher.h @@ -8,16 +8,20 @@ #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/task.h" namespace remoting { class ChromotocolConnection; -class ClientControlMessage; -class ClientEventMessage; -class HostControlMessageHandler; -class HostEventMessageHandler; +class EventMessage; class MessageReader; +namespace protocol { + +class ControlMessage; +class HostStub; +class InputStub; + // A message dispatcher used to listen for messages received in // ChromotocolConnection. It dispatches messages to the corresponding // handler. @@ -39,35 +43,16 @@ class HostMessageDispatcher : // message handlers. // Return true if initalization was successful. bool Initialize(ChromotocolConnection* connection, - HostControlMessageHandler* control_message_handler, - HostEventMessageHandler* event_message_handler); + HostStub* host_stub, InputStub* input_stub); private: - // A single protobuf can contain multiple messages that will be handled by - // different message handlers. We use this wrapper to ensure that the - // protobuf is only deleted after all the handlers have finished executing. - template <typename T> - class RefCountedMessage : public base::RefCounted<RefCountedMessage<T> > { - public: - RefCountedMessage(T* message) : message_(message) { } - - T* message() { return message_.get(); } - - private: - scoped_ptr<T> message_; - }; - // This method is called by |control_channel_reader_| when a control // message is received. - void OnControlMessageReceived(ClientControlMessage* message); + void OnControlMessageReceived(ControlMessage* message); // This method is called by |event_channel_reader_| when a event // message is received. - void OnEventMessageReceived(ClientEventMessage* message); - - // Dummy methods to destroy messages. - template <class T> - static void DeleteMessage(scoped_refptr<T> message) { } + void OnEventMessageReceived(EventMessage* message); // MessageReader that runs on the control channel. It runs a loop // that parses data on the channel and then delegates the message to this @@ -77,12 +62,13 @@ class HostMessageDispatcher : // MessageReader that runs on the event channel. scoped_ptr<MessageReader> event_message_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_; + // Stubs for host and input. These objects are not owned. + // They are called on the thread there data is received, i.e. jingle thread. + HostStub* host_stub_; + InputStub* input_stub_; }; +} // namespace protocol } // namespace remoting #endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ diff --git a/remoting/protocol/host_stub.h b/remoting/protocol/host_stub.h new file mode 100644 index 0000000..a9e2fa5 --- /dev/null +++ b/remoting/protocol/host_stub.h @@ -0,0 +1,36 @@ +// 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. + +// Interface of a host that receives commands from a Chromoting client. +// +// This interterface handles control messages defined in contro.proto. + +#ifndef REMOTING_PROTOCOL_HOST_STUB_H_ +#define REMOTING_PROTOCOL_HOST_STUB_H_ + +#include "base/basictypes.h" + +class Task; + +namespace remoting { +namespace protocol { + +class SuggestResolutionRequest; + +class HostStub { + public: + HostStub() {} + virtual ~HostStub() {}; + + virtual void SuggestResolution( + const SuggestResolutionRequest& msg, Task* done) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(HostStub); +}; + +} // namespace protocol +} // namespace remoting + +#endif // REMOTING_PROTOCOL_HOST_STUB_H_ diff --git a/remoting/protocol/input_stub.h b/remoting/protocol/input_stub.h new file mode 100644 index 0000000..680163b --- /dev/null +++ b/remoting/protocol/input_stub.h @@ -0,0 +1,37 @@ +// 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. + +// Interface for a device that receives input events. +// This interface handles event messages defined in event.proto. + +#ifndef REMOTING_PROTOCOL_INPUT_STUB_H_ +#define REMOTING_PROTOCOL_INPUT_STUB_H_ + +#include "base/basictypes.h" + +class Task; + +namespace remoting { + +class KeyEvent; +class MouseEvent; + +namespace protocol { + +class InputStub { + public: + InputStub() {} + virtual ~InputStub() {} + + virtual void InjectKeyEvent(const KeyEvent& event, Task* done) = 0; + virtual void InjectMouseEvent(const MouseEvent& event, Task* done) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(InputStub); +}; + +} // namespace protocol +} // namespace remoting + +#endif // REMOTING_PROTOCOL_INPUT_STUB_H_ |