Cleaned up Service::StateFromString function.

This commit is contained in:
Gunnar Beutner 2012-09-07 09:47:58 +02:00
parent df6de810cd
commit 91831b3260
1 changed files with 9 additions and 17 deletions

View File

@ -391,24 +391,16 @@ void Service::ApplyCheckResult(const Dictionary::Ptr& cr)
ServiceState Service::StateFromString(const String& state)
{
/* TODO: make this thread-safe */
static map<String, ServiceState> stateLookup;
if (stateLookup.empty()) {
stateLookup["ok"] = StateOK;
stateLookup["warning"] = StateWarning;
stateLookup["critical"] = StateCritical;
stateLookup["uncheckable"] = StateUncheckable;
stateLookup["unknown"] = StateUnknown;
}
map<String, ServiceState>::iterator it;
it = stateLookup.find(state);
if (it == stateLookup.end())
return StateUnknown;
if (state == "ok")
return StateOK;
else if (state == "warning")
return StateWarning;
else if (state == "critical")
return StateCritical;
else if (state == "uncheckable")
return StateUncheckable;
else
return it->second;
return StateUnknown;
}
String Service::StateToString(ServiceState state)