icinga2/icinga/virtualendpoint.cpp

93 lines
3.3 KiB
C++
Raw Normal View History

/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
2012-05-11 13:33:57 +02:00
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "i2-icinga.h"
using namespace icinga;
2012-04-23 13:45:41 +02:00
string VirtualEndpoint::GetAddress(void) const
{
char address[50];
2012-05-10 13:17:15 +02:00
sprintf(address, "virtual:%p", (void *)this);
2012-04-23 13:45:41 +02:00
return address;
}
2012-04-18 15:22:25 +02:00
bool VirtualEndpoint::IsLocal(void) const
{
return true;
}
bool VirtualEndpoint::IsConnected(void) const
{
return true;
}
2012-06-16 03:42:54 +02:00
void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
{
2012-06-16 03:42:54 +02:00
map<string, shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
it = m_TopicHandlers.find(topic);
2012-06-16 03:42:54 +02:00
shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > sig;
if (it == m_TopicHandlers.end()) {
2012-06-16 03:42:54 +02:00
sig = boost::make_shared<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> >();
m_TopicHandlers.insert(make_pair(topic, sig));
} else {
sig = it->second;
}
sig->connect(callback);
2012-04-16 16:27:41 +02:00
RegisterSubscription(topic);
}
2012-06-16 03:42:54 +02:00
void VirtualEndpoint::UnregisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
{
// TODO: implement
//m_TopicHandlers[method] -= callback;
//UnregisterMethodSubscription(method);
2012-04-16 16:27:41 +02:00
throw NotImplementedException();
}
void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage& request)
{
2012-04-16 16:27:41 +02:00
string method;
2012-04-18 15:22:25 +02:00
if (!request.GetMethod(&method))
2012-04-16 16:27:41 +02:00
return;
2012-06-16 03:42:54 +02:00
map<string, shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
it = m_TopicHandlers.find(method);
2012-04-16 16:27:41 +02:00
if (it == m_TopicHandlers.end())
2012-04-19 08:46:41 +02:00
return;
2012-04-16 16:27:41 +02:00
2012-06-16 03:42:54 +02:00
(*it->second)(shared_from_this(), sender, request);
}
void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& response)
{
GetEndpointManager()->ProcessResponseMessage(sender, response);
}
2012-04-23 13:45:41 +02:00
void VirtualEndpoint::Stop(void)
{
/* Nothing to do here. */
}