]> granicus.if.org Git - icinga2/commitdiff
Integrate libdyn with the configfile component.
authorGunnar Beutner <gunnar@beutner.name>
Tue, 12 Jun 2012 07:36:18 +0000 (09:36 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 12 Jun 2012 08:13:57 +0000 (10:13 +0200)
38 files changed:
base/Makefile.am
base/application.cpp
base/application.h
base/base.vcxproj
base/configcollection.cpp [deleted file]
base/configcollection.h [deleted file]
base/confighive.cpp [deleted file]
base/confighive.h [deleted file]
base/configobject.cpp
base/configobject.h
base/i2-base.h
base/objectmap.cpp [moved from dyn/objectmap.cpp with 98% similarity]
base/objectmap.h [moved from dyn/objectmap.h with 91% similarity]
base/objectset.cpp [moved from dyn/objectset.cpp with 98% similarity]
base/objectset.h [moved from dyn/objectset.h with 93% similarity]
components/configfile/Makefile.am
components/configfile/configfile.vcxproj
components/configfile/configfilecomponent.cpp
components/configfile/configfilecomponent.h
components/configfile/i2-configfile.h
components/configrpc/configrpc.vcxproj
components/configrpc/configrpccomponent.cpp
components/configrpc/configrpccomponent.h
components/discovery/discovery.vcxproj
components/discovery/discoverycomponent.cpp
components/discovery/discoverycomponent.h
dyn/Makefile.am
dyn/configitem.cpp
dyn/configitem.h
dyn/dyn.vcxproj
dyn/dynamicobject.cpp [deleted file]
dyn/dynamicobject.h [deleted file]
dyn/i2-dyn.h
dyntest/dyntest.cpp
icinga/icingaapplication.cpp
icinga/icingaapplication.h
icinga/icingacomponent.cpp
icinga/icingacomponent.h

index e6cefbe3f6f3abab77ebeee79640328b10d6f4d0..a3455a0c8cd006a662a3b4d3afa7c98c407b31e2 100644 (file)
@@ -9,10 +9,6 @@ libbase_la_SOURCES =  \
        application.h \
        component.cpp \
        component.h \
-       configcollection.cpp \
-       configcollection.h \
-       confighive.cpp \
-       confighive.h \
        configobject.cpp \
        configobject.h \
        cxx11-compat.h \
@@ -27,6 +23,10 @@ libbase_la_SOURCES =  \
        i2-base.h \
        object.cpp \
        object.h \
+       objectset.cpp \
+       objectset.h \
+       objectmap.cpp \
+       objectmap.h \
        socket.cpp \
        socket.h \
        tcpclient.cpp \
index 0e6a5753c815193fa6b5ca3209576c12a73bb2b5..77f5dde84bd42161d7345a99f323e6e8d20274e2 100644 (file)
@@ -49,8 +49,6 @@ Application::Application(void)
        if (IsDebuggerPresent())
                m_Debugging = true;
 #endif /* _WIN32 */
-
-       m_ConfigHive = make_shared<ConfigHive>();
 }
 
 /**
@@ -197,16 +195,6 @@ void Application::Shutdown(void)
        m_ShuttingDown = true;
 }
 
-/**
- * Returns the application's configuration hive.
- *
- * @returns The config hive.
- */
-ConfigHive::Ptr Application::GetConfigHive(void) const
-{
-       return m_ConfigHive;
-}
-
 /**
  * Loads a component from a shared library.
  *
index befeeff06adc203c7531ea594e531a50fb7426d4..958608d2488f1407891edffcb2146cc93e2361c7 100644 (file)
@@ -47,8 +47,6 @@ public:
 
        static void Log(string message);
 
-       ConfigHive::Ptr GetConfigHive(void) const;
-
        shared_ptr<Component> LoadComponent(const string& path,
            const ConfigObject::Ptr& componentConfig);
        void RegisterComponent(shared_ptr<Component> component);
@@ -67,7 +65,6 @@ private:
 
        static bool m_ShuttingDown; /**< Whether the application is in the process of
                                  shutting down. */
-       ConfigHive::Ptr m_ConfigHive; /**< The application's configuration. */
        map< string, shared_ptr<Component> > m_Components; /**< Components that
                                        were loaded by the application. */
        vector<string> m_Arguments; /**< Command-line arguments */
index 51871ee7b37244f8872d87a0175d236bb976e0a3..f7e4cc647543b4c07495330777641f5212754cf5 100644 (file)
   <ItemGroup>
     <ClCompile Include="application.cpp" />
     <ClCompile Include="component.cpp" />
-    <ClCompile Include="configcollection.cpp" />
-    <ClCompile Include="confighive.cpp" />
     <ClCompile Include="configobject.cpp" />
     <ClCompile Include="dictionary.cpp" />
     <ClCompile Include="exception.cpp" />
     <ClCompile Include="fifo.cpp" />
     <ClCompile Include="object.cpp" />
+    <ClCompile Include="objectmap.cpp" />
+    <ClCompile Include="objectset.cpp" />
     <ClCompile Include="socket.cpp" />
     <ClCompile Include="tcpclient.cpp" />
     <ClCompile Include="tcpserver.cpp" />
   <ItemGroup>
     <ClInclude Include="application.h" />
     <ClInclude Include="component.h" />
-    <ClInclude Include="configcollection.h" />
-    <ClInclude Include="confighive.h" />
     <ClInclude Include="configobject.h" />
     <ClInclude Include="cxx11-compat.h" />
     <ClInclude Include="delegate.h" />
     <ClInclude Include="dictionary.h" />
+    <ClInclude Include="objectmap.h" />
+    <ClInclude Include="objectset.h" />
     <ClInclude Include="observable.h" />
     <ClInclude Include="exception.h" />
     <ClInclude Include="fifo.h" />
