[icinga-checkins] icinga.org: icinga2/master: Don't instantiate abstract objects.

git at icinga.org git at icinga.org
Mon Mar 11 12:04:18 CET 2013


Module: icinga2
Branch: master
Commit: 6f51230a791bc2be3920ae59cbab044b6d292f55
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=6f51230a791bc2be3920ae59cbab044b6d292f55

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Mar 11 12:04:10 2013 +0100

Don't instantiate abstract objects.

Fixes #3669

---

 lib/base/dynamicobject.cpp          |    9 ---------
 lib/base/dynamicobject.h            |    2 --
 lib/config/configitem.cpp           |   30 ++++++++++++++++++++++--------
 lib/config/configitem.h             |    4 +++-
 lib/config/configitembuilder.cpp    |    5 +----
 lib/icinga/host.cpp                 |    5 ++---
 lib/icinga/service-notification.cpp |    5 ++---
 lib/icinga/service.cpp              |    2 +-
 8 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp
index d0693d6..d45edf7 100644
--- a/lib/base/dynamicobject.cpp
+++ b/lib/base/dynamicobject.cpp
@@ -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);
 
@@ -342,14 +341,6 @@ bool DynamicObject::IsLocal(void) const
 /**
  * @threadsafety Always.
  */
-bool DynamicObject::IsAbstract(void) const
-{
-	return m_Abstract;
-}
-
-/**
- * @threadsafety Always.
- */
 bool DynamicObject::IsRegistered(void) const
 {
 	ObjectLock olock(GetType());
diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h
index b002eaa..fd46723 100644
--- a/lib/base/dynamicobject.h
+++ b/lib/base/dynamicobject.h
@@ -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;
 
diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp
index 90e67a9..b73778d 100644
--- a/lib/config/configitem.cpp
+++ b/lib/config/configitem.cpp
@@ -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)
 {
 }
 
@@ -74,6 +76,16 @@ String ConfigItem::GetUnit(void) const
 }
 
 /**
+ * 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.
  *
  * @returns The debug information.
@@ -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) {
diff --git a/lib/config/configitem.h b/lib/config/configitem.h
index 69f765f..42c300a 100644
--- a/lib/config/configitem.h
+++ b/lib/config/configitem.h
@@ -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
diff --git a/lib/config/configitembuilder.cpp b/lib/config/configitembuilder.cpp
index 81c6789..6c6b12f 100644
--- a/lib/config/configitembuilder.cpp
+++ b/lib/config/configitembuilder.cpp
@@ -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);
 }
diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp
index bb8dffd..408d69f 100644
--- a/lib/icinga/host.cpp
+++ b/lib/icinga/host.cpp
@@ -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;
diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp
index 76bd6b3..8a10709 100644
--- a/lib/icinga/service-notification.cpp
+++ b/lib/icinga/service-notification.cpp
@@ -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;
 
 	{
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index bb49c00..3be6ac0 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -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();
 	}
 }





More information about the icinga-checkins mailing list