using namespace icinga;
-IcingaApplication::Ptr ConfigRpcComponent::GetIcingaApplication(void)
-{
- return static_pointer_cast<IcingaApplication>(GetApplication());
-}
-
string ConfigRpcComponent::GetName(void) const
{
return "configcomponent";
void ConfigRpcComponent::Start(void)
{
- IcingaApplication::Ptr icingaApp = GetIcingaApplication();
-
- EndpointManager::Ptr endpointManager = icingaApp->GetEndpointManager();
- ConfigHive::Ptr configHive = icingaApp->GetConfigHive();
+ EndpointManager::Ptr endpointManager = GetEndpointManager();
+ ConfigHive::Ptr configHive = GetConfigHive();
m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
JsonRpcRequest request;
request.SetMethod("config::FetchObjects");
- EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
- endpointManager->SendUnicastRequest(m_ConfigRpcEndpoint, ea.Endpoint, request);
+ GetEndpointManager()->SendUnicastRequest(m_ConfigRpcEndpoint, ea.Endpoint, request);
}
return 0;
int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
{
Endpoint::Ptr client = ea.Sender;
- ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
+ ConfigHive::Ptr configHive = GetConfigHive();
for (ConfigHive::CollectionIterator ci = configHive->Collections.begin(); ci != configHive->Collections.end(); ci++) {
ConfigCollection::Ptr collection = ci->second;
JsonRpcRequest request = MakeObjectMessage(object, "config::ObjectCreated", true);
- EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
- endpointManager->SendUnicastRequest(m_ConfigRpcEndpoint, client, request);
+ GetEndpointManager()->SendUnicastRequest(m_ConfigRpcEndpoint, client, request);
}
}
if (!ShouldReplicateObject(object))
return 0;
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
- mgr->SendMulticastRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectCreated", true));
+ GetEndpointManager()->SendMulticastRequest(m_ConfigRpcEndpoint,
+ MakeObjectMessage(object, "config::ObjectCreated", true));
return 0;
}
if (!ShouldReplicateObject(object))
return 0;
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
- mgr->SendMulticastRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectRemoved", false));
+ GetEndpointManager()->SendMulticastRequest(m_ConfigRpcEndpoint,
+ MakeObjectMessage(object, "config::ObjectRemoved", false));
return 0;
}
properties.GetDictionary()->SetPropertyString(ea.Property, value);
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
- mgr->SendMulticastRequest(m_ConfigRpcEndpoint, msg);
+ GetEndpointManager()->SendMulticastRequest(m_ConfigRpcEndpoint, msg);
return 0;
}
if (!params.GetDictionary()->GetPropertyString("type", &type))
return 0;
- ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
+ ConfigHive::Ptr configHive = GetConfigHive();
ConfigObject::Ptr object = configHive->GetObject(type, name);
if (!object) {
if (!params.GetDictionary()->GetPropertyString("type", &type))
return 0;
- ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
+ ConfigHive::Ptr configHive = GetConfigHive();
ConfigObject::Ptr object = configHive->GetObject(type, name);
if (!object)
namespace icinga
{
-class ConfigRpcComponent : public Component
+class ConfigRpcComponent : public IcingaComponent
{
private:
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
- IcingaApplication::Ptr GetIcingaApplication(void);
-
int NewEndpointHandler(const NewEndpointEventArgs& ea);
int WelcomeMessageHandler(const NewRequestEventArgs& ea);
{
m_DemoEndpoint = make_shared<VirtualEndpoint>();
m_DemoEndpoint->RegisterMethodHandler("demo::HelloWorld",
- bind_weak(&DemoComponent::HelloWorldRequestHAndler, shared_from_this()));
+ bind_weak(&DemoComponent::HelloWorldRequestHandler, shared_from_this()));
m_DemoEndpoint->RegisterMethodSource("demo::HelloWorld");
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
endpointManager->ForeachEndpoint(bind(&DemoComponent::NewEndpointHandler, this, _1));
m_DemoTimer = make_shared<Timer>();
- m_DemoTimer->SetInterval(1);
+ m_DemoTimer->SetInterval(5);
m_DemoTimer->OnTimerExpired += bind_weak(&DemoComponent::DemoTimerHandler, shared_from_this());
m_DemoTimer->Start();
}
return 0;
}
-int DemoComponent::HelloWorldRequestHAndler(const NewRequestEventArgs& nrea)
+int DemoComponent::HelloWorldRequestHandler(const NewRequestEventArgs& nrea)
{
- cout << "Got Hello World from " << nrea.Sender->GetAddress() << endl;
+ cout << "Got 'hello world' from " << nrea.Sender->GetAddress() << endl;
return 0;
}
int DemoTimerHandler(const TimerEventArgs& tea);
int NewEndpointHandler(const NewEndpointEventArgs& neea);
- int HelloWorldRequestHAndler(const NewRequestEventArgs& nrea);
+ int HelloWorldRequestHandler(const NewRequestEventArgs& nrea);
public:
virtual string GetName(void) const;
endpointmanager.h \
icingaapplication.cpp \
icingaapplication.h \
+ icingacomponent.cpp \
+ icingacomponent.h \
identitymessage.cpp \
identitymessage.h \
i2-icinga.h \
using namespace icinga;
-IcingaApplication::Ptr AuthenticationComponent::GetIcingaApplication(void) const
-{
- return static_pointer_cast<IcingaApplication>(GetApplication());
-}
-
string AuthenticationComponent::GetName(void) const
{
return "authenticationcomponent";
m_AuthenticationEndpoint->RegisterMethodHandler("auth::SetIdentity", bind_weak(&AuthenticationComponent::IdentityMessageHandler, shared_from_this()));
m_AuthenticationEndpoint->RegisterMethodSource("auth::Welcome");
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
+ EndpointManager::Ptr mgr = GetEndpointManager();
mgr->OnNewEndpoint += bind_weak(&AuthenticationComponent::NewEndpointHandler, shared_from_this());
mgr->ForeachEndpoint(bind(&AuthenticationComponent::NewEndpointHandler, this, _1));
mgr->RegisterEndpoint(m_AuthenticationEndpoint);
void AuthenticationComponent::Stop(void)
{
- IcingaApplication::Ptr app = GetIcingaApplication();
+ EndpointManager::Ptr mgr = GetEndpointManager();
- if (app) {
- EndpointManager::Ptr mgr = app->GetEndpointManager();
+ if (mgr)
mgr->UnregisterEndpoint(m_AuthenticationEndpoint);
- }
}
int AuthenticationComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
params.SetIdentity("keks");
request.SetParams(params);
- EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
- endpointManager->SendUnicastRequest(m_AuthenticationEndpoint, neea.Endpoint, request);
+ GetEndpointManager()->SendUnicastRequest(m_AuthenticationEndpoint, neea.Endpoint, request);
return 0;
}
JsonRpcRequest request;
request.SetMethod("auth::Welcome");
- EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
- endpointManager->SendUnicastRequest(m_AuthenticationEndpoint, nrea.Sender, request);
+ GetEndpointManager()->SendUnicastRequest(m_AuthenticationEndpoint, nrea.Sender, request);
return 0;
}
namespace icinga
{
-class AuthenticationComponent : public Component
+class AuthenticationComponent : public IcingaComponent
{
private:
VirtualEndpoint::Ptr m_AuthenticationEndpoint;
- IcingaApplication::Ptr GetIcingaApplication(void) const;
-
int NewEndpointHandler(const NewEndpointEventArgs& neea);
int IdentityMessageHandler(const NewRequestEventArgs& nrea);
using namespace icinga;
-IcingaApplication::Ptr DiscoveryComponent::GetIcingaApplication(void) const
-{
- return static_pointer_cast<IcingaApplication>(GetApplication());
-}
-
string DiscoveryComponent::GetName(void) const
{
return "discoverycomponent";
m_DiscoveryEndpoint->RegisterMethodHandler("discovery::GetPeers",
bind_weak(&DiscoveryComponent::GetPeersMessageHandler, shared_from_this()));
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
- mgr->RegisterEndpoint(m_DiscoveryEndpoint);
+ GetEndpointManager()->RegisterEndpoint(m_DiscoveryEndpoint);
}
void DiscoveryComponent::Stop(void)
{
- IcingaApplication::Ptr app = GetIcingaApplication();
+ EndpointManager::Ptr mgr = GetEndpointManager();
- if (app) {
- EndpointManager::Ptr mgr = app->GetEndpointManager();
+ if (mgr)
mgr->UnregisterEndpoint(m_DiscoveryEndpoint);
- }
}
int DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
JsonRpcRequest request;
request.SetMethod("discovery::GetPeers");
- EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
- endpointManager->SendUnicastRequest(m_DiscoveryEndpoint, nrea.Sender, request);
+ GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, nrea.Sender, request);
return 0;
}
namespace icinga
{
-class DiscoveryComponent : public Component
+class DiscoveryComponent : public IcingaComponent
{
private:
VirtualEndpoint::Ptr m_DiscoveryEndpoint;
#include "virtualendpoint.h"
#include "endpointmanager.h"
#include "icingaapplication.h"
+#include "icingacomponent.h"
#include "subscriptioncomponent.h"
#include "subscriptionmessage.h"
#include "authenticationcomponent.h"
<ClCompile Include="endpoint.cpp" />
<ClCompile Include="endpointmanager.cpp" />
<ClCompile Include="icingaapplication.cpp" />
+ <ClCompile Include="icingacomponent.cpp" />
<ClCompile Include="identitymessage.cpp" />
<ClCompile Include="jsonrpcendpoint.cpp" />
<ClCompile Include="subscriptioncomponent.cpp" />
<ClInclude Include="endpointmanager.h" />
<ClInclude Include="i2-icinga.h" />
<ClInclude Include="icingaapplication.h" />
+ <ClInclude Include="icingacomponent.h" />
<ClInclude Include="identitymessage.h" />
<ClInclude Include="jsonrpcendpoint.h" />
<ClInclude Include="subscriptioncomponent.h" />
--- /dev/null
+#include "i2-icinga.h"
+
+using namespace icinga;
+
+IcingaApplication::Ptr IcingaComponent::GetIcingaApplication(void) const
+{
+ return static_pointer_cast<IcingaApplication>(GetApplication());
+}
+
+EndpointManager::Ptr IcingaComponent::GetEndpointManager(void) const
+{
+ IcingaApplication::Ptr app = GetIcingaApplication();
+
+ if (!app)
+ return EndpointManager::Ptr();
+
+ return app->GetEndpointManager();
+}
+
+ConfigHive::Ptr IcingaComponent::GetConfigHive(void) const
+{
+ IcingaApplication::Ptr app = GetIcingaApplication();
+
+ if (!app)
+ return ConfigHive::Ptr();
+
+ return app->GetConfigHive();
+}
--- /dev/null
+#ifndef ICINGACOMPONENT_H
+#define ICINGACOMPONENT_H
+
+namespace icinga
+{
+
+class I2_ICINGA_API IcingaComponent : public Component
+{
+protected:
+ IcingaApplication::Ptr GetIcingaApplication(void) const;
+ EndpointManager::Ptr GetEndpointManager(void) const;
+ ConfigHive::Ptr GetConfigHive(void) const;
+};
+
+}
+
+#endif /* ICINGACOMPONENT_H */
using namespace icinga;
-IcingaApplication::Ptr SubscriptionComponent::GetIcingaApplication(void) const
-{
- return static_pointer_cast<IcingaApplication>(GetApplication());
-}
-
string SubscriptionComponent::GetName(void) const
{
return "subscriptioncomponent";
m_SubscriptionEndpoint->RegisterMethodSource("message::Subscribe");
m_SubscriptionEndpoint->RegisterMethodSource("message::Provide");
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
+ EndpointManager::Ptr mgr = GetEndpointManager();
mgr->OnNewEndpoint += bind_weak(&SubscriptionComponent::NewEndpointHandler, shared_from_this());
mgr->ForeachEndpoint(bind(&SubscriptionComponent::NewEndpointHandler, this, _1));
mgr->RegisterEndpoint(m_SubscriptionEndpoint);
void SubscriptionComponent::Stop(void)
{
- IcingaApplication::Ptr app = GetIcingaApplication();
+ EndpointManager::Ptr mgr = GetEndpointManager();
- if (app) {
- EndpointManager::Ptr mgr = app->GetEndpointManager();
+ if (mgr)
mgr->UnregisterEndpoint(m_SubscriptionEndpoint);
- }
}
int SubscriptionComponent::SyncSubscription(Endpoint::Ptr target, string type, const NewMethodEventArgs& nmea)
subscriptionMessage.SetMethod(nmea.Method);
request.SetParams(subscriptionMessage);
- EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
- endpointManager->SendUnicastRequest(m_SubscriptionEndpoint, target, request);
+ GetEndpointManager()->SendUnicastRequest(m_SubscriptionEndpoint, target, request);
return 0;
}
neea.Endpoint->RegisterMethodSink("message::Subscribe");
neea.Endpoint->RegisterMethodSink("message::Provide");
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
- mgr->ForeachEndpoint(bind(&SubscriptionComponent::SyncSubscriptions, this, neea.Endpoint, _1));
+ GetEndpointManager()->ForeachEndpoint(bind(&SubscriptionComponent::SyncSubscriptions, this, neea.Endpoint, _1));
return 0;
}
namespace icinga
{
-class SubscriptionComponent : public Component
+class SubscriptionComponent : public IcingaComponent
{
private:
VirtualEndpoint::Ptr m_SubscriptionEndpoint;
- IcingaApplication::Ptr GetIcingaApplication(void) const;
-
int NewEndpointHandler(const NewEndpointEventArgs& neea);
int SubscribeMessageHandler(const NewRequestEventArgs& nrea);
int ProvideMessageHandler(const NewRequestEventArgs& nrea);