diff --git a/base/configcollection.cpp b/base/configcollection.cpp
deleted file mode 100644 (file)
index 483a50d..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
-
-#include "i2-base.h"
-
-using namespace icinga;
-
-/**
- * Sets the hive this collection belongs to.
- *
- * @param hive The hive.
- */
-void ConfigCollection::SetHive(const ConfigHive::WeakPtr& hive)
-{
-       m_Hive = hive;
-}
-
-/**
- * Retrieves the hive this collection belongs to.
- *
- * @returns The hive.
- */
-ConfigHive::WeakPtr ConfigCollection::GetHive(void) const
-{
-       return m_Hive;
-}
-
-/**
- * Adds a new object to this collection.
- *
- * @param object The new object.
- */
-void ConfigCollection::AddObject(const ConfigObject::Ptr& object)
-{
-       RemoveObject(object);
-
-       Objects[object->GetName()] = object;
-       object->Commit();
-}
-
-/**
- * Removes an object from this collection
- *
- * @param object The object that is to be removed.
- */
-void ConfigCollection::RemoveObject(const ConfigObject::Ptr& object)
-{
-       ObjectIterator oi = Objects.find(object->GetName());
-
-       if (oi != Objects.end()) {
-               Objects.erase(oi);
-
-               EventArgs ea;
-               ea.Source = object;
-               OnObjectRemoved(ea);
-
-               ConfigHive::Ptr hive = m_Hive.lock();
-               if (hive)
-                       hive->OnObjectRemoved(ea);
-       }
-}
-
-/**
- * Retrieves an object by name.
- *
- * @param name The name of the object.
- * @returns The object or a null pointer if the specified object
- *          could not be found.
- */
-ConfigObject::Ptr ConfigCollection::GetObject(const string& name) const
-{
-       ObjectConstIterator oi = Objects.find(name);
-
-       if (oi == Objects.end())
-               return ConfigObject::Ptr();
-
-       return oi->second;
-}
-
-/**
- * Invokes the specified callback for each object contained in this collection.
- *
- * @param callback The callback.
- */
-void ConfigCollection::ForEachObject(function<int (const EventArgs&)> callback)
-{
-       EventArgs ea;
-
-       for (ObjectIterator oi = Objects.begin(); oi != Objects.end(); oi++) {
-               ea.Source = oi->second;
-               callback(ea);
-       }
-}
diff --git a/base/configcollection.h b/base/configcollection.h
deleted file mode 100644 (file)
index 4f448fa..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
-
-#ifndef CONFIGCOLLECTION_H
-#define CONFIGCOLLECTION_H
-
-namespace icinga
-{
-
-class ConfigHive;
-
-/**
- * A collection of configuration objects that each have the same type.
- *
- * @ingroup base
- */
-class I2_BASE_API ConfigCollection : public Object
-{
-public:
-       typedef shared_ptr<ConfigCollection> Ptr;
-       typedef weak_ptr<ConfigCollection> WeakPtr;
-
-       typedef map<string, ConfigObject::Ptr>::iterator ObjectIterator;
-       typedef map<string, ConfigObject::Ptr>::const_iterator ObjectConstIterator;
-       map<string, ConfigObject::Ptr> Objects;
-
-       void SetHive(const weak_ptr<ConfigHive>& hive);
-       weak_ptr<ConfigHive> GetHive(void) const;
-
-       void AddObject(const ConfigObject::Ptr& object);
-       void RemoveObject(const ConfigObject::Ptr& object);
-       ConfigObject::Ptr GetObject(const string& name = string()) const;
-
-       void ForEachObject(function<int (const EventArgs&)> callback);
-
-       Observable<EventArgs> OnObjectCommitted;
-       Observable<EventArgs> OnObjectRemoved;
-
-private:
-       weak_ptr<ConfigHive> m_Hive;
-
-};
-
-}
-
-#endif /* CONFIGCOLLECTION_H */
diff --git a/base/confighive.cpp b/base/confighive.cpp
deleted file mode 100644 (file)
index 37a4e63..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
-
-#include "i2-base.h"
-
-using namespace icinga;
-
-/**
- * Adds a new object to this hive.
- *
- * @param object The new object.
- */
-void ConfigHive::AddObject(const ConfigObject::Ptr& object)
-{
-       object->SetHive(static_pointer_cast<ConfigHive>(shared_from_this()));
-       GetCollection(object->GetType())->AddObject(object);
-}
-
-/**
- * Removes an object from this hive.
- *
- * @param object The object that is to be removed.
- */
-void ConfigHive::RemoveObject(const ConfigObject::Ptr& object)
-{
-       GetCollection(object->GetType())->RemoveObject(object);
-}
-
-/**
- * Retrieves an object by type and name.
- *
- * @param type The type of the object.
- * @param name The name of the object.
- * @returns The object or a null pointer if the specified object
- *          could not be found.
- */
-ConfigObject::Ptr ConfigHive::GetObject(const string& type, const string& name)
-{
-       return GetCollection(type)->GetObject(name);
-}
-
-/**
- * Retrieves a collection by name. Creates an empty collection
- * if the collection doesn't already exist.
- *
- * @param collection The name of the collection.
- * @returns The collection or a null pointer if the specified collection
- *          could not be found.
- */
-ConfigCollection::Ptr ConfigHive::GetCollection(const string& collection)
-{
-       CollectionConstIterator ci = Collections.find(collection);
-
-       if (ci == Collections.end()) {
-               Collections[collection] = make_shared<ConfigCollection>();
-               ci = Collections.find(collection);
-       }
-
-       return ci->second;
-}
-
-/**
- * Invokes the specified callback for each object contained in this hive.
- *
- * @param type The config object type.
- * @param callback The callback.
- */
-void ConfigHive::ForEachObject(const string& type,
-    function<int (const EventArgs&)> callback)
-{
-       CollectionIterator ci = Collections.find(type);
-
-       if (ci == Collections.end())
-               return;
-
-       ci->second->ForEachObject(callback);
-}
diff --git a/base/confighive.h b/base/confighive.h
deleted file mode 100644 (file)
index ac47320..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
-
-#ifndef CONFIGHIVE_H
-#define CONFIGHIVE_H
-
-namespace icinga
-{
-
-/**
- * A collection of all configuration objects that belong to an application.
- *
- * @ingroup base
- */
-class I2_BASE_API ConfigHive : public Object
-{
-public:
-       typedef shared_ptr<ConfigHive> Ptr;
-       typedef weak_ptr<ConfigHive> WeakPtr;
-
-       typedef map<string, ConfigCollection::Ptr>::iterator CollectionIterator;
-       typedef map<string, ConfigCollection::Ptr>::const_iterator CollectionConstIterator;
-       map<string, ConfigCollection::Ptr> Collections;
-
-       void AddObject(const ConfigObject::Ptr& object);
-       void RemoveObject(const ConfigObject::Ptr& object);
-       ConfigObject::Ptr GetObject(const string& type,
-           const string& name = string());
-       ConfigCollection::Ptr GetCollection(const string& type);
-
-       void ForEachObject(const string& type,
-           function<int (const EventArgs&)> callback);
-
-       Observable<EventArgs> OnObjectCommitted;
-       Observable<EventArgs> OnObjectRemoved;
-};
-
-}
-
-#endif /* CONFIGHIVE_H */
index d0a1ba49ef7cf37bc84bc04dacb6033498ea980e..6a6dd32424277ab37c4963e284c26d6b9d86d3d1 100644 (file)
 
 using namespace icinga;
 
-/**
- * Constructor for the ConfigObject class.
- *
- * @param type The type of the object.
- * @param name The name of the object.
- */
-ConfigObject::ConfigObject(const string& type, const string& name)
+ConfigObject::ConfigObject(Dictionary::Ptr properties)
+       : m_Properties(properties), m_Tags(make_shared<Dictionary>())
+{ }
+
+ConfigObject::ConfigObject(string type, string name)
+       : m_Properties(make_shared<Dictionary>()), m_Tags(make_shared<Dictionary>())
 {
-       m_Type = type;
-       m_Name = name;
-       m_Replicated = false;
+       SetProperty("__type", type);
+       SetProperty("__name", name);
 }
 
-/**
- * Sets the hive this object belongs to.
- *
- * @param hive The hive.
- */
-void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
+void ConfigObject::SetProperties(Dictionary::Ptr properties)
 {
-       if (m_Hive.lock())
-               throw logic_error("Config object already has a parent hive.");
+       m_Properties = properties;
+}
 
-       m_Hive = hive;
+Dictionary::Ptr ConfigObject::GetProperties(void) const
+{
+       return m_Properties;
 }
 
-/**
- * Retrieves the hive this object belongs to.
- *
- * @returns The hive.
- */
-ConfigHive::WeakPtr ConfigObject::GetHive(void) const
+Dictionary::Ptr ConfigObject::GetTags(void) const
 {
-       return m_Hive;
+       return m_Tags;
 }
 
-/**
- * Sets the name of this object.
- *
- * @param name The name.
- */
-void ConfigObject::SetName(const string& name)
+string ConfigObject::GetType(void) const
 {
-       m_Name = name;
+       string type;
+       GetProperties()->GetProperty("__type", &type);
+       return type;
 }
 
