diff --git a/lib/base/dependencygraph.cpp b/lib/base/dependencygraph.cpp index 88cb18194a..58f685ce01 100644 --- a/lib/base/dependencygraph.cpp +++ b/lib/base/dependencygraph.cpp @@ -5,15 +5,15 @@ using namespace icinga; std::mutex DependencyGraph::m_Mutex; -std::map > DependencyGraph::m_Dependencies; +std::map> DependencyGraph::m_Dependencies; -void DependencyGraph::AddDependency(Object* child, Object* parent) +void DependencyGraph::AddDependency(ConfigObject* child, ConfigObject* parent) { std::unique_lock lock(m_Mutex); m_Dependencies[parent][child]++; } -void DependencyGraph::RemoveDependency(Object* child, Object* parent) +void DependencyGraph::RemoveDependency(ConfigObject* child, ConfigObject* parent) { std::unique_lock lock(m_Mutex); @@ -32,16 +32,15 @@ void DependencyGraph::RemoveDependency(Object* child, Object* parent) m_Dependencies.erase(parent); } -std::vector DependencyGraph::GetChildren(const Object::Ptr& parent) +std::vector DependencyGraph::GetChildren(const ConfigObject::Ptr& parent) { - std::vector objects; + std::vector objects; std::unique_lock lock(m_Mutex); auto it = m_Dependencies.find(parent.get()); if (it != m_Dependencies.end()) { - typedef std::pair kv_pair; - for (const kv_pair& kv : it->second) { + for (auto& kv : it->second) { objects.emplace_back(kv.first); } } diff --git a/lib/base/dependencygraph.hpp b/lib/base/dependencygraph.hpp index 43dd97c08f..915c1c2790 100644 --- a/lib/base/dependencygraph.hpp +++ b/lib/base/dependencygraph.hpp @@ -4,7 +4,7 @@ #define DEPENDENCYGRAPH_H #include "base/i2-base.hpp" -#include "base/object.hpp" +#include "base/configobject.hpp" #include #include @@ -18,15 +18,25 @@ namespace icinga { class DependencyGraph { public: - static void AddDependency(Object* child, Object* parent); - static void RemoveDependency(Object* child, Object* parent); - static std::vector GetChildren(const Object::Ptr& parent); + static void AddDependency(ConfigObject* child, ConfigObject* parent); + static void RemoveDependency(ConfigObject* child, ConfigObject* parent); + static std::vector GetChildren(const ConfigObject::Ptr& parent); + + static void AddDependency(ObjectImpl* child, ConfigObject* parent) + { + AddDependency(static_cast(child), parent); + } + + static void RemoveDependency(ObjectImpl* child, ConfigObject* parent) + { + RemoveDependency(static_cast(child), parent); + } private: DependencyGraph(); static std::mutex m_Mutex; - static std::map > m_Dependencies; + static std::map> m_Dependencies; }; } diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 5bf2164a7b..3611799ffc 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -520,7 +520,7 @@ String ScriptUtils::MsiGetComponentPathShim(const String& component) Array::Ptr ScriptUtils::TrackParents(const Object::Ptr& child) { - return Array::FromVector(DependencyGraph::GetChildren(child)); + return Array::FromVector(DependencyGraph::GetChildren(dynamic_pointer_cast(child))); } double ScriptUtils::Ptr(const Object::Ptr& object) diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index 75dcfab93c..9d19580502 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -319,12 +319,7 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo return false; } - for (const Object::Ptr& pobj : parents) { - ConfigObject::Ptr parentObj = dynamic_pointer_cast(pobj); - - if (!parentObj) - continue; - + for (auto& parentObj : parents) { DeleteObjectHelper(parentObj, cascade, errors, diagnosticInformation, cookie); } diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp index 4c40ef3ed4..8b73137893 100644 --- a/lib/remote/objectqueryhandler.cpp +++ b/lib/remote/objectqueryhandler.cpp @@ -208,13 +208,7 @@ bool ObjectQueryHandler::HandleRequest( Array::Ptr used_by = new Array(); metaAttrs.emplace_back("used_by", used_by); - for (auto& pobj : DependencyGraph::GetChildren(obj)) - { - ConfigObject::Ptr configObj = dynamic_pointer_cast(pobj); - - if (!configObj) - continue; - + for (auto& configObj : DependencyGraph::GetChildren(obj)) { used_by->Add(new Dictionary({ { "type", configObj->GetReflectionType()->GetName() }, { "name", configObj->GetName() }