00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }}
00098
00099
00100 #endif