Eris  1.4.0
Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
Eris::Connection Class Reference

Underlying Atlas connection, providing a send interface, and receive (dispatch) system. More...

#include <Connection.h>

Inheritance diagram for Eris::Connection:
Eris::BaseConnection

Public Member Functions

 Connection (boost::asio::io_service &io_service, EventService &eventService, const std::string &cnm, const std::string &host, short port)
 Create an unconnected instance. More...
 
 Connection (boost::asio::io_service &io_service, EventService &eventService, const std::string &cnm, const std::string &socket)
 Create a new connection, with the client-name string specified. More...
 
int connect ()
 If the underlying socket cannot be opened, connect will return an error number immediately. More...
 
int disconnect ()
 Initiate disconnection from the server.
 
TypeServicegetTypeService () const
 
ResponseTrackergetResponder () const
 
EventServicegetEventService ()
 
virtual void send (const Atlas::Objects::Root &obj)
 Transmit an Atlas::Objects instance to the server. More...
 
void setDefaultRouter (Router *router)
 
void clearDefaultRouter ()
 
void registerRouterForTo (Router *router, const std::string &toId)
 
void unregisterRouterForTo (Router *router, const std::string &toId)
 
void registerRouterForFrom (Router *router, const std::string &fromId)
 
void unregisterRouterForFrom (Router *router, const std::string &fromId)
 
void lock ()
 Lock then connection's state. More...
 
void unlock ()
 Unlock the connection (permit status change). More...
 
void refreshServerInfo ()
 Update the information stored about the current server. More...
 
void getServerInfo (ServerInfo &) const
 Retrive the current server information. More...
 
- Public Member Functions inherited from Eris::BaseConnection
virtual ~BaseConnection ()
 destructor, will perform a hard disconnect if necessary
 
virtual int connectRemote (const std::string &host, short port)
 open a connection to the specified host/port; invokes the failure handler if the connection could not be opened. More...
 
virtual int connectLocal (const std::string &socket)
 Try to connect to a local socket.
 
Status getStatus () const
 get the current status of the connection
 
bool isConnected () const
 Ascertain whether or not the connection is usable for transport.
 
const std::string & getHost () const
 Gets the host of the connection. More...
 
short getPort () const
 Gets the port of the connection. More...
 

Public Attributes

sigc::signal< void > GotServerInfo
 
sigc::signal< bool > Disconnecting
 Emitted when the disconnection process is initiated. More...
 
sigc::signal< void, const std::string & > Failure
 Emitted when a non-fatal error occurs. More...
 
sigc::signal< void, StatusStatusChanged
 indicates a status change on the connection More...
 
- Public Attributes inherited from Eris::BaseConnection
sigc::signal< void > Connected
 sent on successful negotiation of a game server connection
 
sigc::signal< void > Disconnected
 final disconnect (or hard disocnnect) notifcation
 

Protected Types

typedef std::deque< Atlas::Objects::Operation::RootOperation > OpDeque
 
typedef std::unordered_map< std::string, Router * > IdRouterMap
 

Protected Member Functions

void setStatus (Status sc) override
 update the connection status (and emit the appropriate signal) More...
 
void handleFailure (const std::string &msg) override
 Process failures (to track when reconnection should be permitted)
 
void handleTimeout (const std::string &msg) override
 
void onConnect () override
 derived-class notification when connection and negotiation is completed
 
void objectArrived (const Atlas::Objects::Root &obj) override
 
void postForDispatch (const Atlas::Objects::Root &obj)
 Inject a local operation into the dispatch queue. More...
 
void cleanupRedispatch (Redispatch *r)
 
void dispatch () override
 
void dispatchOp (const Atlas::Objects::Operation::RootOperation &op)
 
void handleServerInfo (const Atlas::Objects::Operation::RootOperation &op)
 
void onDisconnectTimeout ()
 
- Protected Member Functions inherited from Eris::BaseConnection
 BaseConnection (boost::asio::io_service &io_service, const std::string &cnm, const std::string &id, Atlas::Bridge &br)
 create an unconnected instance More...
 
void stateChanged (StreamSocket::Status status)
 
virtual void setStatus (Status sc)
 update the connection status and generate signals
 
void onConnectTimeout ()
 
void onNegotiateTimeout ()
 
void hardDisconnect (bool emit)
 performs and instant disconnection from the server specified whether the change of state should be signalled
 

Protected Attributes

EventService_eventService
 
const std::string _host
 
const short _port
 port of the server
 
const std::string _localSocket
 