-/**
- * Retrieves the name of this object.
- *
- * @returns The name.
- */
 string ConfigObject::GetName(void) const
 {
-       return m_Name;
+       string name;
+       GetProperties()->GetProperty("__name", &name);
+       return name;
 }
 
-/**
- * Sets the type of this object.
- *
- * @param type The type.
- */
-void ConfigObject::SetType(const string& type)
+void ConfigObject::SetLocal(bool value)
 {
-       m_Type = type;
+       GetProperties()->SetProperty("__local", value ? 1 : 0);
 }
 
-/**
- * Retrieves the type of this object.
- *
- * @returns The type.
- */
-string ConfigObject::GetType(void) const
+bool ConfigObject::IsLocal(void) const
 {
-       return m_Type;
+       bool value;
+       GetProperties()->GetProperty("__local", &value);
+       return (value != 0);
 }
 
-/**
- * Sets whether this object was replicated.
- *
- * @param replicated Whether this object was replicated.
- */
-void ConfigObject::SetReplicated(bool replicated)
+void ConfigObject::SetAbstract(bool value)
 {
-       m_Replicated = replicated;
+       GetProperties()->SetProperty("__abstract", value ? 1 : 0);
 }
 
-/**
- * Retrieves whether this object was replicated.
- *
- * @returns Whether this object was replicated.
- */
-bool ConfigObject::IsReplicated(void) const
+bool ConfigObject::IsAbstract(void) const
 {
-       return m_Replicated;
+       long value;
+       GetProperties()->GetProperty("__abstract", &value);
+       return (value != 0);
 }
 
-/**
- * Handles changed properties by propagating them to the hive
- * and collection this object is contained in.
- *
- */
 void ConfigObject::Commit(void)
 {
-       ConfigHive::Ptr hive = m_Hive.lock();
-       if (hive) {
-               EventArgs ea;
-               ea.Source = shared_from_this();
-               hive->GetCollection(m_Type)->OnObjectCommitted(ea);
-               hive->OnObjectCommitted(ea);
+       ConfigObject::Ptr dobj = GetObject(GetType(), GetName());
+       ConfigObject::Ptr self = static_pointer_cast<ConfigObject>(shared_from_this());
+       assert(!dobj || dobj == self);
+       GetAllObjects()->CheckObject(self);
+}
+
+void ConfigObject::Unregister(void)
+{
+       ConfigObject::Ptr self = static_pointer_cast<ConfigObject>(shared_from_this());
+       GetAllObjects()->RemoveObject(self);
+}
+
+ObjectSet<ConfigObject::Ptr>::Ptr ConfigObject::GetAllObjects(void)
+{
+       static ObjectSet<ConfigObject::Ptr>::Ptr allObjects;
+
+       if (!allObjects) {
+               allObjects = make_shared<ObjectSet<ConfigObject::Ptr> >();
+               allObjects->Start();
        }
+
+       return allObjects;
 }
+
+ConfigObject::TNMap::Ptr ConfigObject::GetObjectsByTypeAndName(void)
+{
+       static ConfigObject::TNMap::Ptr tnmap;
+
+       if (!tnmap) {
+               tnmap = make_shared<ConfigObject::TNMap>(GetAllObjects(), &ConfigObject::TypeAndNameGetter);
+               tnmap->Start();
+       }
+
+       return tnmap;
+}
+
+ConfigObject::Ptr ConfigObject::GetObject(string type, string name)
+{
+       ConfigObject::TNMap::Range range;
+       range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name));
+
+       assert(distance(range.first, range.second) <= 1);
+
+       if (range.first == range.second)
+               return ConfigObject::Ptr();
+       else
+               return range.first->second;
+}
+
+bool ConfigObject::TypeAndNameGetter(const ConfigObject::Ptr& object, pair<string, string> *key)
+{
+        *key = make_pair(object->GetType(), object->GetName());
+
+        return true;
+}
+
+function<bool (ConfigObject::Ptr)> ConfigObject::MakeTypePredicate(string type)
+{
+       return bind(&ConfigObject::TypePredicate, _1, type);
+}
+
+bool ConfigObject::TypePredicate(const ConfigObject::Ptr& object, string type)
+{
+       return (object->GetType() == type);
+}
+
+ConfigObject::TMap::Ptr ConfigObject::GetObjectsByType(void)
+{
+       static ObjectMap<string, ConfigObject::Ptr>::Ptr tmap;
+
+       if (!tmap) {
+               tmap = make_shared<ConfigObject::TMap>(GetAllObjects(), &ConfigObject::TypeGetter);
+               tmap->Start();
+       }
+
+       return tmap;
+}
+
+bool ConfigObject::TypeGetter(const ConfigObject::Ptr& object, string *key)
+{
+       *key = object->GetType();
+       return true;
+}
+
+ConfigObject::TMap::Range ConfigObject::GetObjects(string type)
+{
+       return GetObjectsByType()->GetRange(type);
+}
\ No newline at end of file
index 8871d8c50a7fa261a165a5bc2b9ba331f874183b..52f530c610c5ee31a271544305575b027e1e7cc2 100644 (file)
 #ifndef CONFIGOBJECT_H
 #define CONFIGOBJECT_H
 
-#include <map>
-
 namespace icinga
 {
 
-class ConfigHive;
-
-/**
- * A configuration object that has arbitrary properties.
- *
- * @ingroup base
- */
-class I2_BASE_API ConfigObject : public Dictionary
+class I2_BASE_API ConfigObject : public Object
 {
 public:
        typedef shared_ptr<ConfigObject> Ptr;
        typedef weak_ptr<ConfigObject> WeakPtr;
 
-       ConfigObject(const string& type, const string& name);
+       typedef ObjectMap<pair<string, string>, ConfigObject::Ptr> TNMap;
+       typedef ObjectMap<string, ConfigObject::Ptr> TMap;
+       typedef ObjectSet<ConfigObject::Ptr> Set;
 
-       void SetHive(const weak_ptr<ConfigHive>& hive);
-       weak_ptr<ConfigHive> GetHive(void) const;
+       ConfigObject(Dictionary::Ptr properties);
+       ConfigObject(string type, string name);
 
-       void SetName(const string& name);
-       string GetName(void) const;
+       void SetProperties(Dictionary::Ptr config);
+       Dictionary::Ptr GetProperties(void) const;
+
+       template<typename T>
+       void SetProperty(const string& key, const T& value)
+       {
+               GetProperties()->SetProperty(key, value);
+       }
+
+       template<typename T>
+       bool GetProperty(const string& key, T *value) const
+       {
+               return GetProperties()->GetProperty(key, value);
+       }
+
+       Dictionary::Ptr GetTags(void) const;
+
+       template<typename T>
+       void SetTag(const string& key, const T& value)
+       {
+               GetTags()->SetProperty(key, value);
+       }
+
+       template<typename T>
+       bool GetTag(const string& key, T *value) const
+       {
+               return GetTags()->GetProperty(key, value);
+       }
 
-       void SetType(const string& type);
        string GetType(void) const;
+       string GetName(void) const;
+
+       void SetLocal(bool value);
+       bool IsLocal(void) const;
 
-       void SetReplicated(bool replicated);
-       bool IsReplicated(void) const;
+       void SetAbstract(bool value);
+       bool IsAbstract(void) const;
 
        void Commit(void);
+       void Unregister(void);
+
+       static ObjectSet<ConfigObject::Ptr>::Ptr GetAllObjects(void);
+
+       static TNMap::Ptr GetObjectsByTypeAndName(void);
+       static TMap::Ptr GetObjectsByType(void);
+
+       static ConfigObject::Ptr GetObject(string type, string name);
+       
+       static TMap::Range GetObjects(string type);
+
+       static function<bool (ConfigObject::Ptr)> MakeTypePredicate(string type);
 
 private:
-       weak_ptr<ConfigHive> m_Hive;
+       Dictionary::Ptr m_Properties;
+       Dictionary::Ptr m_Tags;
+
+       static bool TypeAndNameGetter(const ConfigObject::Ptr& object, pair<string, string> *key);
+       static bool TypePredicate(const ConfigObject::Ptr& object, string type);
 
-       string m_Name;
-       string m_Type;
-       bool m_Replicated;
+       static bool TypeGetter(const ConfigObject::Ptr& object, string *key);
 };
 
 }
