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
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 }}
00100
00101
00102 #endif