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

00001 #ifndef _client_Connection_
00002 #define _client_Connection_
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
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     // TODO aconway 2007-01-26: too many friendships, untagle these classes.
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     // TODO aconway 2007-01-26: can these be private?
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 }} // namespace qpid::client
00181 
00182 
00183 #endif

Generated on Tue Apr 17 14:22:03 2007 for Qpid by  doxygen 1.4.7