Eris  1.3.19
Connection.h
1 #ifndef ERIS_CONNECTION_H
2 #define ERIS_CONNECTION_H
3 
4 #include <Eris/BaseConnection.h>
5 #include <Eris/ServerInfo.h>
6 
7 #include <Atlas/Objects/Decoder.h>
8 #include <Atlas/Objects/ObjectsFwd.h>
9 #include <Atlas/Objects/RootOperation.h>
10 
11 #include <deque>
12 #include <map>
13 #include <memory>
14 
18 // Forward declaration of the skstream type
19 class basic_socket_stream;
20 
21 namespace Eris
22 {
23 
24 // Forward declarations
25 class Timeout;
26 class PollData;
27 class TypeService;
28 class Router;
29 class Redispatch;
30 class ResponseTracker;
31 class TestInjector;
32 
34 
37 class Connection :
38  public BaseConnection,
39  public Atlas::Objects::ObjectsDecoder
40 {
41 public:
43 
47  Connection(const std::string &cnm, const std::string& host, short port, bool debug);
48 
49  virtual ~Connection();
50 
54  int connect();
55 
57  int disconnect();
58 
59  TypeService* getTypeService() const
60  { return m_typeService.get(); }
61 
62  ResponseTracker* getResponder() const
63  { return m_responder.get(); }
64 
66 
69  virtual void send(const Atlas::Objects::Root &obj);
70 
71  void setDefaultRouter(Router* router);
72 
73  void clearDefaultRouter();
74 
75  void registerRouterForTo(Router* router, const std::string toId);
76  void unregisterRouterForTo(Router* router, const std::string toId);
77 
78  void registerRouterForFrom(Router* router, const std::string fromId);
79  void unregisterRouterForFrom(Router* router, const std::string fromId);
80 
85  void lock();
86 
89  void unlock();
90 
97  void refreshServerInfo();
98 
104  void getServerInfo(ServerInfo&) const;
105 
106  sigc::signal<void> GotServerInfo;
107 
109 
113  sigc::signal<bool> Disconnecting;
114 
121  sigc::signal<void, const std::string&> Failure;
122 
124 
127  sigc::signal<void, Status> StatusChanged;
128 
129 protected:
132  virtual void setStatus(Status sc);
133 
135  virtual void handleFailure(const std::string &msg);
136 
137  virtual void handleTimeout(const std::string& msg);
138 
139  virtual void onConnect();
140 
141  void objectArrived(const Atlas::Objects::Root& obj);
142 
143  const std::string _host;
144  const short _port;
145  bool _debug;
146 
147  friend class Redispatch;
148  friend class TestInjector;
149 
152  void postForDispatch(const Atlas::Objects::Root& obj);
153 
154  void cleanupRedispatch(Redispatch* r);
155 
156  void gotData(PollData&);
157 
158  void dispatchOp(const Atlas::Objects::Operation::RootOperation& op);
159  void handleServerInfo(const Atlas::Objects::Operation::RootOperation& op);
160 
161  void onDisconnectTimeout();
162 
163  typedef std::deque<Atlas::Objects::Operation::RootOperation> OpDeque;
164  OpDeque m_opDeque;
165 
166  std::auto_ptr<TypeService> m_typeService;
167  Router* m_defaultRouter; // need several of these?
168 
169  typedef std::map<std::string, Router*> IdRouterMap;
170  IdRouterMap m_toRouters;
171  IdRouterMap m_fromRouters;
172 
173  int m_lock;
174 
175  Atlas::Objects::ObjectsEncoder* m_debugRecvEncoder;
176 
177  std::vector<Redispatch*> m_finishedRedispatches;
178  ServerInfo m_info;
179 
180  std::auto_ptr<ResponseTracker> m_responder;
181 };
182 
184 long getNewSerialno();
185 
186 } // of Eris namespace
187 
188 #endif
189