00001
#ifndef ERIS_CONNECTION_H
00002
#define ERIS_CONNECTION_H
00003
00004
#include <Eris/BaseConnection.h>
00005
#include <Eris/Types.h>
00006
00007
#include <Atlas/Message/DecoderBase.h>
00008
00009
#include <deque>
00010
00014
00015
class basic_socket_stream;
00016
00017
namespace Atlas {
00018
namespace Objects {
00019
class Root;
00020
namespace Operation {
00021
class RootOperation;
00022 }
00023 }
00024 }
00025
00026
namespace Eris
00027 {
00028
00029
00030
class Dispatcher;
00031
class WaitForBase;
00032
class Timeout;
00033
class PollData;
00034
class TypeService;
00035
class Lobby;
00036
00038
00041 class Connection :
00042
public BaseConnection,
00043
public Atlas::Message::DecoderBase
00044 {
00045
public:
00047
00050
Connection(
const std::string &cnm,
bool debug);
00051
00052
virtual ~
Connection();
00053
00054
static Connection* getPrimary();
00056 static Connection*
Instance() {
return getPrimary();}
00057
00061
00064
virtual void connect(
const std::string &host,
short port = 6767);
00065
00067
00071
void reconnect();
00072
00074
void disconnect();
00075
00077
00082
00083
00085 Dispatcher*
getDispatcher()
const
00086
{
return _rootDispatch; }
00087
00088 TypeService* getTypeService()
const
00089
{
return _typeService;}
00090
00091 Lobby* getLobby()
const
00092
{
return _lobby; }
00093
00095
00098 Dispatcher*
getDispatcherByPath(
const std::string &path)
const;
00099
void removeDispatcherByPath(
const std::string &stem,
const std::string &n);
00100
00102
void removeIfDispatcherByPath(
const std::string &stem,
const std::string &n);
00103
00105
00108
virtual void send(
const Atlas::Objects::Root &obj);
00109
00111
00113
virtual void send(
const Atlas::Message::Element &msg);
00114
00119
void lock();
00120
00123
void unlock();
00125
00127 SigC::Signal0<bool>
Disconnecting;
00128
00134 SigC::Signal1<void, const std::string&>
Failure;
00135
00138 SigC::Signal1<void, Status>
Timeout;
00139
00141
00144 SigC::Signal1<void, Status>
StatusChanged;
00145
00146
protected:
00149
virtual void setStatus(Status sc);
00150
00152
00155
virtual void objectArrived(
const Atlas::Message::Element& obj);
00156
00158
virtual void handleFailure(
const std::string &msg);
00159
00160
virtual void bindTimeout(
Eris::Timeout &t, Status sc);
00161
00162
virtual void onConnect();
00163
00165
void postForDispatch(
const Atlas::Message::Element &msg);
00166
00167 Dispatcher*
_rootDispatch;
00168 unsigned int _statusLock;
00169
00170
friend class WaitForBase;
00171
00173
void addWait(WaitForBase *w);
00174
00176
00178 std::string
_host;
00179 short _port;
00180
bool _debug;
00181
00183
static Connection*
_theConnection;
00184
00185
private:
00186
void validateSerial(
const Atlas::Objects::Operation::RootOperation &op);
00187
00190 MessageList _repostQueue;
00191
00192
void clearSignalledWaits();
00193
00194
typedef std::list<WaitForBase*> WaitForList;
00195 WaitForList _waitList;
00196
00197
void gotData(PollData&);
00198
00199 TypeService *_typeService;
00200
Lobby *_lobby;
00201 };
00202
00203 }
00204
00205
#endif
00206