00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _ConnectionImpl_
00023 #define _ConnectionImpl_
00024
00025 #include <map>
00026 #include <boost/shared_ptr.hpp>
00027 #include <boost/weak_ptr.hpp>
00028 #include "qpid/framing/FrameHandler.h"
00029 #include "qpid/sys/Mutex.h"
00030 #include "qpid/sys/ShutdownHandler.h"
00031 #include "qpid/sys/TimeoutHandler.h"
00032 #include "ConnectionHandler.h"
00033 #include "Connector.h"
00034
00035 namespace qpid {
00036 namespace client {
00037
00038 class SessionCore;
00039
00040 class ConnectionImpl : public framing::FrameHandler,
00041 public sys::TimeoutHandler,
00042 public sys::ShutdownHandler
00043
00044 {
00045 typedef std::map<uint16_t, boost::weak_ptr<SessionCore> > SessionMap;
00046 typedef std::vector<boost::shared_ptr<SessionCore> > SessionVector;
00047
00048 SessionMap sessions;
00049 ConnectionHandler handler;
00050 boost::shared_ptr<Connector> connector;
00051 framing::ProtocolVersion version;
00052 sys::Mutex lock;
00053 bool isClosed;
00054 bool isClosing;
00055
00056 template <class F> void detachAll(const F&);
00057
00058 SessionVector closeInternal(const sys::Mutex::ScopedLock&);
00059 void incoming(framing::AMQFrame& frame);
00060 void closed(uint16_t, const std::string&);
00061 void idleOut();
00062 void idleIn();
00063 void shutdown();
00064 bool setClosing();
00065
00066 public:
00067 typedef boost::shared_ptr<ConnectionImpl> shared_ptr;
00068
00069 ConnectionImpl(boost::shared_ptr<Connector> c);
00070 ~ConnectionImpl();
00071
00072 void addSession(const boost::shared_ptr<SessionCore>&);
00073
00074 void open(const std::string& host, int port = 5672,
00075 const std::string& uid = "guest",
00076 const std::string& pwd = "guest",
00077 const std::string& virtualhost = "/");
00078 void close();
00079 void handle(framing::AMQFrame& frame);
00080 void erase(uint16_t channel);
00081 boost::shared_ptr<Connector> getConnector() { return connector; }
00082 };
00083
00084 }}
00085
00086
00087 #endif