Use lambda functions for INITIALIZE_ONCE

fixes #12562
This commit is contained in:
Gunnar Beutner 2016-08-27 09:35:08 +02:00
parent 5058c5d75b
commit b5b09216c6
50 changed files with 185 additions and 354 deletions

View File

@ -217,9 +217,8 @@ include(CheckIncludeFileCXX)
check_symbol_exists(__COUNTER__ "" HAVE_COUNTER_MACRO)
if(NOT HAVE_COUNTER_MACRO AND ICINGA2_UNITY_BUILD)
message(STATUS "Your C/C++ compiler does not support the __COUNTER__ macro. Disabling unity build.")
set(ICINGA2_UNITY_BUILD FALSE)
if(NOT HAVE_COUNTER_MACRO)
message(FATAL_ERROR "Your C/C++ compiler does not support the __COUNTER__ macro.")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DI2_DEBUG")

View File

@ -1,7 +1,6 @@
#ifndef CONFIG_H
#define CONFIG_H
#cmakedefine HAVE_COUNTER_MACRO
#cmakedefine HAVE_BACKTRACE_SYMBOLS
#cmakedefine HAVE_PIPE2
#cmakedefine HAVE_VFORK

View File

@ -23,10 +23,19 @@
using namespace icinga;
INITIALIZE_ONCE(&Console::DetectType);
static ConsoleType l_ConsoleType = Console_Dumb;
INITIALIZE_ONCE([]() {
l_ConsoleType = Console_Dumb;
#ifndef _WIN32
if (isatty(1))
l_ConsoleType = Console_VT100;
#else /* _WIN32 */
l_ConsoleType = Console_Windows;
#endif /* _WIN32 */
});
ConsoleColorTag::ConsoleColorTag(int color, ConsoleType consoleType)
: m_Color(color), m_ConsoleType(consoleType)
{ }
@ -46,18 +55,6 @@ std::ostream& icinga::operator<<(std::ostream& fp, const ConsoleColorTag& cct)
return fp;
}
void Console::DetectType(void)
{
l_ConsoleType = Console_Dumb;
#ifndef _WIN32
if (isatty(1))
l_ConsoleType = Console_VT100;
#else /* _WIN32 */
l_ConsoleType = Console_Windows;
#endif /* _WIN32 */
}
void Console::SetType(std::ostream& fp, ConsoleType type)
{
if (&fp == &std::cout || &fp == &std::cerr)

View File

@ -67,66 +67,48 @@ private:
};
#define REGISTER_SCRIPTFUNCTION_NS(ns, name, callback) \
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
void RegisterFunction(void) { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
ScriptGlobal::Set(#ns "." #name, sf); \
} \
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
} } }
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
ScriptGlobal::Set(#ns "." #name, sf); \
}, 10)
#define REGISTER_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback) \
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
void RegisterFunction(void) { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
ScriptGlobal::Set(#ns "." #name, sf); \
Function::Ptr dsf = new icinga::Function("Deprecated#__" #name " (deprecated)", WrapFunction(callback), false, true); \
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
} \
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
} } }
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
ScriptGlobal::Set(#ns "." #name, sf); \
Function::Ptr dsf = new icinga::Function("Deprecated#__" #name " (deprecated)", WrapFunction(callback), false, true); \
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
}, 10)
#define REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
void RegisterFunction(void) { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
ScriptGlobal::Set(#ns "." #name, sf); \
Function::Ptr dsf = new icinga::Function("Deprecated#" #name " (deprecated)", WrapFunction(callback), false, true); \
ScriptGlobal::Set("Deprecated." #name, dsf); \
} \
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
} } }
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
ScriptGlobal::Set(#ns "." #name, sf); \
Function::Ptr dsf = new icinga::Function("Deprecated#" #name " (deprecated)", WrapFunction(callback), false, true); \
ScriptGlobal::Set("Deprecated." #name, dsf); \
}, 10)
#define REGISTER_SAFE_SCRIPTFUNCTION_NS(ns, name, callback) \
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
void RegisterFunction(void) { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
ScriptGlobal::Set(#ns "." #name, sf); \
} \
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
} } }
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
ScriptGlobal::Set(#ns "." #name, sf); \
}, 10)
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback) \
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
void RegisterFunction(void) { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
ScriptGlobal::Set(#ns "." #name, sf); \
Function::Ptr dsf = new icinga::Function("Deprecated#__" #name " (deprecated)", WrapFunction(callback), true, true); \
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
} \
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
} } }
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
ScriptGlobal::Set(#ns "." #name, sf); \
Function::Ptr dsf = new icinga::Function("Deprecated#__" #name " (deprecated)", WrapFunction(callback), true, true); \
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
}, 10)
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
void RegisterFunction(void) { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
ScriptGlobal::Set(#ns "." #name, sf); \
Function::Ptr dsf = new icinga::Function("Deprecated#" #name " (deprecated)", WrapFunction(callback), true, true); \
ScriptGlobal::Set("Deprecated." #name, dsf); \
} \
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
} } }
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
ScriptGlobal::Set(#ns "." #name, sf); \
Function::Ptr dsf = new icinga::Function("Deprecated#" #name " (deprecated)", WrapFunction(callback), true, true); \
ScriptGlobal::Set("Deprecated." #name, dsf); \
}, 10)
}

