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
{
38 // Called when the network connection is authenticating
39 virtual void OnConnectionAuthenticating(ConnectionToClient
* connection
) = 0;
41 // Called when the network connection is authenticated.
42 virtual void OnConnectionAuthenticated(ConnectionToClient
* connection
) = 0;
44 // Called when the network connection is authenticated and all
45 // channels are connected.
46 virtual void OnConnectionChannelsConnected(
47 ConnectionToClient
* connection
) = 0;
49 // Called when the network connection is closed or failed.
50 virtual void OnConnectionClosed(ConnectionToClient
* connection
,
53 // Called when sequence number is updated.
54 virtual void OnSequenceNumberUpdated(ConnectionToClient
* connection
,
55 int64 sequence_number
) = 0;
57 // Called on notification of a route change event, which happens when a
58 // channel is connected.
59 virtual void OnRouteChange(ConnectionToClient
* connection
,
60 const std::string
& channel_name
,
61 const TransportRoute
& route
) = 0;
64 virtual ~EventHandler() {}
67 // Constructs a ConnectionToClient object for the |session|. Takes
68 // ownership of |session|.
69 explicit ConnectionToClient(Session
* session
);
70 ~ConnectionToClient() override
;
72 // Set |event_handler| for connection events. Must be called once when this
74 void SetEventHandler(EventHandler
* event_handler
);
76 // Returns the connection in use.
77 virtual Session
* session();
79 // Disconnect the client connection.
80 virtual void Disconnect();
82 // Update the sequence number when received from the client. EventHandler
84 virtual void UpdateSequenceNumber(int64 sequence_number
);
86 // Get the stubs used by the host to transmit messages to the client.
87 // The stubs must not be accessed before OnConnectionAuthenticated(), or
88 // after OnConnectionClosed().
89 // Note that the audio stub will be NULL if audio is not enabled.
90 virtual VideoStub
* video_stub();
91 virtual AudioStub
* audio_stub();
92 virtual ClientStub
* client_stub();
94 // Set/get the stubs which will handle messages we receive from the client.
95 // All stubs MUST be set before the session's channels become connected.
96 virtual void set_clipboard_stub(ClipboardStub
* clipboard_stub
);
97 virtual ClipboardStub
* clipboard_stub();
98 virtual void set_host_stub(HostStub
* host_stub
);
99 virtual HostStub
* host_stub();
100 virtual void set_input_stub(InputStub
* input_stub
);
101 virtual InputStub
* input_stub();
103 // Session::EventHandler interface.
104 void OnSessionStateChange(Session::State state
) override
;
105 void OnSessionRouteChange(const std::string
& channel_name
,
106 const TransportRoute
& route
) override
;
109 // Callback for channel initialization.
110 void OnChannelInitialized(bool successful
);
112 void NotifyIfChannelsReady();
114 void Close(ErrorCode error
);
116 // Stops writing in the channels.
117 void CloseChannels();
119 // Event handler for handling events sent from this object.
120 EventHandler
* handler_
;
122 // Stubs that are called for incoming messages.
123 ClipboardStub
* clipboard_stub_
;
124 HostStub
* host_stub_
;
125 InputStub
* input_stub_
;
127 // The libjingle channel used to send and receive data from the remote client.
128 scoped_ptr
<Session
> session_
;
130 scoped_ptr
<HostControlDispatcher
> control_dispatcher_
;
131 scoped_ptr
<HostEventDispatcher
> event_dispatcher_
;
132 scoped_ptr
<HostVideoDispatcher
> video_dispatcher_
;
133 scoped_ptr
<AudioWriter
> audio_writer_
;
135 DISALLOW_COPY_AND_ASSIGN(ConnectionToClient
);
138 } // namespace protocol
139 } // namespace remoting
141 #endif // REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_