/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/client/ConnectionImpl.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 
00022 #ifndef _ConnectionImpl_
00023 #define _ConnectionImpl_
00024 
00025 #include <map>
00026 #include <boost/shared_ptr.hpp>
00027 #include <boost/weak_ptr.hpp>
00028 #include "qpid/framing/FrameHandler.h"
00029 #include "qpid/sys/Mutex.h"
00030 #include "qpid/sys/ShutdownHandler.h"
00031 #include "qpid/sys/TimeoutHandler.h"
00032 #include "ConnectionHandler.h"
00033 #include "Connector.h"
00034 
00035 namespace qpid {
00036 namespace client {
00037 
00038 class SessionCore;
00039 
00040 class ConnectionImpl : public framing::FrameHandler,
00041                        public sys::TimeoutHandler, 
00042                        public sys::ShutdownHandler
00043 
00044 {
00045     typedef std::map<uint16_t, boost::weak_ptr<SessionCore> > SessionMap;
00046     typedef std::vector<boost::shared_ptr<SessionCore> > SessionVector;
00047 
00048     SessionMap sessions; 
00049     ConnectionHandler handler;
00050     boost::shared_ptr<Connector> connector;
00051     framing::ProtocolVersion version;
00052     sys::Mutex lock;
00053     bool isClosed;
00054     bool isClosing;
00055 
00056     template <class F> void detachAll(const F&);
00057 
00058     SessionVector closeInternal(const sys::Mutex::ScopedLock&);
00059     void incoming(framing::AMQFrame& frame);    
00060     void closed(uint16_t, const std::string&);
00061     void idleOut();
00062     void idleIn();
00063     void shutdown();
00064     bool setClosing();
00065 
00066   public:
00067     typedef boost::shared_ptr<ConnectionImpl> shared_ptr;
00068 
00069     ConnectionImpl(boost::shared_ptr<Connector> c);
00070     ~ConnectionImpl();
00071     
00072     void addSession(const boost::shared_ptr<SessionCore>&);
00073         
00074     void open(const std::string& host, int port = 5672, 
00075               const std::string& uid = "guest",
00076               const std::string& pwd = "guest", 
00077               const std::string& virtualhost = "/");
00078     void close();
00079     void handle(framing::AMQFrame& frame);
00080     void erase(uint16_t channel);
00081     boost::shared_ptr<Connector> getConnector() { return connector; }
00082 };
00083 
00084 }}
00085 
00086 
00087 #endif

Generated on Thu Apr 10 11:08:17 2008 for Qpid by  doxygen 1.4.7