index 15148806379ef81830b837354d0560ba0648b6fa..e57abdf305ac3d9cdf921a38d3b229a2cc22552d 100644 (file)
@@ -154,9 +154,9 @@ using namespace std::tr1::placeholders;
 #include "tcpclient.h"
 #include "tcpserver.h"
 #include "tlsclient.h"
+#include "objectset.h"
+#include "objectmap.h"
 #include "configobject.h"
-#include "configcollection.h"
-#include "confighive.h"
 #include "application.h"
 #include "component.h"
 
similarity index 98%
rename from dyn/objectmap.cpp
rename to base/objectmap.cpp
index 87e29b3c167744248f88d3aa2c7c1bad8b887bbe..c5ac6be3973dcbdd8d8412f8206bd364e94cba80 100644 (file)
@@ -17,7 +17,7 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#include "i2-dyn.h"
+#include "i2-base.h"
 
 using namespace icinga;
 
similarity index 91%
rename from dyn/objectmap.h
rename to base/objectmap.h
index d4d96da719451186bc34ca04556c4b001a8e74fe..6456ab4c478b7278c2dd5adb871b0e58d2c9e8c5 100644 (file)
@@ -24,7 +24,7 @@ namespace icinga
 {
 
 template<typename TKey = string, typename TValue = Object::Ptr>
-class I2_DYN_API ObjectMap : public Object
+class ObjectMap : public Object
 {
 public:
        typedef shared_ptr<ObjectMap<TKey, TValue> > Ptr;
@@ -56,6 +56,19 @@ public:
                return m_Objects.equal_range(key);
        }
 
+       void ForeachObject(TKey key, function<int (const ObjectSetEventArgs<TValue>&)> callback)
+       {
+               ObjectSetEventArgs<TValue> ea;
+               ea.Source = shared_from_this();
+
+               Range range = GetRange(key);
+
+               for (Iterator it = range.first; it != range.second; it++) {
+                       ea.Target(*it);
+                       callback(ea);
+               }
+       }
+
 private:
        multimap<TKey, TValue> m_Objects;
        typename ObjectSet<TValue>::Ptr m_Parent;
similarity index 98%
rename from dyn/objectset.cpp
rename to base/objectset.cpp
index 87e29b3c167744248f88d3aa2c7c1bad8b887bbe..c5ac6be3973dcbdd8d8412f8206bd364e94cba80 100644 (file)
@@ -17,7 +17,7 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#include "i2-dyn.h"
+#include "i2-base.h"
 
 using namespace icinga;
 
similarity index 93%
rename from dyn/objectset.h
rename to base/objectset.h
index af0796a711bfc4c81656ab792d36b3cc3418f5ad..f7bcde34bcdcc6eb02ce1a737f20bd968e83bf09 100644 (file)
@@ -30,7 +30,7 @@ struct ObjectSetEventArgs : public EventArgs
 };
 
 template<typename TValue>
-class I2_DYN_API ObjectSet : public Object
+class ObjectSet : public Object
 {
 public:
        typedef shared_ptr<ObjectSet<TValue> > Ptr;
@@ -121,6 +121,17 @@ public:
                return m_Objects.end();
        }
 
+       void ForeachObject(function<int (const ObjectSetEventArgs<TValue>&)> callback)
+       {
+               ObjectSetEventArgs<TValue> ea;
+               ea.Source = shared_from_this();
+
+               for (Iterator it = Begin(); it != End(); it++) {
+                       ea.Target(*it);
+                       callback(ea);
+               }
+       }
+
 private:
        set<TValue> m_Objects;
 
index 931ae6790258e8ef2e0906da4cb098b459e9bdd3..57ba9001350fb68b338669b12319b2ecd61d1cb7 100644 (file)
@@ -11,9 +11,7 @@ configfile_la_SOURCES = \
 configfile_la_CPPFLAGS = \
        $(BOOST_CPPFLAGS) \
        -I${top_srcdir}/base \
-       -I${top_srcdir}/icinga \
-       -I${top_srcdir}/jsonrpc \
-       -I${top_srcdir}/third-party/cJSON
+       -I${top_srcdir}/dyn
 
 configfile_la_LDFLAGS = \
        $(BOOST_LDFLAGS) \
@@ -24,5 +22,4 @@ configfile_la_LDFLAGS = \
 
 configfile_la_LIBADD = \
        $(top_builddir)/base/libbase.la \
-       $(top_builddir)/icinga/libicinga.la \
-       $(top_builddir)/third-party/cJSON/libcJSON.la
+       $(top_builddir)/dyn/libdyn.la
index 74e474d155ec3e0ff042473666358de6828063b4..01e6e01d4813afa966111b5be308ed0c6b056d65 100644 (file)
   </ImportGroup>
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\third-party\cJSON;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\icinga;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\third-party\cJSON;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\icinga;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@@ -63,7 +63,7 @@
     <Link>
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>base.lib;dyn.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <Lib>
       <AdditionalDependencies>
@@ -86,7 +86,7 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>base.lib;dyn.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <Lib>
       <AdditionalDependencies>$(OutDir)\base.lib;$(OutDir)\jsonrpc.lib</AdditionalDependencies>
index d89b8c0bedc0dd43ae2e626b1abaf704356a07b7..c7f04a2c8bdf9ecab5d9f608cf94257564550ae2 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#include <iostream>
-#include <fstream>
 #include "i2-configfile.h"
-#include "cJSON.h"
 
 using namespace icinga;
 
@@ -38,66 +35,13 @@ void ConfigFileComponent::Start(void)
        if (!GetConfig()->GetProperty("configFilename", &filename))
                throw logic_error("Missing 'configFilename' property");
 
-       fp.open(filename.c_str(), ifstream::in);
-       if (fp.fail())
-               throw runtime_error("Could not open config file");
-       
-       GetIcingaApplication()->Log("Reading config file: " + filename);
+       Application::Log("Compiling config file: " + filename);
 
-       while (!fp.eof()) {
-               size_t bufferSize = 1024;
-               char *buffer = (char *)fifo->GetWriteBuffer(&bufferSize);
-               fp.read(buffer, bufferSize);
-               if (fp.bad())
-                       throw runtime_error("Could not read from config file");
-               fifo->Write(NULL, fp.gcount());
-       }
+       vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(filename);
 
-       fp.close();
+       Application::Log("Executing config items...");
 
