/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/client/Demux.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 #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 
00035 class ByTransferDest
00036 {
00037     const std::string dest;
00038 public:
00039     ByTransferDest(const std::string& dest);
00040     bool operator()(const framing::FrameSet& frameset) const;
00041 };
00042 
00043 class Demux
00044 {
00045 public:
00046     typedef boost::function<bool(const framing::FrameSet&)> Condition;
00047     typedef sys::BlockingQueue<framing::FrameSet::shared_ptr> Queue;
00048     typedef boost::shared_ptr<Queue> QueuePtr;
00049 
00050     Demux();
00051     ~Demux();
00052     
00053     void handle(framing::FrameSet::shared_ptr);
00054     void close();
00055     void open();
00056 
00057     QueuePtr add(const std::string& name, Condition);
00058     void remove(const std::string& name);
00059     QueuePtr get(const std::string& name);
00060     QueuePtr getDefault();
00061 
00062 private:
00063     struct Record
00064     {
00065         const std::string name;
00066         Condition condition;
00067         QueuePtr queue;
00068 
00069         Record(const std::string& n, Condition c) : name(n), condition(c), queue(new Queue()) {}
00070     };
00071 
00072     sys::Mutex lock;
00073     std::list<Record> records;
00074     QueuePtr defaultQueue;
00075 
00076     typedef std::list<Record>::iterator iterator;
00077 
00078     struct Find
00079     {
00080         const std::string name;
00081         Find(const std::string& name);
00082         bool operator()(const Record& record) const;
00083     };
00084 };
00085 
00086 class ScopedDivert
00087 {
00088     const std::string dest;
00089     Demux& demuxer;
00090     Demux::QueuePtr queue;
00091 public:
00092     ScopedDivert(const std::string& dest, Demux& demuxer);
00093     ~ScopedDivert();
00094     Demux::QueuePtr getQueue();
00095 };
00096 
00097 }} // namespace qpid::client
00098 
00099 
00100 #endif

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