m_CheckerEndpoint->RegisterPublication("checker::CheckResult");
GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint);
- RequestMessage rm;
- rm.SetMethod("checker::AssignService");
- GetEndpointManager()->SendAPIMessage(m_CheckerEndpoint, rm, bind(&CheckerComponent::TestResponseHandler, this, _1));
-
// TODO: get rid of this
ConfigObject::GetAllObjects()->OnObjectAdded.connect(bind(&CheckerComponent::NewServiceHandler, this, _1));
if (!nrea.Request.GetID(&id))
return 0;
+ MessagePart params;
+ if (!nrea.Request.GetParams(¶ms))
+ return 0;
+
+ MessagePart serviceMsg;
+ if (!params.GetProperty("service", &serviceMsg))
+ return 0;
+
+ ConfigObject::Ptr object = make_shared<ConfigObject>(serviceMsg.GetDictionary());
+ Service service(object);
+ m_Services.push(service);
+
+ Application::Log("Accepted service '" + service.GetName() + "'");
+
ResponseMessage rm;
rm.SetID(id);
void DelegationComponent::Start(void)
{
m_AllServices = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
- m_AllServices->OnObjectAdded += bind_weak(&DelegationComponent::NewServiceHandler, shared_from_this());
- m_AllServices->OnObjectCommitted += bind_weak(&DelegationComponent::NewServiceHandler, shared_from_this());
- m_AllServices->OnObjectRemoved += bind_weak(&DelegationComponent::RemovedServiceHandler, shared_from_this());
+ m_AllServices->OnObjectAdded.connect(bind(&DelegationComponent::NewServiceHandler, this, _1));
+ m_AllServices->OnObjectCommitted.connect(bind(&DelegationComponent::NewServiceHandler, this, _1));
+ m_AllServices->OnObjectRemoved.connect(bind(&DelegationComponent::RemovedServiceHandler, this, _1));
m_AllServices->Start();
m_DelegationEndpoint = make_shared<VirtualEndpoint>();
m_DelegationEndpoint->RegisterPublication("checker::AssignService");
m_DelegationEndpoint->RegisterPublication("checker::RevokeService");
GetEndpointManager()->RegisterEndpoint(m_DelegationEndpoint);
-
- RequestMessage rm;
- rm.SetMethod("checker::AssignService");
- GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, rm, bind(&DelegationComponent::TestResponseHandler, this, _1));
}
void DelegationComponent::Stop(void)
params.SetProperty("service", service->GetProperties());
request.SetParams(params);
+ Application::Log("Trying to delegate service '" + service->GetName() + "'");
+
GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
- bind_weak(&DelegationComponent::AssignServiceResponseHandler, shared_from_this()));
+ bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _1));
}
-int DelegationComponent::AssignServiceResponseHandler(const NewResponseEventArgs& nrea)
+int DelegationComponent::AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea)
{
+ if (nrea.TimedOut)
+ Application::Log("Service delegation for service '" + service->GetName() + "' timed out.");
+ else
+ Application::Log("Service delegation for service '" + service->GetName() + "'was successful.");
+
return 0;
}
int NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
int RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
- int AssignServiceResponseHandler(const NewResponseEventArgs& nrea);
+ int AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea);
int RevokeServiceResponseHandler(const NewResponseEventArgs& nrea);
void AssignService(const ConfigObject::Ptr& service);