| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_ | 5 #ifndef REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_ |
| 6 #define REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_ | 6 #define REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_ |
| 7 | 7 |
| 8 #include <deque> | |
| 9 #include <string> | 8 #include <string> |
| 10 #include <vector> | |
| 11 | 9 |
| 12 #include "base/memory/scoped_ptr.h" | 10 #include "remoting/protocol/transport.h" |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "base/threading/non_thread_safe.h" | |
| 15 #include "remoting/protocol/audio_writer.h" | |
| 16 #include "remoting/protocol/session.h" | |
| 17 | 11 |
| 18 namespace remoting { | 12 namespace remoting { |
| 19 namespace protocol { | 13 namespace protocol { |
| 20 | 14 |
| 15 class AudioStub; |
| 21 class ClientStub; | 16 class ClientStub; |
| 22 class ClipboardStub; | 17 class ClipboardStub; |
| 23 class HostControlDispatcher; | |
| 24 class HostEventDispatcher; | |
| 25 class HostStub; | 18 class HostStub; |
| 26 class HostVideoDispatcher; | |
| 27 class InputStub; | 19 class InputStub; |
| 20 class Session; |
| 28 class VideoFeedbackStub; | 21 class VideoFeedbackStub; |
| 29 class VideoStub; | 22 class VideoStub; |
| 30 | 23 |
| 31 // This class represents a remote viewer connection to the chromoting | 24 // This interface represents a remote viewer connection to the chromoting host. |
| 32 // host. It sets up all protocol channels and connects them to the | 25 // It sets up all protocol channels and connects them to the stubs. |
| 33 // stubs. | 26 class ConnectionToClient { |
| 34 class ConnectionToClient : public base::NonThreadSafe, | |
| 35 public Session::EventHandler, | |
| 36 public ChannelDispatcherBase::EventHandler { | |
| 37 public: | 27 public: |
| 38 class EventHandler { | 28 class EventHandler { |
| 39 public: | 29 public: |
| 40 // Called when the network connection is authenticating | 30 // Called when the network connection is authenticating |
| 41 virtual void OnConnectionAuthenticating(ConnectionToClient* connection) = 0; | 31 virtual void OnConnectionAuthenticating(ConnectionToClient* connection) = 0; |
| 42 | 32 |
| 43 // Called when the network connection is authenticated. | 33 // Called when the network connection is authenticated. |
| 44 virtual void OnConnectionAuthenticated(ConnectionToClient* connection) = 0; | 34 virtual void OnConnectionAuthenticated(ConnectionToClient* connection) = 0; |
| 45 | 35 |
| 46 // Called when the network connection is authenticated and all | 36 // Called when the network connection is authenticated and all |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 // Called on notification of a route change event, which happens when a | 49 // Called on notification of a route change event, which happens when a |
| 60 // channel is connected. | 50 // channel is connected. |
| 61 virtual void OnRouteChange(ConnectionToClient* connection, | 51 virtual void OnRouteChange(ConnectionToClient* connection, |
| 62 const std::string& channel_name, | 52 const std::string& channel_name, |
| 63 const TransportRoute& route) = 0; | 53 const TransportRoute& route) = 0; |
| 64 | 54 |
| 65 protected: | 55 protected: |
| 66 virtual ~EventHandler() {} | 56 virtual ~EventHandler() {} |
| 67 }; | 57 }; |
| 68 | 58 |
| 69 // Constructs a ConnectionToClient object for the |session|. Takes | 59 ConnectionToClient() {} |
| 70 // ownership of |session|. | 60 virtual ~ConnectionToClient() {} |
| 71 explicit ConnectionToClient(Session* session); | |
| 72 ~ConnectionToClient() override; | |
| 73 | 61 |
| 74 // Set |event_handler| for connection events. Must be called once when this | 62 // Set |event_handler| for connection events. Must be called once when this |
| 75 // object is created. | 63 // object is created. |
| 76 void SetEventHandler(EventHandler* event_handler); | 64 virtual void SetEventHandler(EventHandler* event_handler) = 0; |
| 77 | 65 |
| 78 // Returns the connection in use. | 66 // Returns the Session object for the connection. |
| 79 virtual Session* session(); | 67 // TODO(sergeyu): Remove this method. |
| 68 virtual Session* session() = 0; |
| 80 | 69 |
| 81 // Disconnect the client connection. | 70 // Disconnect the client connection. |
| 82 virtual void Disconnect(ErrorCode error); | 71 virtual void Disconnect(ErrorCode error) = 0; |
| 83 | 72 |
| 84 // Callback for HostEventDispatcher to be called with a timestamp for each | 73 // Callback for HostEventDispatcher to be called with a timestamp for each |
| 85 // received event. | 74 // received event. |
| 86 virtual void OnInputEventReceived(int64_t timestamp); | 75 virtual void OnInputEventReceived(int64_t timestamp) = 0; |
| 87 | 76 |
| 88 // Get the stubs used by the host to transmit messages to the client. | 77 // Get the stubs used by the host to transmit messages to the client. |
| 89 // The stubs must not be accessed before OnConnectionAuthenticated(), or | 78 // The stubs must not be accessed before OnConnectionAuthenticated(), or |
| 90 // after OnConnectionClosed(). | 79 // after OnConnectionClosed(). |
| 91 // Note that the audio stub will be nullptr if audio is not enabled. | 80 // Note that the audio stub will be nullptr if audio is not enabled. |
| 92 virtual VideoStub* video_stub(); | 81 virtual VideoStub* video_stub() = 0; |
| 93 virtual AudioStub* audio_stub(); | 82 virtual AudioStub* audio_stub() = 0; |
| 94 virtual ClientStub* client_stub(); | 83 virtual ClientStub* client_stub() = 0; |
| 95 | 84 |
| 96 // Set the stubs which will handle messages we receive from the client. These | 85 // Set the stubs which will handle messages we receive from the client. These |
| 97 // must be called in EventHandler::OnConnectionAuthenticated(). | 86 // must be called in EventHandler::OnConnectionAuthenticated(). |
| 98 virtual void set_clipboard_stub(ClipboardStub* clipboard_stub); | 87 virtual void set_clipboard_stub(ClipboardStub* clipboard_stub) = 0; |
| 99 virtual void set_host_stub(HostStub* host_stub); | 88 virtual void set_host_stub(HostStub* host_stub) = 0; |
| 100 virtual void set_input_stub(InputStub* input_stub); | 89 virtual void set_input_stub(InputStub* input_stub) = 0; |
| 101 | 90 |
| 102 // Sets video feedback stub. Can be called at any time after connection is | 91 // Sets video feedback stub. Can be called at any time after connection is |
| 103 // authenticated. | 92 // authenticated. |
| 104 virtual void set_video_feedback_stub(VideoFeedbackStub* video_feedback_stub); | 93 virtual void set_video_feedback_stub( |
| 105 | 94 VideoFeedbackStub* video_feedback_stub) = 0; |
| 106 // Session::EventHandler interface. | |
| 107 void OnSessionStateChange(Session::State state) override; | |
| 108 void OnSessionRouteChange(const std::string& channel_name, | |
| 109 const TransportRoute& route) override; | |
| 110 | |
| 111 // ChannelDispatcherBase::EventHandler interface. | |
| 112 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; | |
| 113 void OnChannelError(ChannelDispatcherBase* channel_dispatcher, | |
| 114 ErrorCode error) override; | |
| 115 | |
| 116 private: | |
| 117 void NotifyIfChannelsReady(); | |
| 118 | |
| 119 void Close(ErrorCode error); | |
| 120 | |
| 121 // Stops writing in the channels. | |
| 122 void CloseChannels(); | |
| 123 | |
| 124 // Event handler for handling events sent from this object. | |
| 125 EventHandler* handler_; | |
| 126 | |
| 127 // The libjingle channel used to send and receive data from the remote client. | |
| 128 scoped_ptr<Session> session_; | |
| 129 | |
| 130 scoped_ptr<HostControlDispatcher> control_dispatcher_; | |
| 131 scoped_ptr<HostEventDispatcher> event_dispatcher_; | |
| 132 scoped_ptr<HostVideoDispatcher> video_dispatcher_; | |
| 133 scoped_ptr<AudioWriter> audio_writer_; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(ConnectionToClient); | |
| 136 }; | 95 }; |
| 137 | 96 |
| 138 } // namespace protocol | 97 } // namespace protocol |
| 139 } // namespace remoting | 98 } // namespace remoting |
| 140 | 99 |
| 141 #endif // REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_ | 100 #endif // REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_ |
| OLD | NEW |