diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index 5729d8d00..e0b92d9de 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -30,7 +30,8 @@ string DelegationComponent::GetName(void) const void DelegationComponent::Start(void) { m_AllServices = boost::make_shared(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service")); - m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::ObjectCommittedHandler, this, _2)); + m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::ServiceCommittedHandler, this, _2)); + m_AllServices->OnObjectRemoved.connect(boost::bind(&DelegationComponent::ServiceRemovedHandler, this, _2)); m_AllServices->Start(); m_DelegationTimer = boost::make_shared(); @@ -60,10 +61,8 @@ void DelegationComponent::Stop(void) mgr->UnregisterEndpoint(m_Endpoint); } -void DelegationComponent::ObjectCommittedHandler(const ConfigObject::Ptr& object) +void DelegationComponent::ServiceCommittedHandler(Service service) { - Service service(object); - string checker = service.GetChecker(); if (!checker.empty()) { @@ -78,6 +77,19 @@ void DelegationComponent::ObjectCommittedHandler(const ConfigObject::Ptr& object } } +void DelegationComponent::ServiceRemovedHandler(Service service) +{ + string checker = service.GetChecker(); + + if (!checker.empty()) { + /* TODO: figure out a better way to clear individual services */ + Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(checker); + + if (endpoint) + ClearServices(endpoint); + } +} + void DelegationComponent::AssignService(const Endpoint::Ptr& checker, const Service& service) { RequestMessage request; diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index 5ff024f2b..57e740ba1 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -41,7 +41,8 @@ private: void NewEndpointHandler(const Endpoint::Ptr& endpoint); void SessionEstablishedHandler(const Endpoint::Ptr& endpoint); - void ObjectCommittedHandler(const ConfigObject::Ptr& object); + void ServiceCommittedHandler(Service service); + void ServiceRemovedHandler(Service service); void DelegationTimerHandler(void); vector GetCheckerCandidates(const Service& service) const;