00001 #ifndef ERIS_CONNECTION_H
00002 #define ERIS_CONNECTION_H
00003
00004 #include <Eris/BaseConnection.h>
00005 #include <Eris/Types.h>
00006 #include <Eris/ServerInfo.h>
00007
00008 #include <Atlas/Objects/Decoder.h>
00009 #include <Atlas/Objects/ObjectsFwd.h>
00010
00011 #include <deque>
00012 #include <map>
00013 #include <memory>
00014
00018
00019 class basic_socket_stream;
00020
00021 namespace Eris
00022 {
00023
00024
00025 class Timeout;
00026 class PollData;
00027 class TypeService;
00028 class Router;
00029 class Redispatch;
00030 class ResponseTracker;
00031 class TestInjector;
00032
00034
00037 class Connection :
00038 public BaseConnection,
00039 public Atlas::Objects::ObjectsDecoder
00040 {
00041 public:
00043
00047 Connection(const std::string &cnm, const std::string& host, short port, bool debug);
00048
00049 virtual ~Connection();
00050
00054 int connect();
00055
00057 int disconnect();
00058
00059 TypeService* getTypeService() const
00060 { return m_typeService.get(); }
00061
00062 ResponseTracker* getResponder() const
00063 { return m_responder.get(); }
00064
00066
00069 virtual void send(const Atlas::Objects::Root &obj);
00070
00071 void setDefaultRouter(Router* router);
00072
00073 void clearDefaultRouter();
00074
00075 void registerRouterForTo(Router* router, const std::string toId);
00076 void unregisterRouterForTo(Router* router, const std::string toId);
00077
00078 void registerRouterForFrom(Router* router, const std::string fromId);
00079 void unregisterRouterForFrom(Router* router, const std::string fromId);
00080
00085 void lock();
00086
00089 void unlock();
00090
00097 void refreshServerInfo();
00098
00104 void getServerInfo(ServerInfo&) const;
00105
00106 sigc::signal<void> GotServerInfo;
00107
00109
00113 sigc::signal<bool> Disconnecting;
00114
00121 sigc::signal<void, const std::string&> Failure;
00122
00124
00127 sigc::signal<void, Status> StatusChanged;
00128
00129 protected:
00132 virtual void setStatus(Status sc);
00133
00135 virtual void handleFailure(const std::string &msg);
00136
00137 virtual void handleTimeout(const std::string& msg);
00138
00139 virtual void onConnect();
00140
00141 void objectArrived(const Atlas::Objects::Root& obj);
00142
00143 const std::string _host;
00144 const short _port;
00145 bool _debug;
00146
00147 private:
00148 friend class Redispatch;
00149 friend class TestInjector;
00150
00153 void postForDispatch(const Atlas::Objects::Root& obj);
00154
00155 void cleanupRedispatch(Redispatch* r);
00156
00157 void gotData(PollData&);
00158
00159 void dispatchOp(const Atlas::Objects::Operation::RootOperation& op);
00160 void handleServerInfo(const Atlas::Objects::Operation::RootOperation& op);
00161
00162 void onDisconnectTimeout();
00163
00164 typedef std::deque<Atlas::Objects::Operation::RootOperation> OpDeque;
00165 OpDeque m_opDeque;
00166
00167 std::auto_ptr<TypeService> m_typeService;
00168 Router* m_defaultRouter;
00169
00170 typedef std::map<std::string, Router*> IdRouterMap;
00171 IdRouterMap m_toRouters;
00172 IdRouterMap m_fromRouters;
00173
00174 int m_lock;
00175
00176 Atlas::Objects::ObjectsEncoder* m_debugRecvEncoder;
00177
00178 std::vector<Redispatch*> m_finishedRedispatches;
00179 ServerInfo m_info;
00180
00181 std::auto_ptr<ResponseTracker> m_responder;
00182 };
00183
00185 long getNewSerialno();
00186
00187 }
00188
00189 #endif
00190