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"
30 class HostControlDispatcher
;
31 class HostEventDispatcher
;
33 // This class represents a remote viewer connection to the chromoting
34 // host. It sets up all protocol channels and connects them to the
36 class ConnectionToClient
: public base::NonThreadSafe
,
37 public Session::EventHandler
{
41 // Called when the network connection is authenticating
42 virtual void OnConnectionAuthenticating(ConnectionToClient
* connection
) = 0;
44 // Called when the network connection is authenticated.
45 virtual void OnConnectionAuthenticated(ConnectionToClient
* connection
) = 0;
47 // Called when the network connection is authenticated and all
48 // channels are connected.
49 virtual void OnConnectionChannelsConnected(
50 ConnectionToClient
* connection
) = 0;
52 // Called when the network connection is closed or failed.
53 virtual void OnConnectionClosed(ConnectionToClient
* connection
,
56 // Called when sequence number is updated.
57 virtual void OnSequenceNumberUpdated(ConnectionToClient
* connection
,
58 int64 sequence_number
) = 0;
60 // Called on notification of a route change event, which happens when a
61 // channel is connected.
62 virtual void OnRouteChange(ConnectionToClient
* connection
,
63 const std::string
& channel_name
,
64 const TransportRoute
& route
) = 0;
67 virtual ~EventHandler() {}
70 // Constructs a ConnectionToClient object for the |session|. Takes
71 // ownership of |session|.
72 explicit ConnectionToClient(Session
* session
);
73 virtual ~ConnectionToClient();
75 // Set |event_handler| for connection events. Must be called once when this
77 void SetEventHandler(EventHandler
* event_handler
);
79 // Returns the connection in use.
80 virtual Session
* session();
82 // Disconnect the client connection.
83 virtual void Disconnect();
85 // Update the sequence number when received from the client. EventHandler
87 virtual void UpdateSequenceNumber(int64 sequence_number
);
89 // Get the stubs used by the host to transmit messages to the client.
90 // The stubs must not be accessed before OnConnectionAuthenticated(), or
91 // after OnConnectionClosed().
92 // Note that the audio stub will be NULL if audio is not enabled.
93 virtual VideoStub
* video_stub();
94 virtual AudioStub
* audio_stub();
95 virtual ClientStub
* client_stub();
97 // Set/get the stubs which will handle messages we receive from the client.
98 // All stubs MUST be set before the session's channels become connected.
99 virtual void set_clipboard_stub(ClipboardStub
* clipboard_stub
);
100 virtual ClipboardStub
* clipboard_stub();
101 virtual void set_host_stub(HostStub
* host_stub
);
102 virtual HostStub
* host_stub();
103 virtual void set_input_stub(InputStub
* input_stub
);
104 virtual InputStub
* input_stub();
106 // Session::EventHandler interface.
107 virtual void OnSessionStateChange(Session::State state
) OVERRIDE
;
108 virtual void OnSessionRouteChange(const std::string
& channel_name
,
109 const TransportRoute
& route
) OVERRIDE
;
112 // Callback for channel initialization.
113 void OnChannelInitialized(bool successful
);
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
<VideoWriter
> video_writer_
;
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_