From de4bc7d7493ea15d22ccad15d4e74a9c5da298c1 Mon Sep 17 00:00:00 2001 From: Robert Middleton Date: Fri, 28 Jul 2023 09:43:54 -0400 Subject: [PATCH] Add a way to remove the HierarchyEventListener (#234) * Add a way to remove the HierarchyEventListener See #233 --- src/main/cpp/hierarchy.cpp | 10 ++++++++++ src/main/include/log4cxx/hierarchy.h | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/cpp/hierarchy.cpp b/src/main/cpp/hierarchy.cpp index e9a63016c..23f352892 100644 --- a/src/main/cpp/hierarchy.cpp +++ b/src/main/cpp/hierarchy.cpp @@ -111,6 +111,16 @@ void Hierarchy::addHierarchyEventListener(const spi::HierarchyEventListenerPtr& } } +void Hierarchy::removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener) +{ + std::unique_lock lock(m_priv->mutex); + + auto found = std::find(m_priv->listeners.begin(), m_priv->listeners.end(), listener); + if(found != m_priv->listeners.end()){ + m_priv->listeners.erase(found); + } +} + void Hierarchy::clear() { std::unique_lock lock(m_priv->mutex); diff --git a/src/main/include/log4cxx/hierarchy.h b/src/main/include/log4cxx/hierarchy.h index 1173a14fa..4bb7400b7 100644 --- a/src/main/include/log4cxx/hierarchy.h +++ b/src/main/include/log4cxx/hierarchy.h @@ -76,6 +76,13 @@ class LOG4CXX_EXPORT Hierarchy : public spi::LoggerRepository void addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener) override; + /** + * Remove a previously added HierarchyEventListener. + * + * ABI TODO: Make virtual and add to LoggerRepository. + */ + void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener); + /** * Call \c configurator if not yet configured. */