• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef REMOTING_PROTOCOL_SESSION_H_
6 #define REMOTING_PROTOCOL_SESSION_H_
7 
8 #include <string>
9 
10 #include "remoting/protocol/errors.h"
11 #include "remoting/protocol/session_config.h"
12 
13 namespace net {
14 class IPEndPoint;
15 }  // namespace net
16 
17 namespace remoting {
18 namespace protocol {
19 
20 class ChannelFactory;
21 struct TransportRoute;
22 
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.
26 class Session {
27  public:
28   enum State {
29     // Created, but not connecting yet.
30     INITIALIZING,
31 
32     // Sent session-initiate, but haven't received session-accept.
33     CONNECTING,
34 
35     // Received session-initiate, but haven't sent session-accept.
36     ACCEPTING,
37 
38     // Session has been accepted and is pending authentication.
39     CONNECTED,
40 
41     // Session has been connected and authenticated.
42     AUTHENTICATED,
43 
44     // Session has been closed.
45     CLOSED,
46 
47     // Connection has failed.
48     FAILED,
49   };
50 
51   class EventHandler {
52    public:
EventHandler()53     EventHandler() {}
~EventHandler()54     virtual ~EventHandler() {}
55 
56     // Called after session state has changed. It is safe to destroy
57     // the session from within the handler if |state| is CLOSED or
58     // FAILED.
59     virtual void OnSessionStateChange(State state) = 0;
60 
61     // Called whenever route for the channel specified with
62     // |channel_name| changes. Session must not be destroyed by the
63     // handler of this event.
64     virtual void OnSessionRouteChange(const std::string& channel_name,
65                                       const TransportRoute& route) = 0;
66 
67     // Called when ready state on one of the channels changes. See
68     // comments in transport.h for explanation on what this state
69     // means and how it can used.
OnSessionChannelReady(const std::string & channel_name,bool ready)70     virtual void OnSessionChannelReady(const std::string& channel_name,
71                                        bool ready) {}
72   };
73 
74 
Session()75   Session() {}
~Session()76   virtual ~Session() {}
77 
78   // Set event handler for this session. |event_handler| must outlive
79   // this object.
80   virtual void SetEventHandler(EventHandler* event_handler) = 0;
81 
82   // Returns error code for a failed session.
83   virtual ErrorCode error() = 0;
84 
85   // JID of the other side.
86   virtual const std::string& jid() = 0;
87 
88   // Configuration of the protocol that was sent or received in the
89   // session-initiate jingle message. Returned pointer is valid until
90   // connection is closed.
91   virtual const CandidateSessionConfig* candidate_config() = 0;
92 
93   // Protocol configuration. Can be called only after session has been accepted.
94   // Returned pointer is valid until connection is closed.
95   virtual const SessionConfig& config() = 0;
96 
97   // Set protocol configuration for an incoming session. Must be
98   // called on the host before the connection is accepted, from
99   // ChromotocolServer::IncomingConnectionCallback.
100   virtual void set_config(const SessionConfig& config) = 0;
101 
102   // GetTransportChannelFactory() returns a factory that creates a new transport
103   // channel for each logical channel. GetMultiplexedChannelFactory() channels
104   // share a single underlying transport channel
105   virtual ChannelFactory* GetTransportChannelFactory() = 0;
106   virtual ChannelFactory* GetMultiplexedChannelFactory() = 0;
107 
108   // Closes connection. Callbacks are guaranteed not to be called
109   // after this method returns. Must be called before the object is
110   // destroyed, unless the state is set to FAILED or CLOSED.
111   virtual void Close() = 0;
112 
113  private:
114   DISALLOW_COPY_AND_ASSIGN(Session);
115 };
116 
117 }  // namespace protocol
118 }  // namespace remoting
119 
120 #endif  // REMOTING_PROTOCOL_SESSION_H_
121