mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
parent
5aacb42c41
commit
11710ef683
@ -52,8 +52,4 @@ void ScriptFunction::Unregister(const String& name)
|
||||
ScriptVariable::Unregister(name);
|
||||
}
|
||||
|
||||
RegisterFunctionHelper::RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function)
|
||||
{
|
||||
ScriptFunction::Register(name, new ScriptFunction(function));
|
||||
}
|
||||
|
||||
|
@ -53,19 +53,14 @@ private:
|
||||
Callback m_Callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class for registering ScriptFunction implementation classes.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_BASE_API RegisterFunctionHelper
|
||||
{
|
||||
public:
|
||||
RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function);
|
||||
};
|
||||
|
||||
#define REGISTER_SCRIPTFUNCTION(name, callback) \
|
||||
I2_EXPORT icinga::RegisterFunctionHelper g_RegisterSF_ ## name(#name, WrapScriptFunction(callback))
|
||||
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## name { \
|
||||
void RegisterFunction(void) { \
|
||||
ScriptFunction::Ptr sf = new icinga::ScriptFunction(WrapScriptFunction(callback)); \
|
||||
ScriptFunction::Register(#name, sf); \
|
||||
} \
|
||||
INITIALIZE_ONCE(RegisterFunction); \
|
||||
} } }
|
||||
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,6 @@ Value StatsFunction::Invoke(Dictionary::Ptr& status, Array::Ptr& perfdata)
|
||||
return m_Callback(status, perfdata);
|
||||
}
|
||||
|
||||
RegisterStatsFunctionHelper::RegisterStatsFunctionHelper(const String& name, const StatsFunction::Callback& function)
|
||||
{
|
||||
StatsFunction::Ptr func = new StatsFunction(function);
|
||||
StatsFunctionRegistry::GetInstance()->Register(name, func);
|
||||
}
|
||||
|
||||
StatsFunctionRegistry *StatsFunctionRegistry::GetInstance(void)
|
||||
{
|
||||
return Singleton<StatsFunctionRegistry>::GetInstance();
|
||||
|
@ -61,19 +61,15 @@ public:
|
||||
static StatsFunctionRegistry *GetInstance(void);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class for registering StatsFunction implementation classes.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_BASE_API RegisterStatsFunctionHelper
|
||||
{
|
||||
public:
|
||||
RegisterStatsFunctionHelper(const String& name, const StatsFunction::Callback& function);
|
||||
};
|
||||
|
||||
#define REGISTER_STATSFUNCTION(name, callback) \
|
||||
I2_EXPORT icinga::RegisterStatsFunctionHelper g_RegisterStF_ ## name(#name, callback)
|
||||
namespace { namespace UNIQUE_NAME(stf) { namespace stf ## name { \
|
||||
void RegisterStatsFunction(void) \
|
||||
{ \
|
||||
StatsFunction::Ptr stf = new StatsFunction(callback); \
|
||||
StatsFunctionRegistry::GetInstance()->Register(#name, stf); \
|
||||
} \
|
||||
INITIALIZE_ONCE(RegisterStatsFunction); \
|
||||
} } }
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,8 @@
|
||||
#include "base/logger.hpp"
|
||||
#include "base/type.hpp"
|
||||
#include "base/serializer.hpp"
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <algorithm>
|
||||
@ -139,13 +137,6 @@ void CLICommand::Unregister(const std::vector<String>& name)
|
||||
GetRegistry().erase(name);
|
||||
}
|
||||
|
||||
RegisterCLICommandHelper::RegisterCLICommandHelper(const String& name, const CLICommand::Ptr& command)
|
||||
{
|
||||
std::vector<String> vname;
|
||||
boost::algorithm::split(vname, name, boost::is_any_of("/"));
|
||||
CLICommand::Register(vname, command);
|
||||
}
|
||||
|
||||
std::vector<String> CLICommand::GetArgumentSuggestions(const String& argument, const String& word) const
|
||||
{
|
||||
return std::vector<String>();
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "base/type.hpp"
|
||||
#include <vector>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
@ -84,20 +86,15 @@ private:
|
||||
static std::map<std::vector<String>, CLICommand::Ptr>& GetRegistry(void);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class for registering CLICommand implementation classes.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_CLI_API RegisterCLICommandHelper
|
||||
{
|
||||
public:
|
||||
RegisterCLICommandHelper(const String& name, const CLICommand::Ptr& command);
|
||||
};
|
||||
|
||||
#define REGISTER_CLICOMMAND(name, klass) \
|
||||
namespace { namespace UNIQUE_NAME(cli) { \
|
||||
I2_EXPORT icinga::RegisterCLICommandHelper l_RegisterCLICommand(name, new klass()); \
|
||||
void RegisterCommand(void) \
|
||||
{ \
|
||||
std::vector<String> vname; \
|
||||
boost::algorithm::split(vname, name, boost::is_any_of("/")); \
|
||||
CLICommand::Register(vname, new klass()); \
|
||||
} \
|
||||
INITIALIZE_ONCE(RegisterCommand); \
|
||||
} }
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "base/objectlock.hpp"
|
||||
#include "base/json.hpp"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
@ -34,24 +33,6 @@ namespace po = boost::program_options;
|
||||
REGISTER_BLACKANDWHITELIST_CLICOMMAND(whitelist);
|
||||
REGISTER_BLACKANDWHITELIST_CLICOMMAND(blacklist);
|
||||
|
||||
RegisterBlackAndWhitelistCLICommandHelper::RegisterBlackAndWhitelistCLICommandHelper(const String& type)
|
||||
{
|
||||
String ltype = type;
|
||||
boost::algorithm::to_lower(ltype);
|
||||
|
||||
std::vector<String> name;
|
||||
name.push_back("node");
|
||||
name.push_back(ltype);
|
||||
name.push_back("add");
|
||||
CLICommand::Register(name, new BlackAndWhitelistCommand(type, BlackAndWhitelistCommandAdd));
|
||||
|
||||
name[2] = "remove";
|
||||
CLICommand::Register(name, new BlackAndWhitelistCommand(type, BlackAndWhitelistCommandRemove));
|
||||
|
||||
name[2] = "list";
|
||||
CLICommand::Register(name, new BlackAndWhitelistCommand(type, BlackAndWhitelistCommandList));
|
||||
}
|
||||
|
||||
BlackAndWhitelistCommand::BlackAndWhitelistCommand(const String& type, BlackAndWhitelistCommandType command)
|
||||
: m_Type(type), m_Command(command)
|
||||
{ }
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define BLACKANDWHITELISTCOMMAND_H
|
||||
|
||||
#include "cli/clicommand.hpp"
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
@ -55,21 +56,27 @@ private:
|
||||
BlackAndWhitelistCommandType m_Command;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class for registering repository CLICommand implementation classes.
|
||||
*
|
||||
* @ingroup cli
|
||||
*/
|
||||
class I2_CLI_API RegisterBlackAndWhitelistCLICommandHelper
|
||||
{
|
||||
public:
|
||||
RegisterBlackAndWhitelistCLICommandHelper(const String& type);
|
||||
};
|
||||
|
||||
#define REGISTER_BLACKANDWHITELIST_CLICOMMAND(type) \
|
||||
namespace { namespace UNIQUE_NAME(blackandwhitelist) { \
|
||||
I2_EXPORT icinga::RegisterBlackAndWhitelistCLICommandHelper l_RegisterBlackAndWhitelistCLICommand_ ## type(#type); \
|
||||
} }
|
||||
namespace { namespace UNIQUE_NAME(blackandwhitelist) { namespace blackandwhitelist ## type { \
|
||||
void RegisterCommand(void) \
|
||||
{ \
|
||||
String ltype = #type; \
|
||||
boost::algorithm::to_lower(ltype); \
|
||||
\
|
||||
std::vector<String> name; \
|
||||
name.push_back("node"); \
|
||||
name.push_back(ltype); \
|
||||
name.push_back("add"); \
|
||||
CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandAdd)); \
|
||||
\
|
||||
name[2] = "remove"; \
|
||||
CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandRemove)); \
|
||||
\
|
||||
name[2] = "list"; \
|
||||
CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandList)); \
|
||||
} \
|
||||
INITIALIZE_ONCE(RegisterCommand); \
|
||||
} } }
|
||||
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,6 @@
|
||||
#include "base/application.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
@ -36,24 +34,6 @@ REGISTER_REPOSITORY_CLICOMMAND(Service);
|
||||
REGISTER_REPOSITORY_CLICOMMAND(Zone);
|
||||
REGISTER_REPOSITORY_CLICOMMAND(Endpoint);
|
||||
|
||||
RegisterRepositoryCLICommandHelper::RegisterRepositoryCLICommandHelper(const String& type)
|
||||
{
|
||||
String ltype = type;
|
||||
boost::algorithm::to_lower(ltype);
|
||||
|
||||
std::vector<String> name;
|
||||
name.push_back("repository");
|
||||
name.push_back(ltype);
|
||||
name.push_back("add");
|
||||
CLICommand::Register(name, new RepositoryObjectCommand(type, RepositoryCommandAdd));
|
||||
|
||||
name[2] = "remove";
|
||||
CLICommand::Register(name, new RepositoryObjectCommand(type, RepositoryCommandRemove));
|
||||
|
||||
name[2] = "list";
|
||||
CLICommand::Register(name, new RepositoryObjectCommand(type, RepositoryCommandList));
|
||||
}
|
||||
|
||||
RepositoryObjectCommand::RepositoryObjectCommand(const String& type, RepositoryCommandType command)
|
||||
: m_Type(type), m_Command(command)
|
||||
{ }
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define REPOSITORYOBJECTCOMMAND_H
|
||||
|
||||
#include "cli/clicommand.hpp"
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
@ -59,21 +60,27 @@ private:
|
||||
RepositoryCommandType m_Command;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class for registering repository CLICommand implementation classes.
|
||||
*
|
||||
* @ingroup cli
|
||||
*/
|
||||
class I2_CLI_API RegisterRepositoryCLICommandHelper
|
||||
{
|
||||
public:
|
||||
RegisterRepositoryCLICommandHelper(const String& type);
|
||||
};
|
||||
|
||||
#define REGISTER_REPOSITORY_CLICOMMAND(type) \
|
||||
namespace { namespace UNIQUE_NAME(repositoryobject) { \
|
||||
I2_EXPORT icinga::RegisterRepositoryCLICommandHelper l_RegisterRepositoryCLICommand_ ## type(#type); \
|
||||
} }
|
||||
namespace { namespace UNIQUE_NAME(repositoryobject) { namespace repositoryobject ## type { \
|
||||
void RegisterCommand(void) \
|
||||
{ \
|
||||
String ltype = #type; \
|
||||
boost::algorithm::to_lower(ltype); \
|
||||
\
|
||||
std::vector<String> name; \
|
||||
name.push_back("repository"); \
|
||||
name.push_back(ltype); \
|
||||
name.push_back("add"); \
|
||||
CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandAdd)); \
|
||||
\
|
||||
name[2] = "remove"; \
|
||||
CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandRemove)); \
|
||||
\
|
||||
name[2] = "list"; \
|
||||
CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandList)); \
|
||||
} \
|
||||
INITIALIZE_ONCE(RegisterCommand); \
|
||||
} } }
|
||||
|
||||
}
|
||||
|
||||
|
@ -85,27 +85,6 @@ public:
|
||||
static DbTypeRegistry *GetInstance(void);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class for registering DynamicObject implementation classes.
|
||||
*
|
||||
* @ingroup ido
|
||||
*/
|
||||
class RegisterDbTypeHelper
|
||||
{
|
||||
public:
|
||||
RegisterDbTypeHelper(const String& name, const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory)
|
||||
{
|
||||
DbType::Ptr dbtype;
|
||||
|
||||
dbtype = DbType::GetByID(tid);
|
||||
|
||||
if (!dbtype)
|
||||
dbtype = new DbType(table, tid, idcolumn, factory);
|
||||
|
||||
DbType::RegisterType(name, dbtype);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Factory function for DbObject-based classes.
|
||||
*
|
||||
@ -118,7 +97,14 @@ intrusive_ptr<T> DbObjectFactory(const DbType::Ptr& type, const String& name1, c
|
||||
}
|
||||
|
||||
#define REGISTER_DBTYPE(name, table, tid, idcolumn, type) \
|
||||
I2_EXPORT icinga::RegisterDbTypeHelper g_RegisterDBT_ ## name(#name, table, tid, idcolumn, DbObjectFactory<type>);
|
||||
namespace { namespace UNIQUE_NAME(ido) { namespace ido ## name { \
|
||||
void RegisterDbType(void) \
|
||||
{ \
|
||||
DbType::Ptr dbtype = new DbType(table, tid, idcolumn, DbObjectFactory<type>); \
|
||||
DbType::RegisterType(#name, dbtype); \
|
||||
} \
|
||||
INITIALIZE_ONCE(RegisterDbType); \
|
||||
} } }
|
||||
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,6 @@ Value ApiFunction::Invoke(const MessageOrigin& origin, const Dictionary::Ptr& ar
|
||||
return m_Callback(origin, arguments);
|
||||
}
|
||||
|
||||
RegisterApiFunctionHelper::RegisterApiFunctionHelper(const String& name, const ApiFunction::Callback& function)
|
||||
{
|
||||
ApiFunction::Ptr func = new ApiFunction(function);
|
||||
ApiFunctionRegistry::GetInstance()->Register(name, func);
|
||||
}
|
||||
|
||||
ApiFunction::Ptr ApiFunction::GetByName(const String& name)
|
||||
{
|
||||
return ApiFunctionRegistry::GetInstance()->GetItem(name);
|
||||
|
@ -78,7 +78,14 @@ public:
|
||||
};
|
||||
|
||||
#define REGISTER_APIFUNCTION(name, ns, callback) \
|
||||
I2_EXPORT icinga::RegisterApiFunctionHelper g_RegisterAF_ ## name(#ns "::" #name, callback)
|
||||
namespace { namespace UNIQUE_NAME(apif) { namespace apif ## name { \
|
||||
void RegisterFunction(void) \
|
||||
{ \
|
||||
ApiFunction::Ptr func = new ApiFunction(callback); \
|
||||
ApiFunctionRegistry::GetInstance()->Register(#ns "::" #name, func); \
|
||||
} \
|
||||
INITIALIZE_ONCE(RegisterFunction); \
|
||||
} } }
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user