00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __PEEKABOT_MESSAGE_HUB_HH
00019 #define __PEEKABOT_MESSAGE_HUB_HH
00020
00021
00022 #include <map>
00023 #include <set>
00024 #include <string>
00025 #include <boost/thread/recursive_mutex.hpp>
00026
00027 #include "Types.hh"
00028 #include "Singleton.hh"
00029
00030 namespace peekabot
00031 {
00032
00039 enum MessageType
00040 {
00045 CLIENT_MESSAGE = 0,
00046
00053 INFO_MESSAGE = 1,
00054
00063 WARNING_MESSAGE = 2,
00064
00068 ERROR_MESSAGE = 3,
00069
00073 DEBUG_MESSAGE = 4,
00074
00081 LOG_MESSAGE = 5
00082 };
00083
00084
00085 class Subscriber;
00086 class Message;
00087
00088
00100 class MessageHub
00101 {
00106 typedef std::set<Subscriber *> SubscriberSet;
00107
00112 typedef std::map<MessageType, SubscriberSet> SubscriberMap;
00113
00121 SubscriberMap m_subscribers;
00122
00127 mutable boost::recursive_mutex m_mutex;
00128
00129 public:
00130 ~MessageHub();
00131
00149 void publish(
00150 MessageType type,
00151 const std::string &msg, ...) const throw();
00152
00166 void publish(
00167 MessageType type, SourceID source,
00168 const std::string &msg, ...) const throw();
00169
00179 void subscribe(MessageType type, Subscriber *recipient) throw();
00180
00186 void subscribe(Subscriber *recipient) throw();
00187
00197 void unsubscribe(MessageType type, Subscriber *recipient) throw();
00198
00199 protected:
00205 void publish(const Message &message) const throw();
00206 };
00207
00208
00209
00214 typedef Singleton<MessageHub> TheMessageHub;
00215
00216
00217 }
00218
00219
00220 #endif // __PEEKABOT_MESSAGE_HUB_HH