Changeset d85532 for src/Patterns/Observer/Relay.cpp
- Timestamp:
- Dec 13, 2011, 12:00:30 PM (14 years ago)
- Children:
- b760ac5
- Parents:
- 2c11c1
- git-author:
- Frederik Heber <heber@…> (12/02/11 10:10:17)
- git-committer:
- Frederik Heber <heber@…> (12/13/11 12:00:30)
- File:
-
- 1 edited
-
src/Patterns/Observer/Relay.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer/Relay.cpp
r2c11c1 rd85532 22 22 #include "Relay.hpp" 23 23 24 #include "Assert.hpp" 25 #include "Channels.hpp" 26 #include "defs.hpp" 27 #include "Notification.hpp" 28 24 29 25 30 /** Constructor for class Relay. 26 31 */ 27 Relay::Relay(string name) : 28 Observer(Observer::BaseConstructor()) 32 Relay::Relay(std::string name) : 33 Observable(name), 34 Updater(NULL) 29 35 { 30 36 #ifdef LOG_OBSERVER … … 42 48 observerLog().addMessage() << "-- Destroying Relay " << observerLog().getName(this); 43 49 #endif 44 if(callTable.count(this)) {45 // delete all entries for this observable46 callees_t callees = callTable[this];47 callees_t::iterator iter;48 for(iter=callees.begin();iter!=callees.end();++iter){49 (*iter).second->subjectKilled(this);50 }51 callTable.erase(this);52 }53 50 } 54 51 55 52 56 53 /** Notify all Observers of changes. 57 * Puts \a *this into Relay::busy Relays, calls Observer::update() for all in callee_t54 * Puts \a *this into Relay::busyObservables, calls Observer::update() for all in callee_t 58 55 * and removes from busy list. 59 56 */ 60 57 void Relay::notifyAll() { 58 ASSERT(Updater != NULL, 59 "Relay::notifyAll() called while Updater is NULL."); 61 60 // we are busy notifying others right now 62 61 // add ourselves to the list of busy subjects to enable circle detection 63 busy Relays.insert(this);62 busyObservables.insert(this); 64 63 // see if anyone has signed up for observation 65 64 // and call all observers … … 86 85 // send out all notifications that need to be done 87 86 88 notificationSet currentNotifications = notifications[ this];87 notificationSet currentNotifications = notifications[Updater]; 89 88 for(notificationSet::iterator it = currentNotifications.begin(); 90 89 it != currentNotifications.end();++it){ 91 (*it)->notifyAll( );90 (*it)->notifyAll(Updater); 92 91 } 93 92 94 notifications.erase( this);93 notifications.erase(Updater); 95 94 96 95 // done with notification, we can leave the set of busy subjects 97 busy Relays.erase(this);96 busyObservables.erase(this); 98 97 } 99 98 … … 106 105 void Relay::update(Observable *publisher) { 107 106 // circle detection 108 if(busy Relays.find(this)!=busyRelays.end()) {107 if(busyObservables.find(this)!=busyObservables.end()) { 109 108 // somehow a circle was introduced... we were busy notifying our 110 109 // observers, but still we are called by one of our sub-Relays … … 122 121 #ifdef LOG_OBSERVER 123 122 observerLog().addMessage() << "-* Update from " << observerLog().getName(publisher) 124 << " relayed by " << observerLog().getName(this) << endl;123 << " relayed by " << observerLog().getName(this); 125 124 #endif 126 125 Updater = publisher; … … 130 129 #ifdef LOG_OBSERVER 131 130 observerLog().addMessage() << "-| Update from " << observerLog().getName(publisher) 132 << " not relayed by " << observerLog().getName(this) << endl;131 << " not relayed by " << observerLog().getName(this); 133 132 #endif 134 133 }
Note:
See TracChangeset
for help on using the changeset viewer.
