Eris  1.4.0
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 Net
23  {
24  class StreamConnect;
25  }
26 }
27 
28 namespace Eris
29 {
30 
31 // Forward declarations
32 
33 class StreamSocket;
34 
36 class BaseConnection : virtual public sigc::trackable
37 {
38 public:
40  virtual ~BaseConnection();
41 
44  virtual int connectRemote(const std::string &host, short port);
45 
49  virtual int connectLocal(const std::string &socket);
50 
52  typedef enum {
53  INVALID_STATUS = 0,
59 
60  // doesn't really belong here, but enums aren't subclassable
61  QUERY_GET
62  } Status;
63 
65  Status getStatus() const
66  { return _status; }
67 
69  bool isConnected() const
70  { return (_status == CONNECTED) || (_status == DISCONNECTING);}
71 
72 
78  const std::string& getHost() const;
79 
85  short getPort() const;
86 
88  sigc::signal<void> Connected;
89 
91  sigc::signal<void> Disconnected;
92 protected:
94 
97  BaseConnection(boost::asio::io_service& io_service, const std::string &cnm, const std::string &id, Atlas::Bridge& br);
98 
99  void stateChanged(StreamSocket::Status status);
100 
102  virtual void setStatus(Status sc);
103 
105  virtual void onConnect();
106 
108  virtual void handleFailure(const std::string &msg) = 0;
109 
110  virtual void handleTimeout(const std::string& msg) = 0;
111 
112  virtual void dispatch() = 0;
113 
114  void onConnectTimeout();
115  void onNegotiateTimeout();
116 
119  void hardDisconnect(bool emit);
120 
121  boost::asio::io_service& _io_service;
122  std::shared_ptr<StreamSocket> _socket;
123 
124  Status _status;
125  const std::string _id;
126 
127  std::string _clientName;
128 
131  Atlas::Bridge& _bridge;
132 
133  std::string _host;
134  short _port;
135 };
136 
137 }
138 
139 #endif
140 
Status
possible states for the connection
Definition: BaseConnection.h:52
std::string _clientName
the client identified used during connection
Definition: BaseConnection.h:127
connection fully established
Definition: BaseConnection.h:56
stream / socket connection in progress
Definition: BaseConnection.h:55
clean disconnection in progress
Definition: BaseConnection.h:58
Every Eris class and type lives inside the Eris namespace; certain utility functions live in the Util...
Definition: Account.cpp:34
finished disconnection
Definition: BaseConnection.h:57
const std::string _id
a unique identifier for this connection
Definition: BaseConnection.h:125
sigc::signal< void > Connected
sent on successful negotiation of a game server connection
Definition: BaseConnection.h:88
Status getStatus() const
get the current status of the connection
Definition: BaseConnection.h:65
Atlas negotiation in progress.
Definition: BaseConnection.h:54
Status _status
current status of the connection
Definition: BaseConnection.h:124
short _port
the port we&#39;re connected to
Definition: BaseConnection.h:134
bool isConnected() const
Ascertain whether or not the connection is usable for transport.
Definition: BaseConnection.h:69
Atlas::Bridge & _bridge
the connection bridge (i.e something implementing objectArrived()) : this can be the derived class it...
Definition: BaseConnection.h:131
std::string _host
the host name we&#39;re connected to
Definition: BaseConnection.h:133
Status
Definition: StreamSocket.h:57
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: BaseConnection.h:36
sigc::signal< void > Disconnected
final disconnect (or hard disocnnect) notifcation
Definition: BaseConnection.h:91
Definition: BaseConnection.h:18