2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* 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. *
|
2012-05-10 12:06:41 +02:00
|
|
|
******************************************************************************/
|
|
|
|
|
2012-04-06 08:56:52 +02:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2012-04-27 13:44:53 +02:00
|
|
|
bool VirtualEndpoint::IsConnected(void) const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-16 13:06:06 +02:00
|
|
|
void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
|
2012-04-06 08:56:52 +02:00
|
|
|
{
|
2012-06-16 13:06:06 +02:00
|
|
|
map<string, shared_ptr<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
|
2012-06-14 15:16:41 +02:00
|
|
|
it = m_TopicHandlers.find(topic);
|
|
|
|
|
2012-06-16 13:06:06 +02:00
|
|
|
shared_ptr<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > sig;
|
2012-06-14 15:16:41 +02:00
|
|
|
|
|
|
|
if (it == m_TopicHandlers.end()) {
|
2012-06-16 13:06:06 +02:00
|
|
|
sig = boost::make_shared<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> >();
|
2012-06-14 15:16:41 +02:00
|
|
|
m_TopicHandlers.insert(make_pair(topic, sig));
|
|
|
|
} else {
|
|
|
|
sig = it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
sig->connect(callback);
|
2012-04-16 16:27:41 +02:00
|
|
|
|
2012-05-15 16:24:04 +02:00
|
|
|
RegisterSubscription(topic);
|
2012-04-06 08:56:52 +02:00
|
|
|
}
|
|
|
|
|
2012-06-16 13:06:06 +02:00
|
|
|
void VirtualEndpoint::UnregisterTopicHandler(string topic, function<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
|
2012-04-06 08:56:52 +02:00
|
|
|
{
|
|
|
|
// TODO: implement
|
2012-05-15 16:24:04 +02:00
|
|
|
//m_TopicHandlers[method] -= callback;
|
|
|
|
//UnregisterMethodSubscription(method);
|
2012-04-06 08:56:52 +02:00
|
|
|
|
2012-04-16 16:27:41 +02:00
|
|
|
throw NotImplementedException();
|
2012-04-06 08:56:52 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 12:53:38 +02:00
|
|
|
void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage& request)
|
2012-04-06 08:56:52 +02:00
|
|
|
{
|
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 13:06:06 +02:00
|
|
|
map<string, shared_ptr<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
|
2012-06-14 15:16:41 +02:00
|
|
|
it = m_TopicHandlers.find(method);
|
2012-04-16 16:27:41 +02:00
|
|
|
|
2012-06-14 15:16: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 13:06:06 +02:00
|
|
|
(*it->second)(GetSelf(), sender, request);
|
2012-04-06 08:56:52 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 12:53:38 +02:00
|
|
|
void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& response)
|
2012-04-06 08:56:52 +02:00
|
|
|
{
|
2012-06-14 11:18:20 +02:00
|
|
|
GetEndpointManager()->ProcessResponseMessage(sender, response);
|
2012-04-06 08:56:52 +02:00
|
|
|
}
|
2012-04-23 13:45:41 +02:00
|
|
|
|
2012-04-27 11:44:34 +02:00
|
|
|
void VirtualEndpoint::Stop(void)
|
|
|
|
{
|
|
|
|
/* Nothing to do here. */
|
|
|
|
}
|