1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "base/dependencygraph.hpp"
5 using namespace icinga;
7 boost::mutex DependencyGraph::m_Mutex;
8 std::map<Object *, std::map<Object *, int> > DependencyGraph::m_Dependencies;
10 void DependencyGraph::AddDependency(Object *parent, Object *child)
12 boost::mutex::scoped_lock lock(m_Mutex);
13 m_Dependencies[child][parent]++;
16 void DependencyGraph::RemoveDependency(Object *parent, Object *child)
18 boost::mutex::scoped_lock lock(m_Mutex);
20 auto& refs = m_Dependencies[child];
21 auto it = refs.find(parent);
32 m_Dependencies.erase(child);
35 std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child)
37 std::vector<Object::Ptr> objects;
39 boost::mutex::scoped_lock lock(m_Mutex);
40 auto it = m_Dependencies.find(child.get());
42 if (it != m_Dependencies.end()) {
43 typedef std::pair<Object *, int> kv_pair;
44 for (const kv_pair& kv : it->second) {
45 objects.emplace_back(kv.first);