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_SESSION_H_
6 #define REMOTING_PROTOCOL_SESSION_H_
10 #include "remoting/protocol/errors.h"
11 #include "remoting/protocol/session_config.h"
21 struct TransportRoute
;
23 // Generic interface for Chromotocol connection used by both client and host.
24 // Provides access to the connection channels, but doesn't depend on the
25 // protocol used for each channel.
29 // Created, but not connecting yet.
32 // Sent session-initiate, but haven't received session-accept.
35 // Received session-initiate, but haven't sent session-accept.
38 // Session has been accepted and is pending authentication.
41 // Session has started authenticating.
44 // Session has been connected and authenticated.
47 // Session has been closed.
50 // Connection has failed.
57 virtual ~EventHandler() {}
59 // Called after session state has changed. It is safe to destroy
60 // the session from within the handler if |state| is AUTHENTICATING
61 // or CLOSED or FAILED.
62 virtual void OnSessionStateChange(State state
) = 0;
64 // Called whenever route for the channel specified with
65 // |channel_name| changes. Session must not be destroyed by the
66 // handler of this event.
67 virtual void OnSessionRouteChange(const std::string
& channel_name
,
68 const TransportRoute
& route
) = 0;
70 // Called when ready state on one of the channels changes. See
71 // comments in transport.h for explanation on what this state
72 // means and how it can used.
73 virtual void OnSessionChannelReady(const std::string
& channel_name
,
81 // Set event handler for this session. |event_handler| must outlive
83 virtual void SetEventHandler(EventHandler
* event_handler
) = 0;
85 // Returns error code for a failed session.
86 virtual ErrorCode
error() = 0;
88 // JID of the other side.
89 virtual const std::string
& jid() = 0;
91 // Configuration of the protocol that was sent or received in the
92 // session-initiate jingle message. Returned pointer is valid until
93 // connection is closed.
94 virtual const CandidateSessionConfig
* candidate_config() = 0;
96 // Protocol configuration. Can be called only after session has been accepted.
97 // Returned pointer is valid until connection is closed.
98 virtual const SessionConfig
& config() = 0;
100 // Set protocol configuration for an incoming session. Must be
101 // called on the host before the connection is accepted, from
102 // ChromotocolServer::IncomingConnectionCallback.
103 virtual void set_config(const SessionConfig
& config
) = 0;
105 // GetTransportChannelFactory() returns a factory that creates a new transport
106 // channel for each logical channel. GetMultiplexedChannelFactory() channels
107 // share a single underlying transport channel
108 virtual ChannelFactory
* GetTransportChannelFactory() = 0;
109 virtual ChannelFactory
* GetMultiplexedChannelFactory() = 0;
111 // Closes connection. Callbacks are guaranteed not to be called
112 // after this method returns. Must be called before the object is
113 // destroyed, unless the state is set to FAILED or CLOSED.
114 virtual void Close() = 0;
117 DISALLOW_COPY_AND_ASSIGN(Session
);
120 } // namespace protocol
121 } // namespace remoting
123 #endif // REMOTING_PROTOCOL_SESSION_H_