| 
            Last change
 on this file since 7d0820 was             1c291d, checked in by Frederik Heber <heber@…>, 13 years ago           | 
        
        
          | 
             
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().
  
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.6 KB
           | 
        
      
      
| Rev | Line |   | 
|---|
| [e2e035e] | 1 | /*
 | 
|---|
 | 2 |  * Channels.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Dec 1, 2011
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef CHANNELS_HPP_
 | 
|---|
 | 9 | #define CHANNELS_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include <map>
 | 
|---|
 | 17 | 
 | 
|---|
| [9b8fa4] | 18 | #include "CodePatterns/Observer/defs.hpp"
 | 
|---|
| [e2e035e] | 19 | 
 | 
|---|
| [1c291d] | 20 | class Observable;
 | 
|---|
 | 21 | class Relay;
 | 
|---|
 | 22 | 
 | 
|---|
| [e2e035e] | 23 | /** Channels aggregate all possible Notifications of an Observable.
 | 
|---|
 | 24 |  *
 | 
|---|
 | 25 |  * Usually, one implements an enumeration of the channel number which is
 | 
|---|
 | 26 |  * visible to the outside only.
 | 
|---|
 | 27 |  *
 | 
|---|
| [1c291d] | 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.
 | 
|---|
| [e2e035e] | 31 |  */
 | 
|---|
 | 32 | class Channels {
 | 
|---|
 | 33 | public:
 | 
|---|
 | 34 |   Channels();
 | 
|---|
 | 35 |   virtual ~Channels();
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 |   void addChannel(size_t no);
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 |   Notification_ptr getChannel(size_t no) const;
 | 
|---|
 | 40 |   size_t getType(Notification_ptr channel) const;
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | protected:
 | 
|---|
 | 43 |   void removeChannel(size_t no);
 | 
|---|
 | 44 | 
 | 
|---|
| [1c291d] | 45 | private:
 | 
|---|
 | 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 | 
 | 
|---|
| [e2e035e] | 62 | private:
 | 
|---|
 | 63 |   typedef std::map< size_t, Notification_ptr> NotificationTypetoRefMap;
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |   NotificationTypetoRefMap ChannelMap;
 | 
|---|
 | 66 | };
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 | #endif /* CHANNELS_HPP_ */
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.