Ignore:
Timestamp:
Dec 13, 2011, 12:00:30 PM (14 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Added unit test on Relay.

  • added new stubs to ObserverStub implementing Relay.
  • Relay is friend of Notification.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Observer/Relay.cpp

    r2c11c1 rd85532  
    2222#include "Relay.hpp"
    2323
     24#include "Assert.hpp"
     25#include "Channels.hpp"
     26#include "defs.hpp"
     27#include "Notification.hpp"
     28
    2429
    2530/** Constructor for class Relay.
    2631 */
    27 Relay::Relay(string name) :
    28   Observer(Observer::BaseConstructor())
     32Relay::Relay(std::string name) :
     33  Observable(name),
     34  Updater(NULL)
    2935{
    3036#ifdef LOG_OBSERVER
     
    4248  observerLog().addMessage() << "-- Destroying Relay " << observerLog().getName(this);
    4349#endif
    44   if(callTable.count(this)) {
    45     // delete all entries for this observable
    46     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   }
    5350}
    5451
    5552
    5653/** Notify all Observers of changes.
    57  * Puts \a *this into Relay::busyRelays, calls Observer::update() for all in callee_t
     54 * Puts \a *this into Relay::busyObservables, calls Observer::update() for all in callee_t
    5855 * and removes from busy list.
    5956 */
    6057void Relay::notifyAll() {
     58  ASSERT(Updater != NULL,
     59      "Relay::notifyAll() called while Updater is NULL.");
    6160  // we are busy notifying others right now
    6261  // add ourselves to the list of busy subjects to enable circle detection
    63   busyRelays.insert(this);
     62  busyObservables.insert(this);
    6463  // see if anyone has signed up for observation
    6564  // and call all observers
     
    8685  // send out all notifications that need to be done
    8786
    88   notificationSet currentNotifications = notifications[this];
     87  notificationSet currentNotifications = notifications[Updater];
    8988  for(notificationSet::iterator it = currentNotifications.begin();
    9089      it != currentNotifications.end();++it){
    91     (*it)->notifyAll();
     90    (*it)->notifyAll(Updater);
    9291  }
    9392
    94   notifications.erase(this);
     93  notifications.erase(Updater);
    9594
    9695   // done with notification, we can leave the set of busy subjects
    97   busyRelays.erase(this);
     96  busyObservables.erase(this);
    9897}
    9998
     
    106105void Relay::update(Observable *publisher) {
    107106  // circle detection
    108   if(busyRelays.find(this)!=busyRelays.end()) {
     107  if(busyObservables.find(this)!=busyObservables.end()) {
    109108    // somehow a circle was introduced... we were busy notifying our
    110109    // observers, but still we are called by one of our sub-Relays
     
    122121#ifdef LOG_OBSERVER
    123122      observerLog().addMessage() << "-* Update from " << observerLog().getName(publisher)
    124                                  << " relayed by " << observerLog().getName(this) << endl;
     123                                 << " relayed by " << observerLog().getName(this);
    125124#endif
    126125      Updater = publisher;
     
    130129#ifdef LOG_OBSERVER
    131130      observerLog().addMessage() << "-| Update from " <<  observerLog().getName(publisher)
    132                                  << " not relayed by " << observerLog().getName(this) << endl;
     131                                 << " not relayed by " << observerLog().getName(this);
    133132#endif
    134133    }
Note: See TracChangeset for help on using the changeset viewer.