source: ThirdParty/CodePatterns/src/Observer/Notification.cpp@ 9eb71b3

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes
Last change on this file since 9eb71b3 was 9eb71b3, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Commented out MemDebug include and Memory::ignore.

  • MemDebug clashes with various allocation operators that use a specific placement in memory. It is so far not possible to wrap new/delete fully. Hence, we stop this effort which so far has forced us to put ever more includes (with clashes) into MemDebug and thereby bloat compilation time.
  • MemDebug does not add that much usefulness which is not also provided by valgrind.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * Notification.cpp
10 *
11 * Created on: Dec 1, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20//#include "CodePatterns/MemDebug.hpp"
21
22#include <boost/thread/locks.hpp>
23
24#include "CodePatterns/Observer/Notification.hpp"
25#include "CodePatterns/Observer/Observer.hpp"
26#include "CodePatterns/Observer/ObserverLog.hpp"
27
28Notification::Notification(size_t _channelno) :
29 channelno(_channelno)
30{}
31
32Notification::~Notification(){}
33
34void Notification::addObserver(Observer *target, const int priority)
35{
36 boost::recursive_mutex::scoped_lock guard(TargetsLock);
37 targets.insert( std::make_pair(priority, target) );
38}
39
40void Notification::removeObserver(Observer *target)
41{
42 boost::recursive_mutex::scoped_lock guard(TargetsLock);
43 for(targets_t::iterator iter=targets.begin();iter!=targets.end();) {
44 if((*iter).second == target) {
45 targets.erase(iter++);
46 } else {
47 ++iter;
48 }
49 }
50}
51
52void Notification::notifyAll(Observable * const publisher)
53{
54 boost::recursive_mutex::scoped_lock guard(TargetsLock);
55 // copy such that signOff() within receiving update() does not affect iterating
56 // this is because within the same thread and with the update() signOff() may be
57 // called and when executed it modifies targets
58 targets_t temp_targets = targets;
59 for(targets_t::iterator it=temp_targets.begin();
60 it!=temp_targets.end();++it){
61#ifdef LOG_OBSERVER
62 observerLog().addMessage() << "-> Sending update from " << observerLog().getName(publisher)
63 << " for channel " << channelno
64 << " to " << observerLog().getName((*it).second);
65#endif
66 (*it).second->recieveNotification(publisher,this);
67 }
68}
69
70void Notification::subjectKilled(Observable * const publisher)
71{
72 boost::recursive_mutex::scoped_lock guard(TargetsLock);
73 // copy such that signOff() within receiving subjectKilled() does not affect iterating
74 // this is because within the same thread and with the subjectKilled() signOff() may be
75 // called and when executed it modifies targets
76 for(targets_t::iterator it=targets.begin();
77 !targets.empty();it=targets.begin()){
78 Observer *target = (*it).second;
79 const size_t prior_size = targets.size();
80 target->subjectKilled(publisher);
81 if (prior_size == targets.size())
82 targets.erase(it);
83 }
84}
Note: See TracBrowser for help on using the repository browser.