00001 #ifndef _IncomingMessage_
00002 #define _IncomingMessage_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qpid/sys/Monitor.h"
00025 #include <map>
00026 #include <queue>
00027 #include <vector>
00028 #include <boost/variant.hpp>
00029
00030 namespace qpid {
00031 namespace client {
00032
00033 class Message;
00034
00044 class IncomingMessage {
00045 public:
00047 struct Reference {
00048 std::string data;
00049 std::vector<Message> messages;
00050 };
00051
00053 class Destination {
00054 public:
00055 virtual ~Destination();
00056
00058 virtual void message(const Message&) = 0;
00059
00061 virtual void empty() = 0;
00062 };
00063
00064
00066 class WaitableDestination : public Destination
00067 {
00068 public:
00069 WaitableDestination();
00070 void message(const Message& msg);
00071 void empty();
00073 bool wait(Message& msgOut);
00074 void shutdown();
00075
00076 private:
00077 struct Empty {};
00078 typedef boost::variant<Message,Empty> Item;
00079 sys::Monitor monitor;
00080 std::queue<Item> queue;
00081 bool shutdownFlag;
00082 };
00083
00084
00085
00087 void openReference(const std::string& name);
00088
00090 void appendReference(const std::string& name,
00091 const std::string& data);
00092
00096 Message& createMessage(const std::string& destination,
00097 const std::string& reference);
00098
00102 Reference& getReference(const std::string& name);
00103
00107 void closeReference(const std::string& name);
00108
00113 void addDestination(std::string name, Destination&);
00114
00116 void removeDestination(std::string name);
00117
00119 Destination& getDestination(const std::string& name);
00120 private:
00121
00122 typedef std::map<std::string, Reference> ReferenceMap;
00123 typedef std::map<std::string, Destination*> DestinationMap;
00124
00125 Reference& getRefUnlocked(const std::string& name);
00126 Destination& getDestUnlocked(const std::string& name);
00127
00128 mutable sys::Mutex lock;
00129 ReferenceMap references;
00130 DestinationMap destinations;
00131 };
00132
00133 }}
00134
00135
00136 #endif