Eris  1.3.19
Connection.h
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 #include <Atlas/Objects/RootOperation.h>
00010 
00011 #include <deque>
00012 #include <map>
00013 #include <memory>
00014 
00018 // Forward declaration of the skstream type
00019 class basic_socket_stream;
00020 
00021 namespace Eris
00022 {
00023 
00024 // Forward declarations
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     friend class Redispatch;
00148     friend class TestInjector;
00149 
00152     void postForDispatch(const Atlas::Objects::Root& obj);
00153 
00154     void cleanupRedispatch(Redispatch* r);
00155 
00156     void gotData(PollData&);
00157 
00158     void dispatchOp(const Atlas::Objects::Operation::RootOperation& op);
00159     void handleServerInfo(const Atlas::Objects::Operation::RootOperation& op);
00160 
00161     void onDisconnectTimeout();
00162 
00163     typedef std::deque<Atlas::Objects::Operation::RootOperation> OpDeque;
00164     OpDeque m_opDeque; 
00165 
00166     std::auto_ptr<TypeService> m_typeService;
00167     Router* m_defaultRouter; // need several of these?
00168 
00169     typedef std::map<std::string, Router*> IdRouterMap;
00170     IdRouterMap m_toRouters;
00171     IdRouterMap m_fromRouters;
00172 
00173     int m_lock;
00174 
00175     Atlas::Objects::ObjectsEncoder* m_debugRecvEncoder;
00176 
00177     std::vector<Redispatch*> m_finishedRedispatches;
00178     ServerInfo m_info;
00179 
00180     std::auto_ptr<ResponseTracker> m_responder;
00181 };
00182 
00184 long getNewSerialno();
00185 
00186 } // of Eris namespace
00187 
00188 #endif
00189