mirror of
https://github.com/Icinga/icinga2.git
synced 2026-02-03 20:40:17 -05:00
This commit removes EmbeddedNamespaceValue and ConstEmbeddedNamespaceValue and reduces NamespaceValue down to a simple struct without inheritance or member functions. The code from these clases is inlined into the Namespace class. The class hierarchy determining whether a value is const is moved to an attribute of NamespaceValue. This is done in preparation for changes to the locking in the Namespace class. Currently, it relies on a recursive mutex. In the future, a shared mutex (read/write lock) should be used instead, which cannot allow recursive locking (without failing or risk deadlocking on lock upgrades). With this change, all operations requiring a lock for one operation are within one function, no recursive locking is not needed any more.
28 lines
721 B
C++
28 lines
721 B
C++
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
|
|
|
#include "base/dictionary.hpp"
|
|
#include "base/function.hpp"
|
|
#include "base/functionwrapper.hpp"
|
|
#include "base/scriptframe.hpp"
|
|
#include "base/initialize.hpp"
|
|
#include "base/json.hpp"
|
|
|
|
using namespace icinga;
|
|
|
|
static String JsonEncodeShim(const Value& value)
|
|
{
|
|
return JsonEncode(value);
|
|
}
|
|
|
|
INITIALIZE_ONCE([]() {
|
|
Namespace::Ptr jsonNS = new Namespace(true);
|
|
|
|
/* Methods */
|
|
jsonNS->Set("encode", new Function("Json#encode", JsonEncodeShim, { "value" }, true));
|
|
jsonNS->Set("decode", new Function("Json#decode", JsonDecode, { "value" }, true));
|
|
|
|
jsonNS->Freeze();
|
|
|
|
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
|
|
systemNS->Set("Json", jsonNS, true, true);
|
|
});
|