-       fifo->Write("\0", 1);
-
-       /* TODO: implement config parsing, for now we just use JSON */
-       cJSON *jsonobj = cJSON_Parse((const char *)fifo->GetReadBuffer());
-       fifo->Read(NULL, fifo->GetSize());
-
-       if (jsonobj == NULL)
-               throw ConfigParserException("Could not parse config file.");
-
-       for (cJSON *typeobj = jsonobj->child; typeobj != NULL; typeobj = typeobj->next) {
-               string type = typeobj->string;
-
-               for (cJSON *object = typeobj->child; object != NULL; object = object->next) {
-                       string name = object->string;
-
-                       ConfigObject::Ptr cfgobj = make_shared<ConfigObject>(type, name);
-
-                       for (cJSON *property = object->child; property != NULL; property = property->next) {
-                               string key = property->string;
-                               
-                               if (property->type == cJSON_String) {
-                                       string value = property->valuestring;
-
-                                       cfgobj->SetProperty(key, value);
-                               } else if (property->type == cJSON_Array) {
-                                       Dictionary::Ptr items = make_shared<Dictionary>();
-
-                                       for (cJSON *item = property->child; item != NULL; item = item->next) {
-                                               if (item->type != cJSON_String)
-                                                       continue;
-
-                                               items->AddUnnamedProperty(item->valuestring);
-                                       }
-
-                                       cfgobj->SetProperty(key, items);
-                               }
-                       }
-
-                       GetConfigHive()->AddObject(cfgobj);
-               }
-       }
-
-       cJSON_Delete(jsonobj);
+       ConfigVM::ExecuteItems(configItems);
 }
 
 void ConfigFileComponent::Stop(void)
index fd4d4df85b65e3c3910f6d267ca1c8d53c0b9307..618450deb957ab2db8f4d24c43b0a3ac9f051f49 100644 (file)
@@ -33,7 +33,7 @@ DEFINE_EXCEPTION_CLASS(ConfigParserException);
 /**
  * @ingroup configfile
  */
