]> granicus.if.org Git - icinga2/commitdiff
Implement the __get_object function
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 12 Nov 2014 18:08:36 +0000 (19:08 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 12 Nov 2014 18:08:36 +0000 (19:08 +0100)
lib/base/scriptutils.cpp
lib/base/scriptutils.hpp

index 9ad8200ef0af74703ea04512667aa1977dafa906..bc74a5a70adb32ffbe5aa3e0e9c63d7e1a6b9d3e 100644 (file)
@@ -24,6 +24,7 @@
 #include "base/json.hpp"
 #include "base/logger.hpp"
 #include "base/objectlock.hpp"
+#include "base/dynamictype.hpp"
 #include <boost/foreach.hpp>
 #include <boost/regex.hpp>
 #include <algorithm>
@@ -42,6 +43,7 @@ REGISTER_SCRIPTFUNCTION(exit, &ScriptUtils::Exit);
 REGISTER_SCRIPTFUNCTION(typeof, &ScriptUtils::TypeOf);
 REGISTER_SCRIPTFUNCTION(keys, &ScriptUtils::Keys);
 REGISTER_SCRIPTFUNCTION(random, &Utility::Random);
+REGISTER_SCRIPTFUNCTION(__get_object, &ScriptUtils::GetObject);
 
 bool ScriptUtils::Regex(const String& pattern, const String& text)
 {
@@ -210,3 +212,13 @@ Array::Ptr ScriptUtils::Keys(const Dictionary::Ptr& dict)
        return result;
 }
 
+DynamicObject::Ptr ScriptUtils::GetObject(const String& type, const String& name)
+{
+       DynamicType::Ptr dtype = DynamicType::GetByName(type);
+
+       if (!dtype)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type name"));
+
+       return dtype->GetObject(name);
+}
+
index 1ba25e0a48484669c4a8453079aa2f3bf6ed3f0f..1a158f8cb91891eb274eb58bf707d89f3758eae8 100644 (file)
@@ -25,6 +25,7 @@
 #include "base/array.hpp"
 #include "base/dictionary.hpp"
 #include "base/type.hpp"
+#include "base/dynamicobject.hpp"
 
 namespace icinga
 {
@@ -44,6 +45,7 @@ public:
        static void Exit(int code);
        static Type::Ptr TypeOf(const Value& value);
        static Array::Ptr Keys(const Dictionary::Ptr& dict);
+       static DynamicObject::Ptr GetObject(const String& type, const String& name);
 
 private:
        ScriptUtils(void);