Rev 1319 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1309 | runge | 1 | /* |
| 2 | * Subscriber.h |
||
| 3 | * |
||
| 4 | * Created on: Apr 25, 2009 |
||
| 5 | * Author: Mattias Runge |
||
| 6 | */ |
||
| 7 | |||
| 1318 | runge | 8 | #ifndef SUBSCRIBER_H_ |
| 9 | #define SUBSCRIBER_H_ |
||
| 1309 | runge | 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> |
||
| 1311 | runge | 19 | #include "message/Message.h" |
| 1315 | runge | 20 | #include "log/Logger.h" |
| 1317 | runge | 21 | #include "thread/Thread.h" |
| 1318 | runge | 22 | #include "thread/Queue.hpp" |
| 1309 | runge | 23 | #include <boost/make_shared.hpp> |
| 24 | |||
| 25 | namespace atom { |
||
| 26 | |||
| 1311 | runge | 27 | using namespace message; |
| 1309 | runge | 28 | |
| 1317 | runge | 29 | class Subscriber : public boost::signals::trackable, public thread::Thread |
| 1309 | runge | 30 | { |
| 31 | public: |
||
| 1403 | runge | 32 | typedef boost::shared_ptr<Subscriber> Pointer; |
| 1309 | runge | 33 | |
| 1403 | runge | 34 | Subscriber(bool receive_from_self); |
| 1309 | runge | 35 | virtual ~Subscriber(); |
| 36 | |||
| 37 | protected: |
||
| 1403 | runge | 38 | void PutMessage(Message::pointer message); |
| 39 | Message::pointer CreateMessage() const; |
||
| 1309 | runge | 40 | |
| 1403 | runge | 41 | virtual void OnMessage(Message::pointer message) = 0; |
| 1309 | runge | 42 | |
| 43 | private: |
||
| 1315 | runge | 44 | log::Logger LOG; |
| 1309 | runge | 45 | |
| 1403 | runge | 46 | thread::Queue<Message::pointer> queue_; |
| 47 | bool receive_from_self_; |
||
| 48 | |||
| 49 | boost::condition on_message_condition_; |
||
| 50 | boost::mutex guard_mutex_; |
||
| 51 | |||
| 52 | void Slot_OnMessage(Message::pointer message); |
||
| 53 | |||
| 54 | void Run(); |
||
| 1309 | runge | 55 | }; |
| 56 | |||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 1318 | runge | 60 | #endif /* SUBSCRIBER_H_ */ |