mirror of https://github.com/Icinga/icinga2.git
Merge pull request #9608 from Icinga/move-types-namespace
Move Types namespace into type.cpp and simplify Type::GetByName()
This commit is contained in:
commit
421ac1735c
|
@ -11,7 +11,7 @@ using namespace icinga;
|
||||||
|
|
||||||
boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFrames;
|
boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFrames;
|
||||||
|
|
||||||
static Namespace::Ptr l_SystemNS, l_TypesNS, l_StatsNS, l_InternalNS;
|
static Namespace::Ptr l_SystemNS, l_StatsNS, l_InternalNS;
|
||||||
|
|
||||||
/* Ensure that this gets called with highest priority
|
/* Ensure that this gets called with highest priority
|
||||||
* and wins against other static initializers in lib/icinga, etc.
|
* and wins against other static initializers in lib/icinga, etc.
|
||||||
|
@ -33,9 +33,6 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
|
|
||||||
l_SystemNS->Set("Configuration", new Configuration());
|
l_SystemNS->Set("Configuration", new Configuration());
|
||||||
|
|
||||||
l_TypesNS = new Namespace(true);
|
|
||||||
globalNS->Set("Types", l_TypesNS, true);
|
|
||||||
|
|
||||||
l_StatsNS = new Namespace(true);
|
l_StatsNS = new Namespace(true);
|
||||||
globalNS->Set("StatsFunctions", l_StatsNS, true);
|
globalNS->Set("StatsFunctions", l_StatsNS, true);
|
||||||
|
|
||||||
|
@ -45,7 +42,6 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
|
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
l_SystemNS->Freeze();
|
l_SystemNS->Freeze();
|
||||||
l_TypesNS->Freeze();
|
|
||||||
l_StatsNS->Freeze();
|
l_StatsNS->Freeze();
|
||||||
l_InternalNS->Freeze();
|
l_InternalNS->Freeze();
|
||||||
}, InitializePriority::FreezeNamespaces);
|
}, InitializePriority::FreezeNamespaces);
|
||||||
|
|
|
@ -9,6 +9,21 @@ using namespace icinga;
|
||||||
|
|
||||||
Type::Ptr Type::TypeInstance;
|
Type::Ptr Type::TypeInstance;
|
||||||
|
|
||||||
|
static Namespace::Ptr l_TypesNS = new Namespace(true);
|
||||||
|
|
||||||
|
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
|
ScriptGlobal::GetGlobals()->Set("Types", l_TypesNS, true);
|
||||||
|
}, InitializePriority::CreateNamespaces);
|
||||||
|
|
||||||
|
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
|
l_TypesNS->Freeze();
|
||||||
|
|
||||||
|
ObjectLock olock (l_TypesNS);
|
||||||
|
for (const auto& t : l_TypesNS) {
|
||||||
|
VERIFY(t.second.Val.IsObjectType<Type>());
|
||||||
|
}
|
||||||
|
}, InitializePriority::FreezeNamespaces);
|
||||||
|
|
||||||
/* Ensure that the priority is lower than the basic namespace initialization in scriptframe.cpp. */
|
/* Ensure that the priority is lower than the basic namespace initialization in scriptframe.cpp. */
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
Type::Ptr type = new TypeType();
|
Type::Ptr type = new TypeType();
|
||||||
|
@ -29,16 +44,9 @@ void Type::Register(const Type::Ptr& type)
|
||||||
|
|
||||||
Type::Ptr Type::GetByName(const String& name)
|
Type::Ptr Type::GetByName(const String& name)
|
||||||
{
|
{
|
||||||
Namespace::Ptr typesNS = ScriptGlobal::Get("Types", &Empty);
|
|
||||||
|
|
||||||
if (!typesNS)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
Value ptype;
|
Value ptype;
|
||||||
if (!typesNS->Get(name, &ptype))
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
if (!ptype.IsObjectType<Type>())
|
if (!l_TypesNS->Get(name, &ptype))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return ptype;
|
return ptype;
|
||||||
|
|
Loading…
Reference in New Issue