OpDeque m_opDeque
 store of all the received ops waiting to be dispatched
 
std::unique_ptr< TypeServicem_typeService
 
Routerm_defaultRouter
 
IdRouterMap m_toRouters
 
IdRouterMap m_fromRouters
 
int m_lock
 
std::vector< Redispatch * > m_finishedRedispatches
 
ServerInfo m_info
 
std::unique_ptr< ResponseTrackerm_responder
 
- Protected Attributes inherited from Eris::BaseConnection
boost::asio::io_service & _io_service
 
std::shared_ptr< StreamSocket_socket
 
Status _status
 current status of the connection
 
const std::string _id
 a unique identifier for this connection
 
std::string _clientName
 the client identified used during connection
 
Atlas::Bridge & _bridge
 the connection bridge (i.e something implementing objectArrived()) : this can be the derived class itself, or any other object
 
std::string _host
 the host name we're connected to
 
short _port
 the port we're connected to
 

Friends

class Redispatch
 
class TestInjector
 

Additional Inherited Members

- Public Types inherited from Eris::BaseConnection
enum  Status {
  INVALID_STATUS = 0, NEGOTIATE, CONNECTING, CONNECTED,
  DISCONNECTED, DISCONNECTING, QUERY_GET
}
 possible states for the connection More...
 

Detailed Description

Underlying Atlas connection, providing a send interface, and receive (dispatch) system.

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

◆ Connection() [1/2]

Eris::Connection::Connection ( boost::asio::io_service &  io_service,
EventService eventService,
const std::string &  cnm,
const std::string &  host,
short  port 
)

Create an unconnected instance.

Create a new connection, with the client-name string specified. The client-name is sent during Atlas negotiation of the connection.

Parameters
debugPerform extra (slower) validation on the connection

◆ Connection() [2/2]

Eris::Connection::Connection ( boost::asio::io_service &  io_service,
EventService eventService,
const std::string &  cnm,
const std::string &  socket 
)

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

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

Parameters
debugPerform extra (slower) validation on the connection

References Eris::BaseConnection::hardDisconnect().

Member Function Documentation

◆ connect()

int Eris::Connection::connect ( )

If the underlying socket cannot be opened, connect will return an error number immediately.

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

References _port, Eris::BaseConnection::connectLocal(), and Eris::BaseConnection::connectRemote().

◆ getServerInfo()

void Eris::Connection::getServerInfo ( ServerInfo si) const

Retrive the current server information.

Check the status field of the returned object before using this data, since it may be out of date or invalid.

◆ lock()

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.

Referenced by Eris::Account::netDisconnecting().

◆ postForDispatch()

void Eris::Connection::postForDispatch ( const Atlas::Objects::Root &  obj)
protected

Inject a local operation into the dispatch queue.

Used by the redispatch mechanism.

References m_opDeque.

◆ refreshServerInfo()

void Eris::Connection::refreshServerInfo ( )

Update the information stored about the current server.

While the refresh is taking place, the current info is still available, but with it's status set to QUERYING. The signal GotServerInfo will be emitted once the new data is received.

References Eris::BaseConnection::_status, Eris::BaseConnection::CONNECTED, Eris::getNewSerialno(), m_opDeque, and send().

◆ send()

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

◆ setStatus()

void Eris::Connection::setStatus ( Status  sc)
overrideprotected

update the connection status (and emit the appropriate signal)

Parameters
scThe new status of the connection

References Eris::BaseConnection::_status, and StatusChanged.

Referenced by disconnect().

◆ unlock()

void Eris::Connection::unlock ( )

Unlock the connection (permit status change).

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

References Eris::BaseConnection::_status, Eris::BaseConnection::DISCONNECTING, Eris::BaseConnection::hardDisconnect(), and m_opDeque.

Referenced by Eris::Account::isLoggedIn().

Member Data Documentation

◆ Disconnecting

sigc::signal<bool> Eris::Connection::Disconnecting

Emitted when the disconnection process is initiated.

The argument is a flag indicating if the disconnection was clean or not.

Referenced by disconnect(), and Eris::Account::isLoggedIn().

◆ Failure

sigc::signal<void, const std::string&> Eris::Connection::Failure

Emitted when a non-fatal error occurs.

Tthese 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

Referenced by Eris::Account::Account(), and handleFailure().

◆ StatusChanged

sigc::signal<void, Status> Eris::Connection::StatusChanged

indicates a status change on the connection

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.

Referenced by setStatus().


The documentation for this class was generated from the following files: