Ignore:
Timestamp:
Mar 18, 2013, 6:29:41 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Children:
3f30cc
Parents:
b9273a
git-author:
Frederik Heber <heber@…> (03/18/13 18:22:47)
git-committer:
Frederik Heber <heber@…> (03/18/13 18:29:41)
Message:

Channels and Notifications pass on subjectKilled().

  • if we only sign on to a single notification channel, we miss on subjectKilled() completely. Hence, we have to chance of properly signing off again or, at least, to know that we must not anymore.
  • Hence, Observable's dstor now calls subjectKilled() on its Channels which passes the call on to all its Notifications that in turn use the subjectKilled() slot of their targets along with the passed-through Observable instance.
  • also added observerLog verbosity when signing on/off to channels.
  • explained this in header documentation of Observable, Channels, and Notification.
  • TESTFIX: ObserverUnitTest did not properly signOff() before deleting instances in relayNotificationTest().
Location:
src/CodePatterns/Observer
Files:
3 edited

Legend:

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

    rb9273a r1c291d  
    1818#include "CodePatterns/Observer/defs.hpp"
    1919
     20class Observable;
     21class Relay;
     22
    2023/** Channels aggregate all possible Notifications of an Observable.
    2124 *
     
    2326 * visible to the outside only.
    2427 *
     28 * \note Channels::subjectKilled() needs to be called by owning Observable.
     29 * It is passed on to Notification such that Observer that have only signed
     30 * on to single channel still know when their observable has died.
    2531 */
    2632class Channels {
     
    3844
    3945private:
     46  //! grant Observable access to notifyAll() and subjectKilled()
     47  friend class Observable;
     48  //!> grant Relay access to notifyAll()
     49  friend class Relay;
     50
     51  /** Informs channel subscribers about imminent dstor call.
     52   *
     53   * This is meant to be called from Observable only.
     54   * Channels and Notifications are strictly attached to an Observable. Hence,
     55   * it makes no sense to inform them on their own. Especially, neither has
     56   * any knowledge on the publisher.
     57   *
     58   * \param *publisher Observable about to be destroyed
     59   */
     60  void subjectKilled(Observable * const publisher);
     61
     62private:
    4063  typedef std::map< size_t, Notification_ptr> NotificationTypetoRefMap;
    4164
  • src/CodePatterns/Observer/Notification.hpp

    rb9273a r1c291d  
    1616#include <set>
    1717
     18class Channels;
    1819class Observable;
    1920class Observer;
     
    2627 * with the usual OBSERVE() macro to generate both the specific and
    2728 * the global message of change.
     29 *
     30 * \note Notification::subjectKilled() needs to be called by owning Channels.
     31 * We use the passed on Observable instance to let Observers that have only
     32 * signed on to single channel know when their observable has died.
    2833 */
    2934class Notification {
    30   //!> grant Observable access to notifyAll()
    31   friend class Observable;
    32   //!> grant Relay access to notifyAll()
    33   friend class Relay;
    3435public:
    3536  Notification(size_t _channelno);
     
    4344  void removeObserver(Observer *target);
    4445
     46private:
     47  //!> grant Observable access to notifyAll() and subjectKilled()
     48  friend class Observable;
     49  //!> grant Channels access to notifyAll() and subjectKilled()
     50  friend class Channels;
     51  //!> grant Relay access to notifyAll()
     52  friend class Relay;
     53
    4554  void notifyAll(Observable * const publisher);
     55
     56  /** Informs channel subscribers about dstor call.
     57   *
     58   * This is meant to be called from Observable only.
     59   * Channels and Notifications are strictly attached to an Observable. Hence,
     60   * it makes no sense to inform them on their own. Especially, neither has
     61   * any knowledge on the publisher.
     62   *
     63   * \param *publisher Observable about to be destroyed
     64   */
     65  void subjectKilled(Observable * const publisher);
     66
    4667private:
    47   std::set<Observer*> targets;
     68  typedef std::set<Observer*> targets_t;
     69  targets_t targets;
    4870  const size_t channelno;
    4971};
  • src/CodePatterns/Observer/Observable.hpp

    rb9273a r1c291d  
    3030 * to avoid memory issues when many observable are around but only few
    3131 * are actually observed.
     32 *
     33 * \note We have to clean our Channels from static NotificationChannels and
     34 * we call Channels::subjectKilled() to let Observers that have only signed
     35 * on to single channel still know when their observable has died.
    3236 */
    3337class Observable : public Observer {
Note: See TracChangeset for help on using the changeset viewer.