icinga2/icinga/virtualendpoint.cpp

85 lines
2.8 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-04-18 15:22:25 +02:00
void VirtualEndpoint::RegisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback)
{
m_MethodHandlers[method] += callback;
2012-04-16 16:27:41 +02:00
RegisterMethodSink(method);
}
2012-04-18 15:22:25 +02:00
void VirtualEndpoint::UnregisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback)
{
// TODO: implement
2012-04-16 16:27:41 +02:00
//m_MethodHandlers[method] -= callback;
//UnregisterMethodSink(method);
2012-04-16 16:27:41 +02:00
throw NotImplementedException();
}
2012-04-18 15:22:25 +02:00
void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& 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-04-18 15:22:25 +02:00
map<string, Event<NewRequestEventArgs> >::iterator i = m_MethodHandlers.find(method);
2012-04-16 16:27:41 +02:00
if (i == m_MethodHandlers.end())
2012-04-19 08:46:41 +02:00
return;
2012-04-16 16:27:41 +02:00
2012-04-18 15:22:25 +02:00
NewRequestEventArgs nrea;
nrea.Source = shared_from_this();
nrea.Sender = sender;
nrea.Request = request;
2012-04-16 16:27:41 +02:00
i->second(nrea);
}
2012-04-18 15:22:25 +02:00
void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& response)
{
2012-04-16 16:27:41 +02:00
// TODO: figure out which request this response belongs to and notify the caller
throw NotImplementedException();
}
2012-04-23 13:45:41 +02:00
void VirtualEndpoint::Stop(void)
{
/* Nothing to do here. */
}