Implement property change handler for next_check.

Fixes #3547
This commit is contained in:
Gunnar Beutner 2013-01-22 12:44:23 +01:00
parent 61f2b5f0cf
commit 7e31cb639f
4 changed files with 20 additions and 0 deletions

View File

@ -30,6 +30,7 @@ void CheckerComponent::Start(void)
m_Endpoint->RegisterSubscription("checker");
Service::OnCheckerChanged.connect(bind(&CheckerComponent::CheckerChangedHandler, this, _1));
Service::OnNextCheckChanged.connect(bind(&CheckerComponent::NextCheckChangedHandler, this, _1));
DynamicObject::OnUnregistered.connect(bind(&CheckerComponent::ObjectRemovedHandler, this, _1));
m_CheckTimer = boost::make_shared<Timer>();
@ -144,6 +145,20 @@ void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
}
}
void CheckerComponent::NextCheckChangedHandler(const Service::Ptr& service)
{
/* remove and re-insert the service from the set in order to force an index update */
typedef nth_index<ServiceSet, 0>::type ServiceView;
ServiceView& idx = boost::get<0>(m_IdleServices);
ServiceView::iterator it = idx.find(service);
if (it == idx.end())
return;
idx.erase(it);
idx.insert(service);
}
void CheckerComponent::ObjectRemovedHandler(const DynamicObject::Ptr& object)
{
Service::Ptr service = dynamic_pointer_cast<Service>(object);

View File

@ -74,6 +74,7 @@ private:
void AdjustCheckTimer(void);
void CheckerChangedHandler(const Service::Ptr& service);
void NextCheckChangedHandler(const Service::Ptr& service);
void ObjectRemovedHandler(const DynamicObject::Ptr& object);
};

View File

@ -53,6 +53,7 @@ const int Service::CheckIntervalDivisor = 5;
boost::signal<void (const Service::Ptr&, const CheckResultMessage&)> Service::OnCheckResultReceived;
boost::signal<void (const Service::Ptr&, const String&)> Service::OnCheckerChanged;
boost::signal<void (const Service::Ptr&, const Value&)> Service::OnNextCheckChanged;
Service::Service(const Dictionary::Ptr& serializedObject)
: DynamicObject(serializedObject)
@ -479,6 +480,8 @@ void Service::OnAttributeChanged(const String& name, const Value& oldValue)
{
if (name == "checker")
OnCheckerChanged(GetSelf(), oldValue);
else if (name == "next_check")
OnNextCheckChanged(GetSelf(), oldValue);
}
void Service::BeginExecuteCheck(const function<void (void)>& callback)

View File

@ -131,6 +131,7 @@ public:
static boost::signal<void (const Service::Ptr& service, const CheckResultMessage&)> OnCheckResultReceived;
static boost::signal<void (const Service::Ptr&, const String&)> OnCheckerChanged;
static boost::signal<void (const Service::Ptr&, const Value&)> OnNextCheckChanged;
protected:
virtual void OnAttributeChanged(const String& name, const Value& oldValue);