00001 #ifndef ERIS_CONNECTION_H
00002 #define ERIS_CONNECTION_H
00003
00004 #include <deque>
00005 #include <Atlas/Message/DecoderBase.h>
00006 #include <Atlas/Objects/Operation/RootOperation.h>
00007
00008 #include <Eris/BaseConnection.h>
00009 #include <Eris/Types.h>
00010
00014
00015 class basic_socket_stream;
00016
00017 namespace Eris
00018 {
00019
00020
00021 class Dispatcher;
00022 class WaitForBase;
00023 class Timeout;
00024 class PollData;
00025 class TypeInfoEngine;
00026 class Lobby;
00027
00029
00032 class Connection :
00033 public BaseConnection,
00034 public Atlas::Message::DecoderBase
00035 {
00036 public:
00038
00041 Connection(const std::string &cnm, bool debug);
00042
00043 virtual ~Connection();
00044
00045 static Connection* getPrimary();
00047 static Connection* Instance() {return getPrimary();}
00048
00052
00055 virtual void connect(const std::string &host, short port = 6767);
00056
00058
00062 void reconnect();
00063
00065 void disconnect();
00066
00068
00073
00074
00076 Dispatcher* getDispatcher() const
00077 { return _rootDispatch; }
00078
00079 TypeInfoEngine* getTypeInfoEngine() const
00080 { return _ti_engine;}
00081
00082 Lobby* getLobby() const
00083 { return _lobby; }
00084
00086
00089 Dispatcher* getDispatcherByPath(const std::string &path) const;
00090 void removeDispatcherByPath(const std::string &stem, const std::string &n);
00091
00093 void removeIfDispatcherByPath(const std::string &stem, const std::string &n);
00094
00096
00099 virtual void send(const Atlas::Objects::Root &obj);
00100
00102
00104 virtual void send(const Atlas::Message::Object &msg);
00105
00110 void lock();
00111
00114 void unlock();
00116
00118 SigC::Signal0<bool> Disconnecting;
00119
00125 SigC::Signal1<void, const std::string&> Failure;
00126
00129 SigC::Signal1<void, Status> Timeout;
00130
00132
00135 SigC::Signal1<void, Status> StatusChanged;
00136
00137 protected:
00140 virtual void setStatus(Status sc);
00141
00143
00146 virtual void ObjectArrived(const Atlas::Message::Object& obj);
00147
00149 virtual void handleFailure(const std::string &msg);
00150
00151 virtual void bindTimeout(Eris::Timeout &t, Status sc);
00152
00153 virtual void onConnect();
00154
00156 void postForDispatch(const Atlas::Message::Object &msg);
00157
00158 Dispatcher* _rootDispatch;
00159 unsigned int _statusLock;
00160
00161 friend class WaitForBase;
00162
00164 void addWait(WaitForBase *w);
00165
00167
00169 std::string _host;
00170 short _port;
00171 bool _debug;
00172
00174 static Connection* _theConnection;
00175
00176 private:
00177 void validateSerial(const Atlas::Objects::Operation::RootOperation &op);
00178
00181 MessageList _repostQueue;
00182
00183 void clearSignalledWaits();
00184
00185 typedef std::list<WaitForBase*> WaitForList;
00186 WaitForList _waitList;
00187
00188 void gotData(PollData&);
00189
00190 TypeInfoEngine *_ti_engine;
00191 Lobby *_lobby;
00192 };
00193
00194 }
00195
00196 #endif
00197