Clean up some of the type checks.

Refs #5925
This commit is contained in:
Gunnar Beutner 2014-04-07 22:06:05 +02:00
parent c522b42c45
commit 32e1c02b9a
3 changed files with 11 additions and 20 deletions

View File

@ -111,13 +111,16 @@ bool Dependency::IsAvailable(DependencyType dt) const
return true; return true;
} }
bool is_service = parent->GetType() == DynamicType::GetByName("Service"); Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(parent);
int state; int state;
if (is_service) if (service)
state = ServiceStateToFilter(static_pointer_cast<Service>(parent)->GetState()); state = ServiceStateToFilter(service->GetState());
else else
state = HostStateToFilter(static_pointer_cast<Host>(parent)->GetState()); state = HostStateToFilter(host->GetState());
/* check state */ /* check state */
if (state & GetStateFilter()) { if (state & GetStateFilter()) {

View File

@ -40,18 +40,12 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
Value raw_command = commandObj->GetCommandLine(); Value raw_command = commandObj->GetCommandLine();
bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable);
if (is_service) {
service = static_pointer_cast<Service>(checkable);
host = service->GetHost();
} else
host = static_pointer_cast<Host>(checkable);
std::vector<MacroResolver::Ptr> resolvers; std::vector<MacroResolver::Ptr> resolvers;
if (is_service) if (service)
resolvers.push_back(service); resolvers.push_back(service);
resolvers.push_back(host); resolvers.push_back(host);
resolvers.push_back(commandObj); resolvers.push_back(commandObj);

View File

@ -37,18 +37,12 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable)
EventCommand::Ptr commandObj = checkable->GetEventCommand(); EventCommand::Ptr commandObj = checkable->GetEventCommand();
Value raw_command = commandObj->GetCommandLine(); Value raw_command = commandObj->GetCommandLine();
bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable);
if (is_service) {
service = static_pointer_cast<Service>(checkable);
host = service->GetHost();
} else
host = static_pointer_cast<Host>(checkable);
std::vector<MacroResolver::Ptr> resolvers; std::vector<MacroResolver::Ptr> resolvers;
if (is_service) if (service)
resolvers.push_back(service); resolvers.push_back(service);
resolvers.push_back(host); resolvers.push_back(host);
resolvers.push_back(commandObj); resolvers.push_back(commandObj);