-class ConfigFileComponent : public IcingaComponent
+class ConfigFileComponent : public Component
 {
 public:
        typedef shared_ptr<ConfigFileComponent> Ptr;
index 25dbe9334592166c66050667e61d34a8c9eabdce..0c534de886f2cff29860ead74b3a6ed1670a00b0 100644 (file)
@@ -28,7 +28,7 @@
  */
 
 #include <i2-base.h>
-#include <i2-icinga.h>
+#include <i2-dyn.h>
 
 #include "configfilecomponent.h"
 
index f42b96386ddb7dc4625311ded67b57745332ce7a..47805d16a83e000196778cde1ad1a6b1f0528935 100644 (file)
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <LinkIncremental>true</LinkIncremental>
-    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LinkIncremental>false</LinkIncremental>
-    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
index 37c2c36974edaa7620c29b8c7a2f84d6bd770c05..01190acaff95ea6679f49c6b96d5d5547bf31762 100644 (file)
@@ -29,7 +29,6 @@ string ConfigRpcComponent::GetName(void) const
 void ConfigRpcComponent::Start(void)
 {
        EndpointManager::Ptr endpointManager = GetEndpointManager();
-       ConfigHive::Ptr configHive = GetConfigHive();
 
        m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
 
@@ -38,8 +37,9 @@ void ConfigRpcComponent::Start(void)
                m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
                    bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
 
-               configHive->OnObjectCommitted += bind_weak(&ConfigRpcComponent::LocalObjectCommittedHandler, shared_from_this());
-               configHive->OnObjectRemoved += bind_weak(&ConfigRpcComponent::LocalObjectRemovedHandler, shared_from_this());
+               ConfigObject::GetAllObjects()->OnObjectAdded += bind_weak(&ConfigRpcComponent::LocalObjectCommittedHandler, shared_from_this());
+               ConfigObject::GetAllObjects()->OnObjectCommitted += bind_weak(&ConfigRpcComponent::LocalObjectCommittedHandler, shared_from_this());
+               ConfigObject::GetAllObjects()->OnObjectRemoved += bind_weak(&ConfigRpcComponent::LocalObjectRemovedHandler, shared_from_this());
 
                m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
                m_ConfigRpcEndpoint->RegisterPublication("config::ObjectRemoved");
@@ -110,27 +110,23 @@ bool ConfigRpcComponent::ShouldReplicateObject(const ConfigObject::Ptr& object)
 int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
 {
        Endpoint::Ptr client = ea.Sender;
-       ConfigHive::Ptr configHive = GetConfigHive();
+       ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
 
-       for (ConfigHive::CollectionIterator ci = configHive->Collections.begin(); ci != configHive->Collections.end(); ci++) {
-               ConfigCollection::Ptr collection = ci->second;
+       for (ConfigObject::Set::Iterator ci = allObjects->Begin(); ci != allObjects->End(); ci++) {
+               ConfigObject::Ptr object = *ci;
 
-               for (ConfigCollection::ObjectIterator oi = collection->Objects.begin(); oi != collection->Objects.end(); oi++) {
-                       ConfigObject::Ptr object = oi->second;
+               if (!ShouldReplicateObject(object))
+                       continue;
 
-                       if (!ShouldReplicateObject(object))
-                               continue;
+               RequestMessage request = MakeObjectMessage(object, "config::ObjectCreated", true);
 
-                       RequestMessage request = MakeObjectMessage(object, "config::ObjectCreated", true);
-
-                       GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
-               }
+               GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
        }
 
        return 0;
 }
 
-int ConfigRpcComponent::LocalObjectCommittedHandler(const EventArgs& ea)
+int ConfigRpcComponent::LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
 {
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        
@@ -143,7 +139,7 @@ int ConfigRpcComponent::LocalObjectCommittedHandler(const EventArgs& ea)
        return 0;
 }
 
-int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
+int ConfigRpcComponent::LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
 {
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        
@@ -159,7 +155,6 @@ int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
 int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
 {
        RequestMessage message = ea.Request;
-       bool was_null = false;
 
        MessagePart params;
        if (!message.GetParams(&params))
@@ -173,26 +168,18 @@ int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs&
        if (!params.GetProperty("type", &type))
                return 0;
 
-       ConfigHive::Ptr configHive = GetConfigHive();
-       ConfigObject::Ptr object = configHive->GetObject(type, name);
-
-       if (!object) {
-               was_null = true;
-               object = make_shared<ConfigObject>(type, name);
-       }
-
        MessagePart properties;
        if (!params.GetProperty("properties", &properties))
                return 0;
 
-       for (DictionaryIterator i = properties.Begin(); i != properties.End(); i++) {
-               object->SetProperty(i->first, i->second);
-       }
+       ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
 
-       if (was_null) {
-               object->SetReplicated(true);
-               configHive->AddObject(object);
-       }
+       if (!object)
+               object = make_shared<ConfigObject>(properties.GetDictionary());
+       else
+               object->SetProperties(properties.GetDictionary());
+
+       object->Commit();
 
        return 0;
 }
@@ -213,14 +200,13 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea
        if (!params.GetProperty("type", &type))
                return 0;
 
-       ConfigHive::Ptr configHive = GetConfigHive();
-       ConfigObject::Ptr object = configHive->GetObject(type, name);
+       ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
 
        if (!object)
                return 0;
 
-       if (object->IsReplicated())
-               configHive->RemoveObject(object);
+       if (!object->IsLocal())
+               object->Unregister();
 
        return 0;
 }
index a7a0eda4eb49b022952b0f375a8bf92a2962298a..2ae882d6a46f6476a8b5214c3e0aa577f852c8b6 100644 (file)
@@ -28,14 +28,19 @@ namespace icinga
  */
 class ConfigRpcComponent : public IcingaComponent
 {
+public:
+       virtual string GetName(void) const;
+       virtual void Start(void);
+       virtual void Stop(void);
+
 private:
        VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
 
        int NewEndpointHandler(const NewEndpointEventArgs& ea);
        int SessionEstablishedHandler(const EventArgs& ea);
 
-       int LocalObjectCommittedHandler(const EventArgs& ea);
-       int LocalObjectRemovedHandler(const EventArgs& ea);
+       int LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
+       int LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
 
        int FetchObjectsHandler(const NewRequestEventArgs& ea);
        int RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
@@ -45,10 +50,6 @@ private:
            string method, bool includeProperties);
 
        static bool ShouldReplicateObject(const ConfigObject::Ptr& object);
-public:
-       virtual string GetName(void) const;
-       virtual void Start(void);
-       virtual void Stop(void);
 };
 
 }
index ff09b4f25740ee8c6d2ef58c3373589193195f89..4e6a6ed42d012249f8e7aa69a0775c5f94df0aba 100644 (file)
@@ -58,7 +58,7 @@
     <Link>
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -76,7 +76,7 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
index 9965353bfbbc9b3a0e601b365cb3c3ed9ed5b59f..b9b50396b0478840f34a38346b4b7f42fdd88dca 100644 (file)
@@ -348,14 +348,10 @@ bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string mess
        if (!roles)
                return false;
 
-       ConfigHive::Ptr configHive = GetConfigHive();
-       ConfigCollection::Ptr roleCollection = configHive->GetCollection("role");
+       ConfigObject::TMap::Range range = ConfigObject::GetObjects("role");
 
-       for (DictionaryIterator ip = roles->Begin(); ip != roles->End(); ip++) {
-               ConfigObject::Ptr role = roleCollection->GetObject(ip->second);
-
-               if (!role)
-                       continue;
+       for (ConfigObject::TMap::Iterator ip = range.first; ip != range.second; ip++) {
+               ConfigObject::Ptr role = ip->second;
 
                Object::Ptr object;
                if (!role->GetProperty(messageType, &object))
@@ -395,10 +391,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
        message.GetNode(&info->Node);
        message.GetService(&info->Service);
 
-       ConfigHive::Ptr configHive = GetConfigHive();
-       ConfigCollection::Ptr endpointCollection = configHive->GetCollection("endpoint");
-
-       ConfigObject::Ptr endpointConfig = endpointCollection->GetObject(identity);
+       ConfigObject::Ptr endpointConfig = ConfigObject::GetObject("endpoint", identity);
        Dictionary::Ptr roles;
        if (endpointConfig) {
                Object::Ptr object;
@@ -485,31 +478,6 @@ int DiscoveryComponent::RegisterComponentMessageHandler(const NewRequestEventArg
        return 0;
 }
 
-/**
- * Processes "endpoint" config objects.
- *
- * @param ea Event arguments for the new config object.
- * @returns 0
- */
-int DiscoveryComponent::EndpointConfigHandler(const EventArgs& ea)
-{
-       ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
-
-       EndpointManager::Ptr endpointManager = GetEndpointManager();
-
-       /* Check if we're already connected to this endpoint. */
-       if (endpointManager->GetEndpointByIdentity(object->GetName()))
-               return 0;
-
-       string node, service;
-       if (object->GetProperty("node", &node) && object->GetProperty("service", &service)) {
-               /* reconnect to this endpoint */
-               endpointManager->AddConnection(node, service);
-       }
-
-       return 0;
-}
-
 /**
  * Checks whether we have to reconnect to other components and removes stale
  * components from the registry.
@@ -525,8 +493,21 @@ int DiscoveryComponent::DiscoveryTimerHandler(const TimerEventArgs& tea)
        time(&now);
 
        /* check whether we have to reconnect to one of our upstream endpoints */
-       ConfigCollection::Ptr endpointCollection = GetConfigHive()->GetCollection("endpoint");
-       endpointCollection->ForEachObject(bind(&DiscoveryComponent::EndpointConfigHandler, this, _1));
+       ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint");
+
+       for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
+               ConfigObject::Ptr object = it->second;
+
+               /* Check if we're already connected to this endpoint. */
+               if (endpointManager->GetEndpointByIdentity(object->GetName()))
+                       continue;
+
+               string node, service;
+               if (object->GetProperty("node", &node) && object->GetProperty("service", &service)) {
+                       /* reconnect to this endpoint */
+                       endpointManager->AddConnection(node, service);
+               }
+       }
 
        map<string, ComponentDiscoveryInfo::Ptr>::iterator curr, i;
        for (i = m_Components.begin(); i != m_Components.end(); ) {
index 6a93cd1cdf258a3cf6cda3a65a909ee0b3be506e..75bc0ea5eb9bc0bf77283dfb6d765aba507211ff 100644 (file)
@@ -76,8 +76,6 @@ private:
 
        void FinishDiscoverySetup(Endpoint::Ptr endpoint);
 
-       int EndpointConfigHandler(const EventArgs& ea);
-
        bool HasMessagePermission(Dictionary::Ptr roles, string messageType, string message);
 
        static const int RegistrationTTL = 300;
index 5aeea9611975fa9136228e62f965dc297d8cef14..c66654070acfe888db854fea004f07fb4ba93741 100644 (file)
@@ -21,13 +21,7 @@ libdyn_la_SOURCES = \
        expression.cpp \
        expression.h \
        expressionlist.cpp \
-       expressionlist.h \
-       dynamicobject.cpp \
-       dynamicobject.h \
-       objectset.cpp \
-       objectset.h \
-       objectmap.cpp \
-       objectmap.h
+       expressionlist.h
 
 libdyn_la_CPPFLAGS = \
        -DI2_DYN_BUILD \
index fbc77c111f932817c10cfd2492f1354cbd1cf4cc..ea274cec3cdefa69dcdead4ca3623e8e105c77ac 100644 (file)
@@ -107,26 +107,27 @@ ConfigItem::TNMap::Ptr ConfigItem::GetObjectsByTypeAndName(void)
 
 void ConfigItem::Commit(void)
 {
-       DynamicObject::Ptr dobj = m_DynamicObject.lock();
+       ConfigObject::Ptr dobj = m_ConfigObject.lock();
 
-       if (!dobj) {
-               dobj = DynamicObject::GetObject(GetType(), GetName());
+       Dictionary::Ptr properties = make_shared<Dictionary>();
+       CalculateProperties(properties);
 
-               if (!dobj)
-                       dobj = make_shared<DynamicObject>();
+       if (!dobj)
+               dobj = ConfigObject::GetObject(GetType(), GetName());
 
-               m_DynamicObject = dobj;
-       }
+       if (!dobj)
+               dobj = make_shared<ConfigObject>(properties);
+       else
+               dobj->SetProperties(properties);
+
+       m_ConfigObject = dobj;
 
-       Dictionary::Ptr properties = make_shared<Dictionary>();
-       CalculateProperties(properties);
-       dobj->SetConfig(properties);
        dobj->Commit();
 
        ConfigItem::Ptr ci = GetObject(GetType(), GetName());
        ConfigItem::Ptr self = static_pointer_cast<ConfigItem>(shared_from_this());
        if (ci && ci != self) {
-               ci->m_DynamicObject.reset();
+               ci->m_ConfigObject.reset();
                GetAllObjects()->RemoveObject(ci);
        }
        GetAllObjects()->CheckObject(self);
@@ -134,7 +135,7 @@ void ConfigItem::Commit(void)
 
 void ConfigItem::Unregister(void)
 {
-       // TODO: unregister associated DynamicObject
+       // TODO: unregister associated ConfigObject
 
        ConfigItem::Ptr self = static_pointer_cast<ConfigItem>(shared_from_this());
        GetAllObjects()->RemoveObject(self);
index 4e85f9a29e0fc0bf018db0f2734b7cc28d10aa87..4358ce93fec07f8c7e217ca4863af911bda77c4d 100644 (file)
@@ -57,7 +57,7 @@ private:
        vector<string> m_Parents;
        ExpressionList::Ptr m_ExpressionList;
 
-       DynamicObject::WeakPtr m_DynamicObject;
+       ConfigObject::WeakPtr m_ConfigObject;
 
        static bool GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key);
 };
index 02b53261218105f08fb2f23489b512ccf7f0a34b..4d4f244d34a48beb1dafc76f52b3db880f11e449 100644 (file)
     <ClInclude Include="configvm.h" />
     <ClInclude Include="config_parser.h" />
     <ClInclude Include="debuginfo.h" />
-    <ClInclude Include="dynamicobject.h" />
     <ClInclude Include="expression.h" />
     <ClInclude Include="expressionlist.h" />
     <ClInclude Include="i2-dyn.h" />
-    <ClInclude Include="objectmap.h" />
-    <ClInclude Include="objectset.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="configcompiler.cpp" />
     <ClCompile Include="configvm.cpp" />
     <ClCompile Include="config_lexer.cc" />
     <ClCompile Include="config_parser.cc" />
-    <ClCompile Include="dynamicobject.cpp" />
     <ClCompile Include="expression.cpp" />
     <ClCompile Include="expressionlist.cpp" />
-    <ClCompile Include="objectmap.cpp" />
-    <ClCompile Include="objectset.cpp" />
   </ItemGroup>
   <ItemGroup>
     <None Include="config_lexer.ll">
diff --git a/dyn/dynamicobject.cpp b/dyn/dynamicobject.cpp
deleted file mode 100644 (file)
index 542b23b..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
-
-#include "i2-dyn.h"
-
-using namespace icinga;
-
-DynamicObject::DynamicObject(void)
-       : m_Config(make_shared<Dictionary>()), m_Tags(make_shared<Dictionary>())
-{
-}
-
-void DynamicObject::SetConfig(Dictionary::Ptr config)
-{
-       m_Config = config;
-}
-
-Dictionary::Ptr DynamicObject::GetConfig(void) const
-{
-       return m_Config;
-}
-
-Dictionary::Ptr DynamicObject::GetTags(void)
-{
-       if (!m_Tags)
-               m_Tags = make_shared<Dictionary>();
-
-       return m_Tags;
-}
-
-string DynamicObject::GetType(void) const
-{
-       string type;
-       GetConfig()->GetProperty("__type", &type);
-       return type;
-}
-
-string DynamicObject::GetName(void) const
-{
-       string name;
-       GetConfig()->GetProperty("__name", &name);
-       return name;
-}
-
-void DynamicObject::Commit(void)
-{
-       DynamicObject::Ptr dobj = GetObject(GetType(), GetName());
-       DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this());
-       assert(!dobj || dobj == self);
-       GetAllObjects()->CheckObject(self);
-}
-
-void DynamicObject::Unregister(void)
-{
-       DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this());
-       GetAllObjects()->RemoveObject(self);
-}
-
-ObjectSet<DynamicObject::Ptr>::Ptr DynamicObject::GetAllObjects(void)
-{
-       static ObjectSet<DynamicObject::Ptr>::Ptr allObjects;
-
-       if (!allObjects) {
-               allObjects = make_shared<ObjectSet<DynamicObject::Ptr> >();
-               allObjects->Start();
-       }
-
-       return allObjects;
-}
-
-DynamicObject::TNMap::Ptr DynamicObject::GetObjectsByTypeAndName(void)
-{
-       static DynamicObject::TNMap::Ptr tnmap;
-
-       if (!tnmap) {
-               tnmap = make_shared<DynamicObject::TNMap>(GetAllObjects(), &DynamicObject::GetTypeAndName);
-               tnmap->Start();
-       }
-
-       return tnmap;
-}
-
-DynamicObject::Ptr DynamicObject::GetObject(string type, string name)
-{
-       DynamicObject::TNMap::Range range;
-       range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name));
-
-       assert(distance(range.first, range.second) <= 1);
-
-       if (range.first == range.second)
-               return DynamicObject::Ptr();
-       else
-               return range.first->second;
-}
-
-bool DynamicObject::GetTypeAndName(const DynamicObject::Ptr& object, pair<string, string> *key)
-{
-        *key = make_pair(object->GetType(), object->GetName());
-
-        return true;
-}
-
diff --git a/dyn/dynamicobject.h b/dyn/dynamicobject.h
deleted file mode 100644 (file)
index e8d118a..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
-
-#ifndef DYNAMICOBJECT_H
-#define DYNAMICOBJECT_H
-
-namespace icinga
-{
-
-class I2_DYN_API DynamicObject : public Object
-{
-public:
-       typedef shared_ptr<DynamicObject> Ptr;
-       typedef weak_ptr<DynamicObject> WeakPtr;
-
-       typedef ObjectMap<pair<string, string>, DynamicObject::Ptr> TNMap;
-
-       DynamicObject(void);
-
-       void SetConfig(Dictionary::Ptr config);
-       Dictionary::Ptr GetConfig(void) const;
-
-       Dictionary::Ptr GetTags(void);
-
-       string GetType(void) const;
-       string GetName(void) const;
-
-       void Commit(void);
-       void Unregister(void);
-
-       static ObjectSet<DynamicObject::Ptr>::Ptr GetAllObjects(void);
-       static TNMap::Ptr GetObjectsByTypeAndName(void);
-       static DynamicObject::Ptr GetObject(string type, string name);
-
-private:
-       Dictionary::Ptr m_Config;
-       Dictionary::Ptr m_Tags;
-
-       static bool GetTypeAndName(const DynamicObject::Ptr& object, pair<string, string> *key);
-};
-
-}
-
-#endif /* DYNAMICOBJECT_H */
index da65f7d681a365909912fc54628500d8ecd56d5a..ce20b737c5880e031357cf755d3d10300c895ea8 100644 (file)
@@ -41,9 +41,6 @@
 #include "debuginfo.h"
 #include "expression.h"
 #include "expressionlist.h"