View File

@ -31,8 +31,7 @@ static String JsonEncodeShim(const Value& value)
return JsonEncode(value);
}
static void InitializeJsonObj(void)
{
INITIALIZE_ONCE([]() {
Dictionary::Ptr jsonObj = new Dictionary();
/* Methods */
@ -40,7 +39,4 @@ static void InitializeJsonObj(void)
jsonObj->Set("decode", new Function("Json#decode", WrapFunction(JsonDecode), true));
ScriptGlobal::Set("Json", jsonObj);
}
INITIALIZE_ONCE(InitializeJsonObj);
});

View File

@ -31,7 +31,6 @@
using namespace icinga;
REGISTER_TYPE(Logger);
INITIALIZE_ONCE(&Logger::StaticInitialize);
std::set<Logger::Ptr> Logger::m_Loggers;
boost::mutex Logger::m_Mutex;
@ -39,14 +38,13 @@ bool Logger::m_ConsoleLogEnabled = true;
bool Logger::m_TimestampEnabled = true;
LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
void Logger::StaticInitialize(void)
{
INITIALIZE_ONCE([]() {
ScriptGlobal::Set("LogDebug", LogDebug);
ScriptGlobal::Set("LogNotice", LogNotice);
ScriptGlobal::Set("LogInformation", LogInformation);
ScriptGlobal::Set("LogWarning", LogWarning);
ScriptGlobal::Set("LogCritical", LogCritical);
}
});
/**
* Constructor for the Logger class.

View File

@ -90,8 +90,6 @@ public:
static void SetConsoleLogSeverity(LogSeverity logSeverity);
static LogSeverity GetConsoleLogSeverity(void);
static void StaticInitialize(void);
virtual void ValidateSeverity(const String& value, const ValidationUtils& utils) override;
protected:

View File

@ -158,8 +158,7 @@ static double MathSign(double x)
return 0;
}
static void InitializeMathObj(void)
{
INITIALIZE_ONCE([]() {
Dictionary::Ptr mathObj = new Dictionary();
/* Constants */
@ -196,7 +195,4 @@ static void InitializeMathObj(void)
mathObj->Set("sign", new Function("Math#sign", WrapFunction(MathSign), true));
ScriptGlobal::Set("Math", mathObj);
}
INITIALIZE_ONCE(InitializeMathObj);
});

View File

@ -237,14 +237,11 @@ static void TypeInfoTimerHandler(void)
}
}
static void StartTypeInfoTimer(void)
{
INITIALIZE_ONCE([]() {
l_ObjectCountTimer = new Timer();
l_ObjectCountTimer->SetInterval(10);
l_ObjectCountTimer->OnTimerExpired.connect(boost::bind(TypeInfoTimerHandler));
l_ObjectCountTimer->Start();
}
INITIALIZE_ONCE(StartTypeInfoTimer);
});
#endif /* I2_LEAK_DEBUG */

