Eris  1.3.23
BaseConnection.h
1 #ifndef ERIS_BASE_CONNECTION_H
2 #define ERIS_BASE_CONNECTION_H
3 
4 #include <Atlas/Objects/ObjectsFwd.h>
5 
6 #include <sigc++/trackable.h>
7 #include <sigc++/signal.h>
8 
9 #include <string>
10 #include <memory>
11 #include <functional>
12 
13 class stream_socket_stream;
14 
15 namespace Atlas
16 {
17  class Bridge;
18  class Codec;
19  namespace Net
20  {
21  class StreamConnect;
22  }
23 }
24 
25 namespace Eris
26 {
27 
28 // Forward declarations
29 class Timeout;
30 
32 class BaseConnection : virtual public sigc::trackable
33 {
34 public:
36  virtual ~BaseConnection();
37 
40  virtual int connect(const std::string &host, short port);
41 
45  virtual int connectLocal(const std::string &socket);
46 
48  typedef enum {
49  INVALID_STATUS = 0,
55 
56  // doesn't really belong here, but enums aren't subclassable
57  QUERY_GET
58  } Status;
59 
61  Status getStatus() const
62  { return _status; }
63 
65  bool isConnected() const
66  { return (_status == CONNECTED) || (_status == DISCONNECTING);}
67 
71  int getFileDescriptor();
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(const std::string &cnm, const std::string &id, Atlas::Bridge *br);
98 
100  void recv();
101 
103  virtual void setStatus(Status sc);
104 
106  virtual void onConnect();
107 
109  virtual void handleFailure(const std::string &msg) = 0;
110 
111  virtual void handleTimeout(const std::string& msg) = 0;
112 
113  void onConnectTimeout();
114  void onNegotiateTimeout();
115 
118  void hardDisconnect(bool emit);
119 
121  void nonblockingConnect();
122 
124  void pollNegotiation();
125 
126  Atlas::Objects::ObjectsEncoder* _encode;
127  Atlas::Net::StreamConnect* _sc;
128  Atlas::Codec* m_codec;
129 
130  Status _status;
131  const std::string _id;
132 
133  stream_socket_stream* _stream;
134  std::function<int(void)> _open_next_func;
135  std::function<bool(void)> _is_ready_func;
136 
137  std::string _clientName;
138 
141  Atlas::Bridge* _bridge;
143 
144  std::string _host;
145  short _port;
146 };
147 
148 }
149 
150 #endif
151 
Atlas::Objects::ObjectsEncoder * _encode
the objects encoder, bound to _codec
Definition: BaseConnection.h:126
Status
possible states for the connection
Definition: BaseConnection.h:48
std::function< bool(void)> _is_ready_func
a method for calling "is_ready" on the stream, if such functionality is available ...
Definition: BaseConnection.h:135
std::function< int(void)> _open_next_func
a method for calling "open_next" on the stream, if such functionality is available ...
Definition: BaseConnection.h:134
std::string _clientName
the client identified used during connection
Definition: BaseConnection.h:137
connection fully established
Definition: BaseConnection.h:52
Atlas::Net::StreamConnect * _sc
negotiation object (NULL after connection!)
Definition: BaseConnection.h:127
stream / socket connection in progress
Definition: BaseConnection.h:51
Timeout * _timeout
network level timeouts
Definition: BaseConnection.h:142
clean disconnection in progress
Definition: BaseConnection.h:54
Definition: Account.cpp:33
finished disconnection
Definition: BaseConnection.h:53
const std::string _id
a unique identifier for this connection
Definition: BaseConnection.h:131
Atlas::Bridge * _bridge
the connection bridge (i.e something implementing objectArrived()) : this can be the derived class it...
Definition: BaseConnection.h:141
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:61
Atlas negotiation in progress.
Definition: BaseConnection.h:50
Status _status
current status of the connection
Definition: BaseConnection.h:130
short _port
the port we&#39;re connected to
Definition: BaseConnection.h:145
Timeout.
Definition: Timeout.h:12
bool isConnected() const
Ascertain whether or not the connection is usable for transport.
Definition: BaseConnection.h:65
std::string _host
the host name we&#39;re connected to
Definition: BaseConnection.h:144
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: BaseConnection.h:32
sigc::signal< void > Disconnected
final disconnect (or hard disocnnect) notifcation
Definition: BaseConnection.h:91
stream_socket_stream * _stream
the underlying iostream channel
Definition: BaseConnection.h:133
Definition: BaseConnection.h:15