Connection.h

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 
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 private:
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 

Generated on Mon Jan 29 21:53:03 2007 for Eris by  doxygen 1.5.1