Ignore:
Timestamp:
Apr 24, 2010, 3:27:00 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
033a05
Parents:
8a34392
Message:

Added methods for specialized Notifications from the Observer Framework

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Observer.cpp

    r8a34392 rccacba  
    2727map<Observable*, int> Observable::depth;  //!< Map of Observables to the depth of the DAG of Observers
    2828map<Observable*,multimap<int,Observer*>*> Observable::callTable; //!< Table for each Observable of all its Observers
     29std::map<Observable*,std::set<Notification*> > Observable::notifications;
    2930set<Observable*> Observable::busyObservables; //!< Set of Observables that are currently busy notifying their sign-on'ed Observers
    3031
     
    6869}
    6970
     71void Observable::enque_notification_internal(Observable *publisher, Notification_ptr notification){
     72  ASSERT(notification->owner==publisher,"Some object tried to send a notification it does not own");
     73  notifications[publisher].insert(notification);
     74}
     75
    7076/** Constructor for Observable Protector.
    7177 * Basically, calls start_observer_internal(). Hence use this class instead of
     
    97103 * and removes from busy list.
    98104 */
    99 void Observable::notifyAll() {
     105void Observable::notifyAll() try {
    100106  // we are busy notifying others right now
    101107  // add ourselves to the list of busy subjects to enable circle detection
     
    113119    }
    114120  }
    115   // done with notification, we can leave the set of busy subjects
     121
     122  // send out all notifications that need to be done
     123
     124  notificationSet currentNotifications = notifications[this];
     125  for(notificationSet::iterator it = currentNotifications.begin();
     126      it != currentNotifications.end();++it){
     127    (*it)->notifyAll();
     128  }
     129
     130  notifications.erase(this);
     131
     132   // done with notification, we can leave the set of busy subjects
    116133  busyObservables.erase(this);
    117134}
     135ASSERT_NOCATCH("Exception thrown from Observer Update")
    118136
    119137/** Handles passing on updates from sub-Observables.
     
    191209}
    192210
     211void Observable::signOn(Observer *target, Notification_ptr notification){
     212  ASSERT(notification->owner==this,
     213         "Trying to sign on for a notification that is not provided by this object");
     214
     215  notification->addObserver(target);
     216}
     217
     218void Observable::signOff(Observer *target, Notification_ptr notification){
     219  ASSERT(notification->owner==this,
     220         "Trying to sign off from a notification that is not provided by this object");
     221
     222  notification->removeObserver(target);
     223}
     224
    193225bool Observable::isBlocked(){
    194226  return depth.count(this) > 0;
     
    233265Observer::~Observer()
    234266{}
     267
     268/**
     269 * Method for specialized notifications.
     270 * Most Observers wont need or use this, so it is implemented
     271 * empty in the base case;
     272 */
     273void Observer::recieveNotification(Observable *publisher, Notification_ptr notification){
     274}
     275
     276Notification::Notification(Observable *_owner) :
     277    owner(_owner)
     278{}
     279
     280Notification::~Notification(){}
     281
     282void Notification::addObserver(Observer *target){
     283  targets.insert(target);
     284}
     285
     286void Notification::removeObserver(Observer *target){
     287  targets.erase(target);
     288}
     289
     290void Notification::notifyAll(){
     291  for(std::set<Observer*>::iterator it=targets.begin();
     292      it!=targets.end();++it){
     293    (*it)->recieveNotification(owner,this);
     294  }
     295}
Note: See TracChangeset for help on using the changeset viewer.