From 188ba53b74c530b323b9b45de34882d9444175af Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 4 Dec 2024 10:57:30 +0100 Subject: [PATCH] DependencyGraph: switch "parent" and "child" terminology The .ti files call `DependencyGraph::AddDependency(this, service.get())`. Obviously, `service.get()` is the parent and `this` (Downtime, Notification, ...) is the child. The DependencyGraph terminology should reflect this not to confuse its future users. --- lib/base/dependencygraph.cpp | 16 ++++++++-------- lib/base/dependencygraph.hpp | 6 +++--- lib/base/scriptutils.cpp | 2 +- lib/remote/configobjectutility.cpp | 2 +- lib/remote/objectqueryhandler.cpp | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/base/dependencygraph.cpp b/lib/base/dependencygraph.cpp index 025eb3ea3..88cb18194 100644 --- a/lib/base/dependencygraph.cpp +++ b/lib/base/dependencygraph.cpp @@ -7,18 +7,18 @@ using namespace icinga; std::mutex DependencyGraph::m_Mutex; std::map > DependencyGraph::m_Dependencies; -void DependencyGraph::AddDependency(Object *parent, Object *child) +void DependencyGraph::AddDependency(Object* child, Object* parent) { std::unique_lock lock(m_Mutex); - m_Dependencies[child][parent]++; + m_Dependencies[parent][child]++; } -void DependencyGraph::RemoveDependency(Object *parent, Object *child) +void DependencyGraph::RemoveDependency(Object* child, Object* parent) { std::unique_lock lock(m_Mutex); - auto& refs = m_Dependencies[child]; - auto it = refs.find(parent); + auto& refs = m_Dependencies[parent]; + auto it = refs.find(child); if (it == refs.end()) return; @@ -29,15 +29,15 @@ void DependencyGraph::RemoveDependency(Object *parent, Object *child) refs.erase(it); if (refs.empty()) - m_Dependencies.erase(child); + m_Dependencies.erase(parent); } -std::vector DependencyGraph::GetParents(const Object::Ptr& child) +std::vector DependencyGraph::GetChildren(const Object::Ptr& parent) { std::vector objects; std::unique_lock lock(m_Mutex); - auto it = m_Dependencies.find(child.get()); + auto it = m_Dependencies.find(parent.get()); if (it != m_Dependencies.end()) { typedef std::pair kv_pair; diff --git a/lib/base/dependencygraph.hpp b/lib/base/dependencygraph.hpp index 51aa90eca..43dd97c08 100644 --- a/lib/base/dependencygraph.hpp +++ b/lib/base/dependencygraph.hpp @@ -18,9 +18,9 @@ namespace icinga { class DependencyGraph { public: - static void AddDependency(Object *parent, Object *child); - static void RemoveDependency(Object *parent, Object *child); - static std::vector GetParents(const Object::Ptr& child); + static void AddDependency(Object* child, Object* parent); + static void RemoveDependency(Object* child, Object* parent); + static std::vector GetChildren(const Object::Ptr& parent); private: DependencyGraph(); diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 7fe856de3..5bf2164a7 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::GetParents(child)); + return Array::FromVector(DependencyGraph::GetChildren(child)); } double ScriptUtils::Ptr(const Object::Ptr& object) diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index 60268f6e1..75dcfab93 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -303,7 +303,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bool cascade, const Array::Ptr& errors, const Array::Ptr& diagnosticInformation, const Value& cookie) { - std::vector parents = DependencyGraph::GetParents(object); + auto parents (DependencyGraph::GetChildren(object)); Type::Ptr type = object->GetReflectionType(); diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp index ad73030da..4c40ef3ed 100644 --- a/lib/remote/objectqueryhandler.cpp +++ b/lib/remote/objectqueryhandler.cpp @@ -208,7 +208,7 @@ bool ObjectQueryHandler::HandleRequest( Array::Ptr used_by = new Array(); metaAttrs.emplace_back("used_by", used_by); - for (const Object::Ptr& pobj : DependencyGraph::GetParents((obj))) + for (auto& pobj : DependencyGraph::GetChildren(obj)) { ConfigObject::Ptr configObj = dynamic_pointer_cast(pobj);