eris  1.4.0
A WorldForge client library.
Eris::BaseConnection Class Referenceabstract

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

#include <BaseConnection.h>

Inheritance diagram for Eris::BaseConnection:
Collaboration diagram for Eris::BaseConnection:

Public Types

enum  Status {
  INVALID_STATUS = 0, NEGOTIATE, CONNECTING, CONNECTED,
  DISCONNECTED, DISCONNECTING, QUERY_GET
}
 possible states for the connection More...
 

Public Member Functions

virtual ~BaseConnection ()
 destructor, will perform a hard disconnect if necessary More...
 
virtual int connectRemote (const std::string &host, short port)
 
virtual int connectLocal (const std::string &socket)
 
Status getStatus () const
 get the current status of the connection More...
 
bool isConnected () const
 Ascertain whether or not the connection is usable for transport. More...
 
const std::string & getHost () const
 
short getPort () const
 
Atlas::Objects::Factories & getFactories ()
 
const Atlas::Objects::Factories & getFactories () const
 

Public Attributes

sigc::signal< void > Connected
 sent on successful negotiation of a game server connection More...
 
sigc::signal< void > Disconnected
 final disconnect (or hard disocnnect) notifcation More...
 

Protected Member Functions

 BaseConnection (boost::asio::io_service &io_service, std::string clientName, std::string id)
 create an unconnected instance More...
 
void stateChanged (StreamSocket::Status status)
 
virtual void setStatus (Status sc)
 update the connection status and generate signals More...
 
virtual void onConnect ()
 derived-class notification when connection and negotiation is completed More...
 
virtual void handleFailure (const std::string &msg)=0
 derived-class notification when a failure occurs More...
 
virtual void handleTimeout (const std::string &msg)=0
 
virtual void dispatch ()=0
 
void onConnectTimeout ()
 
void onNegotiateTimeout ()
 
void hardDisconnect (bool emit)
 

Protected Attributes

boost::asio::io_service & _io_service
 
std::unique_ptr< Atlas::Objects::Factories > _factories
 
std::shared_ptr< StreamSocket_socket
 
Status _status
 current status of the connection More...
 
const std::string _id
 a unique identifier for this connection More...
 
std::string _clientName
 the client identified used during connection More...
 
Atlas::Bridge * _bridge
 
std::string _host
 the host name we're connected to More...
 
short _port
 the port we're connected to More...
 

Detailed Description

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

Definition at line 39 of file BaseConnection.h.

Member Enumeration Documentation

◆ Status

possible states for the connection

Enumerator
INVALID_STATUS 

indicates an illegal state

NEGOTIATE 

Atlas negotiation in progress.

CONNECTING 

stream / socket connection in progress

CONNECTED 

connection fully established

DISCONNECTED 

finished disconnection

DISCONNECTING 

clean disconnection in progress

QUERY_GET 

meta-query performing GET operation

Definition at line 55 of file BaseConnection.h.

Constructor & Destructor Documentation

◆ ~BaseConnection()

Eris::BaseConnection::~BaseConnection ( )
virtual

destructor, will perform a hard disconnect if necessary

Definition at line 54 of file BaseConnection.cpp.

References _status, DISCONNECTED, and hardDisconnect().

◆ BaseConnection()

Eris::BaseConnection::BaseConnection ( boost::asio::io_service &  io_service,
std::string  clientName,
std::string  id 
)
protected

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. Id is a unique string to identify timeouts created by the connection (and potentially errors in the future)

Definition at line 38 of file BaseConnection.cpp.

Member Function Documentation

◆ connectLocal()

◆ connectRemote()

int Eris::BaseConnection::connectRemote ( const std::string &  host,
short  port 
)
virtual

open a connection to the specified host/port; invokes the failure handler if the connection could not be opened.

Definition at line 65 of file BaseConnection.cpp.

References _bridge, _clientName, CONNECTING, Eris::StreamSocket::Callbacks::dispatch, hardDisconnect(), Eris::StreamSocket::NEGOTIATE, setStatus(), and Eris::StreamSocket::Callbacks::stateChanged.

Referenced by Eris::Connection::connect().

◆ getHost()

const std::string & Eris::BaseConnection::getHost ( ) const

Gets the host of the connection.

Returns
The host of the connection.

Definition at line 203 of file BaseConnection.cpp.

References _host.

◆ getPort()

short Eris::BaseConnection::getPort ( ) const

Gets the port of the connection.

Returns
The port of the connection.

Definition at line 208 of file BaseConnection.cpp.

References _port.

◆ getStatus()

Status Eris::BaseConnection::getStatus ( ) const
inline

get the current status of the connection

Definition at line 68 of file BaseConnection.h.

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

◆ handleFailure()

virtual void Eris::BaseConnection::handleFailure ( const std::string &  msg)
protectedpure virtual

derived-class notification when a failure occurs

Implemented in Eris::Connection, and Eris::MetaQuery.

Referenced by connectLocal().

◆ hardDisconnect()

void Eris::BaseConnection::hardDisconnect ( bool  emit)
protected

performs and instant disconnection from the server specified whether the change of state should be signalled

Definition at line 162 of file BaseConnection.cpp.

References _status, DISCONNECTED, Disconnected, and setStatus().

Referenced by Eris::Connection::Connection(), connectLocal(), connectRemote(), Eris::Connection::disconnect(), onConnect(), Eris::Connection::onConnect(), Eris::Connection::send(), Eris::Connection::unlock(), and ~BaseConnection().

◆ isConnected()

◆ onConnect()

void Eris::BaseConnection::onConnect ( )
protectedvirtual

derived-class notification when connection and negotiation is completed

Reimplemented in Eris::Connection, and Eris::MetaQuery.

Definition at line 178 of file BaseConnection.cpp.

References _host, _port, Connected, and hardDisconnect().

Referenced by connectLocal(), and Eris::Connection::onConnect().

◆ setStatus()

void Eris::BaseConnection::setStatus ( Status  sc)
protectedvirtual

update the connection status and generate signals

Reimplemented in Eris::Connection.

Definition at line 198 of file BaseConnection.cpp.

References _status.

Referenced by connectLocal(), connectRemote(), and hardDisconnect().

Member Data Documentation

◆ _bridge

Atlas::Bridge* Eris::BaseConnection::_bridge
protected

the connection bridge (i.e something implementing objectArrived()) : this can be the derived class itself, or any other object

Definition at line 139 of file BaseConnection.h.

Referenced by Eris::Connection::Connection(), connectLocal(), and connectRemote().

◆ _clientName

std::string Eris::BaseConnection::_clientName
protected

the client identified used during connection

Definition at line 135 of file BaseConnection.h.

Referenced by connectLocal(), and connectRemote().

◆ _host

std::string Eris::BaseConnection::_host
protected

the host name we're connected to

Definition at line 141 of file BaseConnection.h.

Referenced by connectLocal(), getHost(), and onConnect().

◆ _id

const std::string Eris::BaseConnection::_id
protected

a unique identifier for this connection

Definition at line 133 of file BaseConnection.h.

◆ _port

short Eris::BaseConnection::_port
protected

the port we're connected to

Definition at line 142 of file BaseConnection.h.

Referenced by getPort(), and onConnect().

◆ _status

◆ Connected

sigc::signal<void> Eris::BaseConnection::Connected

sent on successful negotiation of a game server connection

Definition at line 95 of file BaseConnection.h.

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

◆ Disconnected

sigc::signal<void> Eris::BaseConnection::Disconnected

final disconnect (or hard disocnnect) notifcation

Definition at line 98 of file BaseConnection.h.

Referenced by hardDisconnect().


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