| Last change
 on this file since 3324cf was             d85532, checked in by Frederik Heber <heber@…>, 14 years ago | 
        
          | 
Added unit test on Relay.
 added new stubs to ObserverStub implementing Relay.
Relay is friend of Notification.
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.1 KB | 
      
      
| Rev | Line |  | 
|---|
| [e2e035e] | 1 | /* | 
|---|
|  | 2 | * Notification.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Dec 1, 2011 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef NOTIFICATION_HPP_ | 
|---|
|  | 9 | #define NOTIFICATION_HPP_ | 
|---|
|  | 10 |  | 
|---|
|  | 11 | // include config.h | 
|---|
|  | 12 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 13 | #include <config.h> | 
|---|
|  | 14 | #endif | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #include <set> | 
|---|
|  | 17 |  | 
|---|
|  | 18 | class Observable; | 
|---|
|  | 19 | class Observer; | 
|---|
| [d85532] | 20 | class Relay; | 
|---|
| [e2e035e] | 21 |  | 
|---|
|  | 22 | /** Notifications are sort of news channels of an Observable. | 
|---|
|  | 23 | * Via the NOTIFY() macro updates can be transmitted in a specific channel. | 
|---|
|  | 24 | * Observers can subscribe to Notification in much the same way as they can to | 
|---|
|  | 25 | * the Observable itself. Usually, Notifications are used along | 
|---|
|  | 26 | * with the usual OBSERVE() macro to generate both the specific and | 
|---|
|  | 27 | * the global message of change. | 
|---|
|  | 28 | */ | 
|---|
|  | 29 | class Notification { | 
|---|
| [d85532] | 30 | //!> grant Observable access to notifyAll() | 
|---|
| [e2e035e] | 31 | friend class Observable; | 
|---|
| [d85532] | 32 | //!> grant Relay access to notifyAll() | 
|---|
|  | 33 | friend class Relay; | 
|---|
| [e2e035e] | 34 | public: | 
|---|
|  | 35 | Notification(size_t _channelno); | 
|---|
|  | 36 | virtual ~Notification(); | 
|---|
|  | 37 |  | 
|---|
|  | 38 | size_t getChannelNo() const { return channelno; } | 
|---|
|  | 39 |  | 
|---|
|  | 40 | protected: | 
|---|
|  | 41 |  | 
|---|
|  | 42 | void addObserver(Observer *target); | 
|---|
|  | 43 | void removeObserver(Observer *target); | 
|---|
|  | 44 |  | 
|---|
|  | 45 | void notifyAll(Observable * const publisher); | 
|---|
|  | 46 | private: | 
|---|
|  | 47 | std::set<Observer*> targets; | 
|---|
|  | 48 | const size_t channelno; | 
|---|
|  | 49 | }; | 
|---|
|  | 50 |  | 
|---|
|  | 51 |  | 
|---|
|  | 52 |  | 
|---|
|  | 53 | #endif /* NOTIFICATION_HPP_ */ | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.