/home/aconway/svn/qpid/cpp/lib/client/Connection.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
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          * Requests that the server close this channel, then removes
00147          * the association to the channel from this connection
00148          *
00149          * @param channel a pointer to the channel instance to close
00150          */
00151         void closeChannel(Channel* channel);
00152         /*
00153          * Removes the channel from association with this connection,
00154          * without sending a close request to the server.
00155          *
00156          * @param channel a pointer to the channel instance to
00157          * disassociate
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

Generated on Thu Jan 25 11:48:13 2007 for Qpid by  doxygen 1.5.1