eris 1.4.0
A WorldForge client library.
BaseConnection.h
1#ifndef ERIS_BASE_CONNECTION_H
2#define ERIS_BASE_CONNECTION_H
3
4#include "StreamSocket.h"
5
6#include <Atlas/Objects/ObjectsFwd.h>
7#include <Atlas/Negotiate.h>
8
9#include <sigc++/trackable.h>
10#include <sigc++/signal.h>
11
12#include <boost/asio/io_service.hpp>
13
14#include <string>
15#include <memory>
16#include <functional>
17
18namespace Atlas
19{
20 class Bridge;
21 class Codec;
22 namespace Objects {
23 class Factories;
24 }
25 namespace Net
26 {
27 class StreamConnect;
28 }
29}
30
31namespace Eris
32{
33
34// Forward declarations
35
36class StreamSocket;
37
39class BaseConnection : virtual public sigc::trackable
40{
41public:
43 virtual ~BaseConnection();
44
47 virtual int connectRemote(const std::string &host, short port);
48
52 virtual int connectLocal(const std::string &socket);
53
55 typedef enum {
62
63 // doesn't really belong here, but enums aren't subclassable
66
69 { return _status; }
70
72 bool isConnected() const
73 { return (_status == CONNECTED) || (_status == DISCONNECTING);}
74
75
81 const std::string& getHost() const;
82
88 short getPort() const;
89
90 Atlas::Objects::Factories& getFactories();
91
92 const Atlas::Objects::Factories& getFactories() const;
93
95 sigc::signal<void> Connected;
96
98 sigc::signal<void> Disconnected;
99protected:
101
104 BaseConnection(boost::asio::io_service& io_service, std::string clientName, std::string id);
105
106 void stateChanged(StreamSocket::Status status);
107
109 virtual void setStatus(Status sc);
110
112 virtual void onConnect();
113
115 virtual void handleFailure(const std::string &msg) = 0;
116
117 virtual void handleTimeout(const std::string& msg) = 0;
118
119 virtual void dispatch() = 0;
120
121 void onConnectTimeout();
122 void onNegotiateTimeout();
123
126 void hardDisconnect(bool emit);
127
128 boost::asio::io_service& _io_service;
129 std::unique_ptr<Atlas::Objects::Factories> _factories;
130 std::shared_ptr<StreamSocket> _socket;
131
133 const std::string _id;
134
135 std::string _clientName;
136
139 Atlas::Bridge* _bridge;
140
141 std::string _host;
142 short _port;
143};
144
145}
146
147#endif
148
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
Atlas::Bridge * _bridge
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
Definition: Account.cpp:33