• Main Page
  • Related Pages
  • Classes
  • Files
  • File List

src/MessageHub.hh

00001 /*
00002  * This file is part of peekabot.
00003  *
00004  * peekabot is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * peekabot is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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

Generated on Sun Jan 30 2011 for peekabot by  doxygen 1.7.1