eris
1.4.0
A WorldForge client library.
|
Public Types | |
enum | Status { INVALID_STATUS = 0 , NEGOTIATE , CONNECTING , CONNECTED , DISCONNECTED , DISCONNECTING , QUERY_GET } |
possible states for the connection More... | |
Public Member Functions | |
Connection (boost::asio::io_service &io_service, EventService &eventService, std::string clientName, const std::string &host, short port) | |
Create an unconnected instance. More... | |
Connection (boost::asio::io_service &io_service, EventService &eventService, std::string clientName, std::string socket) | |
int | connect () |
int | disconnect () |
Initiate disconnection from the server. More... | |
TypeService & | getTypeService () const |
ResponseTracker & | getResponder () const |
EventService & | getEventService () |
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 (const std::string &fromId) |
void | lock () |
void | unlock () |
void | refreshServerInfo () |
void | getServerInfo (ServerInfo &) const |
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 > | GotServerInfo |
sigc::signal< bool > | Disconnecting |
sigc::signal< void, const std::string & > | Failure |
sigc::signal< void, Status > | StatusChanged |
indicates a status change on the connection More... | |
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 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 |
void | handleFailure (const std::string &msg) override |
Process failures (to track when reconnection should be permitted) More... | |
void | handleTimeout (const std::string &msg) override |
void | onConnect () override |
derived-class notification when connection and negotiation is completed More... | |
virtual void | objectArrived (Atlas::Objects::Root obj) |
void | postForDispatch (const Atlas::Objects::Root &obj) |
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 () |
void | stateChanged (StreamSocket::Status status) |
void | onConnectTimeout () |
void | onNegotiateTimeout () |
void | hardDisconnect (bool emit) |
Protected Attributes | |
std::unique_ptr< ConnectionDecoder > | m_decoder |
EventService & | _eventService |
const std::string | _host |
const short | _port |
port of the server More... | |
const std::string | _localSocket |
OpDeque | m_opDeque |
store of all the received ops waiting to be dispatched More... | |
std::unique_ptr< TypeService > | m_typeService |
Router * | m_defaultRouter |
IdRouterMap | m_toRouters |
IdRouterMap | m_fromRouters |
int | m_lock |
std::vector< std::unique_ptr< Redispatch > > | m_finishedRedispatches |
ServerInfo | m_info |
std::unique_ptr< ResponseTracker > | m_responder |
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 |
Friends | |
struct | ConnectionDecoder |
class | Redispatch |
class | TestInjector |
Definition at line 44 of file Connection.h.
|
inherited |
possible states for the connection
Definition at line 55 of file BaseConnection.h.
Eris::Connection::Connection | ( | boost::asio::io_service & | io_service, |
EventService & | eventService, | ||
std::string | clientName, | ||
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.
debug | Perform extra (slower) validation on the connection |
Definition at line 48 of file Connection.cpp.
References Eris::BaseConnection::_bridge.
Eris::Connection::Connection | ( | boost::asio::io_service & | io_service, |
EventService & | eventService, | ||
std::string | clientName, | ||
std::string | socket | ||
) |
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 |
Definition at line 66 of file Connection.cpp.
References Eris::BaseConnection::_bridge.
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.
Definition at line 96 of file Connection.cpp.
References _port, Eris::BaseConnection::connectLocal(), and Eris::BaseConnection::connectRemote().
|
virtualinherited |
Try to connect to a local socket.
Definition at line 98 of file BaseConnection.cpp.
References Eris::BaseConnection::_bridge, Eris::BaseConnection::_clientName, Eris::BaseConnection::CONNECTING, Eris::StreamSocket::Callbacks::dispatch, Eris::BaseConnection::hardDisconnect(), Eris::BaseConnection::setStatus(), and Eris::StreamSocket::Callbacks::stateChanged.
Referenced by connect().
|
virtualinherited |
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 Eris::BaseConnection::_bridge, Eris::BaseConnection::_clientName, Eris::BaseConnection::CONNECTING, Eris::StreamSocket::Callbacks::dispatch, Eris::BaseConnection::hardDisconnect(), Eris::StreamSocket::NEGOTIATE, Eris::BaseConnection::setStatus(), and Eris::StreamSocket::Callbacks::stateChanged.
Referenced by connect().
int Eris::Connection::disconnect | ( | ) |
Initiate disconnection from the server.
Definition at line 105 of file Connection.cpp.
References Eris::BaseConnection::_status, Eris::BaseConnection::CONNECTED, Eris::BaseConnection::DISCONNECTED, Eris::BaseConnection::DISCONNECTING, Disconnecting, Eris::BaseConnection::hardDisconnect(), and setStatus().
|
inherited |
Gets the host of the connection.
Definition at line 203 of file BaseConnection.cpp.
References Eris::BaseConnection::_host.
|
inherited |
Gets the port of the connection.
Definition at line 208 of file BaseConnection.cpp.
References Eris::BaseConnection::_port.
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.
Definition at line 242 of file Connection.cpp.
|
inlineinherited |
get the current status of the connection
Definition at line 68 of file BaseConnection.h.
References Eris::BaseConnection::_status.
|
overrideprotectedvirtual |
Process failures (to track when reconnection should be permitted)
Implements Eris::BaseConnection.
Definition at line 336 of file Connection.cpp.
References Failure.
Referenced by send().
|
protectedinherited |
performs and instant disconnection from the server @emit specified whether the change of state should be signalled
Definition at line 162 of file BaseConnection.cpp.
References Eris::BaseConnection::_status, Eris::BaseConnection::DISCONNECTED, Eris::BaseConnection::Disconnected, and Eris::BaseConnection::setStatus().
Referenced by Eris::BaseConnection::connectLocal(), Eris::BaseConnection::connectRemote(), disconnect(), send(), unlock(), and Eris::BaseConnection::~BaseConnection().
|
inlineinherited |
Ascertain whether or not the connection is usable for transport.
Definition at line 72 of file BaseConnection.h.
References Eris::BaseConnection::_status, Eris::BaseConnection::CONNECTED, and Eris::BaseConnection::DISCONNECTING.
Referenced by Eris::Room::createRoom(), Eris::Room::emote(), Eris::Room::leave(), Eris::Account::login(), Eris::Account::logout(), Eris::Person::msg(), Eris::Account::refreshCharacterInfo(), Eris::Room::say(), Eris::Account::takeCharacter(), and Eris::Account::takeTransferredCharacter().
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.
Definition at line 217 of file Connection.cpp.
Referenced by Eris::Account::netDisconnecting().
|
overrideprotectedvirtual |
derived-class notification when connection and negotiation is completed
Reimplemented from Eris::BaseConnection.
Definition at line 359 of file Connection.cpp.
References Eris::BaseConnection::onConnect().
|
protected |
Inject a local operation into the dispatch queue. Used by the redispatch mechanism.
Definition at line 370 of file Connection.cpp.
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.
Definition at line 246 of file Connection.cpp.
References Eris::BaseConnection::_status, Eris::BaseConnection::CONNECTED, Eris::getNewSerialno(), and send().
|
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
Definition at line 160 of file Connection.cpp.
References Eris::BaseConnection::_status, Eris::BaseConnection::CONNECTED, Eris::BaseConnection::DISCONNECTING, handleFailure(), and Eris::BaseConnection::hardDisconnect().
Referenced by Eris::Room::createRoom(), Eris::Avatar::emote(), Eris::Room::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::Avatar::say(), Eris::Room::say(), Eris::Avatar::sayTo(), Eris::Avatar::send(), Eris::Account::takeCharacter(), Eris::Account::takeTransferredCharacter(), Eris::Avatar::touch(), and Eris::Avatar::useStop().
|
overrideprotectedvirtual |
update the connection status (and emit the appropriate signal)
sc | The new status of the connection |
Reimplemented from Eris::BaseConnection.
Definition at line 331 of file Connection.cpp.
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.
Definition at line 221 of file Connection.cpp.
References Eris::BaseConnection::_status, Eris::BaseConnection::DISCONNECTING, Eris::BaseConnection::hardDisconnect(), and m_opDeque.
|
protectedinherited |
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 Connection(), Eris::BaseConnection::connectLocal(), and Eris::BaseConnection::connectRemote().
|
protectedinherited |
the client identified used during connection
Definition at line 135 of file BaseConnection.h.
Referenced by Eris::BaseConnection::connectLocal(), and Eris::BaseConnection::connectRemote().
|
protectedinherited |
a unique identifier for this connection
Definition at line 133 of file BaseConnection.h.
|
protected |
|
protectedinherited |
current status of the connection
Definition at line 132 of file BaseConnection.h.
Referenced by disconnect(), Eris::BaseConnection::getStatus(), Eris::BaseConnection::hardDisconnect(), Eris::BaseConnection::isConnected(), refreshServerInfo(), send(), Eris::BaseConnection::setStatus(), setStatus(), unlock(), and Eris::BaseConnection::~BaseConnection().
|
inherited |
sent on successful negotiation of a game server connection
Definition at line 95 of file BaseConnection.h.
Referenced by Eris::Account::Account(), and Eris::BaseConnection::onConnect().
|
inherited |
final disconnect (or hard disocnnect) notifcation
Definition at line 98 of file BaseConnection.h.
Referenced by Eris::BaseConnection::hardDisconnect().
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.
Definition at line 134 of file Connection.h.
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
Definition at line 142 of file Connection.h.
Referenced by Eris::Account::Account(), and handleFailure().
|
protected |
store of all the received ops waiting to be dispatched
Definition at line 191 of file Connection.h.
Referenced by postForDispatch(), and unlock().
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.
Definition at line 148 of file Connection.h.
Referenced by setStatus().