if (ea.Endpoint->HasIdentity()) {
JsonRpcRequest request;
request.SetMethod("config::FetchObjects");
- ea.Endpoint->ProcessRequest(m_ConfigRpcEndpoint, request);
+
+ EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
+ endpointManager->SendUnicastRequest(m_ConfigRpcEndpoint, ea.Endpoint, request);
}
return 0;
if (!ShouldReplicateObject(object))
continue;
- client->ProcessRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectCreated", true));
+ JsonRpcRequest request = MakeObjectMessage(object, "config::ObjectCreated", true);
+
+ EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
+ endpointManager->SendUnicastRequest(m_ConfigRpcEndpoint, client, request);
}
}
{
m_AuthenticationEndpoint = make_shared<VirtualEndpoint>();
m_AuthenticationEndpoint->RegisterMethodHandler("auth::SetIdentity", bind_weak(&AuthenticationComponent::IdentityMessageHandler, shared_from_this()));
+ m_AuthenticationEndpoint->RegisterMethodSource("auth::Welcome");
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
mgr->OnNewEndpoint += bind_weak(&AuthenticationComponent::NewEndpointHandler, shared_from_this());
params.SetIdentity("keks");
request.SetParams(params);
- neea.Endpoint->ProcessRequest(m_AuthenticationEndpoint, request);
+ EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
+ endpointManager->SendUnicastRequest(m_AuthenticationEndpoint, neea.Endpoint, request);
return 0;
}
/* there's no authentication for now, just tell them it's ok to send messages */
JsonRpcRequest request;
request.SetMethod("auth::Welcome");
- nrea.Sender->ProcessRequest(m_AuthenticationEndpoint, request);
+
+ EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
+ endpointManager->SendUnicastRequest(m_AuthenticationEndpoint, nrea.Sender, request);
return 0;
}
--- /dev/null
+#include "i2-icinga.h"
+
+using namespace icinga;
+
+IcingaApplication::Ptr DiscoveryComponent::GetIcingaApplication(void) const
+{
+ return static_pointer_cast<IcingaApplication>(GetApplication());
+}
+
+string DiscoveryComponent::GetName(void) const
+{
+ return "discoverycomponent";
+}
+
+void DiscoveryComponent::Start(void)
+{
+ m_DiscoveryEndpoint = make_shared<VirtualEndpoint>();
+ m_DiscoveryEndpoint->RegisterMethodSource("discovery::PeerAvailable");
+ m_DiscoveryEndpoint->RegisterMethodHandler("auth::Welcome",
+ bind_weak(&DiscoveryComponent::WelcomeMessageHandler, shared_from_this()));
+ m_DiscoveryEndpoint->RegisterMethodHandler("discovery::GetPeers",
+ bind_weak(&DiscoveryComponent::GetPeersMessageHandler, shared_from_this()));
+
+ EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
+ mgr->RegisterEndpoint(m_DiscoveryEndpoint);
+}
+
+void DiscoveryComponent::Stop(void)
+{
+ IcingaApplication::Ptr app = GetIcingaApplication();
+
+ if (app) {
+ EndpointManager::Ptr mgr = app->GetEndpointManager();
+ mgr->UnregisterEndpoint(m_DiscoveryEndpoint);
+ }
+}
+
+int DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
+{
+ neea.Endpoint->OnIdentityChanged += bind_weak(&DiscoveryComponent::IdentityChangedHandler, shared_from_this());
+
+ /* TODO: register handler for new sink/source */
+
+ return 0;
+}
+
+int DiscoveryComponent::IdentityChangedHandler(const EventArgs& neea)
+{
+ /* TODO: send information about this client to all other clients */
+
+ return 0;
+}
+
+int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
+{
+ JsonRpcRequest request;
+ request.SetMethod("discovery::GetPeers");
+
+ EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
+ endpointManager->SendUnicastRequest(m_DiscoveryEndpoint, nrea.Sender, request);
+
+ return 0;
+}
+
+int DiscoveryComponent::GetPeersMessageHandler(const NewRequestEventArgs& nrea)
+{
+ /* TODO: send information about all available clients to this client */
+
+ return 0;
+}
--- /dev/null
+#ifndef DISCOVERYCOMPONENT_H
+#define DISCOVERYCOMPONENT_H
+
+namespace icinga
+{
+
+class DiscoveryComponent : public Component
+{
+private:
+ VirtualEndpoint::Ptr m_DiscoveryEndpoint;
+
+ IcingaApplication::Ptr GetIcingaApplication(void) const;
+
+ int NewEndpointHandler(const NewEndpointEventArgs& neea);
+ int IdentityChangedHandler(const EventArgs& neea);
+ int WelcomeMessageHandler(const NewRequestEventArgs& nrea);
+ int GetPeersMessageHandler(const NewRequestEventArgs& nrea);
+
+public:
+ virtual string GetName(void) const;
+ virtual void Start(void);
+ virtual void Stop(void);
+};
+
+}
+
+#endif /* DISCOVERYCOMPONENT_H */
void Endpoint::SetIdentity(string identity)
{
m_Identity = identity;
+
+ EventArgs ea;
+ ea.Source = shared_from_this();
+ OnIdentityChanged(ea);
}
bool Endpoint::HasIdentity(void) const
int CountMethodSinks(void) const;
int CountMethodSources(void) const;
+
+ Event<EventArgs> OnIdentityChanged;
};
}
#include "subscriptionmessage.h"
#include "authenticationcomponent.h"
#include "identitymessage.h"
+#include "discoverycomponent.h"
#endif /* I2ICINGA_H */
</ItemGroup>
<ItemGroup>
<ClCompile Include="authenticationcomponent.cpp" />
+ <ClCompile Include="discoverycomponent.cpp" />
<ClCompile Include="endpoint.cpp" />
<ClCompile Include="endpointmanager.cpp" />
<ClCompile Include="icingaapplication.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="authenticationcomponent.h" />
+ <ClInclude Include="discoverycomponent.h" />
<ClInclude Include="endpoint.h" />
<ClInclude Include="endpointmanager.h" />
<ClInclude Include="i2-icinga.h" />