1 /******************************************************************************
3 * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
22 using namespace icinga;
25 * Returns the name of the component.
29 string DemoComponent::GetName(void) const
31 return "democomponent";
35 * Starts the component.
37 void DemoComponent::Start(void)
39 m_DemoEndpoint = make_shared<VirtualEndpoint>();
40 m_DemoEndpoint->RegisterTopicHandler("demo::HelloWorld",
41 bind_weak(&DemoComponent::HelloWorldRequestHandler, shared_from_this()));
42 m_DemoEndpoint->RegisterPublication("demo::HelloWorld");
43 GetEndpointManager()->RegisterEndpoint(m_DemoEndpoint);
45 m_DemoTimer = make_shared<Timer>();
46 m_DemoTimer->SetInterval(5);
47 m_DemoTimer->OnTimerExpired += bind_weak(&DemoComponent::DemoTimerHandler, shared_from_this());
52 * Stops the component.
54 void DemoComponent::Stop(void)
56 IcingaApplication::Ptr app = GetIcingaApplication();
59 EndpointManager::Ptr endpointManager = app->GetEndpointManager();
60 endpointManager->UnregisterEndpoint(m_DemoEndpoint);
65 * Periodically sends a demo::HelloWorld message.
67 * @param - Event arguments for the timer.
70 int DemoComponent::DemoTimerHandler(const TimerEventArgs&)
72 Application::Log("Sending multicast 'hello world' message.");
74 RequestMessage request;
75 request.SetMethod("demo::HelloWorld");
77 EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
78 endpointManager->SendMulticastMessage(m_DemoEndpoint, request);
84 * Processes demo::HelloWorld messages.
86 int DemoComponent::HelloWorldRequestHandler(const NewRequestEventArgs& nrea)
88 Application::Log("Got 'hello world' from address=" + nrea.Sender->GetAddress() + ", identity=" + nrea.Sender->GetIdentity());
93 EXPORT_COMPONENT(demo, DemoComponent);