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
3 // found in the LICENSE file.
5 #ifndef REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_
6 #define REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_
12 #include "base/memory/scoped_ptr.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"
23 class HostControlDispatcher
;
24 class HostEventDispatcher
;
26 class HostVideoDispatcher
;
30 // This class represents a remote viewer connection to the chromoting
31 // host. It sets up all protocol channels and connects them to the
33 class ConnectionToClient
: public base::NonThreadSafe
,
34 public Session::EventHandler
,
35 public ChannelDispatcherBase::EventHandler
{
39 // Called when the network connection is authenticating
40 virtual void OnConnectionAuthenticating(ConnectionToClient
* connection
) = 0;
42 // Called when the network connection is authenticated.
43 virtual void OnConnectionAuthenticated(ConnectionToClient
* connection
) = 0;
45 // Called when the network connection is authenticated and all
46 // channels are connected.
47 virtual void OnConnectionChannelsConnected(
48 ConnectionToClient
* connection
) = 0;
50 // Called when the network connection is closed or failed.
51 virtual void OnConnectionClosed(ConnectionToClient
* connection
,
54 // Called when sequence number is updated.
55 virtual void OnEventTimestamp(ConnectionToClient
* connection
,
58 // Called on notification of a route change event, which happens when a
59 // channel is connected.
60 virtual void OnRouteChange(ConnectionToClient
* connection
,
61 const std::string
& channel_name
,
62 const TransportRoute
& route
) = 0;
65 virtual ~EventHandler() {}
68 // Constructs a ConnectionToClient object for the |session|. Takes
69 // ownership of |session|.
70 explicit ConnectionToClient(Session
* session
);
71 ~ConnectionToClient() override
;
73 // Set |event_handler| for connection events. Must be called once when this
75 void SetEventHandler(EventHandler
* event_handler
);
77 // Returns the connection in use.
78 virtual Session
* session();
80 // Disconnect the client connection.
81 virtual void Disconnect();
83 // Callback for HostEventDispatcher to be called with a timestamp for each
85 virtual void OnEventTimestamp(int64 timestamp
);
87 // Get the stubs used by the host to transmit messages to the client.
88 // The stubs must not be accessed before OnConnectionAuthenticated(), or
89 // after OnConnectionClosed().
90 // Note that the audio stub will be nullptr if audio is not enabled.
91 virtual VideoStub
* video_stub();
92 virtual AudioStub
* audio_stub();
93 virtual ClientStub
* client_stub();
95 // Set/get the stubs which will handle messages we receive from the client.
96 // All stubs MUST be set before the session's channels become connected.
97 virtual void set_clipboard_stub(ClipboardStub
* clipboard_stub
);
98 virtual ClipboardStub
* clipboard_stub();
99 virtual void set_host_stub(HostStub
* host_stub
);
100 virtual HostStub
* host_stub();
101 virtual void set_input_stub(InputStub
* input_stub
);
102 virtual InputStub
* input_stub();
104 // Session::EventHandler interface.
105 void OnSessionStateChange(Session::State state
) override
;
106 void OnSessionRouteChange(const std::string
& channel_name
,
107 const TransportRoute
& route
) override
;
109 // ChannelDispatcherBase::EventHandler interface.
110 void OnChannelInitialized(ChannelDispatcherBase
* channel_dispatcher
) override
;
111 void OnChannelError(ChannelDispatcherBase
* channel_dispatcher
,
112 ErrorCode error
) override
;
115 void NotifyIfChannelsReady();
117 void Close(ErrorCode error
);
119 // Stops writing in the channels.
120 void CloseChannels();
122 // Event handler for handling events sent from this object.
123 EventHandler
* handler_
;
125 // Stubs that are called for incoming messages.
126 ClipboardStub
* clipboard_stub_
;
127 HostStub
* host_stub_
;
128 InputStub
* input_stub_
;
130 // The libjingle channel used to send and receive data from the remote client.
131 scoped_ptr
<Session
> session_
;
133 scoped_ptr
<HostControlDispatcher
> control_dispatcher_
;
134 scoped_ptr
<HostEventDispatcher
> event_dispatcher_
;
135 scoped_ptr
<HostVideoDispatcher
> video_dispatcher_
;
136 scoped_ptr
<AudioWriter
> audio_writer_
;
138 DISALLOW_COPY_AND_ASSIGN(ConnectionToClient
);
141 } // namespace protocol
142 } // namespace remoting
144 #endif // REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_