Ice 3.7 C++11 API Reference
SessionHelper.h
Go to the documentation of this file.
1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef GLACIER2_SESSION_HELPER_H
6 #define GLACIER2_SESSION_HELPER_H
7 
8 #include <IceUtil/Shared.h>
9 #include <IceUtil/Handle.h>
10 #include <IceUtil/Thread.h>
11 #include <IceUtil/Mutex.h>
12 
13 #include <Ice/Initialize.h>
14 #include <Ice/Properties.h>
15 #include <Ice/Communicator.h>
16 #include <Ice/ObjectAdapter.h>
17 #include <Ice/Ice.h>
18 
19 #include <Glacier2/Session.h>
20 #include <Glacier2/Router.h>
21 
22 #include <map>
23 #include <string>
24 
25 namespace Glacier2
26 {
27 
29 const int GLACIER2_SSL_PORT = 4064;
31 const int GLACIER2_TCP_PORT = 4063;
32 
39 #ifndef ICE_CPP11_MAPPING
40  : public virtual IceUtil::Shared
41 #endif
42 {
43 public:
44  virtual ~SessionHelper();
45 
49  virtual void destroy() = 0;
50 
56  virtual Ice::CommunicatorPtr communicator() const = 0;
57 
63  virtual std::string categoryForClient() const = 0;
64 
72  virtual Ice::ObjectPrxPtr addWithUUID(const Ice::ObjectPtr& servant) = 0;
73 
78  virtual SessionPrxPtr session() const = 0;
79 
84  virtual bool isConnected() const = 0;
85 
92  virtual Ice::ObjectAdapterPtr objectAdapter() = 0;
93 
94 #ifndef ICE_CPP11_MAPPING
95  bool operator==(const SessionHelper&) const;
96  bool operator!=(const SessionHelper&) const;
97 #endif
98 
99 };
101 
107 #ifndef ICE_CPP11_MAPPING
108  : public virtual IceUtil::Shared
109 #endif
110 {
111 public:
112  virtual ~SessionCallback();
113 
118  virtual void createdCommunicator(const SessionHelperPtr& session) = 0;
119 
124  virtual void connected(const SessionHelperPtr& session) = 0;
125 
130  virtual void disconnected(const SessionHelperPtr& session) = 0;
131 
137  virtual void connectFailed(const SessionHelperPtr& session, const Ice::Exception& ex) = 0;
138 };
140 
142 class SessionThreadCallback;
144 
150 #ifdef ICE_CPP11_MAPPING
151  : public std::enable_shared_from_this<SessionFactoryHelper>
152 #else
153  : public virtual IceUtil::Shared
154 #endif
155 {
157  friend class SessionThreadCallback; // To access thread functions
159 
160 public:
161 
168 
175 
181  SessionFactoryHelper(const Ice::PropertiesPtr& properties, const SessionCallbackPtr& callback);
182 
184 
188  void destroy();
189 
194  void setRouterIdentity(const Ice::Identity& identity);
195 
201 
206  void setRouterHost(const std::string& host);
207 
212  std::string getRouterHost() const;
213 
215  ICE_DEPRECATED_API("is deprecated, use SessionFactoryHelper::setProtocol instead")
216  void setSecure(bool);
217  ICE_DEPRECATED_API("is deprecated, use SessionFactoryHelper::getProtocol instead")
218  bool getSecure() const;
220 
225  void setProtocol(const std::string& protocol);
226 
231  std::string getProtocol() const;
232 
237  void setTimeout(int timeout);
238 
243  int getTimeout() const;
244 
249  void setPort(int port);
250 
255  int getPort() const;
256 
261  Ice::InitializationData getInitializationData() const;
262 
267  void setConnectContext(const std::map<std::string, std::string>& context);
268 
273  void setUseCallbacks(bool b);
274 
279  bool getUseCallbacks() const;
280 
285  SessionHelperPtr connect();
286 
291  SessionHelperPtr connect(const std::string& username, const std::string& password);
292 
293 private:
294 
295  IceUtil::ThreadPtr addThread(const SessionHelper*, const IceUtil::ThreadPtr&);
296 
297  Ice::InitializationData createInitData();
298  std::string getRouterFinderStr();
299  int getPortInternal() const;
300  std::string createProxyStr(const Ice::Identity& ident);
301  void setDefaultProperties();
302 
303  IceUtil::Mutex _mutex;
304  std::string _routerHost;
305  Ice::Identity _identity;
306  std::string _protocol;
307  int _port;
308  int _timeout;
309  Ice::InitializationData _initData;
310  SessionCallbackPtr _callback;
311  std::map<std::string, std::string> _context;
312  bool _useCallbacks;
313  std::map<const SessionHelper*, IceUtil::ThreadPtr> _threads;
314 };
316 
317 }
318 
319 #endif
Ice::operator!=
bool operator!=(const C &lhs, const C &rhs)
Relational operator for generated structs and classes.
Definition: Comparable.h:196
Glacier2::SessionHelper::isConnected
virtual bool isConnected() const =0
Determines whether the session is active.
GLACIER2_API
#define GLACIER2_API
Definition: PermissionsVerifierF.h:50
Glacier2::SessionCallback
Allows an application to receive notification about events in the lifecycle of a Glacier2 session.
Definition: SessionHelper.h:110
Glacier2::SessionHelper::communicator
virtual Ice::CommunicatorPtr communicator() const =0
Obtains the communicator created by the SessionHelper.
ICE_DEFINE_PTR
#define ICE_DEFINE_PTR(TPtr, T)
Definition: Config.h:359
Glacier2::SessionHelper
Encapsulates a Glacier2 session and provides much of the same functionality as Glacier2::Application ...
Definition: SessionHelper.h:42
ObjectAdapter.h
Glacier2::SessionFactoryHelper::getRouterIdentity
Ice::Identity getRouterIdentity() const
Obtains the object identity of the Glacier2 router.
Properties.h
ICE_DEPRECATED_API
#define ICE_DEPRECATED_API(msg)
Definition: Config.h:217
Glacier2::SessionHelperPtr
::std::shared_ptr< SessionHelper > SessionHelperPtr
Definition: SessionHelper.h:100
Glacier2::SessionFactoryHelper::~SessionFactoryHelper
~SessionFactoryHelper()
Ice::operator==
bool operator==(const C &lhs, const C &rhs)
Relational operator for generated structs and classes.
Definition: Comparable.h:184
Handle.h
Glacier2::SessionFactoryHelper::getRouterHost
std::string getRouterHost() const
Obtains the host name of the Glacier2 router.
Glacier2::SessionCallback::disconnected
virtual void disconnected(const SessionHelperPtr &session)=0
Called after the Glacier2 session is destroyed.
Glacier2::SessionCallbackPtr
::std::shared_ptr< SessionCallback > SessionCallbackPtr
Definition: SessionHelper.h:139
IceUtil
Definition: Optional.h:1095
Glacier2::SessionFactoryHelper::SessionFactoryHelper
SessionFactoryHelper(const Ice::InitializationData &initData, const SessionCallbackPtr &callback)
Use this constructor when you want to provide your own instance of InitializationData.
Glacier2::GLACIER2_SSL_PORT
const int GLACIER2_SSL_PORT
The IANA-registered port number for Glacier2 via SSL.
Definition: SessionHelper.h:29
Glacier2::SessionHelper::destroy
virtual void destroy()=0
Initiates the destruction of the Glacier2 session, including the communicator created by the SessionH...
Ice.h
Initialize.h
Glacier2
Definition: PermissionsVerifier.h:66
Glacier2::SessionCallback::connected
virtual void connected(const SessionHelperPtr &session)=0
Called after successfully establishing the Glacier2 session.
Shared.h
Thread.h
Glacier2::GLACIER2_TCP_PORT
const int GLACIER2_TCP_PORT
The IANA-registered port number for Glacier2 via TCP.
Definition: SessionHelper.h:31
Router.h
Glacier2::SessionHelper::addWithUUID
virtual Ice::ObjectPrxPtr addWithUUID(const Ice::ObjectPtr &servant)=0
Adds a servant to the callback object adapter using a UUID for the identity name.
Glacier2::SessionHelper::objectAdapter
virtual Ice::ObjectAdapterPtr objectAdapter()=0
Obtains the callback object adapter.
Glacier2::SessionFactoryHelper::setRouterIdentity
void setRouterIdentity(const Ice::Identity &identity)
Sets the object identity of the Glacier2 router.
Mutex.h
IceUtil::Exception
Abstract base class for all Ice exceptions.
Definition: Exception.h:22
Ice
Definition: BuiltinSequences.h:56
Glacier2::SessionHelper::~SessionHelper
virtual ~SessionHelper()
Glacier2::SessionFactoryHelper::SessionFactoryHelper
SessionFactoryHelper(const SessionCallbackPtr &callback)
This constructor is useful when your application has no other configuration requirements.
Glacier2::SessionHelper::session
virtual SessionPrxPtr session() const =0
Obtains a proxy for the Glacier2 session.
Glacier2::SessionCallback::createdCommunicator
virtual void createdCommunicator(const SessionHelperPtr &session)=0
Called after successfully initializing a communicator.
Glacier2::SessionFactoryHelperPtr
::std::shared_ptr< SessionFactoryHelper > SessionFactoryHelperPtr
Definition: SessionHelper.h:315
Glacier2::SessionFactoryHelper::setRouterHost
void setRouterHost(const std::string &host)
Sets the host name of the Glacier2 router.
IceUtil::ThreadPtr
Handle< Thread > ThreadPtr
Definition: Thread.h:156
Glacier2::SessionCallback::connectFailed
virtual void connectFailed(const SessionHelperPtr &session, const Ice::Exception &ex)=0
Called if a failure occurred while attempting to establish a Glacier2 session.
Glacier2::SessionHelper::categoryForClient
virtual std::string categoryForClient() const =0
Obtains the category that must be used in the identities of all callback objects.
Glacier2::SessionFactoryHelper
Facilitates the creation of new Glacier2 sessions.
Definition: SessionHelper.h:155
Communicator.h
Glacier2::SessionCallback::~SessionCallback
virtual ~SessionCallback()
Ice::InitializationData
Encapsulates data to initialize a communicator.
Definition: Initialize.h:279
Session.h
Ice::Identity
The identity of an Ice object.
Definition: Identity.h:67
IceUtil::Shared
Definition: Shared.h:78
Glacier2::SessionFactoryHelper::SessionFactoryHelper
SessionFactoryHelper(const Ice::PropertiesPtr &properties, const SessionCallbackPtr &callback)
This constructor is convenient when you want to supply an initial set of properties.
Glacier2::SessionFactoryHelper::destroy
void destroy()
Blocks until all background threads are terminated.