View File

@ -22,15 +22,12 @@
using namespace icinga;
static void RegisterObjectType(void)
{
INITIALIZE_ONCE_WITH_PRIORITY([]() {
Type::Ptr type = new ObjectType();
type->SetPrototype(Object::GetPrototype());
Type::Register(type);
Object::TypeInstance = type;
}
INITIALIZE_ONCE_WITH_PRIORITY(&RegisterObjectType, 20);
}, 20);
ObjectType::ObjectType(void)
{ }

View File

@ -49,27 +49,19 @@ private:
};
#define REGISTER_BUILTIN_TYPE(type, prototype) \
namespace { namespace UNIQUE_NAME(prt) { namespace prt ## type { \
void RegisterBuiltinType(void) \
{ \
icinga::Type::Ptr t = new PrimitiveType(#type, "None"); \
t->SetPrototype(prototype); \
icinga::Type::Register(t); \
} \
INITIALIZE_ONCE_WITH_PRIORITY(RegisterBuiltinType, 15); \
} } }
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
icinga::Type::Ptr t = new PrimitiveType(#type, "None"); \
t->SetPrototype(prototype); \
icinga::Type::Register(t); \
}, 15)
#define REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, factory) \
namespace { namespace UNIQUE_NAME(prt) { namespace prt ## type { \
void RegisterPrimitiveType(void) \
{ \
icinga::Type::Ptr t = new PrimitiveType(#type, #base, factory);\
t->SetPrototype(prototype); \
icinga::Type::Register(t); \
type::TypeInstance = t; \
} \
INITIALIZE_ONCE_WITH_PRIORITY(RegisterPrimitiveType, 15); \
} } } \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
icinga::Type::Ptr t = new PrimitiveType(#type, #base, factory); \
t->SetPrototype(prototype); \
icinga::Type::Register(t); \
type::TypeInstance = t; \
}, 15); \
DEFINE_TYPE_INSTANCE(type)
#define REGISTER_PRIMITIVE_TYPE(type, base, prototype) \

View File

@ -56,8 +56,6 @@ static std::map<Process::ConsoleHandle, Process::ProcessHandle> l_FDs[IOTHREADS]
#endif /* _WIN32 */
static boost::once_flag l_OnceFlag = BOOST_ONCE_INIT;
INITIALIZE_ONCE(&Process::StaticInitialize);
Process::Process(const Process::Arguments& arguments, const Dictionary::Ptr& extraEnvironment)
: m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment), m_Timeout(600)
#ifdef _WIN32
@ -76,8 +74,7 @@ Process::~Process(void)
#endif /* _WIN32 */
}
void Process::StaticInitialize(void)
{
INITIALIZE_ONCE([]() {
for (int tid = 0; tid < IOTHREADS; tid++) {
#ifdef _WIN32
l_Events[tid] = CreateEvent(NULL, TRUE, FALSE, NULL);
@ -104,7 +101,7 @@ void Process::StaticInitialize(void)
# endif /* HAVE_PIPE2 */
#endif /* _WIN32 */
}
}
});
void Process::ThreadInitialize(void)
{

View File

@ -79,7 +79,6 @@ public:
static Arguments PrepareCommand(const Value& command);
static void StaticInitialize(void);
static void ThreadInitialize(void);
static String PrettyPrintArguments(const Arguments& arguments);

View File

@ -26,22 +26,19 @@ using namespace icinga;
boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFrames;
Array::Ptr ScriptFrame::m_Imports;
INITIALIZE_ONCE_WITH_PRIORITY(&ScriptFrame::StaticInitialize, 50);
void ScriptFrame::StaticInitialize(void)
{
INITIALIZE_ONCE_WITH_PRIORITY([]() {
Dictionary::Ptr systemNS = new Dictionary();
ScriptGlobal::Set("System", systemNS);
AddImport(systemNS);
ScriptFrame::AddImport(systemNS);
Dictionary::Ptr typesNS = new Dictionary();
ScriptGlobal::Set("Types", typesNS);
AddImport(typesNS);
ScriptFrame::AddImport(typesNS);
Dictionary::Ptr deprecatedNS = new Dictionary();
ScriptGlobal::Set("Deprecated", deprecatedNS);
AddImport(deprecatedNS);
}
ScriptFrame::AddImport(deprecatedNS);
}, 50);
ScriptFrame::ScriptFrame(void)
: Locals(new Dictionary()), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)

