2012-07-14 15:59:59 +02:00
|
|
|
#include "i2-base.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
map<String, ScriptFunction::Ptr> ScriptFunction::m_Functions;
|
2012-07-14 15:59:59 +02:00
|
|
|
|
|
|
|
ScriptFunction::ScriptFunction(const Callback& function)
|
|
|
|
: m_Callback(function)
|
|
|
|
{ }
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void ScriptFunction::Register(const String& name, const ScriptFunction::Ptr& function)
|
2012-07-14 15:59:59 +02:00
|
|
|
{
|
|
|
|
m_Functions[name] = function;
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void ScriptFunction::Unregister(const String& name)
|
2012-07-14 15:59:59 +02:00
|
|
|
{
|
|
|
|
m_Functions.erase(name);
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
ScriptFunction::Ptr ScriptFunction::GetByName(const String& name)
|
2012-07-14 15:59:59 +02:00
|
|
|
{
|
2012-08-02 09:38:08 +02:00
|
|
|
map<String, ScriptFunction::Ptr>::iterator it;
|
2012-07-14 15:59:59 +02:00
|
|
|
|
|
|
|
it = m_Functions.find(name);
|
|
|
|
|
|
|
|
if (it == m_Functions.end())
|
|
|
|
return ScriptFunction::Ptr();
|
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void ScriptFunction::Invoke(const ScriptTask::Ptr& task, const vector<Value>& arguments)
|
2012-07-14 15:59:59 +02:00
|
|
|
{
|
|
|
|
m_Callback(task, arguments);
|
|
|
|
}
|