From d7344ce32949cf66f5d3b99c07551e8cd7914d36 Mon Sep 17 00:00:00 2001 From: Julien Malik <julien.malik@c-s.fr> Date: Mon, 19 Sep 2011 19:49:38 +0200 Subject: [PATCH] BUG: fix FilterWatcher to avoid calling the start/end callback several times --- Code/Common/otbFilterWatcherBase.cxx | 21 ++++++++++++++------- Code/Common/otbFilterWatcherBase.h | 20 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Code/Common/otbFilterWatcherBase.cxx b/Code/Common/otbFilterWatcherBase.cxx index 742eb90d37..c3950d302a 100644 --- a/Code/Common/otbFilterWatcherBase.cxx +++ b/Code/Common/otbFilterWatcherBase.cxx @@ -25,20 +25,27 @@ namespace otb FilterWatcherBase ::FilterWatcherBase() +: m_Comment("Not watching an object"), + m_Process(0), + m_StartTag(0), + m_EndTag(0), + m_ProgressTag(0), + m_Started(false), + m_Ended(false) { - // Initialize state - m_Comment = "Not watching an object"; - m_Process = 0; } FilterWatcherBase ::FilterWatcherBase(itk::ProcessObject* process, const char *comment) +: m_Comment(comment), + m_Process(process), + m_StartTag(0), + m_EndTag(0), + m_ProgressTag(0), + m_Started(false), + m_Ended(false) { - // Initialize state - m_Process = process; - m_Comment = comment; - // Create a series of commands m_StartFilterCommand = CommandType::New(); m_EndFilterCommand = CommandType::New(); diff --git a/Code/Common/otbFilterWatcherBase.h b/Code/Common/otbFilterWatcherBase.h index ef739e490c..65e6fe677b 100644 --- a/Code/Common/otbFilterWatcherBase.h +++ b/Code/Common/otbFilterWatcherBase.h @@ -94,13 +94,21 @@ protected: /** Callback method to show the StartEvent */ virtual void StartFilterCallback() { - this->StartFilter(); + if (!m_Started) + { + this->StartFilter(); + m_Started = true; + } } /** Callback method to show the EndEvent */ virtual void EndFilterCallback() { - this->EndFilter(); + if (!m_Ended) + { + this->EndFilter(); + m_Ended = true; + } } /** Callback method to show the ProgressEvent */ @@ -142,6 +150,14 @@ protected: /** Progress observer */ unsigned long m_ProgressTag; + /** Some filters (for ex. persistents) invoke the StartEvent several times + * Work around this by remembering if it was called or not */ + bool m_Started; + + /** Some filters (for ex. persistents) invoke the EndEvent several times + * Work around this by remembering if it was called or not */ + bool m_Ended; + private: }; -- GitLab