View File

@ -40,8 +40,6 @@ struct I2_BASE_API ScriptFrame
ScriptFrame(const Value& self);
~ScriptFrame(void);
static void StaticInitialize(void);
void IncreaseStackDepth(void);
void DecreaseStackDepth(void);

View File

@ -27,8 +27,6 @@
using namespace icinga;
INITIALIZE_ONCE(&StackTrace::StaticInitialize);
#ifdef _MSC_VER
# pragma optimize("", off)
#endif /* _MSC_VER */
@ -85,13 +83,12 @@ StackTrace::StackTrace(PEXCEPTION_POINTERS exi)
}
#endif /* _WIN32 */
void StackTrace::StaticInitialize(void)
{
#ifdef _WIN32
INITIALIZE_ONCE([]() {
(void) SymSetOptions(SYMOPT_UNDNAME | SYMOPT_LOAD_LINES);
(void) SymInitialize(GetCurrentProcess(), NULL, TRUE);
});
#endif /* _WIN32 */
}
/**
* Prints a stacktrace to the specified stream.

View File

@ -62,14 +62,10 @@ public:
};
#define REGISTER_STATSFUNCTION(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); \
} } }
INITIALIZE_ONCE([]() { \
StatsFunction::Ptr stf = new StatsFunction(callback); \
StatsFunctionRegistry::GetInstance()->Register(#name, stf); \
})
}

View File

@ -25,15 +25,12 @@ using namespace icinga;
Type::Ptr Type::TypeInstance;
static void RegisterTypeType(void)
{
INITIALIZE_ONCE_WITH_PRIORITY([]() {
Type::Ptr type = new TypeType();
type->SetPrototype(TypeType::GetPrototype());
Type::TypeInstance = type;
Type::Register(type);
}
INITIALIZE_ONCE_WITH_PRIORITY(RegisterTypeType, 20);
}, 20);
String Type::ToString(void) const
{

View File

@ -138,30 +138,20 @@ class I2_BASE_API TypeImpl
};
#define REGISTER_TYPE(type) \
namespace { namespace UNIQUE_NAME(rt) { \
void RegisterType ## type(void) \
{ \
icinga::Type::Ptr t = new TypeImpl<type>(); \
type::TypeInstance = t; \
icinga::Type::Register(t); \
} \
\
INITIALIZE_ONCE_WITH_PRIORITY(RegisterType ## type, 10); \
} } \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
icinga::Type::Ptr t = new TypeImpl<type>(); \
type::TypeInstance = t; \
icinga::Type::Register(t); \
}, 10); \
DEFINE_TYPE_INSTANCE(type)
#define REGISTER_TYPE_WITH_PROTOTYPE(type, prototype) \
namespace { namespace UNIQUE_NAME(rt) { \
void RegisterType ## type(void) \
{ \
icinga::Type::Ptr t = new TypeImpl<type>(); \
t->SetPrototype(prototype); \
type::TypeInstance = t; \
icinga::Type::Register(t); \
} \
\
INITIALIZE_ONCE_WITH_PRIORITY(RegisterType ## type, 10); \
} } \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
icinga::Type::Ptr t = new TypeImpl<type>(); \
t->SetPrototype(prototype); \
type::TypeInstance = t; \
icinga::Type::Register(t); \
}, 10); \
DEFINE_TYPE_INSTANCE(type)
#define DEFINE_TYPE_INSTANCE(type) \

View File

@ -32,10 +32,6 @@
#define TOKENPASTE(x, y) x ## y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
#ifdef HAVE_COUNTER_MACRO
# define UNIQUE_NAME(prefix) TOKENPASTE2(prefix, __COUNTER__)
#else /* HAVE_COUNTER_MACRO */
# define UNIQUE_NAME(prefix) prefix
#endif /* HAVE_COUNTER_MACRO */
#define UNIQUE_NAME(prefix) TOKENPASTE2(prefix, __COUNTER__)
#endif /* VISIBILITY_H */

