ApiFunction: store own name

This commit is contained in:
Alexander A. Klimov 2025-03-31 10:44:22 +02:00
parent 061338156c
commit ee0d9d1b55
2 changed files with 10 additions and 4 deletions

View File

@ -5,8 +5,8 @@
using namespace icinga;
ApiFunction::ApiFunction(Callback function)
: m_Callback(std::move(function))
ApiFunction::ApiFunction(const char* name, Callback function)
: m_Name(name), m_Callback(std::move(function))
{ }
Value ApiFunction::Invoke(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& arguments)

View File

@ -25,7 +25,12 @@ public:
typedef std::function<Value(const MessageOrigin::Ptr& origin, const Dictionary::Ptr&)> Callback;
ApiFunction(Callback function);
ApiFunction(const char* name, Callback function);
const char* GetName() const noexcept
{
return m_Name;
}
Value Invoke(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& arguments);
@ -33,6 +38,7 @@ public:
static void Register(const String& name, const ApiFunction::Ptr& function);
private:
const char* m_Name;
Callback m_Callback;
};
@ -49,7 +55,7 @@ public:
#define REGISTER_APIFUNCTION(name, ns, callback) \
INITIALIZE_ONCE([]() { \
ApiFunction::Ptr func = new ApiFunction(callback); \
ApiFunction::Ptr func = new ApiFunction(#ns "::" #name, callback); \
ApiFunctionRegistry::GetInstance()->Register(#ns "::" #name, func); \
})