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