From 28599c99d023389c34ab76f8e0769bd6a40e1ac4 Mon Sep 17 00:00:00 2001 From: adrian Date: Thu, 4 Oct 2012 11:28:11 +0000 Subject: [PATCH] Listener handler revisited (onTrigger toggles the current flow), typo. git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1713 8c4709b5-6ec9-48aa-a5cd-a96041d1645a --- src/core/sal/Listener.cc | 6 ++++++ src/core/sal/Listener.hpp | 10 +++++----- src/core/sal/ListenerManager.cc | 6 ++---- src/core/sal/SimulatorController.hpp | 5 +++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/core/sal/Listener.cc b/src/core/sal/Listener.cc index a2bac66f..6290615e 100644 --- a/src/core/sal/Listener.cc +++ b/src/core/sal/Listener.cc @@ -8,6 +8,12 @@ BaseListener::~BaseListener() simulator.removeListener(this); } +void BaseListener::onTrigger() +{ + assert(m_Parent && "FATAL ERROR: The listener has no parent!"); + simulator.toggle(m_Parent); +} + bool TroubleListener::isMatching(const TroubleEvent* pEv) const { for (unsigned i = 0; i < m_WatchNumbers.size(); i++) { diff --git a/src/core/sal/Listener.hpp b/src/core/sal/Listener.hpp index 17a8e485..c4dd5284 100644 --- a/src/core/sal/Listener.hpp +++ b/src/core/sal/Listener.hpp @@ -42,7 +42,7 @@ public: */ virtual bool onAddition() { return true; } /** - * This method is called when an experiment flow removes an listener from + * This method is called when an experiment flow removes a listener from * the listener-management by calling \c removeListener(), \c clearListeners() * or by deleting a complete flow (\c removeFlow()). More specifically, this * listener handler will be called *before* the listener is actually deleted. @@ -50,11 +50,11 @@ public: virtual void onDeletion() { } /** * This method is called when an previously added listener is about to be - * triggered by the simulator-backend. More specifically, this listener handler - * will be called *before* the listener is actually triggered, i.e. before the - * corresponding coroutine is toggled. + * triggered by the simulator-backend. \c onTrigger() toggles the experiment + * flow specified by \c BaseListener::getParent(). You can use this handler + * as a callback function by overwriting this method appropriately. */ - virtual void onTrigger() { } + virtual void onTrigger(); /** * Decreases the listener counter by one. When this counter reaches zero, the * listener will be triggered. diff --git a/src/core/sal/ListenerManager.cc b/src/core/sal/ListenerManager.cc index a211a803..6d6184b4 100644 --- a/src/core/sal/ListenerManager.cc +++ b/src/core/sal/ListenerManager.cc @@ -236,10 +236,8 @@ void ListenerManager::triggerActiveListeners() m_pFired = *it; // Inform (call) the simulator's (internal) listener handler that we are about // to trigger an listener (*before* we actually toggle the experiment flow): - m_pFired->onTrigger(); - ExperimentFlow* pFlow = m_pFired->getParent(); - assert(pFlow && "FATAL ERROR: The listener has no parent experiment (owner)!"); - simulator.m_Flows.toggle(pFlow); + m_pFired->onDeletion(); // the listener has already been deleted (in the buffer-list)! + m_pFired->onTrigger(); // onTrigger will toggle the correct coroutine } } m_FireList.clear(); diff --git a/src/core/sal/SimulatorController.hpp b/src/core/sal/SimulatorController.hpp index 229edd16..21ab86e4 100644 --- a/src/core/sal/SimulatorController.hpp +++ b/src/core/sal/SimulatorController.hpp @@ -235,6 +235,11 @@ public: * @see ListenerManager::dereference() */ inline BaseListener* dereference(index_t idx) { return m_LstList.dereference(idx); } + /** + * Toggles the provided experiment flow by activating its coroutine. + * @param pfl the experiment flow to be activated + */ + void toggle(ExperimentFlow* pfl) { m_Flows.toggle(pfl); } }; // FIXME (see SimulatorController.cc): Weird, homeless global variable