]> granicus.if.org Git - icinga2/blob - lib/base/object-script.cpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / object-script.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/object.hpp"
4 #include "base/dictionary.hpp"
5 #include "base/function.hpp"
6 #include "base/functionwrapper.hpp"
7 #include "base/scriptframe.hpp"
8
9 using namespace icinga;
10
11 static String ObjectToString()
12 {
13         ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
14         Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
15         REQUIRE_NOT_NULL(self);
16         return self->ToString();
17 }
18
19 static void ObjectNotifyAttribute(const String& attribute)
20 {
21         ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
22         Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
23         REQUIRE_NOT_NULL(self);
24         self->NotifyField(self->GetReflectionType()->GetFieldId(attribute));
25 }
26
27 static Object::Ptr ObjectClone()
28 {
29         ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
30         Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
31         REQUIRE_NOT_NULL(self);
32         return self->Clone();
33 }
34
35 Object::Ptr Object::GetPrototype()
36 {
37         static Dictionary::Ptr prototype = new Dictionary({
38                         { "to_string", new Function("Object#to_string", ObjectToString, {}, true) },
39                         { "notify_attribute", new Function("Object#notify_attribute", ObjectNotifyAttribute, { "attribute" }, false) },
40                         { "clone", new Function("Object#clone", ObjectClone, {}, true) }
41         });
42
43         return prototype;
44 }
45