Ignore:
Timestamp:
Oct 30, 2015, 11:43:20 AM (10 years ago)
Author:
Frederik Heber <heber@…>
Children:
1f96ec
Parents:
e24dde
git-author:
Frederik Heber <heber@…> (07/04/15 22:33:12)
git-committer:
Frederik Heber <heber@…> (10/30/15 11:43:20)
Message:

Extracted all static Observable maps (and mutex) into singleton GlobalObservableInfo.

  • this way we may safely control is destruction, i.e. it is always valid as it boils down to a primitive void pointer which does not need to be destroyed or constructed.
  • Minimized code where mutex is locked.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodePatterns/Observer/Observable.hpp

    re24dde r959c82  
    1818#include <string>
    1919#include <boost/function.hpp>
    20 #include <boost/thread.hpp>
    2120
    2221#include "CodePatterns/Range.hpp"
    2322#include "CodePatterns/Observer/defs.hpp"
     23#include "CodePatterns/Observer/GlobalObservableInfo.hpp"
    2424#include "CodePatterns/Observer/Observer.hpp"
    2525
    2626class Graveyard;
     27class scoped_lock;
    2728
    2829/**
     
    4849  typedef std::vector<size_t> channels_t;
    4950
    50   Observable(std::string _name, const channels_t &_channels = channels_t());
     51  Observable(
     52      std::string _name,
     53      const channels_t &_channels = channels_t());
    5154  virtual ~Observable();
    52 
    53   /** This class is only used to distinguish from size_t in the overload.
    54    *
    55    * It encapsulates a const int (the priority level) and checks valid bounds
    56    * in constructor.
    57    *
    58    */
    59   class PriorityLevel {
    60   public:
    61     explicit PriorityLevel(const int i);
    62     ~PriorityLevel();
    63 
    64     const int level;
    65   private:
    66     static range<int> ValidRange;
    67   };
    6855
    6956private:
     
    9279   * ussually no need to order the update sequence.
    9380   */
    94   virtual void signOn(Observer *target, PriorityLevel priority = PriorityDefault) const;
     81  virtual void signOn(
     82      Observer * target,
     83      GlobalObservableInfo::PriorityLevel priority = GlobalObservableInfo::PriorityDefault) const;
    9584
    9685  /**
     
    10695      Observer *target,
    10796      size_t channelno,
    108       PriorityLevel priority = PriorityDefault) const;
     97      GlobalObservableInfo::PriorityLevel priority =
     98          GlobalObservableInfo::PriorityDefault) const;
    10999
    110100  /**
     
    143133  static void enque_notification_internal(Observable *publisher, Notification_ptr notification);
    144134
     135protected:
     136
    145137  typedef std::map<Observable*, Channels *> ChannelMap;
    146138  static ChannelMap NotificationChannels;
    147 
    148   static PriorityLevel PriorityDefault;
    149 
    150 protected:
    151   typedef std::multimap<int,Observer*> callees_t;
    152   typedef std::set<Notification*> notificationSet;
    153   static std::map<Observable*, int> depth;
    154   static std::map<Observable*,callees_t> callTable;
    155   static std::map<Observable*,notificationSet> notifications;
    156   static std::set<Observable*> busyObservables;
    157 
    158   static boost::recursive_mutex ObservablesMapLock; //!< a lock for the pointer of the instance
    159139
    160140private:
Note: See TracChangeset for help on using the changeset viewer.