/opt/workspace/qpid/tags/M2/Final/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         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          * Requests that the server close this channel, then removes
00151          * the association to the channel from this connection
00152          *
00153          * @param channel a pointer to the channel instance to close
00154          */
00155         void closeChannel(Channel* channel);
00156         /*
00157          * Removes the channel from association with this connection,
00158          * without sending a close request to the server.
00159          *
00160          * @param channel a pointer to the channel instance to
00161          * disassociate
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

Generated on Mon Nov 26 19:13:17 2007 for Qpid by  doxygen 1.5.1