View File

@ -88,15 +88,11 @@ private:
};
#define REGISTER_CLICOMMAND(name, klass) \
namespace { namespace UNIQUE_NAME(cli) { \
void RegisterCommand(void) \
{ \
std::vector<String> vname; \
boost::algorithm::split(vname, name, boost::is_any_of("/")); \
CLICommand::Register(vname, new klass()); \
} \
INITIALIZE_ONCE(RegisterCommand); \
} }
INITIALIZE_ONCE([]() { \
std::vector<String> vname; \
boost::algorithm::split(vname, name, boost::is_any_of("/")); \
CLICommand::Register(vname, new klass()); \
})
}

View File

@ -57,26 +57,22 @@ private:
};
#define REGISTER_BLACKANDWHITELIST_CLICOMMAND(type) \
namespace { namespace UNIQUE_NAME(blackandwhitelist) { namespace blackandwhitelist ## type { \
void RegisterCommand(void) \
{ \
String ltype = #type; \
boost::algorithm::to_lower(ltype); \
INITIALIZE_ONCE([]() { \
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)); \
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] = "remove"; \
CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandRemove)); \
\
name[2] = "list"; \
CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandList)); \
} \
INITIALIZE_ONCE(RegisterCommand); \
} } }
name[2] = "list"; \
CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandList)); \
})
}

View File

@ -61,26 +61,22 @@ private:
};
#define REGISTER_REPOSITORY_CLICOMMAND(type) \
namespace { namespace UNIQUE_NAME(repositoryobject) { namespace repositoryobject ## type { \
void RegisterCommand(void) \
{ \
String ltype = #type; \
boost::algorithm::to_lower(ltype); \
INITIALIZE_ONCE([]() { \
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)); \
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] = "remove"; \
CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandRemove)); \
\
name[2] = "list"; \
CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandList)); \
} \
INITIALIZE_ONCE(RegisterCommand); \
} } }
name[2] = "list"; \
CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandList)); \
})
}

View File

@ -27,22 +27,17 @@
#include "base/application.hpp"
#define REGISTER_CONFIG_FRAGMENT(id, name, fragment) \
namespace { \
void RegisterConfigFragment(void) \
{ \
icinga::Expression *expression = icinga::ConfigCompiler::CompileText(name, fragment); \
VERIFY(expression); \
try { \
icinga::ScriptFrame frame; \
expression->Evaluate(frame); \
} catch (const std::exception& ex) { \
std::cerr << icinga::DiagnosticInformation(ex) << std::endl; \
icinga::Application::Exit(1); \
} \
delete expression; \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
icinga::Expression *expression = icinga::ConfigCompiler::CompileText(name, fragment); \
VERIFY(expression); \
try { \
icinga::ScriptFrame frame; \
expression->Evaluate(frame); \
} catch (const std::exception& ex) { \
std::cerr << icinga::DiagnosticInformation(ex) << std::endl; \
icinga::Application::Exit(1); \
} \
\
INITIALIZE_ONCE_WITH_PRIORITY(RegisterConfigFragment, 5); \
}
delete expression; \
}, 5)
#endif /* CONFIGFRAGMENT_H */

View File

