icinga2/icinga/discoverycomponent.cpp

48 lines
1.3 KiB
C++
Raw Normal View History

2012-04-23 16:49:02 +02:00
#include "i2-icinga.h"
using namespace icinga;
string DiscoveryComponent::GetName(void) const
{
return "discoverycomponent";
}
void DiscoveryComponent::Start(void)
{
m_DiscoveryEndpoint = make_shared<VirtualEndpoint>();
2012-04-25 20:35:37 +02:00
m_DiscoveryEndpoint->RegisterMethodHandler("message::Welcome",
bind_weak(&DiscoveryComponent::GetPeersMessageHandler, shared_from_this()));
2012-04-23 16:49:02 +02:00
m_DiscoveryEndpoint->RegisterMethodSource("discovery::PeerAvailable");
m_DiscoveryEndpoint->RegisterMethodHandler("discovery::GetPeers",
bind_weak(&DiscoveryComponent::GetPeersMessageHandler, shared_from_this()));
GetEndpointManager()->RegisterEndpoint(m_DiscoveryEndpoint);
2012-04-23 16:49:02 +02:00
}
void DiscoveryComponent::Stop(void)
{
EndpointManager::Ptr mgr = GetEndpointManager();
2012-04-23 16:49:02 +02:00
if (mgr)
2012-04-23 16:49:02 +02:00
mgr->UnregisterEndpoint(m_DiscoveryEndpoint);
}
2012-04-25 20:35:37 +02:00
int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& neea)
2012-04-23 16:49:02 +02:00
{
JsonRpcRequest request;
request.SetMethod("discovery::GetPeers");
2012-04-25 20:35:37 +02:00
GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, neea.Sender, request);
/* TODO: send information about this client to all other clients */
2012-04-23 16:49:02 +02:00
return 0;
}
int DiscoveryComponent::GetPeersMessageHandler(const NewRequestEventArgs& nrea)
{
/* TODO: send information about all available clients to this client */
return 0;
}