/* * Relay.hpp * * Created on: Dec 1, 2011 * Author: heber */ #ifndef RELAY_HPP_ #define RELAY_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Observer/Observable.hpp" /** * A Relay acts as a node in a many-to-one observation. * * All Observable::update() calls will pass through this relay. Hence, if an * instance desires to observe all atoms and be notified of each single change, * he would otherwise be forced to not only Observable:signon() to each and * every one of them but also to keep track of all newly created ones. * * Instead he simply uses Relay::signOn() of the specific Relay he wishes * to use (note Relay should are singleton of nature but are not required to * inherit the Singleton pattern) and will get notified as if he were * signOn()'ed to each atom because Observer::update() will get passed through * the Relay. I.e. the given reference to the Observer points to the atom that * initiated the update() call and not to the Relay. */ class Relay : public Observable { public: Relay(std::string _name); virtual ~Relay(); virtual void signOn(Observer *target, PriorityLevel priority = Observable::PriorityDefault) const; virtual void signOff(Observer *target) const; virtual void signOn(Observer *target, size_t channelno, PriorityLevel priority = Observable::PriorityDefault) const; virtual void signOff(Observer *target, size_t channelno) const; protected: virtual void update(Observable *publisher); virtual void recieveNotification(Observable *publisher, Notification_ptr notification); virtual void subjectKilled(Observable *publisher); virtual void notifyAll(); private: //!> Current peer that called last update on us, to be passed on to Observers Observable *Updater; }; #endif /* RELAY_HPP_ */