/* * GlobalObservableInfo.hpp * * Created on: Jul 4, 2015 * Author: heber */ #ifndef GLOBALOBSERVABLEINFO_HPP_ #define GLOBALOBSERVABLEINFO_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "CodePatterns/Range.hpp" #include "CodePatterns/Singleton.hpp" #include class Channels; class Observable; class Observer; class Notification; /** This class contains all global maps storing information about observers * and which is signed on to which Observable. * * All infrastructure for the observer-pattern is bundled at a central place * this is more efficient if many objects can be observed (inherit from observable) * but only few are actually coupled with observers. E.g. TMV has over 500.000 Atoms, * which might become observable. Handling Observable infrastructure in each of * these would use memory for each atom. By handling Observer-infrastructure * here we only need memory for objects that actually are observed. * See [Gamma et al, 1995] p. 297 * * We have transfered this information into a single singleton as we need to * control the time when the information is destroyed. Objects in here must * remain valid and accessible till the very last Observable in some other * module (i.e. not in this library) is destroyed. */ class GlobalObservableInfo : public Singleton { //!> singleton pattern is friend to access private cstor friend class Singleton; private: /** Private cstor for GlobalObservableInfo. * * Must be private as is singleton. * */ GlobalObservableInfo(); /** Dstor for GlobalObservableInfo. * */ ~GlobalObservableInfo(); public: /** This class is only used to distinguish from size_t in the overload. * * It encapsulates a const int (the priority level) and checks valid bounds * in constructor. * */ class PriorityLevel { public: /** Constructor of PriorityLevel. * * \note We check whether the level is within Observable::PriorityLevel::ValidRange. * * @param i priority level encapsulated in this class. */ explicit PriorityLevel(const int i); ~PriorityLevel(); const int level; private: friend class GlobalObservableInfo; static range ValidRange; }; public: boost::recursive_mutex& getObservablesMapMutex() { return ObservablesMapLock; } typedef std::multimap callees_t; typedef std::set notificationSet; std::map& getdepth() { return depth; } typedef std::map calltable_t; calltable_t& getcallTable() { return callTable; } std::map >& getnotifications() { return notifications; } std::set& getbusyObservables() { return busyObservables; } const range& getValidRange() { return PriorityLevel::ValidRange; } static const PriorityLevel PriorityDefault; private: std::map depth; std::map callTable; std::map notifications; std::set busyObservables; boost::recursive_mutex ObservablesMapLock; //!< a lock for the pointer of the instance }; #endif /* GLOBALOBSERVABLEINFO_HPP_ */