mirror of
https://github.com/Icinga/icinga2.git
synced 2025-06-02 21:00:16 +02:00
parent
4350403e1b
commit
afc1b9bdc5
@ -34,6 +34,10 @@ void ScriptFrame::StaticInitialize(void)
|
|||||||
ScriptGlobal::Set("System", systemNS);
|
ScriptGlobal::Set("System", systemNS);
|
||||||
AddImport(systemNS);
|
AddImport(systemNS);
|
||||||
|
|
||||||
|
Dictionary::Ptr typesNS = new Dictionary();
|
||||||
|
ScriptGlobal::Set("Types", typesNS);
|
||||||
|
AddImport(typesNS);
|
||||||
|
|
||||||
Dictionary::Ptr deprecatedNS = new Dictionary();
|
Dictionary::Ptr deprecatedNS = new Dictionary();
|
||||||
ScriptGlobal::Set("Deprecated", deprecatedNS);
|
ScriptGlobal::Set("Deprecated", deprecatedNS);
|
||||||
AddImport(deprecatedNS);
|
AddImport(deprecatedNS);
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "base/type.hpp"
|
#include "base/type.hpp"
|
||||||
#include "base/scriptglobal.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
|
#include "base/objectlock.hpp"
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
@ -43,12 +45,17 @@ void Type::Register(const Type::Ptr& type)
|
|||||||
{
|
{
|
||||||
VERIFY(GetByName(type->GetName()) == NULL);
|
VERIFY(GetByName(type->GetName()) == NULL);
|
||||||
|
|
||||||
ScriptGlobal::Set(type->GetName(), type);
|
ScriptGlobal::Set("Types." + type->GetName(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Ptr Type::GetByName(const String& name)
|
Type::Ptr Type::GetByName(const String& name)
|
||||||
{
|
{
|
||||||
Value ptype = ScriptGlobal::Get(name, &Empty);
|
Dictionary::Ptr typesNS = ScriptGlobal::Get("Types", &Empty);
|
||||||
|
|
||||||
|
if (!typesNS)
|
||||||
|
return Type::Ptr();
|
||||||
|
|
||||||
|
Value ptype = typesNS->Get(name);
|
||||||
|
|
||||||
if (!ptype.IsObjectType<Type>())
|
if (!ptype.IsObjectType<Type>())
|
||||||
return Type::Ptr();
|
return Type::Ptr();
|
||||||
@ -56,6 +63,25 @@ Type::Ptr Type::GetByName(const String& name)
|
|||||||
return ptype;
|
return ptype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Type::Ptr> Type::GetAllTypes(void)
|
||||||
|
{
|
||||||
|
std::vector<Type::Ptr> types;
|
||||||
|
|
||||||
|
Dictionary::Ptr typesNS = ScriptGlobal::Get("Types", &Empty);
|
||||||
|
|
||||||
|
if (typesNS) {
|
||||||
|
ObjectLock olock(typesNS);
|
||||||
|
|
||||||
|
BOOST_FOREACH(const Dictionary::Pair& kv, typesNS) {
|
||||||
|
if (kv.second.IsObjectType<Type>())
|
||||||
|
types.push_back(kv.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
String Type::GetPluralName(void) const
|
String Type::GetPluralName(void) const
|
||||||
{
|
{
|
||||||
String name = GetName();
|
String name = GetName();
|
||||||
|
@ -97,6 +97,7 @@ public:
|
|||||||
|
|
||||||
static void Register(const Type::Ptr& type);
|
static void Register(const Type::Ptr& type);
|
||||||
static Type::Ptr GetByName(const String& name);
|
static Type::Ptr GetByName(const String& name);
|
||||||
|
static std::vector<Type::Ptr> GetAllTypes(void);
|
||||||
|
|
||||||
virtual void SetField(int id, const Value& value, bool suppress_events = false, const Value& cookie = Empty) override;
|
virtual void SetField(int id, const Value& value, bool suppress_events = false, const Value& cookie = Empty) override;
|
||||||
virtual Value GetField(int id) const override;
|
virtual Value GetField(int id) const override;
|
||||||
|
@ -453,18 +453,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
|
|||||||
|
|
||||||
std::set<String> types;
|
std::set<String> types;
|
||||||
|
|
||||||
std::vector<Type::Ptr> all_types;
|
BOOST_FOREACH(const Type::Ptr& type, Type::GetAllTypes()) {
|
||||||
Dictionary::Ptr globals = ScriptGlobal::GetGlobals();
|
|
||||||
|
|
||||||
{
|
|
||||||
ObjectLock olock(globals);
|
|
||||||
BOOST_FOREACH(const Dictionary::Pair& kv, globals) {
|
|
||||||
if (kv.second.IsObjectType<Type>())
|
|
||||||
all_types.push_back(kv.second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FOREACH(const Type::Ptr& type, all_types) {
|
|
||||||
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
|
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
|
||||||
types.insert(type->GetName());
|
types.insert(type->GetName());
|
||||||
}
|
}
|
||||||
|
@ -34,21 +34,12 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName)
|
|||||||
String uname = pluralName;
|
String uname = pluralName;
|
||||||
boost::algorithm::to_lower(uname);
|
boost::algorithm::to_lower(uname);
|
||||||
|
|
||||||
{
|
BOOST_FOREACH(const Type::Ptr&type, Type::GetAllTypes()) {
|
||||||
Dictionary::Ptr globals = ScriptGlobal::GetGlobals();
|
String pname = type->GetPluralName();
|
||||||
ObjectLock olock(globals);
|
boost::algorithm::to_lower(pname);
|
||||||
BOOST_FOREACH(const Dictionary::Pair& kv, globals) {
|
|
||||||
if (!kv.second.IsObjectType<Type>())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Type::Ptr type = kv.second;
|
if (uname == pname)
|
||||||
|
return type;
|
||||||
String pname = type->GetPluralName();
|
|
||||||
boost::algorithm::to_lower(pname);
|
|
||||||
|
|
||||||
if (uname == pname)
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Type::Ptr();
|
return Type::Ptr();
|
||||||
|
@ -38,18 +38,7 @@ public:
|
|||||||
virtual void FindTargets(const String& type,
|
virtual void FindTargets(const String& type,
|
||||||
const boost::function<void (const Value&)>& addTarget) const override
|
const boost::function<void (const Value&)>& addTarget) const override
|
||||||
{
|
{
|
||||||
std::vector<Type::Ptr> targets;
|
BOOST_FOREACH(const Type::Ptr& target, Type::GetAllTypes()) {
|
||||||
|
|
||||||
{
|
|
||||||
Dictionary::Ptr globals = ScriptGlobal::GetGlobals();
|
|
||||||
ObjectLock olock(globals);
|
|
||||||
BOOST_FOREACH(const Dictionary::Pair& kv, globals) {
|
|
||||||
if (kv.second.IsObjectType<Type>())
|
|
||||||
targets.push_back(kv.second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FOREACH(const Type::Ptr& target, targets) {
|
|
||||||
addTarget(target);
|
addTarget(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user