task->FinishResult(Empty);
}
-Service::Ptr Host::GetServiceByShortName(const String& name) const
+Service::Ptr Host::GetServiceByShortName(const Value& name) const
{
- ValidateServicesCache();
+ if (name.IsScalar()) {
+ ValidateServicesCache();
- map<String, weak_ptr<Service> >& services = m_ServicesCache[GetName()];
- map<String, weak_ptr<Service> >::iterator it = services.find(name);
+ map<String, weak_ptr<Service> >& services = m_ServicesCache[GetName()];
+ map<String, weak_ptr<Service> >::iterator it = services.find(name);
- if (it != services.end()) {
- Service::Ptr service = it->second.lock();
- assert(service);
- return service;
- }
+ if (it != services.end()) {
+ Service::Ptr service = it->second.lock();
+ assert(service);
+ return service;
+ }
- return Service::GetByName(name);
+ return Service::GetByName(name);
+ } else if (name.IsObjectType<Dictionary>()) {
+ Dictionary::Ptr dict = name;
+ return GetByName(dict->Get("host"))->GetServiceByShortName(dict->Get("service"));
+ } else {
+ BOOST_THROW_EXCEPTION(invalid_argument("Host/Service name pair is invalid."));
+ }
}
set<Host::Ptr> Host::GetParentHosts(void) const
if (dependencies) {
String key;
- BOOST_FOREACH(tie(key, tuples::ignore), dependencies) {
- // TODO(#3660): look up { host = "name", service = "name" } pairs
- parents.insert(GetServiceByShortName(key));
+ Value value;
+ BOOST_FOREACH(tie(key, value), dependencies) {
+ parents.insert(GetServiceByShortName(value));
}
}
bool IsInDowntime(void) const;
bool IsUp(void) const;
- shared_ptr<Service> GetServiceByShortName(const String& name) const;
+ shared_ptr<Service> GetServiceByShortName(const Value& name) const;
set<shared_ptr<Service> > GetServices(void) const;
static void InvalidateServicesCache(void);
if (dependencies) {
String key;
- BOOST_FOREACH(tie(key, tuples::ignore), dependencies) {
- // TODO(#3660): look up { host = "name", service = "name" } pairs
- Service::Ptr service = GetHost()->GetServiceByShortName(key);
+ Value value;
+ BOOST_FOREACH(tie(key, value), dependencies) {
+ Service::Ptr service = GetHost()->GetServiceByShortName(value);
if (service->GetName() == GetName())
continue;