Apache Qpid C++ API
Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation

qpid/client/Demux.h

Go to the documentation of this file.
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 #include <list>
00023 #include <boost/function.hpp>
00024 #include <boost/shared_ptr.hpp>
00025 #include "qpid/framing/FrameSet.h"
00026 #include "qpid/sys/Mutex.h"
00027 #include "qpid/sys/BlockingQueue.h"
00028 
00029 #ifndef _Demux_
00030 #define _Demux_
00031 
00032 namespace qpid {
00033 namespace client {
00034 
00036 class ByTransferDest
00037 {
00038     const std::string dest;
00039 public:
00040     ByTransferDest(const std::string& dest);
00041     bool operator()(const framing::FrameSet& frameset) const;
00042 };
00043 
00045 class Demux
00046 {
00047 public:
00048     typedef boost::function<bool(const framing::FrameSet&)> Condition;
00049     typedef sys::BlockingQueue<framing::FrameSet::shared_ptr> Queue;
00050     typedef boost::shared_ptr<Queue> QueuePtr;
00051 
00052     Demux();
00053     ~Demux();
00054     
00055     void handle(framing::FrameSet::shared_ptr);
00056     void close(const sys::ExceptionHolder& ex);
00057     void open();
00058 
00059     QueuePtr add(const std::string& name, Condition);
00060     void remove(const std::string& name);
00061     QueuePtr get(const std::string& name);
00062     QueuePtr getDefault();
00063 
00064 private:
00065     struct Record
00066     {
00067         const std::string name;
00068         Condition condition;
00069         QueuePtr queue;
00070 
00071         Record(const std::string& n, Condition c) : name(n), condition(c), queue(new Queue()) {}
00072     };
00073 
00074     sys::Mutex lock;
00075     std::list<Record> records;
00076     QueuePtr defaultQueue;
00077 
00078     typedef std::list<Record>::iterator iterator;
00079 
00080     struct Find
00081     {
00082         const std::string name;
00083         Find(const std::string& name);
00084         bool operator()(const Record& record) const;
00085     };
00086 };
00087 
00088 class ScopedDivert
00089 {
00090     const std::string dest;
00091     Demux& demuxer;
00092     Demux::QueuePtr queue;
00093 public:
00094     ScopedDivert(const std::string& dest, Demux& demuxer);
00095     ~ScopedDivert();
00096     Demux::QueuePtr getQueue();
00097 };
00098 
00099 }} // namespace qpid::client
00100 
00101 
00102 #endif

Qpid C++ API Reference
Generated on Tue Dec 8 15:39:47 2009 for Qpid C++ Client API by doxygen 1.4.7