From 53a24b01ab93a35ccd6acc0ac9776b1a036b1d0e Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Tue, 9 Sep 2014 04:36:43 -0400 Subject: [PATCH] sim: Automatically unregister probe listeners The ProbeListener base class automatically registers itself with a probe manager. Currently, the class does not unregister a itself when it is destroyed, which makes removing probes listeners somewhat cumbersome. This patch adds an automatic call to manager->removeListener in the ProbeListener destructor, which solves the problem. --- src/sim/probe/probe.cc | 8 +++++++- src/sim/probe/probe.hh | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sim/probe/probe.cc b/src/sim/probe/probe.cc index 6f1a3d535..600d9dcc4 100644 --- a/src/sim/probe/probe.cc +++ b/src/sim/probe/probe.cc @@ -62,11 +62,17 @@ ProbeListenerObject::~ProbeListenerObject() listeners.clear(); } -ProbeListener::ProbeListener(ProbeManager *manager, const std::string &name) +ProbeListener::ProbeListener(ProbeManager *_manager, const std::string &_name) + : manager(_manager), name(_name) { manager->addListener(name, *this); } +ProbeListener::~ProbeListener() +{ + manager->removeListener(name, *this); +} + ProbeListenerObject* ProbeListenerObjectParams::create() { diff --git a/src/sim/probe/probe.hh b/src/sim/probe/probe.hh index 5a0bf11c9..2946f4664 100644 --- a/src/sim/probe/probe.hh +++ b/src/sim/probe/probe.hh @@ -104,7 +104,11 @@ class ProbeListener { public: ProbeListener(ProbeManager *manager, const std::string &name); - virtual ~ProbeListener() {} + virtual ~ProbeListener(); + + protected: + ProbeManager *const manager; + const std::string name; }; /** -- 2.30.2