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 
18 namespace 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 
31 namespace Eris
32 {
33 
34 // Forward declarations
35 
36 class StreamSocket;
37 
39 class BaseConnection : virtual public sigc::trackable
40 {
41 public:
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 {
56  INVALID_STATUS = 0,
62 
63  // doesn't really belong here, but enums aren't subclassable
64  QUERY_GET
65  } Status;
66 
68  Status getStatus() const
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;
99 protected:
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 
132  Status _status;
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 
Status
possible states for the connection
std::string _clientName
the client identified used during connection
connection fully established
stream / socket connection in progress
Status getStatus() const
get the current status of the connection
clean disconnection in progress
Definition: Account.cpp:33
const std::string _id
a unique identifier for this connection
Atlas::Bridge * _bridge
sigc::signal< void > Connected
sent on successful negotiation of a game server connection
Atlas negotiation in progress.
Status _status
current status of the connection
short _port
the port we&#39;re connected to
bool isConnected() const
Ascertain whether or not the connection is usable for transport.
std::string _host
the host name we&#39;re connected to
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
sigc::signal< void > Disconnected
final disconnect (or hard disocnnect) notifcation