-#include "objectset.h"
-#include "objectmap.h"
-#include "dynamicobject.h"
 #include "configitem.h"
 #include "configcompiler.h"
 #include "configvm.h"
index 3ac8a15a716480096f23237160f54ee341471c63..e114ce79f7ca76aff97b707edf76a45e110da0e7 100644 (file)
@@ -1,5 +1,5 @@
 #include <i2-dyn.h>
-#include <i2-jsonrpc.h>
+//#include <i2-jsonrpc.h>
 
 using namespace icinga;
 
index 5ce487dc61a2276d02ab078c27bcef6d1d1aa542..f4c326848310ecd82e923e5ac3203fbc2f157a9f 100644 (file)
@@ -52,25 +52,32 @@ int IcingaApplication::Main(const vector<string>& args)
        string componentDirectory = GetExeDirectory() + "/../lib/icinga2";
        AddComponentSearchDir(componentDirectory);
 
-       /* register handler for 'icinga' config objects */
-       ConfigCollection::Ptr icingaCollection = GetConfigHive()->GetCollection("icinga");
-       function<int (const EventArgs&)> NewIcingaConfigHandler = bind_weak(&IcingaApplication::NewIcingaConfigHandler, shared_from_this());
-       icingaCollection->OnObjectCommitted += NewIcingaConfigHandler;
-       icingaCollection->ForEachObject(NewIcingaConfigHandler);
-       icingaCollection->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedIcingaConfigHandler, shared_from_this());
+       ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga");
+
+       if (!icingaConfig)
+               throw runtime_error("Configuration must contain an 'application' object named 'icinga'.");
+
+       if (!icingaConfig->IsLocal())
+               throw runtime_error("'icinga' application object must be 'local'.");
+
+       icingaConfig->GetProperty("privkey", &m_PrivateKeyFile);
+       icingaConfig->GetProperty("pubkey", &m_PublicKeyFile);
+       icingaConfig->GetProperty("cakey", &m_CAKeyFile);
+       icingaConfig->GetProperty("node", &m_Node);
+       icingaConfig->GetProperty("service", &m_Service);
 
        /* register handler for 'component' config objects */
