/* * Notification.hpp * * Created on: Dec 1, 2011 * Author: heber */ #ifndef NOTIFICATION_HPP_ #define NOTIFICATION_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include class Channels; class Observable; class Observer; class Relay; /** Notifications are sort of news channels of an Observable. * Via the NOTIFY() macro updates can be transmitted in a specific channel. * Observers can subscribe to Notification in much the same way as they can to * the Observable itself. Usually, Notifications are used along * with the usual OBSERVE() macro to generate both the specific and * the global message of change. * * \note Notification::subjectKilled() needs to be called by owning Channels. * We use the passed on Observable instance to let Observers that have only * signed on to single channel know when their observable has died. */ class Notification { public: Notification(size_t _channelno); virtual ~Notification(); size_t getChannelNo() const { return channelno; } protected: void addObserver(Observer *target); void removeObserver(Observer *target); private: //!> grant Observable access to notifyAll() and subjectKilled() friend class Observable; //!> grant Channels access to notifyAll() and subjectKilled() friend class Channels; //!> grant Relay access to notifyAll() friend class Relay; void notifyAll(Observable * const publisher); /** Informs channel subscribers about dstor call. * * This is meant to be called from Observable only. * Channels and Notifications are strictly attached to an Observable. Hence, * it makes no sense to inform them on their own. Especially, neither has * any knowledge on the publisher. * * \param *publisher Observable about to be destroyed */ void subjectKilled(Observable * const publisher); /** Getter for the number of Observer for this notification (channel). * * \return number of added observers */ size_t getNumberOfObservers() const { return targets.size(); } private: typedef std::set targets_t; targets_t targets; const size_t channelno; }; #endif /* NOTIFICATION_HPP_ */