Merge pull request #10263 from Icinga/DependencyGraph-parent-child

DependencyGraph: switch "parent" and "child" terminology
This commit is contained in:
Julian Brost 2024-12-12 15:13:08 +01:00 committed by GitHub
commit 3642ca3369
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 14 deletions

View File

@ -7,18 +7,18 @@ using namespace icinga;
std::mutex DependencyGraph::m_Mutex; std::mutex DependencyGraph::m_Mutex;
std::map<Object *, std::map<Object *, int> > DependencyGraph::m_Dependencies; std::map<Object *, std::map<Object *, int> > DependencyGraph::m_Dependencies;
void DependencyGraph::AddDependency(Object *parent, Object *child) void DependencyGraph::AddDependency(Object* child, Object* parent)
{ {
std::unique_lock<std::mutex> lock(m_Mutex); std::unique_lock<std::mutex> 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<std::mutex> lock(m_Mutex); std::unique_lock<std::mutex> lock(m_Mutex);
auto& refs = m_Dependencies[child]; auto& refs = m_Dependencies[parent];
auto it = refs.find(parent); auto it = refs.find(child);
if (it == refs.end()) if (it == refs.end())
return; return;
@ -29,15 +29,15 @@ void DependencyGraph::RemoveDependency(Object *parent, Object *child)
refs.erase(it); refs.erase(it);
if (refs.empty()) if (refs.empty())
m_Dependencies.erase(child); m_Dependencies.erase(parent);
} }
std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child) std::vector<Object::Ptr> DependencyGraph::GetChildren(const Object::Ptr& parent)
{ {
std::vector<Object::Ptr> objects; std::vector<Object::Ptr> objects;
std::unique_lock<std::mutex> lock(m_Mutex); std::unique_lock<std::mutex> lock(m_Mutex);
auto it = m_Dependencies.find(child.get()); auto it = m_Dependencies.find(parent.get());
if (it != m_Dependencies.end()) { if (it != m_Dependencies.end()) {
typedef std::pair<Object *, int> kv_pair; typedef std::pair<Object *, int> kv_pair;

View File

@ -18,9 +18,9 @@ namespace icinga {
class DependencyGraph class DependencyGraph
{ {
public: public:
static void AddDependency(Object *parent, Object *child); static void AddDependency(Object* child, Object* parent);
static void RemoveDependency(Object *parent, Object *child); static void RemoveDependency(Object* child, Object* parent);
static std::vector<Object::Ptr> GetParents(const Object::Ptr& child); static std::vector<Object::Ptr> GetChildren(const Object::Ptr& parent);
private: private:
DependencyGraph(); DependencyGraph();

View File

@ -520,7 +520,7 @@ String ScriptUtils::MsiGetComponentPathShim(const String& component)
Array::Ptr ScriptUtils::TrackParents(const Object::Ptr& child) 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) double ScriptUtils::Ptr(const Object::Ptr& object)

View File

@ -303,7 +303,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bool cascade, bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bool cascade,
const Array::Ptr& errors, const Array::Ptr& diagnosticInformation, const Value& cookie) const Array::Ptr& errors, const Array::Ptr& diagnosticInformation, const Value& cookie)
{ {
std::vector<Object::Ptr> parents = DependencyGraph::GetParents(object); auto parents (DependencyGraph::GetChildren(object));
Type::Ptr type = object->GetReflectionType(); Type::Ptr type = object->GetReflectionType();

View File

@ -208,7 +208,7 @@ bool ObjectQueryHandler::HandleRequest(
Array::Ptr used_by = new Array(); Array::Ptr used_by = new Array();
metaAttrs.emplace_back("used_by", used_by); 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<ConfigObject>(pobj); ConfigObject::Ptr configObj = dynamic_pointer_cast<ConfigObject>(pobj);