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 static u_int16_t channelIdCounter;
00072
00073 std::string host;
00074 int port;
00075 const u_int32_t max_frame_size;
00076 std::map<int, Channel*> channels;
00077 Connector* connector;
00078 qpid::framing::OutputHandler* out;
00079 ResponseHandler responses;
00080 volatile bool closed;
00081 qpid::framing::ProtocolVersion version;
00082
00083 void channelException(Channel* channel, qpid::framing::AMQMethodBody* body, QpidError& e);
00084 void error(int code, const std::string& msg, int classid = 0, int methodid = 0);
00085 void closeChannel(Channel* channel, u_int16_t code, std::string& text, u_int16_t classId = 0, u_int16_t methodId = 0);
00086 void sendAndReceive(qpid::framing::AMQFrame* frame, const qpid::framing::AMQMethodBody& body);
00087
00088 virtual void handleMethod(qpid::framing::AMQMethodBody::shared_ptr body);
00089 virtual void handleHeader(qpid::framing::AMQHeaderBody::shared_ptr body);
00090 virtual void handleContent(qpid::framing::AMQContentBody::shared_ptr body);
00091 virtual void handleHeartbeat(qpid::framing::AMQHeartbeatBody::shared_ptr body);
00092
00093 public:
00107 Connection( bool debug = false, u_int32_t max_frame_size = 65536,
00108 qpid::framing::ProtocolVersion* _version = &(qpid::framing::highestProtocolVersion));
00109 ~Connection();
00110
00128 void open(const std::string& host, int port = 5672,
00129 const std::string& uid = "guest", const std::string& pwd = "guest",
00130 const std::string& virtualhost = "/");
00135 void close();
00144 void openChannel(Channel* channel);
00145
00146
00147
00148
00149
00150
00151 void closeChannel(Channel* channel);
00152
00153
00154
00155
00156
00157
00158
00159 void removeChannel(Channel* channel);
00160
00161 virtual void received(qpid::framing::AMQFrame* frame);
00162
00163 virtual void idleOut();
00164 virtual void idleIn();
00165
00166 virtual void shutdown();
00167
00171 inline u_int32_t getMaxFrameSize(){ return max_frame_size; }
00172 };
00173
00174 }
00175 }
00176
00177
00178 #endif