-       ConfigCollection::Ptr componentCollection = GetConfigHive()->GetCollection("component");
-       function<int (const EventArgs&)> NewComponentHandler = bind_weak(&IcingaApplication::NewComponentHandler, shared_from_this());
-       componentCollection->OnObjectCommitted += NewComponentHandler;
-       componentCollection->ForEachObject(NewComponentHandler);
-       componentCollection->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedComponentHandler, shared_from_this());
+       static ConfigObject::Set::Ptr componentObjects = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
+       function<int (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = bind_weak(&IcingaApplication::NewComponentHandler, shared_from_this());
+       componentObjects->OnObjectAdded += NewComponentHandler;
+       componentObjects->OnObjectCommitted += NewComponentHandler;
+       componentObjects->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedComponentHandler, shared_from_this());
+       componentObjects->Start();
 
        /* load config file */
        ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
-       fileComponentConfig->SetProperty("configFilename", args[1]);
-       fileComponentConfig->SetProperty("replicate", 0);
-       GetConfigHive()->AddObject(fileComponentConfig);
+       fileComponentConfig->GetProperties()->SetProperty("configFilename", args[1]);
+       fileComponentConfig->Commit();
 
        if (!GetPrivateKeyFile().empty() && !GetPublicKeyFile().empty() && !GetCAKeyFile().empty()) {
                /* set up SSL context */
@@ -103,12 +110,12 @@ EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
        return m_EndpointManager;
 }
 
-int IcingaApplication::NewComponentHandler(const EventArgs& ea)
+int IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
 {
-       ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
+       ConfigObject::Ptr object = ea.Target;
        
        /* don't allow replicated config objects */
-       if (object->IsReplicated())
+       if (!object->IsLocal())
                return 0;
 
        string path;
@@ -125,9 +132,9 @@ int IcingaApplication::NewComponentHandler(const EventArgs& ea)
        return 0;
 }
 
-int IcingaApplication::DeletedComponentHandler(const EventArgs& ea)
+int IcingaApplication::DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
 {
-       ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
+       ConfigObject::Ptr object = ea.Target;
 
        Component::Ptr component = GetComponent(object->GetName());
        UnregisterComponent(component);
@@ -135,87 +142,26 @@ int IcingaApplication::DeletedComponentHandler(const EventArgs& ea)
        return 0;
 }
 
-int IcingaApplication::NewIcingaConfigHandler(const EventArgs& ea)
-{
-       ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
-       
-       /* don't allow replicated config objects */
-       if (object->IsReplicated())
-               return 0;
-
-       string privkey;
-       if (object->GetProperty("privkey", &privkey))
-               SetPrivateKeyFile(privkey);
-
-       string pubkey;
-       if (object->GetProperty("pubkey", &pubkey))
-               SetPublicKeyFile(pubkey);
-
-       string cakey;
-       if (object->GetProperty("cakey", &cakey))
-               SetCAKeyFile(cakey);
-
-       string node;
-       if (object->GetProperty("node", &node))
-               SetNode(node);
-
-       string service;
-       if (object->GetProperty("service", &service))
-               SetService(service);
-
-       return 0;
-}
-
-int IcingaApplication::DeletedIcingaConfigHandler(const EventArgs&)
-{
-       throw runtime_error("Unsupported operation.");
-}
-
-void IcingaApplication::SetPrivateKeyFile(string privkey)
-{
-       m_PrivateKeyFile = privkey;
-}
-
 string IcingaApplication::GetPrivateKeyFile(void) const
 {
        return m_PrivateKeyFile;
 }
 
-void IcingaApplication::SetPublicKeyFile(string pubkey)
-{
-       m_PublicKeyFile = pubkey;
-}
-
 string IcingaApplication::GetPublicKeyFile(void) const
 {
        return m_PublicKeyFile;
 }
 
-void IcingaApplication::SetCAKeyFile(string cakey)
-{
-       m_CAKeyFile = cakey;
-}
-
 string IcingaApplication::GetCAKeyFile(void) const
 {
        return m_CAKeyFile;
 }
 
-void IcingaApplication::SetNode(string node)
-{
-       m_Node = node;
-}
-
 string IcingaApplication::GetNode(void) const
 {
        return m_Node;
 }
 
-void IcingaApplication::SetService(string service)
-{
-       m_Service = service;
-}
-
 string IcingaApplication::GetService(void) const
 {
        return m_Service;
index cf717297584ce8ca214c26cccd14f11d5e47d354..de6b82b0ee01de5b1d1b54ba3f67c93d96be1e95 100644 (file)
@@ -38,19 +38,10 @@ public:
 
        EndpointManager::Ptr GetEndpointManager(void);
 
-       void SetPrivateKeyFile(string privkey);
        string GetPrivateKeyFile(void) const;
-
-       void SetPublicKeyFile(string pubkey);
        string GetPublicKeyFile(void) const;
-
-       void SetCAKeyFile(string cakey);
        string GetCAKeyFile(void) const;
-
-       void SetNode(string node);
        string GetNode(void) const;
-
-       void SetService(string service);
        string GetService(void) const;
 
 private:
@@ -62,11 +53,8 @@ private:
        string m_Node;
        string m_Service;
 
-       int NewComponentHandler(const EventArgs& ea);
-       int DeletedComponentHandler(const EventArgs& ea);
-
-       int NewIcingaConfigHandler(const EventArgs& ea);
-       int DeletedIcingaConfigHandler(const EventArgs& ea);
+       int NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
+       int DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
 
        int NewRpcListenerHandler(const EventArgs& ea);
        int DeletedRpcListenerHandler(const EventArgs& ea);
index 8e711336adbc81fbcddc7bf36ce4e2742bc63aba..f33f4bb348d0f76fe3d46e61e5f394923aa1e816 100644 (file)
@@ -36,13 +36,3 @@ EndpointManager::Ptr IcingaComponent::GetEndpointManager(void) const
 
        return app->GetEndpointManager();
 }
-
-ConfigHive::Ptr IcingaComponent::GetConfigHive(void) const
-{
-       IcingaApplication::Ptr app = GetIcingaApplication();
-
-       if (!app)
-               return ConfigHive::Ptr();
-
-       return app->GetConfigHive();
-}
index 63836a20ee797156bd1ce1ed31b53d3b1612576e..700409353063fa904961df80bda9928bed87ab66 100644 (file)
@@ -33,7 +33,6 @@ class I2_ICINGA_API IcingaComponent : public Component
 protected:
        IcingaApplication::Ptr GetIcingaApplication(void) const;
        EndpointManager::Ptr GetEndpointManager(void) const;
-       ConfigHive::Ptr GetConfigHive(void) const;
 };
 
 }