Subversion Repositories HomeAutomation

Rev

Rev 1318 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * Subscriber.h
  3.  *
  4.  *  Created on: Apr 25, 2009
  5.  *      Author: Mattias Runge
  6.  */
  7.  
  8. #ifndef SUBSCRIBER_H_
  9. #define SUBSCRIBER_H_
  10.  
  11. #include <iostream>
  12.  
  13. #include <boost/bind.hpp>
  14. #include <boost/signal.hpp>
  15. #include <boost/thread.hpp>
  16. #include <boost/thread/mutex.hpp>
  17. #include <boost/thread/condition.hpp>
  18. #include <boost/thread/locks.hpp>
  19. #include "Broker.h"
  20. #include "message/Message.h"
  21. #include "log/Logger.h"
  22. #include "thread/Thread.h"
  23. #include "thread/Queue.hpp"
  24. #include <boost/make_shared.hpp>
  25.  
  26. namespace atom {
  27. namespace broker {
  28.  
  29. using namespace message;
  30.  
  31. class Subscriber : public boost::signals::trackable, public thread::Thread
  32. {
  33.     typedef boost::mutex::scoped_lock lock;
  34.  
  35. public:
  36.     typedef boost::shared_ptr<Subscriber> pointer;
  37.  
  38.     Subscriber(boost::shared_ptr<Broker> broker, bool receiveFromMyself);
  39.     virtual ~Subscriber();
  40.  
  41. protected:
  42.     boost::shared_ptr<Broker> myBroker;
  43.  
  44.     void put(Message::pointer message);
  45.     virtual void onNewMessage(Message::pointer message);
  46.  
  47. private:
  48.     log::Logger LOG;
  49.     thread::Queue<Message::pointer> myQueue;
  50.     bool myReceiveFromMyself;
  51.     boost::condition myCondition;
  52.     boost::mutex myMutex;
  53.  
  54.     void newMessageHandler(Message::pointer message);
  55.     void run();
  56. };
  57.  
  58. }
  59. }
  60.  
  61. #endif /* SUBSCRIBER_H_ */
  62.