1 #ifndef ERIS_BASE_CONNECTION_H
2 #define ERIS_BASE_CONNECTION_H
4 #include "StreamSocket.h"
6 #include <Atlas/Objects/ObjectsFwd.h>
7 #include <Atlas/Negotiate.h>
9 #include <sigc++/trackable.h>
10 #include <sigc++/signal.h>
12 #include <boost/asio/io_service.hpp>
47 virtual int connectRemote(
const std::string &host,
short port);
81 const std::string&
getHost()
const;
90 Atlas::Objects::Factories& getFactories();
92 const Atlas::Objects::Factories& getFactories()
const;
104 BaseConnection(boost::asio::io_service& io_service, std::string clientName, std::string
id);
117 virtual void handleTimeout(
const std::string& msg) = 0;
119 virtual void dispatch() = 0;
121 void onConnectTimeout();
122 void onNegotiateTimeout();
128 boost::asio::io_service& _io_service;
129 std::unique_ptr<Atlas::Objects::Factories> _factories;
130 std::shared_ptr<StreamSocket> _socket;
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
const std::string & getHost() const
virtual void handleFailure(const std::string &msg)=0
derived-class notification when a failure occurs
sigc::signal< void > Connected
sent on successful negotiation of a game server connection
Status _status
current status of the connection
void hardDisconnect(bool emit)
virtual int connectLocal(const std::string &socket)
virtual ~BaseConnection()
destructor, will perform a hard disconnect if necessary
sigc::signal< void > Disconnected
final disconnect (or hard disocnnect) notifcation
const std::string _id
a unique identifier for this connection
virtual void onConnect()
derived-class notification when connection and negotiation is completed
std::string _clientName
the client identified used during connection
short _port
the port we're connected to
bool isConnected() const
Ascertain whether or not the connection is usable for transport.
std::string _host
the host name we're connected to
virtual void setStatus(Status sc)
update the connection status and generate signals
BaseConnection(boost::asio::io_service &io_service, std::string clientName, std::string id)
create an unconnected instance
virtual int connectRemote(const std::string &host, short port)
Status getStatus() const
get the current status of the connection
Status
possible states for the connection
@ DISCONNECTING
clean disconnection in progress
@ CONNECTING
stream / socket connection in progress
@ INVALID_STATUS
indicates an illegal state
@ DISCONNECTED
finished disconnection
@ QUERY_GET
meta-query performing GET operation
@ NEGOTIATE
Atlas negotiation in progress.
@ CONNECTED
connection fully established