Eris 1.3.16
|
00001 #ifndef ERIS_CONNECTION_H 00002 #define ERIS_CONNECTION_H 00003 00004 #include <Eris/BaseConnection.h> 00005 #include <Eris/ServerInfo.h> 00006 00007 #include <Atlas/Objects/Decoder.h> 00008 #include <Atlas/Objects/ObjectsFwd.h> 00009 00010 #include <deque> 00011 #include <map> 00012 #include <memory> 00013 00017 // Forward declaration of the skstream type 00018 class basic_socket_stream; 00019 00020 namespace Eris 00021 { 00022 00023 // Forward declarations 00024 class Timeout; 00025 class PollData; 00026 class TypeService; 00027 class Router; 00028 class Redispatch; 00029 class ResponseTracker; 00030 class TestInjector; 00031 00033 00036 class Connection : 00037 public BaseConnection, 00038 public Atlas::Objects::ObjectsDecoder 00039 { 00040 public: 00042 00046 Connection(const std::string &cnm, const std::string& host, short port, bool debug); 00047 00048 virtual ~Connection(); 00049 00053 int connect(); 00054 00056 int disconnect(); 00057 00058 TypeService* getTypeService() const 00059 { return m_typeService.get(); } 00060 00061 ResponseTracker* getResponder() const 00062 { return m_responder.get(); } 00063 00065 00068 virtual void send(const Atlas::Objects::Root &obj); 00069 00070 void setDefaultRouter(Router* router); 00071 00072 void clearDefaultRouter(); 00073 00074 void registerRouterForTo(Router* router, const std::string toId); 00075 void unregisterRouterForTo(Router* router, const std::string toId); 00076 00077 void registerRouterForFrom(Router* router, const std::string fromId); 00078 void unregisterRouterForFrom(Router* router, const std::string fromId); 00079 00084 void lock(); 00085 00088 void unlock(); 00089 00096 void refreshServerInfo(); 00097 00103 void getServerInfo(ServerInfo&) const; 00104 00105 sigc::signal<void> GotServerInfo; 00106 00108 00112 sigc::signal<bool> Disconnecting; 00113 00120 sigc::signal<void, const std::string&> Failure; 00121 00123 00126 sigc::signal<void, Status> StatusChanged; 00127 00128 protected: 00131 virtual void setStatus(Status sc); 00132 00134 virtual void handleFailure(const std::string &msg); 00135 00136 virtual void handleTimeout(const std::string& msg); 00137 00138 virtual void onConnect(); 00139 00140 void objectArrived(const Atlas::Objects::Root& obj); 00141 00142 const std::string _host; 00143 const short _port; 00144 bool _debug; 00145 00146 friend class Redispatch; 00147 friend class TestInjector; 00148 00151 void postForDispatch(const Atlas::Objects::Root& obj); 00152 00153 void cleanupRedispatch(Redispatch* r); 00154 00155 void gotData(PollData&); 00156 00157 void dispatchOp(const Atlas::Objects::Operation::RootOperation& op); 00158 void handleServerInfo(const Atlas::Objects::Operation::RootOperation& op); 00159 00160 void onDisconnectTimeout(); 00161 00162 typedef std::deque<Atlas::Objects::Operation::RootOperation> OpDeque; 00163 OpDeque m_opDeque; 00164 00165 std::auto_ptr<TypeService> m_typeService; 00166 Router* m_defaultRouter; // need several of these? 00167 00168 typedef std::map<std::string, Router*> IdRouterMap; 00169 IdRouterMap m_toRouters; 00170 IdRouterMap m_fromRouters; 00171 00172 int m_lock; 00173 00174 Atlas::Objects::ObjectsEncoder* m_debugRecvEncoder; 00175 00176 std::vector<Redispatch*> m_finishedRedispatches; 00177 ServerInfo m_info; 00178 00179 std::auto_ptr<ResponseTracker> m_responder; 00180 }; 00181 00183 long getNewSerialno(); 00184 00185 } // of Eris namespace 00186 00187 #endif 00188