MCPcopy Create free account
hub / github.com/Icinga/icinga2 / AddDependency

Method AddDependency

lib/icinga/checkable-dependency.cpp:66–98  ·  view source on GitHub ↗

* Add the provided dependency to the current Checkable list of dependencies. * * @param dependency The dependency to add. */

Source from the content-addressed store, hash-verified

64 * @param dependency The dependency to add.
65 */
66void Checkable::AddDependency(const Dependency::Ptr& dependency)
67{
68 std::unique_lock lock(m_DependencyMutex);
69
70 auto dependencyGroupKey(GetDependencyGroupKey(dependency));
71 if (m_PendingDependencies != nullptr) {
72 (*m_PendingDependencies)[dependencyGroupKey].emplace(dependency);
73 return;
74 }
75
76 std::set<Dependency::Ptr> dependencies;
77 bool removeGroup(false);
78
79 DependencyGroup::Ptr existingGroup;
80 if (auto it(m_DependencyGroups.find(dependencyGroupKey)); it != m_DependencyGroups.end()) {
81 existingGroup = it->second;
82 std::tie(dependencies, removeGroup) = DependencyGroup::Unregister(existingGroup, this);
83 m_DependencyGroups.erase(it);
84 }
85
86 dependencies.emplace(dependency);
87
88 auto dependencyGroup(DependencyGroup::Register(new DependencyGroup(dependency->GetRedundancyGroup(), dependencies)));
89 m_DependencyGroups.emplace(dependencyGroupKey, dependencyGroup);
90
91 lock.unlock();
92
93 if (existingGroup) {
94 dependencies.erase(dependency);
95 DependencyGroup::OnChildRemoved(existingGroup, {dependencies.begin(), dependencies.end()}, removeGroup);
96 }
97 DependencyGroup::OnChildRegistered(this, dependencyGroup);
98}
99
100/**
101 * Remove the provided dependency from the current Checkable list of dependencies.

Callers

nothing calls this directly

Calls 6

GetDependencyGroupKeyFunction · 0.85
emplaceMethod · 0.80
findMethod · 0.80
endMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected