]> granicus.if.org Git - icinga2/commitdiff
Don't instantiate abstract objects.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 11 Mar 2013 11:04:10 +0000 (12:04 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 11 Mar 2013 11:04:10 +0000 (12:04 +0100)
Fixes #3669

lib/base/dynamicobject.cpp
lib/base/dynamicobject.h
lib/config/configitem.cpp
lib/config/configitem.h
lib/config/configitembuilder.cpp
lib/icinga/host.cpp
lib/icinga/service-notification.cpp
lib/icinga/service.cpp

index d0693d64f4033ee0abe26061f709e5e3841055df..d45edf775823430c75351f8b30c612f33fd75d55 100644 (file)
@@ -38,7 +38,6 @@ DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject)
        RegisterAttribute("__name", Attribute_Config, &m_Name);
        RegisterAttribute("__type", Attribute_Config, &m_Type);
        RegisterAttribute("__local", Attribute_Config, &m_Local);
-       RegisterAttribute("__abstract", Attribute_Config, &m_Abstract);
        RegisterAttribute("__source", Attribute_Local, &m_Source);
        RegisterAttribute("methods", Attribute_Config, &m_Methods);
 
@@ -339,14 +338,6 @@ bool DynamicObject::IsLocal(void) const
        return m_Local;
 }
 
-/**
- * @threadsafety Always.
- */
-bool DynamicObject::IsAbstract(void) const
-{
-       return m_Abstract;
-}
-
 /**
  * @threadsafety Always.
  */
index b002eaac8dcddc9c2298087f8909de76f767a67e..fd467237c0b0e3885d160af04b8766ae921866b4 100644 (file)
@@ -71,7 +71,6 @@ public:
        String GetName(void) const;
 
        bool IsLocal(void) const;
-       bool IsAbstract(void) const;
        bool IsRegistered(void) const;
 
        void SetSource(const String& value);
@@ -113,7 +112,6 @@ private:
        Attribute<String> m_Name;
        Attribute<String> m_Type;
        Attribute<bool> m_Local;
-       Attribute<bool> m_Abstract;
        Attribute<String> m_Source;
        Attribute<Dictionary::Ptr> m_Methods;
 
index 90e67a9cd38d9d500e762bfa50c430a4f9977001..b73778da868c982138db072a2381578adaadf482 100644 (file)
@@ -31,15 +31,17 @@ signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnRemoved;
  *
  * @param type The object type.
  * @param name The name of the item.
+ * @param unit The unit of the item.
+ * @param abstract Whether the item is a template.
  * @param exprl Expression list for the item.
  * @param parents Parent objects for the item.
  * @param debuginfo Debug information.
  */
 ConfigItem::ConfigItem(const String& type, const String& name,
-    const String& unit, const ExpressionList::Ptr& exprl,
+    const String& unit, bool abstract, const ExpressionList::Ptr& exprl,
     const vector<String>& parents, const DebugInfo& debuginfo)
-       : m_Type(type), m_Name(name), m_Unit(unit), m_ExpressionList(exprl),
-         m_Parents(parents), m_DebugInfo(debuginfo)
+       : m_Type(type), m_Name(name), m_Unit(unit), m_Abstract(abstract),
+         m_ExpressionList(exprl), m_Parents(parents), m_DebugInfo(debuginfo)
 {
 }
 
@@ -73,6 +75,16 @@ String ConfigItem::GetUnit(void) const
        return m_Unit;
 }
 
+/**
+ * Checks whether the item is abstract.
+ *
+ * @returns true if the item is abstract, false otherwise.
+ */
+bool ConfigItem::IsAbstract(void) const
+{
+       return m_Abstract;
+}
+
 /**
  * Retrieves the debug information for the configuration item.
  *
@@ -251,7 +263,7 @@ DynamicObject::Ptr ConfigItem::Commit(void)
        /* Update or create the object and apply the configuration settings. */
        bool was_null = false;
 
-       if (!dobj) {
+       if (!dobj && !IsAbstract()) {
                dobj = dtype->CreateObject(update);
                was_null = true;
        }
@@ -265,10 +277,12 @@ DynamicObject::Ptr ConfigItem::Commit(void)
                m_DynamicObject = dobj;
        }
 
-       if (dobj->IsAbstract())
-               dobj->Unregister();
-       else
-               dobj->Register();
+       if (dobj) {
+               if (IsAbstract())
+                       dobj->Unregister();
+               else
+                       dobj->Register();
+       }
 
        /* notify our children of the update */
        BOOST_FOREACH(const ConfigItem::WeakPtr wchild, children) {
index 69f765f40281ebe91eb8fcb570a65521d0ad67fc..42c300af42266308d38c0f2bd908972d35a07ceb 100644 (file)
@@ -35,12 +35,13 @@ public:
        typedef weak_ptr<ConfigItem> WeakPtr;
 
        ConfigItem(const String& type, const String& name, const String& unit,
-           const ExpressionList::Ptr& exprl, const vector<String>& parents,
+           bool abstract, const ExpressionList::Ptr& exprl, const vector<String>& parents,
            const DebugInfo& debuginfo);
 
        String GetType(void) const;
        String GetName(void) const;
        String GetUnit(void) const;
+       bool IsAbstract(void) const;
 
        vector<String> GetParents(void) const;
 
@@ -75,6 +76,7 @@ private:
        String m_Type; /**< The object type. */
        String m_Name; /**< The name. */
        String m_Unit; /**< The compilation unit. */
+       bool m_Abstract; /**< Whether this is a template. */
 
        ExpressionList::Ptr m_ExpressionList;
        vector<String> m_Parents; /**< The names of parent configuration
index 81c6789f5e2cbcf8d31d57e66c30b5c0651931aa..6c6b12f654e995a92660f542b536b7f08a93faf1 100644 (file)
@@ -139,9 +139,6 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void)
        Expression localExpr("__local", OperatorSet, m_Local, m_DebugInfo);
        exprl->AddExpression(localExpr);
 
-       Expression abstractExpr("__abstract", OperatorSet, m_Abstract, m_DebugInfo);
-       exprl->AddExpression(abstractExpr);
-
-       return boost::make_shared<ConfigItem>(m_Type, m_Name, m_Unit, exprl, m_Parents,
+       return boost::make_shared<ConfigItem>(m_Type, m_Name, m_Unit, m_Abstract, exprl, m_Parents,
            m_DebugInfo);
 }
index bb8dffd097cc9ec1d1f6da2f5bba8aef53219bf5..408d69f61c4f5b0f86698c23c942ad6990d67b39 100644 (file)
@@ -208,9 +208,8 @@ void Host::UpdateSlaveServices(void)
 
        ConfigItem::Ptr item = ConfigItem::GetObject("Host", GetName());
 
-       /* Don't create slave services unless we own this object
-        * and it's not a template. */
-       if (!item || IsAbstract())
+       /* Don't create slave services unless we own this object */
+       if (!item)
                return;
 
        Dictionary::Ptr oldServices = m_SlaveServices;
index 76bd6b38495c66151e6dd461fc05a6709defa215..8a107092e0d69a30ae65ac1ea5041d241a9f359f 100644 (file)
@@ -191,9 +191,8 @@ void Service::UpdateSlaveNotifications(void)
 
        item = ConfigItem::GetObject("Service", GetName());
 
-       /* Don't create slave notifications unless we own this object
-        * and it's not a template. */
-       if (!item || IsAbstract())
+       /* Don't create slave notifications unless we own this object */
+       if (!item)
                return;
 
        {
index bb49c00ee8570d17b9dddc085b808fe7a691954a..3be6ac0ca4d8e48ec8f425ff832dab79999f9c10 100644 (file)
@@ -362,7 +362,7 @@ void Service::OnAttributeChanged(const String& name)
                ConfigItem::Ptr item = ConfigItem::GetObject("Service", GetName());
 
                /* update the next check timestamp if we're the owner of this service */
-               if (item && !IsAbstract())
+               if (item)
                        UpdateNextCheck();
        }
 }