Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

Eris::Connection Class Reference

Connection tracks the life-time of a client-server session; note this may extend beyond a single TCP connection, if re-connections occur. More...

#include <Connection.h>

Inheritance diagram for Eris::Connection:

Eris::BaseConnection List of all members.

Public Member Functions

 Connection (const std::string &cnm, bool debug)
 Create a new connection, with the client-name string specified.
virtual void connect (const std::string &host, short port=6767)
 If the underlying socket cannot be opened, Connect will throw an exception immediately.
void reconnect ()
 This will attempt reconnection to the server, providing a connection was completely established sucessfully before the error occurred.
void disconnect ()
 Initiate disconnection from the server.
DispatchergetDispatcher () const
 get the root dispatcher for incoming messages
TypeService * getTypeService () const
LobbygetLobby () const
DispatchergetDispatcherByPath (const std::string &path) const
 Note that an invalid path specification will cause an exception to be thrown.
void removeDispatcherByPath (const std::string &stem, const std::string &n)
 Remove a node from the dispatcher tree.
void removeIfDispatcherByPath (const std::string &stem, const std::string &n)
 Remove the dispatch node iff found, otherwise do nothing.
virtual void send (const Atlas::Objects::Root &obj)
 If the connection is not fully connected, an exception will be thrown.
virtual void send (const Atlas::Message::Element &msg)
 The same comments regarding connection status and disconnect operation apply as above.
void lock ()
 Lock then connection's state.
void unlock ()
 Unlock the connection (permit status change).

Static Public Member Functions

ConnectiongetPrimary ()
ConnectionInstance ()
 deprecated

Public Attributes

SigC::Signal0< bool > Disconnecting
 Emitted when the disconnection process is initiated.
SigC::Signal1< void, const
std::string & > 
Failure
 Emitted when a non-fatal error occurs; these are nearly always network related, such as connections being lost, or host names not found.
SigC::Signal1< void, StatusTimeout
 Emitted when a network-level timeout occurs; the status code indicates in which stage of operation the timeout occurred.
SigC::Signal1< void, StatusStatusChanged
 emitted when the connection status changes; This will often correspond to the emission of a more specific signal (such as Connected), which should be used where available.

Protected Member Functions

virtual void setStatus (Status sc)
 update the connection status (and emit the appropriate signal)
virtual void objectArrived (const Atlas::Message::Element &obj)
 objectArrived is the entry point for all data from the server into the client; notably, the message is forwarded to the root of the dispatcher tree and thus disseminated to all matching nodes.
virtual void handleFailure (const std::string &msg)
 Process failures (to track when reconnection should be permitted).
virtual void bindTimeout (Eris::Timeout &t, Status sc)
virtual void onConnect ()
 derived-class notification when connection and negotiation is completed
void postForDispatch (const Atlas::Message::Element &msg)
 this is how waitForBase gets it's payload back into the dispatch queue
void addWait (WaitForBase *w)
 register a new WaitFor into the list

Protected Attributes

Dispatcher_rootDispatch
 the root of the dispatch tree
unsigned int _statusLock
 locks connection to current state while > 0
std::string _host
 This is cleared if connection fails during establishment (i.e CONNECTING and NEGOTIATE states), to indicate that re-connection is not possible.
short _port
 port of the server
bool _debug

Static Protected Attributes

Connection_theConnection = NULL
 static singleton instance

Friends

class WaitForBase

Detailed Description

Connection tracks the life-time of a client-server session; note this may extend beyond a single TCP connection, if re-connections occur.


Constructor & Destructor Documentation

Eris::Connection::Connection const std::string &  cnm,
bool  debug
 

Create a new connection, with the client-name string specified.

The client-name is sent during Atlas negotiation of the connection.

Parameters:
debug Perform extra (slower) validation on the connection


Member Function Documentation

void Eris::Connection::connect const std::string &  host,
short  port = 6767
[virtual]
 

If the underlying socket cannot be opened, Connect will throw an exception immediately.

Providing the basic connection is established, other failures will be reported via the Failure signal.

Reimplemented from Eris::BaseConnection.

Dispatcher* Eris::Connection::getDispatcher  )  const [inline]
 

get the root dispatcher for incoming messages

Note the behaviour has changed since earlier versions of Eris; formerly it called select() internally to check for data (and hence was guranteed to be non-blocking. With the addition of the poll interface and PollDefault implementation, this call will now block if no data is pending on the connection.

Dispatcher * Eris::Connection::getDispatcherByPath const std::string &  path  )  const
 

Note that an invalid path specification will cause an exception to be thrown.

To access the root node, pass either an empty path or ":"; this is identical to calling GetDispatcher().

void Eris::Connection::lock  ) 
 

Lock then connection's state.

This prevents the connection changing status until a corresponding unlock() call is issued. The only use at present is to hold the connection in the 'DISCONNECTING' state while other objects clean up and so on. In the future locking may also be applicable to other states.

void Eris::Connection::reconnect  ) 
 

This will attempt reconnection to the server, providing a connection was completely established sucessfully before the error occurred.

Otherwise, an exception will be thrown. This is prevent Reconnect being called on an invalid host, for example.

void Eris::Connection::removeDispatcherByPath const std::string &  stem,
const std::string &  n
 

Remove a node from the dispatcher tree.

Throws InvalidOperation if path is invalid, or the the node is not found.

void Eris::Connection::send const Atlas::Objects::Root &  obj  )  [virtual]
 

If the connection is not fully connected, an exception will be thrown.

To correctly handle disconnection, callers should therefore validate the connection using IsConnected first

void Eris::Connection::setStatus Status  sc  )  [protected, virtual]
 

update the connection status (and emit the appropriate signal)

Parameters:
sc The new status of the connection

Reimplemented from Eris::BaseConnection.

void Eris::Connection::unlock  ) 
 

Unlock the connection (permit status change).

See Connection::lock for more information about status locking.


Member Data Documentation

SigC::Signal1<void, const std::string&> Eris::Connection::Failure
 

Emitted when a non-fatal error occurs; these are nearly always network related, such as connections being lost, or host names not found.

The connection will be placed into the DISCONNECTED state after the signal is emitted; thus the current state (when the failure occured) is still valid during the callback


The documentation for this class was generated from the following files:
Generated on Wed Nov 10 20:56:36 2004 for Eris by  doxygen 1.3.9.1