00001 #ifndef _client_Connection_
00002 #define _client_Connection_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <map>
00025 #include <string>
00026 #include "qpid/QpidError.h"
00027 #include "ClientChannel.h"
00028 #include "Connector.h"
00029 #include "qpid/sys/Mutex.h"
00030 #include "qpid/sys/ShutdownHandler.h"
00031 #include "qpid/sys/TimeoutHandler.h"
00032
00033
00034 namespace qpid {
00035
00042 namespace client {
00043
00048 class ConnectionForChannel :
00049 public framing::InputHandler,
00050 public framing::OutputHandler,
00051 public sys::TimeoutHandler,
00052 public sys::ShutdownHandler
00053
00054 {
00055 private:
00056 friend class Channel;
00057 virtual void erase(framing::ChannelId) = 0;
00058 };
00059
00060
00072 class Connection : public ConnectionForChannel
00073 {
00074 typedef std::map<framing::ChannelId, Channel*> ChannelMap;
00075
00076 framing::ChannelId channelIdCounter;
00077 static const std::string OK;
00078
00079 framing::ProtocolVersion version;
00080 const uint32_t max_frame_size;
00081 ChannelMap channels;
00082 Connector defaultConnector;
00083 Connector* connector;
00084 framing::OutputHandler* out;
00085 bool isOpen;
00086 sys::Mutex shutdownLock;
00087 Channel channel0;
00088 bool debug;
00089
00090 void erase(framing::ChannelId);
00091 void channelException(
00092 Channel&, framing::AMQMethodBody*, const QpidError&);
00093 void closeChannels();
00094 bool markClosed();
00095
00096
00097 friend class Channel;
00098
00099 public:
00113 Connection(bool debug = false, uint32_t max_frame_size = 65536,
00114 framing::ProtocolVersion=framing::highestProtocolVersion);
00115 ~Connection();
00116
00134 void open(const std::string& host, int port = 5672,
00135 const std::string& uid = "guest",
00136 const std::string& pwd = "guest",
00137 const std::string& virtualhost = "/");
00138
00145 void close(framing::ReplyCode=200, const std::string& msg=OK,
00146 framing::ClassId = 0, framing::MethodId = 0);
00147
00158 void openChannel(Channel&);
00159
00160
00161
00162 void send(framing::AMQFrame*);
00163 void received(framing::AMQFrame*);
00164 void idleOut();
00165 void idleIn();
00166 void shutdown();
00167
00169 void setConnector(Connector& connector);
00170
00174 inline uint32_t getMaxFrameSize(){ return max_frame_size; }
00175
00177 framing::ProtocolVersion getVersion() const { return version; }
00178 };
00179
00180 }}
00181
00182
00183 #endif