mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-29 00:24:23 +02:00
Replace std::shared_ptr<NamespaceValue> with NamespaceValue::Ptr
refs #7361
This commit is contained in:
parent
aa4cad7482
commit
768044a754
@ -60,28 +60,28 @@ private:
|
|||||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), false); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), false); \
|
||||||
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
|
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
|
||||||
nsp->SetAttribute(#name, std::make_shared<ConstEmbeddedNamespaceValue>(sf)); \
|
nsp->SetAttribute(#name, new ConstEmbeddedNamespaceValue(sf)); \
|
||||||
}, 10)
|
}, 10)
|
||||||
|
|
||||||
#define REGISTER_SAFE_FUNCTION(ns, name, callback, args) \
|
#define REGISTER_SAFE_FUNCTION(ns, name, callback, args) \
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), true); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), true); \
|
||||||
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
|
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
|
||||||
nsp->SetAttribute(#name, std::make_shared<ConstEmbeddedNamespaceValue>(sf)); \
|
nsp->SetAttribute(#name, new ConstEmbeddedNamespaceValue(sf)); \
|
||||||
}, 10)
|
}, 10)
|
||||||
|
|
||||||
#define REGISTER_FUNCTION_NONCONST(ns, name, callback, args) \
|
#define REGISTER_FUNCTION_NONCONST(ns, name, callback, args) \
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), false); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), false); \
|
||||||
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
|
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
|
||||||
nsp->SetAttribute(#name, std::make_shared<EmbeddedNamespaceValue>(sf)); \
|
nsp->SetAttribute(#name, new EmbeddedNamespaceValue(sf)); \
|
||||||
}, 10)
|
}, 10)
|
||||||
|
|
||||||
#define REGISTER_SAFE_FUNCTION_NONCONST(ns, name, callback, args) \
|
#define REGISTER_SAFE_FUNCTION_NONCONST(ns, name, callback, args) \
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), true); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), true); \
|
||||||
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
|
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
|
||||||
nsp->SetAttribute(#name, std::make_shared<EmbeddedNamespaceValue>(sf)); \
|
nsp->SetAttribute(#name, new EmbeddedNamespaceValue(sf)); \
|
||||||
}, 10)
|
}, 10)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,5 @@ INITIALIZE_ONCE([]() {
|
|||||||
jsonNSBehavior->Freeze();
|
jsonNSBehavior->Freeze();
|
||||||
|
|
||||||
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
|
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
|
||||||
systemNS->SetAttribute("Json", std::make_shared<ConstEmbeddedNamespaceValue>(jsonNS));
|
systemNS->SetAttribute("Json", new ConstEmbeddedNamespaceValue(jsonNS));
|
||||||
});
|
});
|
||||||
|
@ -181,5 +181,5 @@ INITIALIZE_ONCE([]() {
|
|||||||
mathNSBehavior->Freeze();
|
mathNSBehavior->Freeze();
|
||||||
|
|
||||||
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
|
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
|
||||||
systemNS->SetAttribute("Math", std::make_shared<ConstEmbeddedNamespaceValue>(mathNS));
|
systemNS->SetAttribute("Math", new ConstEmbeddedNamespaceValue(mathNS));
|
||||||
});
|
});
|
||||||
|
@ -75,7 +75,7 @@ void Namespace::RemoveAttribute(const String& field)
|
|||||||
m_Data.erase(it);
|
m_Data.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<NamespaceValue> Namespace::GetAttribute(const String& key) const
|
NamespaceValue::Ptr Namespace::GetAttribute(const String& key) const
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ std::shared_ptr<NamespaceValue> Namespace::GetAttribute(const String& key) const
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Namespace::SetAttribute(const String& key, const std::shared_ptr<NamespaceValue>& nsVal)
|
void Namespace::SetAttribute(const String& key, const NamespaceValue::Ptr& nsVal)
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ void ConstEmbeddedNamespaceValue::Set(const Value& value, bool overrideFrozen, c
|
|||||||
|
|
||||||
void NamespaceBehavior::Register(const Namespace::Ptr& ns, const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) const
|
void NamespaceBehavior::Register(const Namespace::Ptr& ns, const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) const
|
||||||
{
|
{
|
||||||
ns->SetAttribute(field, std::make_shared<EmbeddedNamespaceValue>(value));
|
ns->SetAttribute(field, new EmbeddedNamespaceValue(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen)
|
void NamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen)
|
||||||
@ -182,7 +182,7 @@ void ConstNamespaceBehavior::Register(const Namespace::Ptr& ns, const String& fi
|
|||||||
if (m_Frozen && !overrideFrozen)
|
if (m_Frozen && !overrideFrozen)
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Namespace is read-only and must not be modified.", debugInfo));
|
BOOST_THROW_EXCEPTION(ScriptError("Namespace is read-only and must not be modified.", debugInfo));
|
||||||
|
|
||||||
ns->SetAttribute(field, std::make_shared<ConstEmbeddedNamespaceValue>(value));
|
ns->SetAttribute(field, new ConstEmbeddedNamespaceValue(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConstNamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen)
|
void ConstNamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "base/i2-base.hpp"
|
#include "base/i2-base.hpp"
|
||||||
#include "base/object.hpp"
|
#include "base/object.hpp"
|
||||||
|
#include "base/shared-object.hpp"
|
||||||
#include "base/value.hpp"
|
#include "base/value.hpp"
|
||||||
#include "base/debuginfo.hpp"
|
#include "base/debuginfo.hpp"
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -14,8 +15,10 @@
|
|||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
struct NamespaceValue
|
struct NamespaceValue : public SharedObject
|
||||||
{
|
{
|
||||||
|
DECLARE_PTR_TYPEDEFS(NamespaceValue);
|
||||||
|
|
||||||
virtual Value Get(const DebugInfo& debugInfo = DebugInfo()) const = 0;
|
virtual Value Get(const DebugInfo& debugInfo = DebugInfo()) const = 0;
|
||||||
virtual void Set(const Value& value, bool overrideFrozen, const DebugInfo& debugInfo = DebugInfo()) = 0;
|
virtual void Set(const Value& value, bool overrideFrozen, const DebugInfo& debugInfo = DebugInfo()) = 0;
|
||||||
};
|
};
|
||||||
@ -66,9 +69,9 @@ class Namespace final : public Object
|
|||||||
public:
|
public:
|
||||||
DECLARE_OBJECT(Namespace);
|
DECLARE_OBJECT(Namespace);
|
||||||
|
|
||||||
typedef std::map<String, std::shared_ptr<NamespaceValue> >::iterator Iterator;
|
typedef std::map<String, NamespaceValue::Ptr>::iterator Iterator;
|
||||||
|
|
||||||
typedef std::map<String, std::shared_ptr<NamespaceValue> >::value_type Pair;
|
typedef std::map<String, NamespaceValue::Ptr>::value_type Pair;
|
||||||
|
|
||||||
Namespace(NamespaceBehavior *behavior = new NamespaceBehavior);
|
Namespace(NamespaceBehavior *behavior = new NamespaceBehavior);
|
||||||
|
|
||||||
@ -78,8 +81,8 @@ public:
|
|||||||
bool Contains(const String& field) const;
|
bool Contains(const String& field) const;
|
||||||
void Remove(const String& field, bool overrideFrozen = false);
|
void Remove(const String& field, bool overrideFrozen = false);
|
||||||
|
|
||||||
std::shared_ptr<NamespaceValue> GetAttribute(const String& field) const;
|
NamespaceValue::Ptr GetAttribute(const String& field) const;
|
||||||
void SetAttribute(const String& field, const std::shared_ptr<NamespaceValue>& nsVal);
|
void SetAttribute(const String& field, const NamespaceValue::Ptr& nsVal);
|
||||||
void RemoveAttribute(const String& field);
|
void RemoveAttribute(const String& field);
|
||||||
|
|
||||||
Iterator Begin();
|
Iterator Begin();
|
||||||
@ -93,7 +96,7 @@ public:
|
|||||||
static Object::Ptr GetPrototype();
|
static Object::Ptr GetPrototype();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<String, std::shared_ptr<NamespaceValue> > m_Data;
|
std::map<String, NamespaceValue::Ptr> m_Data;
|
||||||
std::unique_ptr<NamespaceBehavior> m_Behavior;
|
std::unique_ptr<NamespaceBehavior> m_Behavior;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,22 +22,22 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
|||||||
auto systemNSBehavior = new ConstNamespaceBehavior();
|
auto systemNSBehavior = new ConstNamespaceBehavior();
|
||||||
systemNSBehavior->Freeze();
|
systemNSBehavior->Freeze();
|
||||||
Namespace::Ptr systemNS = new Namespace(systemNSBehavior);
|
Namespace::Ptr systemNS = new Namespace(systemNSBehavior);
|
||||||
globalNS->SetAttribute("System", std::make_shared<ConstEmbeddedNamespaceValue>(systemNS));
|
globalNS->SetAttribute("System", new ConstEmbeddedNamespaceValue(systemNS));
|
||||||
|
|
||||||
systemNS->SetAttribute("Configuration", std::make_shared<EmbeddedNamespaceValue>(new Configuration()));
|
systemNS->SetAttribute("Configuration", new EmbeddedNamespaceValue(new Configuration()));
|
||||||
|
|
||||||
auto typesNSBehavior = new ConstNamespaceBehavior();
|
auto typesNSBehavior = new ConstNamespaceBehavior();
|
||||||
typesNSBehavior->Freeze();
|
typesNSBehavior->Freeze();
|
||||||
Namespace::Ptr typesNS = new Namespace(typesNSBehavior);
|
Namespace::Ptr typesNS = new Namespace(typesNSBehavior);
|
||||||
globalNS->SetAttribute("Types", std::make_shared<ConstEmbeddedNamespaceValue>(typesNS));
|
globalNS->SetAttribute("Types", new ConstEmbeddedNamespaceValue(typesNS));
|
||||||
|
|
||||||
auto statsNSBehavior = new ConstNamespaceBehavior();
|
auto statsNSBehavior = new ConstNamespaceBehavior();
|
||||||
statsNSBehavior->Freeze();
|
statsNSBehavior->Freeze();
|
||||||
Namespace::Ptr statsNS = new Namespace(statsNSBehavior);
|
Namespace::Ptr statsNS = new Namespace(statsNSBehavior);
|
||||||
globalNS->SetAttribute("StatsFunctions", std::make_shared<ConstEmbeddedNamespaceValue>(statsNS));
|
globalNS->SetAttribute("StatsFunctions", new ConstEmbeddedNamespaceValue(statsNS));
|
||||||
|
|
||||||
Namespace::Ptr internalNS = new Namespace(l_InternalNSBehavior);
|
Namespace::Ptr internalNS = new Namespace(l_InternalNSBehavior);
|
||||||
globalNS->SetAttribute("Internal", std::make_shared<ConstEmbeddedNamespaceValue>(internalNS));
|
globalNS->SetAttribute("Internal", new ConstEmbeddedNamespaceValue(internalNS));
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
|
@ -65,7 +65,7 @@ void ScriptGlobal::Set(const String& name, const Value& value, bool overrideFroz
|
|||||||
|
|
||||||
void ScriptGlobal::SetConst(const String& name, const Value& value)
|
void ScriptGlobal::SetConst(const String& name, const Value& value)
|
||||||
{
|
{
|
||||||
GetGlobals()->SetAttribute(name, std::make_shared<ConstEmbeddedNamespaceValue>(value));
|
GetGlobals()->SetAttribute(name, new ConstEmbeddedNamespaceValue(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptGlobal::Exists(const String& name)
|
bool ScriptGlobal::Exists(const String& name)
|
||||||
|
@ -689,7 +689,7 @@ ExpressionResult SetConstExpression::DoEvaluate(ScriptFrame& frame, DebugHint *d
|
|||||||
CHECK_RESULT(operandres);
|
CHECK_RESULT(operandres);
|
||||||
Value operand = operandres.GetValue();
|
Value operand = operandres.GetValue();
|
||||||
|
|
||||||
globals->SetAttribute(m_Name, std::make_shared<ConstEmbeddedNamespaceValue>(operand));
|
globals->SetAttribute(m_Name, new ConstEmbeddedNamespaceValue(operand));
|
||||||
|
|
||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ void IcingaApplication::StaticInitialize()
|
|||||||
auto icingaNSBehavior = new ConstNamespaceBehavior();
|
auto icingaNSBehavior = new ConstNamespaceBehavior();
|
||||||
icingaNSBehavior->Freeze();
|
icingaNSBehavior->Freeze();
|
||||||
Namespace::Ptr icingaNS = new Namespace(icingaNSBehavior);
|
Namespace::Ptr icingaNS = new Namespace(icingaNSBehavior);
|
||||||
globalNS->SetAttribute("Icinga", std::make_shared<ConstEmbeddedNamespaceValue>(icingaNS));
|
globalNS->SetAttribute("Icinga", new ConstEmbeddedNamespaceValue(icingaNS));
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_STATSFUNCTION(IcingaApplication, &IcingaApplication::StatsFunc);
|
REGISTER_STATSFUNCTION(IcingaApplication, &IcingaApplication::StatsFunc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user