Eris  1.3.23
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Eris::BaseConnection Class Referenceabstract

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

#include <BaseConnection.h>

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

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
 
virtual int connect (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.
 
int getFileDescriptor ()
 get the underlyinmg file descriptor (socket). More...
 
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 > Connected
 sent on successful negotiation of a game server connection
 
sigc::signal< void > Disconnected
 final disconnect (or hard disocnnect) notifcation
 

Protected Member Functions

 BaseConnection (const std::string &cnm, const std::string &id, Atlas::Bridge *br)
 create an unconnected instance More...
 
void recv ()
 perform a blocking read from the underlying socket
 
virtual void setStatus (Status sc)
 update the connection status and generate signals
 
virtual void onConnect ()
 derived-class notification when connection and negotiation is completed
 
virtual void handleFailure (const std::string &msg)=0
 derived-class notification when a failure occurs
 
virtual void handleTimeout (const std::string &msg)=0
 
void onConnectTimeout ()
 
void onNegotiateTimeout ()
 
void hardDisconnect (bool emit)
 performs and instant disconnection from the server specified whether the change of state should be signalled
 
void nonblockingConnect ()
 complete the connection state and start negotiation
 
void pollNegotiation ()
 track negotation of the Atlas codecs / stream
 

Protected Attributes

Atlas::Objects::ObjectsEncoder * _encode
 the objects encoder, bound to _codec
 
Atlas::Net::StreamConnect * _sc
 negotiation object (NULL after connection!)
 
Atlas::Codec * m_codec
 
Status _status
 current status of the connection
 
const std::string _id
 a unique identifier for this connection
 
stream_socket_stream * _stream
 the underlying iostream channel
 
std::function< int(void)> _open_next_func
 a method for calling "open_next" on the stream, if such functionality is available
 
std::function< bool(void)> _is_ready_func
 a method for calling "is_ready" on the stream, if such functionality is available
 
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
 
Timeout_timeout
 network level timeouts
 
std::string _host
 the host name we're connected to
 
short _port
 the port we're connected to
 

Detailed Description

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

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

Constructor & Destructor Documentation

§ BaseConnection()

Eris::BaseConnection::BaseConnection ( const std::string &  cnm,
const std::string &  id,
Atlas::Bridge *  br 
)
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)

References _bridge.

Member Function Documentation

§ connect()

int Eris::BaseConnection::connect ( 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.

References _host, _is_ready_func, _open_next_func, _port, _stream, _timeout, CONNECTING, DISCONNECTED, Eris::Timeout::Expired, hardDisconnect(), NEGOTIATE, and setStatus().

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

§ getFileDescriptor()

int Eris::BaseConnection::getFileDescriptor ( )

get the underlyinmg file descriptor (socket).

This is so GUI / widget libraries which steal the main-loop, but can monitor file-decriptors work. The obvious examples being Gtk+/– and Qt

References _stream.

§ getHost()

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

Gets the host of the connection.

Returns
The host of the connection.

References _host.

§ getPort()

short Eris::BaseConnection::getPort ( ) const

Gets the port of the connection.

Returns
The port of the connection.

References _port.


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