| [e2e035e] | 1 | /*
 | 
|---|
 | 2 |  * Relay.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Dec 1, 2011
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef RELAY_HPP_
 | 
|---|
 | 9 | #define RELAY_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
| [9b8fa4] | 16 | #include "CodePatterns/Observer/Observable.hpp"
 | 
|---|
| [e2e035e] | 17 | 
 | 
|---|
 | 18 | /**
 | 
|---|
| [d85532] | 19 |  * A Relay acts as a node in a many-to-one observation.
 | 
|---|
| [e2e035e] | 20 |  *
 | 
|---|
 | 21 |  * All Observable::update() calls will pass through this relay. Hence, if an
 | 
|---|
 | 22 |  * instance desires to observe all atoms and be notified of each single change,
 | 
|---|
 | 23 |  * he would otherwise be forced to not only Observable:signon() to each and
 | 
|---|
 | 24 |  * every one of them but also to keep track of all newly created ones.
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  * Instead he simply uses Relay::signOn() of the specific Relay he wishes
 | 
|---|
 | 27 |  * to use (note Relay should are singleton of nature but are not required to
 | 
|---|
 | 28 |  * inherit the Singleton pattern) and will get notified as if he were
 | 
|---|
 | 29 |  * signOn()'ed to each atom because Observer::update() will get passed through
 | 
|---|
 | 30 |  * the Relay. I.e. the given reference to the Observer points to the atom that
 | 
|---|
 | 31 |  * initiated the update() call and not to the Relay.
 | 
|---|
 | 32 |  */
 | 
|---|
 | 33 | class Relay : public Observable {
 | 
|---|
 | 34 | public:
 | 
|---|
 | 35 |   Relay(std::string _name);
 | 
|---|
 | 36 |   virtual ~Relay();
 | 
|---|
 | 37 | 
 | 
|---|
| [b760ac5] | 38 |   virtual void signOn(Observer *target, PriorityLevel priority = Observable::PriorityDefault) const;
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 |   virtual void signOff(Observer *target) const;
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 |   virtual void signOn(Observer *target, size_t channelno) const;
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 |   virtual void signOff(Observer *target, size_t channelno) const;
 | 
|---|
| [e2e035e] | 45 | 
 | 
|---|
 | 46 | protected:
 | 
|---|
 | 47 |   virtual void update(Observable *publisher);
 | 
|---|
| [b760ac5] | 48 |   virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
 | 
|---|
| [e2e035e] | 49 |   virtual void subjectKilled(Observable *publisher);
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 |   virtual void notifyAll();
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | private:
 | 
|---|
 | 54 |   //!> Current peer that called last update on us, to be passed on to Observers
 | 
|---|
 | 55 |   Observable *Updater;
 | 
|---|
 | 56 | };
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | #endif /* RELAY_HPP_ */
 | 
|---|