Make sure the dependency graph is properly updated when adding and removing objects

fixes #11686
fixes #11374
This commit is contained in:
Gunnar Beutner 2016-05-09 13:48:30 +02:00
parent 9baa08d24a
commit b8e911b0e5
7 changed files with 22 additions and 9 deletions

View File

@ -34,7 +34,20 @@ void DependencyGraph::AddDependency(Object *parent, Object *child)
void DependencyGraph::RemoveDependency(Object *parent, Object *child)
{
boost::mutex::scoped_lock lock(m_Mutex);
m_Dependencies[child][parent]--;
std::map<Object *, int>& refs = m_Dependencies[child];
std::map<Object *, int>::iterator it = refs.find(parent);
if (it == refs.end())
return;
it->second--;
if (it->second == 0)
refs.erase(it);
if (refs.empty())
m_Dependencies.erase(child);
}
std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child)

View File

@ -67,7 +67,7 @@ class Comment : ConfigObject < CommentNameComposer
if (!newValue.IsEmpty()) {
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
DependencyGraph::RemoveDependency(this, service.get());
DependencyGraph::AddDependency(this, service.get());
}
}}}
navigate {{{

View File

@ -55,7 +55,7 @@ class Dependency : CustomVarObject < DependencyNameComposer
if (!newValue.IsEmpty()) {
Service::Ptr service = Service::GetByNamePair(GetParentHostName(), newValue);
DependencyGraph::RemoveDependency(this, service.get());
DependencyGraph::AddDependency(this, service.get());
}
}}}
navigate {{{
@ -82,7 +82,7 @@ class Dependency : CustomVarObject < DependencyNameComposer
if (!newValue.IsEmpty()) {
Service::Ptr service = Service::GetByNamePair(GetParentHostName(), newValue);
DependencyGraph::RemoveDependency(this, service.get());
DependencyGraph::AddDependency(this, service.get());
}
}}}
navigate {{{

View File

@ -54,7 +54,7 @@ class Downtime : ConfigObject < DowntimeNameComposer
if (!newValue.IsEmpty()) {
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
DependencyGraph::RemoveDependency(this, service.get());
DependencyGraph::AddDependency(this, service.get());
}
}}}
navigate {{{

View File

@ -74,7 +74,7 @@ class Notification : CustomVarObject < NotificationNameComposer
if (!newValue.IsEmpty()) {
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
DependencyGraph::RemoveDependency(this, service.get());
DependencyGraph::AddDependency(this, service.get());
}
}}}
navigate {{{

View File

@ -53,7 +53,7 @@ class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
if (!newValue.IsEmpty()) {
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
DependencyGraph::RemoveDependency(this, service.get());
DependencyGraph::AddDependency(this, service.get());
}
}}}
navigate {{{

View File

@ -901,7 +901,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
<< "\t" << klass.Parent << "::Start(runtimeCreated);" << std::endl << std::endl;
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
if (!(it->Type.IsName))
if (!it->Type.IsName && it->TrackAccessor.empty())
continue;
m_Impl << "\t" << "Track" << it->GetFriendlyName() << "(Empty, Get" << it->GetFriendlyName() << "());" << std::endl;
@ -913,7 +913,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
<< "\t" << klass.Parent << "::Stop(runtimeRemoved);" << std::endl << std::endl;
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
if (!(it->Type.IsName))
if (!it->Type.IsName && it->TrackAccessor.empty())
continue;
m_Impl << "\t" << "Track" << it->GetFriendlyName() << "(Get" << it->GetFriendlyName() << "(), Empty);" << std::endl;