00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <map>
00022 #include <string>
00023
00024 #ifndef _Connection_
00025 #define _Connection_
00026
00027 #include <QpidError.h>
00028 #include <Connector.h>
00029 #include <sys/ShutdownHandler.h>
00030 #include <sys/TimeoutHandler.h>
00031
00032 #include <framing/amqp_framing.h>
00033 #include <ClientExchange.h>
00034 #include <IncomingMessage.h>
00035 #include <ClientMessage.h>
00036 #include <MessageListener.h>
00037 #include <ClientQueue.h>
00038 #include <ResponseHandler.h>
00039 #include <AMQP_HighestVersion.h>
00040
00041 namespace qpid {
00042
00049 namespace client {
00050
00051 class Channel;
00052
00064 class Connection : public virtual qpid::framing::InputHandler,
00065 public virtual qpid::sys::TimeoutHandler,
00066 public virtual qpid::sys::ShutdownHandler,
00067 private virtual qpid::framing::BodyHandler{
00068
00069 typedef std::map<int, Channel*>::iterator iterator;
00070
00071 const bool debug;
00072 u_int16_t channelIdCounter;
00073
00074 std::string host;
00075 int port;
00076 const u_int32_t max_frame_size;
00077 std::map<int, Channel*> channels;
00078 Connector* connector;
00079 qpid::framing::OutputHandler* out;
00080 ResponseHandler responses;
00081 volatile bool closed;
00082 qpid::framing::ProtocolVersion version;
00083 bool tcpNoDelay;
00084
00085 void channelException(Channel* channel, qpid::framing::AMQMethodBody* body, QpidError& e);
00086 void error(int code, const std::string& msg, int classid = 0, int methodid = 0);
00087 void closeChannel(Channel* channel, u_int16_t code, std::string& text, u_int16_t classId = 0, u_int16_t methodId = 0);
00088 void sendAndReceive(qpid::framing::AMQFrame* frame, const qpid::framing::AMQMethodBody& body);
00089
00090 virtual void handleMethod(qpid::framing::AMQMethodBody::shared_ptr body);
00091 virtual void handleHeader(qpid::framing::AMQHeaderBody::shared_ptr body);
00092 virtual void handleContent(qpid::framing::AMQContentBody::shared_ptr body);
00093 virtual void handleHeartbeat(qpid::framing::AMQHeartbeatBody::shared_ptr body);
00094
00095 public:
00109 Connection( bool debug = false, u_int32_t max_frame_size = 65536,
00110 qpid::framing::ProtocolVersion* _version = &(qpid::framing::highestProtocolVersion));
00111 ~Connection();
00112
00113 void setTcpNoDelay(bool on);
00114
00132 void open(const std::string& host, int port = 5672,
00133 const std::string& uid = "guest", const std::string& pwd = "guest",
00134 const std::string& virtualhost = "");
00139 void close();
00148 void openChannel(Channel* channel);
00149
00150
00151
00152
00153
00154
00155 void closeChannel(Channel* channel);
00156
00157
00158
00159
00160
00161
00162
00163 void removeChannel(Channel* channel);
00164
00165 virtual void received(qpid::framing::AMQFrame* frame);
00166
00167 virtual void idleOut();
00168 virtual void idleIn();
00169
00170 virtual void shutdown();
00171
00175 inline u_int32_t getMaxFrameSize(){ return max_frame_size; }
00176 };
00177
00178 }
00179 }
00180
00181
00182 #endif