2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-04-25 14:33:45 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/apifunction.hpp"
|
|
|
|
#include "base/singleton.hpp"
|
2014-04-25 14:33:45 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
ApiFunction::ApiFunction(Callback function)
|
|
|
|
: m_Callback(std::move(function))
|
2014-05-03 20:02:22 +02:00
|
|
|
{ }
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
Value ApiFunction::Invoke(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& arguments)
|
2014-04-25 14:33:45 +02:00
|
|
|
{
|
2014-05-03 20:02:22 +02:00
|
|
|
return m_Callback(origin, arguments);
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
ApiFunction::Ptr ApiFunction::GetByName(const String& name)
|
|
|
|
{
|
|
|
|
return ApiFunctionRegistry::GetInstance()->GetItem(name);
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
void ApiFunction::Register(const String& name, const ApiFunction::Ptr& function)
|
2014-04-25 14:33:45 +02:00
|
|
|
{
|
2014-05-03 20:02:22 +02:00
|
|
|
ApiFunctionRegistry::GetInstance()->Register(name, function);
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
void ApiFunction::Unregister(const String& name)
|
2014-04-25 14:33:45 +02:00
|
|
|
{
|
2014-05-03 20:02:22 +02:00
|
|
|
ApiFunctionRegistry::GetInstance()->Unregister(name);
|
|
|
|
}
|
2014-04-25 14:33:45 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ApiFunctionRegistry *ApiFunctionRegistry::GetInstance()
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
|
|
|
return Singleton<ApiFunctionRegistry>::GetInstance();
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|