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"
17 #include "remoting/protocol/video_writer.h"
26 class HostControlDispatcher
;
27 class HostEventDispatcher
;
29 // This class represents a remote viewer connection to the chromoting
30 // host. It sets up all protocol channels and connects them to the
32 class ConnectionToClient
: public base::NonThreadSafe
,
33 public Session::EventHandler
{
37 // Called when the network connection is authenticating
38 virtual void OnConnectionAuthenticating(ConnectionToClient
* connection
) = 0;
40 // Called when the network connection is authenticated.
41 virtual void OnConnectionAuthenticated(ConnectionToClient
* connection
) = 0;
43 // Called when the network connection is authenticated and all
44 // channels are connected.
45 virtual void OnConnectionChannelsConnected(
46 ConnectionToClient
* connection
) = 0;
48 // Called when the network connection is closed or failed.
49 virtual void OnConnectionClosed(ConnectionToClient
* connection
,
52 // Called when sequence number is updated.
53 virtual void OnSequenceNumberUpdated(ConnectionToClient
* connection
,
54 int64 sequence_number
) = 0;
56 // Called on notification of a route change event, which happens when a
57 // channel is connected.
58 virtual void OnRouteChange(ConnectionToClient
* connection
,
59 const std::string
& channel_name
,
60 const TransportRoute
& route
) = 0;
63 virtual ~EventHandler() {}
66 // Constructs a ConnectionToClient object for the |session|. Takes
67 // ownership of |session|.
68 explicit ConnectionToClient(Session
* session
);
69 virtual ~ConnectionToClient();
71 // Set |event_handler| for connection events. Must be called once when this
73 void SetEventHandler(EventHandler
* event_handler
);
75 // Returns the connection in use.
76 virtual Session
* session();
78 // Disconnect the client connection.
79 virtual void Disconnect();
81 // Update the sequence number when received from the client. EventHandler
83 virtual void UpdateSequenceNumber(int64 sequence_number
);
85 // Get the stubs used by the host to transmit messages to the client.
86 // The stubs must not be accessed before OnConnectionAuthenticated(), or
87 // after OnConnectionClosed().
88 // Note that the audio stub will be NULL if audio is not enabled.
89 virtual VideoStub
* video_stub();
90 virtual AudioStub
* audio_stub();
91 virtual ClientStub
* client_stub();
93 // Set/get the stubs which will handle messages we receive from the client.
94 // All stubs MUST be set before the session's channels become connected.
95 virtual void set_clipboard_stub(ClipboardStub
* clipboard_stub
);
96 virtual ClipboardStub
* clipboard_stub();
97 virtual void set_host_stub(HostStub
* host_stub
);
98 virtual HostStub
* host_stub();
99 virtual void set_input_stub(InputStub
* input_stub
);
100 virtual InputStub
* input_stub();
102 // Session::EventHandler interface.
103 virtual void OnSessionStateChange(Session::State state
) OVERRIDE
;
104 virtual void OnSessionRouteChange(const std::string
& channel_name
,
105 const TransportRoute
& route
) OVERRIDE
;
108 // Callback for channel initialization.
109 void OnChannelInitialized(bool successful
);
111 void NotifyIfChannelsReady();
113 void Close(ErrorCode error
);
115 // Stops writing in the channels.
116 void CloseChannels();
118 // Event handler for handling events sent from this object.
119 EventHandler
* handler_
;
121 // Stubs that are called for incoming messages.
122 ClipboardStub
* clipboard_stub_
;
123 HostStub
* host_stub_
;
124 InputStub
* input_stub_
;
126 // The libjingle channel used to send and receive data from the remote client.
127 scoped_ptr
<Session
> session_
;
129 scoped_ptr
<HostControlDispatcher
> control_dispatcher_
;
130 scoped_ptr
<HostEventDispatcher
> event_dispatcher_
;
131 scoped_ptr
<VideoWriter
> video_writer_
;
132 scoped_ptr
<AudioWriter
> audio_writer_
;
134 DISALLOW_COPY_AND_ASSIGN(ConnectionToClient
);
137 } // namespace protocol
138 } // namespace remoting
140 #endif // REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_