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_HOST_H_
6 #define REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_
10 #include "base/callback_forward.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/protocol/errors.h"
23 class CandidateSessionConfig
;
26 class ExtensionMessage
;
30 class TransportFactory
;
31 struct TransportRoute
;
34 class ConnectionToHost
{
36 // The UI implementations maintain corresponding definitions of this
37 // enumeration in client_session.js and
38 // android/java/src/org/chromium/chromoting/jni/JniInterface.java. Be sure to
39 // update these locations if you make any changes to the ordering.
49 // Returns the literal string of |state|.
50 static const char* StateToString(State state
);
52 class HostEventCallback
{
54 virtual ~HostEventCallback() {}
56 // Called when state of the connection changes.
57 virtual void OnConnectionState(State state
, ErrorCode error
) = 0;
59 // Called when ready state of the connection changes. When |ready|
60 // is set to false some data sent by the peers may be
61 // delayed. This is used to indicate in the UI when connection is
62 // temporarily broken.
63 virtual void OnConnectionReady(bool ready
) = 0;
65 // Called when the route type (direct vs. STUN vs. proxied) changes.
66 virtual void OnRouteChanged(const std::string
& channel_name
,
67 const protocol::TransportRoute
& route
) = 0;
70 virtual ~ConnectionToHost() {}
72 // Allows to set a custom protocol configuration (e.g. for tests). Cannot be
73 // called after Connect().
74 virtual void set_candidate_config(
75 scoped_ptr
<CandidateSessionConfig
> config
) = 0;
77 // Set the stubs which will handle messages from the host.
78 // The caller must ensure that stubs out-live the connection.
79 // Unless otherwise specified, all stubs must be set before Connect()
81 virtual void set_client_stub(ClientStub
* client_stub
) = 0;
82 virtual void set_clipboard_stub(ClipboardStub
* clipboard_stub
) = 0;
83 virtual void set_video_stub(VideoStub
* video_stub
) = 0;
84 // If no audio stub is specified then audio will not be requested.
85 virtual void set_audio_stub(AudioStub
* audio_stub
) = 0;
87 // Initiates a connection to the host specified by |host_jid|.
88 // |signal_strategy| is used to signal to the host, and must outlive the
89 // connection. Data channels will be negotiated over |transport_factory|.
90 // |authenticator| will be used to authenticate the session and data channels.
91 // |event_callback| will be notified of changes in the state of the connection
92 // and must outlive the ConnectionToHost.
93 // Caller must set stubs (see below) before calling Connect.
94 virtual void Connect(SignalStrategy
* signal_strategy
,
95 scoped_ptr
<TransportFactory
> transport_factory
,
96 scoped_ptr
<Authenticator
> authenticator
,
97 const std::string
& host_jid
,
98 HostEventCallback
* event_callback
) = 0;
100 // Returns the session configuration that was negotiated with the host.
101 virtual const SessionConfig
& config() = 0;
103 // Stubs for sending data to the host.
104 virtual ClipboardStub
* clipboard_forwarder() = 0;
105 virtual HostStub
* host_stub() = 0;
106 virtual InputStub
* input_stub() = 0;
108 // Return the current state of ConnectionToHost.
109 virtual State
state() const = 0;
112 } // namespace protocol
113 } // namespace remoting
115 #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_