Eris 1.3.18
|
Underlying Atlas connection, providing a send interface, and receive (dispatch) system. More...
#include <Connection.h>
Public Member Functions | |
Connection (const std::string &cnm, const std::string &host, short port, bool debug) | |
Create an unconnected instance. | |
int | connect () |
If the underlying socket cannot be opened, connect will return an error number immediately. | |
int | disconnect () |
Initiate disconnection from the server. | |
TypeService * | getTypeService () const |
ResponseTracker * | getResponder () const |
virtual void | send (const Atlas::Objects::Root &obj) |
Transmit an Atlas::Objects instance to the server. | |
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. | |
void | unlock () |
Unlock the connection (permit status change). | |
void | refreshServerInfo () |
Update the information stored about the current server. | |
void | getServerInfo (ServerInfo &) const |
Retrive the current server information. | |
Public Attributes | |
sigc::signal< void > | GotServerInfo |
sigc::signal< bool > | Disconnecting |
Emitted when the disconnection process is initiated. | |
sigc::signal< void, const std::string & > | Failure |
Emitted when a non-fatal error occurs. | |
sigc::signal< void, Status > | StatusChanged |
indicates a status change on the connection | |
Protected Types | |
typedef std::deque < Atlas::Objects::Operation::RootOperation > | OpDeque |
typedef std::map< std::string, Router * > | IdRouterMap |
Protected Member Functions | |
virtual void | setStatus (Status sc) |
update the connection status (and emit the appropriate signal) | |
virtual void | handleFailure (const std::string &msg) |
Process failures (to track when reconnection should be permitted) | |
virtual void | handleTimeout (const std::string &msg) |
virtual void | onConnect () |
derived-class notification when connection and negotiation is completed | |
void | objectArrived (const Atlas::Objects::Root &obj) |
void | postForDispatch (const Atlas::Objects::Root &obj) |
Inject a local operation into the dispatch queue. | |
void | cleanupRedispatch (Redispatch *r) |
void | gotData (PollData &) |
void | dispatchOp (const Atlas::Objects::Operation::RootOperation &op) |
void | handleServerInfo (const Atlas::Objects::Operation::RootOperation &op) |
void | onDisconnectTimeout () |
Protected Attributes | |
const std::string | _host |
the host name we're connected to | |
const short | _port |
port of the server | |
bool | _debug |
OpDeque | m_opDeque |
store of all the recived ops waiting to be dispatched | |
std::auto_ptr< TypeService > | m_typeService |
Router * | m_defaultRouter |
IdRouterMap | m_toRouters |
IdRouterMap | m_fromRouters |
int | m_lock |
Atlas::Objects::ObjectsEncoder * | m_debugRecvEncoder |
std::vector< Redispatch * > | m_finishedRedispatches |
ServerInfo | m_info |
std::auto_ptr< ResponseTracker > | m_responder |
Friends | |
class | Redispatch |
class | TestInjector |
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.
Eris::Connection::Connection | ( | const std::string & | cnm, |
const std::string & | host, | ||
short | port, | ||
bool | debug | ||
) |
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.
debug | Perform extra (slower) validation on the connection |
References Eris::BaseConnection::connect().
int Eris::Connection::connect | ( | ) |
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.
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().
void Eris::Connection::postForDispatch | ( | const Atlas::Objects::Root & | obj | ) | [protected] |
Inject a local operation into the dispatch queue.
Used by the redispatch mechansim.
References m_opDeque.
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, and send().
void Eris::Connection::send | ( | const Atlas::Objects::Root & | obj | ) | [virtual] |
Transmit an Atlas::Objects instance to the server.
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
References Eris::BaseConnection::_encode, Eris::BaseConnection::_status, Eris::BaseConnection::_stream, Eris::BaseConnection::CONNECTED, Eris::BaseConnection::DISCONNECTING, handleFailure(), and Eris::BaseConnection::hardDisconnect().
Referenced by Eris::Avatar::attack(), Eris::Account::createAccount(), Eris::Account::createCharacter(), Eris::Room::createRoom(), Eris::Avatar::drop(), Eris::Room::emote(), Eris::Avatar::emote(), Eris::Lobby::join(), Eris::Room::leave(), Eris::Account::logout(), Eris::Avatar::moveInDirection(), Eris::Avatar::moveToPoint(), Eris::Person::msg(), Eris::Avatar::place(), Eris::Account::refreshCharacterInfo(), refreshServerInfo(), Eris::Room::say(), Eris::Avatar::say(), Eris::TypeService::sendRequest(), Eris::Avatar::take(), Eris::Account::takeCharacter(), Eris::Avatar::touch(), Eris::Avatar::useOn(), Eris::Avatar::useStop(), and Eris::Avatar::wield().
void Eris::Connection::setStatus | ( | Status | sc | ) | [protected, virtual] |
update the connection status (and emit the appropriate signal)
sc | The new status of the connection |
Reimplemented from Eris::BaseConnection.
References Eris::BaseConnection::_status, and StatusChanged.
Referenced by disconnect().
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.
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().
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().
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().