@ -97,14 +97,10 @@ intrusive_ptr<T> DbObjectFactory(const DbType::Ptr& type, const String& name1, c
}
#define REGISTER_DBTYPE(name, table, tid, idcolumn, type) \
namespace { namespace UNIQUE_NAME(ido) { namespace ido ## name { \
void RegisterDbType(void) \
{ \
DbType::Ptr dbtype = new DbType(#name, table, tid, idcolumn, DbObjectFactory<type>); \
DbType::RegisterType(dbtype); \
} \
INITIALIZE_ONCE(RegisterDbType); \
} } }
INITIALIZE_ONCE([]() { \
DbType::Ptr dbtype = new DbType(#name, table, tid, idcolumn, DbObjectFactory<type>); \
DbType::RegisterType(dbtype); \
})
}

View File

@ -30,7 +30,6 @@
using namespace icinga;
REGISTER_DBTYPE(Endpoint, "endpoint", DbObjectTypeEndpoint, "endpoint_object_id", EndpointDbObject);
INITIALIZE_ONCE(&EndpointDbObject::StaticInitialize);

View File

@ -27,12 +27,9 @@ using namespace icinga;
REGISTER_TYPE(HelloApplication);
INITIALIZE_ONCE(&HelloApplication::StaticInitialize);
void HelloApplication::StaticInitialize(void)
{
INITIALIZE_ONCE([]() {
ScriptGlobal::Set("ApplicationType", "HelloApplication");
}
});
/**
* The entry point for the hello application.

View File

@ -36,8 +36,6 @@ public:
DECLARE_OBJECT(HelloApplication);
DECLARE_OBJECTNAME(HelloApplication);
static void StaticInitialize(void);
virtual int Main(void) override;
};

View File

@ -30,15 +30,12 @@
using namespace icinga;
INITIALIZE_ONCE(&Dependency::RegisterApplyRuleHandler);
void Dependency::RegisterApplyRuleHandler(void)
{
INITIALIZE_ONCE([]() {
std::vector<String> targets;
targets.push_back("Host");
targets.push_back("Service");
ApplyRule::RegisterType("Dependency", targets);
}
});
bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
{

View File

@ -49,8 +49,6 @@ public:
bool IsAvailable(DependencyType dt) const;
static void RegisterApplyRuleHandler(void);
virtual void ValidateStates(const Array::Ptr& value, const ValidationUtils& utils) override;
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);

View File

@ -31,12 +31,9 @@ using namespace icinga;
REGISTER_TYPE(HostGroup);
INITIALIZE_ONCE(&HostGroup::RegisterObjectRuleHandler);
void HostGroup::RegisterObjectRuleHandler(void)
{
INITIALIZE_ONCE([]() {
ObjectRule::RegisterType("HostGroup");
}
});
bool HostGroup::EvaluateObjectRule(const Host::Ptr& host, const ConfigItem::Ptr& group)
{

View File

@ -46,8 +46,6 @@ public:
bool ResolveGroupMembership(const Host::Ptr& host, bool add = true, int rstack = 0);
static void RegisterObjectRuleHandler(void);
static void EvaluateObjectRules(const Host::Ptr& host);
private:

View File

@ -30,15 +30,12 @@
using namespace icinga;
INITIALIZE_ONCE(&Notification::RegisterApplyRuleHandler);
void Notification::RegisterApplyRuleHandler(void)
{
INITIALIZE_ONCE([]() {
std::vector<String> targets;
targets.push_back("Host");
targets.push_back("Service");
ApplyRule::RegisterType("Notification", targets);
}
});
bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
{

View File

@ -104,8 +104,6 @@ public:
static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
static void RegisterApplyRuleHandler(void);
virtual void Validate(int types, const ValidationUtils& utils) override;
virtual void ValidateStates(const Array::Ptr& value, const ValidationUtils& utils) override;

View File

@ -29,15 +29,12 @@
using namespace icinga;
INITIALIZE_ONCE(&ScheduledDowntime::RegisterApplyRuleHandler);
void ScheduledDowntime::RegisterApplyRuleHandler(void)
{
INITIALIZE_ONCE([]() {
std::vector<String> targets;
targets.push_back("Host");
targets.push_back("Service");
ApplyRule::RegisterType("ScheduledDowntime", targets);
}
});
bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
{

View File

@ -48,8 +48,6 @@ public:
Checkable::Ptr GetCheckable(void) const;
static void RegisterApplyRuleHandler(void);
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);

View File

@ -29,14 +29,11 @@
using namespace icinga;
INITIALIZE_ONCE(&Service::RegisterApplyRuleHandler);
void Service::RegisterApplyRuleHandler(void)
{
INITIALIZE_ONCE([]() {
std::vector<String> targets;
targets.push_back("Host");
ApplyRule::RegisterType("Service", targets);
}
});
bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule)
{

View File

@ -54,8 +54,6 @@ public:
static StateType StateTypeFromString(const String& state);
static String StateTypeToString(StateType state);
static void RegisterApplyRuleHandler(void);
static void EvaluateApplyRules(const Host::Ptr& host);
protected:

View File

@ -31,12 +31,9 @@ using namespace icinga;
REGISTER_TYPE(ServiceGroup);
INITIALIZE_ONCE(&ServiceGroup::RegisterObjectRuleHandler);
void ServiceGroup::RegisterObjectRuleHandler(void)
{
INITIALIZE_ONCE([]() {
ObjectRule::RegisterType("ServiceGroup");
}
});
bool ServiceGroup::EvaluateObjectRule(const Service::Ptr& service, const ConfigItem::Ptr& group)
{

View File

@ -46,8 +46,6 @@ public:
bool ResolveGroupMembership(const Service::Ptr& service, bool add = true, int rstack = 0);
static void RegisterObjectRuleHandler(void);
static void EvaluateObjectRules(const Service::Ptr& service);
private:

View File

@ -31,12 +31,9 @@ using namespace icinga;
REGISTER_TYPE(UserGroup);
INITIALIZE_ONCE(&UserGroup::RegisterObjectRuleHandler);
void UserGroup::RegisterObjectRuleHandler(void)
{
INITIALIZE_ONCE([]() {
ObjectRule::RegisterType("UserGroup");
}
});
bool UserGroup::EvaluateObjectRule(const User::Ptr& user, const ConfigItem::Ptr& group)
{

View File

@ -46,8 +46,6 @@ public:
bool ResolveGroupMembership(const User::Ptr& user, bool add = true, int rstack = 0);
static void RegisterObjectRuleHandler(void);
static void EvaluateObjectRules(const User::Ptr& user);
private:

View File

@ -73,20 +73,16 @@ public:
};
#define REGISTER_APIACTION(name, types, callback) \
namespace { namespace UNIQUE_NAME(apia) { namespace apia ## name { \
void RegisterAction(void) \
{ \
String registerName = #name; \
boost::algorithm::replace_all(registerName, "_", "-"); \
std::vector<String> registerTypes; \
String typeNames = types; \
if (!typeNames.IsEmpty()) \
boost::algorithm::split(registerTypes, typeNames, boost::is_any_of(";")); \
ApiAction::Ptr action = new ApiAction(registerTypes, callback); \
ApiActionRegistry::GetInstance()->Register(registerName, action); \
} \
INITIALIZE_ONCE(RegisterAction); \
} } }
INITIALIZE_ONCE([]() { \
String registerName = #name; \
boost::algorithm::replace_all(registerName, "_", "-"); \
std::vector<String> registerTypes; \
String typeNames = types; \
if (!typeNames.IsEmpty()) \
boost::algorithm::split(registerTypes, typeNames, boost::is_any_of(";")); \
ApiAction::Ptr action = new ApiAction(registerTypes, callback); \
ApiActionRegistry::GetInstance()->Register(registerName, action); \
})
}

View File

@ -67,14 +67,10 @@ public:
};
#define REGISTER_APIFUNCTION(name, ns, 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); \
} } }
INITIALIZE_ONCE([]() { \
ApiFunction::Ptr func = new ApiFunction(callback); \
ApiFunctionRegistry::GetInstance()->Register(#ns "::" #name, func); \
})
}

View File

@ -31,17 +31,13 @@
using namespace icinga;
INITIALIZE_ONCE(&ApiListener::StaticInitialize);
REGISTER_APIFUNCTION(UpdateObject, config, &ApiListener::ConfigUpdateObjectAPIHandler);
REGISTER_APIFUNCTION(DeleteObject, config, &ApiListener::ConfigDeleteObjectAPIHandler);
void ApiListener::StaticInitialize(void)
{
INITIALIZE_ONCE([]() {
ConfigObject::OnActiveChanged.connect(&ApiListener::ConfigUpdateObjectHandler);
ConfigObject::OnVersionChanged.connect(&ApiListener::ConfigUpdateObjectHandler);
}
});
void ApiListener::ConfigUpdateObjectHandler(const ConfigObject::Ptr& object, const Value& cookie)
{

View File

@ -55,8 +55,6 @@ public:
DECLARE_OBJECT(ApiListener);
DECLARE_OBJECTNAME(ApiListener);
static void StaticInitialize(void);
static boost::signals2::signal<void(bool)> OnMasterChanged;
ApiListener(void);

View File

@ -24,11 +24,6 @@
using namespace icinga;
static bool ObjectNameLessComparer(const ConfigObject::Ptr& a, const ConfigObject::Ptr& b)
{
return a->GetName() < b->GetName();
}
void ApiListener::UpdateObjectAuthority(void)
{
Zone::Ptr my_zone = Zone::GetLocalZone();
@ -55,7 +50,11 @@ void ApiListener::UpdateObjectAuthority(void)
if (num_total > 1 && endpoints.size() <= 1 && (mainTime == 0 || Utility::GetTime() - mainTime < 60))
return;
std::sort(endpoints.begin(), endpoints.end(), ObjectNameLessComparer);
std::sort(endpoints.begin(), endpoints.end(),
[](const ConfigObject::Ptr& a, const ConfigObject::Ptr& b) {
return a->GetName() < b->GetName();
}
);
}
for (const Type::Ptr& type : Type::GetAllTypes()) {

View File

@ -57,15 +57,12 @@ static void ScriptFrameCleanupHandler(void)
l_ApiScriptFrames.erase(key);
}
static void InitScriptFrameCleanup(void)
{
INITIALIZE_ONCE([]() {
l_FrameCleanupTimer = new Timer();
l_FrameCleanupTimer->OnTimerExpired.connect(boost::bind(ScriptFrameCleanupHandler));
l_FrameCleanupTimer->SetInterval(30);
l_FrameCleanupTimer->Start();
}
INITIALIZE_ONCE(InitScriptFrameCleanup);
});
bool ConsoleHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params)
{

View File

@ -61,15 +61,11 @@ public:
};
#define REGISTER_URLHANDLER(url, klass) \
namespace { namespace UNIQUE_NAME(apif) { namespace apif ## name { \
void RegisterHandler(void) \
{ \
Url::Ptr uurl = new Url(url); \
HttpHandler::Ptr handler = new klass(); \
HttpHandler::Register(uurl, handler); \
} \
INITIALIZE_ONCE(RegisterHandler); \
} } }
INITIALIZE_ONCE([]() { \
Url::Ptr uurl = new Url(url); \
HttpHandler::Ptr handler = new klass(); \
HttpHandler::Register(uurl, handler); \
})
}

View File

@ -31,15 +31,12 @@ REGISTER_APIFUNCTION(Heartbeat, event, &JsonRpcConnection::HeartbeatAPIHandler);
static Timer::Ptr l_HeartbeatTimer;
static void StartHeartbeatTimer(void)
{
INITIALIZE_ONCE([]() {
l_HeartbeatTimer = new Timer();
l_HeartbeatTimer->OnTimerExpired.connect(boost::bind(&JsonRpcConnection::HeartbeatTimerHandler));
l_HeartbeatTimer->SetInterval(10);
l_HeartbeatTimer->Start();
}
INITIALIZE_ONCE(StartHeartbeatTimer);
});
void JsonRpcConnection::HeartbeatTimerHandler(void)
{