1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "base/type.hpp"
4 #include "base/dictionary.hpp"
5 #include "base/function.hpp"
6 #include "base/functionwrapper.hpp"
7 #include "base/scriptframe.hpp"
9 using namespace icinga;
11 static void InvokeAttributeHandlerHelper(const Function::Ptr& callback,
12 const Object::Ptr& object, const Value& cookie)
14 callback->Invoke({ object });
17 static void TypeRegisterAttributeHandler(const String& fieldName, const Function::Ptr& callback)
19 ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
20 Type::Ptr self = static_cast<Type::Ptr>(vframe->Self);
21 REQUIRE_NOT_NULL(self);
23 int fid = self->GetFieldId(fieldName);
24 self->RegisterAttributeHandler(fid, std::bind(&InvokeAttributeHandlerHelper, callback, _1, _2));
27 Object::Ptr TypeType::GetPrototype()
29 static Dictionary::Ptr prototype = new Dictionary({
30 { "register_attribute_handler", new Function("Type#register_attribute_handler", TypeRegisterAttributeHandler, { "field", "callback" }, false) }