]> granicus.if.org Git - icinga2/commitdiff
Added dyn test class.
authorGunnar Beutner <gunnar@beutner.name>
Wed, 30 May 2012 08:43:58 +0000 (10:43 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 30 May 2012 10:43:33 +0000 (12:43 +0200)
16 files changed:
base/base.vcxproj
components/configfile/configfile.vcxproj
dyn/dyn.vcxproj
dyn/dynamicdictionary.h
dyn/dynamicobject.cpp
dyn/dynamicobject.h
dyn/i2-dyn.h
dyn/objectmap.cpp [new file with mode: 0644]
dyn/objectmap.h [moved from dyn/objectspace.h with 63% similarity]
dyn/objectset.cpp [new file with mode: 0644]
dyn/objectset.h [new file with mode: 0644]
dyn/objectspace.cpp [deleted file]
dyntest/dyntest.cpp [new file with mode: 0644]
dyntest/dyntest.vcxproj [new file with mode: 0644]
icinga.sln
jsonrpc/jsonrpc.vcxproj

index 32a4b87e4e8bbef14d3e15af8970c7e365e2b579..51871ee7b37244f8872d87a0175d236bb976e0a3 100644 (file)
   </ImportGroup>
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <IncludePath>$(SolutionDir)\mmatch;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\third-party\mmatch;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <IncludePath>$(SolutionDir)\mmatch;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\third-party\mmatch;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
index 61612eb004677e4cb1c4cea08d2d58534e3f89fe..74e474d155ec3e0ff042473666358de6828063b4 100644 (file)
   </ImportGroup>
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\cJSON;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\third-party\cJSON;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\cJSON;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\third-party\cJSON;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
index 50d64aa19d45453aff0380ac1e6de6de636d8637..9ac948ab45a94ce011b56a2bd983bb38090be782 100644 (file)
     <ClInclude Include="dynamicdictionary.h" />
     <ClInclude Include="dynamicobject.h" />
     <ClInclude Include="i2-dyn.h" />
-    <ClInclude Include="objectspace.h" />
+    <ClInclude Include="objectmap.h" />
+    <ClInclude Include="objectset.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="dynamicdictionary.cpp" />
     <ClCompile Include="dynamicobject.cpp" />
-    <ClCompile Include="objectspace.cpp" />
+    <ClCompile Include="objectmap.cpp" />
+    <ClCompile Include="objectset.cpp" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
     <ProjectGuid>{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}</ProjectGuid>
@@ -62,7 +64,7 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>_WINDLL;I2_DYN_BUILD;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -78,7 +80,7 @@
       <Optimization>MaxSpeed</Optimization>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>_WINDLL;I2_DYN_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
index 30aafe76a5ec65ab402d7f40b88ea0ca279b24ec..465a7ebed41fe6a006bc6bbd4cd109c4f0202599 100644 (file)
@@ -38,7 +38,7 @@ struct DynamicDictionaryValue
        DynamicDictionaryOperator Operator;
 };
 
-class DynamicDictionary : public Object
+class I2_DYN_API DynamicDictionary : public Object
 {
 public:
        typedef shared_ptr<DynamicDictionary> Ptr;
index e61d3dd4f1792c6ab580516cbc8cee7201e3d213..a136341a62d649b4c8b38893acd4daf36e033fe0 100644 (file)
 
 using namespace icinga;
 
-DynamicDictionary::Ptr DynamicObject::GetProperties(void) const
+DynamicObject::DynamicObject(void)
+       : m_Config(make_shared<Dictionary>()), m_Tags(make_shared<Dictionary>())
 {
-       return m_Properties;
 }
 
-void DynamicObject::SetProperties(DynamicDictionary::Ptr properties)
-{      
-       m_Properties = properties;
-       Dictionary::Ptr resolvedProperties = properties->ToFlatDictionary();
-       Reload(resolvedProperties);
-}
-
-string DynamicObject::GetName(void) const
-{
-       return m_Name;
-}
-
-void DynamicObject::SetName(string name)
-{
-       m_Name = name;
-}
-
-string DynamicObject::GetType(void) const
-{
-       return m_Type;
-}
-
-void DynamicObject::SetType(string type)
+Dictionary::Ptr DynamicObject::GetConfig(void) const
 {
-       m_Type = type;
+       return m_Config;
 }
 
-bool DynamicObject::IsLocal(void) const
+Dictionary::Ptr DynamicObject::GetTags(void) const
 {
-       return m_Local;
-}
-
-void DynamicObject::SetLocal(bool value)
-{
-       m_Local = value;
-}
-
-bool DynamicObject::IsAbstract(void) const
-{
-       return m_Abstract;
-}
-
-void DynamicObject::SetAbstract(bool value)
-{
-       m_Abstract = value;
+       return m_Tags;
 }
 
 void DynamicObject::Commit(void)
 {
-       // TODO: link properties to parent objects
-
-       Dictionary::Ptr resolvedProperties = m_Properties->ToFlatDictionary();
-       Reload(resolvedProperties);
+       DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this());
+       ObjectSet::GetAllObjects()->CheckObject(self);
 }
 
-void DynamicObject::Reload(Dictionary::Ptr resolvedProperties)
+void DynamicObject::Unregister(void)
 {
-       resolvedProperties->GetProperty("__name", &m_Name);
-       resolvedProperties->GetProperty("__type", &m_Type);
-       resolvedProperties->GetProperty("__local", &m_Local);
-       resolvedProperties->GetProperty("__abstract", &m_Abstract);
+       DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this());
+       ObjectSet::GetAllObjects()->RemoveObject(self);
 }
index 86088961ab00f261e9ff58d239db2533e7602dd7..d665dda2e2a7ec88012fc81a3970b61304759e5f 100644 (file)
 namespace icinga
 {
 
-class DynamicObject : public Object
+class I2_DYN_API DynamicObject : public Object
 {
 public:
        typedef shared_ptr<DynamicObject> Ptr;
        typedef weak_ptr<DynamicObject> WeakPtr;
 
-       void AddParentObject(DynamicObject::Ptr parent);
-       void RemoveParentObject(DynamicObject::Ptr parent);
+       DynamicObject(void);
 
-       void AddChildObject(DynamicObject::WeakPtr parent);
-       void RemoveChildObject(DynamicObject::WeakPtr parent);
-
-       DynamicDictionary::Ptr GetProperties(void) const;
-       void SetProperties(DynamicDictionary::Ptr properties);
-
-       Dictionary::Ptr GetResolvedProperties(void) const;
-
-       string GetName(void) const;
-       string GetType(void) const;
-       bool IsLocal(void) const;
-       bool IsAbstract(void) const;
+       Dictionary::Ptr GetConfig(void) const;
+       Dictionary::Ptr GetTags(void) const;
 
        void Commit(void);
-
-protected:
-       virtual void Reload(Dictionary::Ptr resolvedProperties);
+       void Unregister(void);
 
 private:
-       set<DynamicObject::Ptr> m_Parents;
-       set<DynamicObject::WeakPtr> m_Children;
-       DynamicDictionary::Ptr m_Properties;
-
-       string m_Type;
-       string m_Name;
-       bool m_Local;
-       bool m_Abstract;
-
-       void SetName(string name);
-       void SetType(string type);
-       void SetLocal(bool local);
-       void SetAbstract(bool abstract);
+       Dictionary::Ptr m_Config;
+       Dictionary::Ptr m_Tags;
 };
 
 }
index 806d4bc23447dae71d93e7824c59bf0bee06ec73..13ede7c25ace91c83a9f84827191e4c91af4bcb4 100644 (file)
 
 #include <i2-base.h>
 
+#ifdef I2_DYN_BUILD
+#      define I2_DYN_API I2_EXPORT
+#else /* I2_DYN_BUILD */
+#      define I2_DYN_API I2_IMPORT
+#endif /* I2_DYN_BUILD */
+
 #include "dynamicdictionary.h"
 #include "dynamicobject.h"
-#include "objectspace.h"
+#include "objectset.h"
+#include "objectmap.h"
 
 #endif /* I2DYN_H */
diff --git a/dyn/objectmap.cpp b/dyn/objectmap.cpp
new file mode 100644 (file)
index 0000000..6c7b76b
--- /dev/null
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * 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;
+
+ObjectMap::ObjectMap(const ObjectSet::Ptr& parent, ObjectKeyGetter keygetter)
+       : m_Parent(parent), m_KeyGetter(keygetter)
+{
+       assert(m_Parent);
+       assert(m_KeyGetter);
+}
+
+void ObjectMap::Start(void)
+{
+       m_Parent->OnObjectAdded += bind_weak(&ObjectMap::ObjectAddedHandler, shared_from_this());
+       m_Parent->OnObjectCommitted += bind_weak(&ObjectMap::ObjectCommittedHandler, shared_from_this());
+       m_Parent->OnObjectRemoved += bind_weak(&ObjectMap::ObjectRemovedHandler, shared_from_this());
+
+       for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
+               AddObject(*it);
+}
+
+void ObjectMap::AddObject(const Object::Ptr& object)
+{
+       string key;
+       if (!m_KeyGetter(object, &key))
+               return;
+
+       m_Objects.insert(pair<string, Object::Ptr>(key, object));
+}
+
+void ObjectMap::RemoveObject(const Object::Ptr& object)
+{
+       string key;
+       if (!m_KeyGetter(object, &key))
+               return;
+
+       pair<Iterator, Iterator> range = GetRange(key);
+
+       for (Iterator i = range.first; i != range.second; i++) {
+               if (i->second == object) {
+                       m_Objects.erase(i);
+                       break;
+               }
+       }
+}
+
+void ObjectMap::CheckObject(const Object::Ptr& object)
+{
+       RemoveObject(object);
+       AddObject(object);
+}
+
+ObjectMap::Range ObjectMap::GetRange(string key)
+{
+       return m_Objects.equal_range(key);
+}
+
+int ObjectMap::ObjectAddedHandler(const ObjectSetEventArgs& ea)
+{
+       AddObject(ea.Object);
+       return 0;
+}
+
+int ObjectMap::ObjectCommittedHandler(const ObjectSetEventArgs& ea)
+{
+       CheckObject(ea.Object);
+       return 0;
+}
+
+int ObjectMap::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
+{
+       RemoveObject(ea.Object);
+       return 0;
+}
similarity index 63%
rename from dyn/objectspace.h
rename to dyn/objectmap.h
index de3f24aca771319cbdf4c556e65c1904cc37c810..dc60262f31b13ff0690f802534f842c0bf9e9243 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef OBJECTSPACE_H
-#define OBJECTSPACE_H
+#ifndef OBJECTMAP_H
+#define OBJECTMAP_H
 
 namespace icinga
 {
 
-typedef function<DynamicObject::Ptr()> DynamicObjectFactory;
+typedef function<bool (const Object::Ptr&, string *key)> ObjectKeyGetter;
 
-class ObjectSpace : public Object
+class I2_DYN_API ObjectMap : public Object
 {
 public:
-       void RegisterClass(string name, DynamicObjectFactory factory);
-       void UnregisterClass(string name);
+       typedef shared_ptr<ObjectMap> Ptr;
+       typedef weak_ptr<ObjectMap> WeakPtr;
 
-       Dictionary::Ptr SerializeObject(DynamicObject::Ptr object);
-       DynamicObject::Ptr UnserializeObject(Dictionary::Ptr serializedObject);
+       typedef multimap<string, Object::Ptr>::iterator Iterator;
+       typedef pair<Iterator, Iterator> Range;
 
-       vector<DynamicObject::Ptr> FindObjects(function<bool (DynamicObject::Ptr)> predicate);
+       ObjectMap(const ObjectSet::Ptr& parent, ObjectKeyGetter keygetter);
+
+       void Start(void);
+
+       Range GetRange(string key);
 
 private:
-       map<string, DynamicObjectFactory> m_Classes;
-       set<DynamicObject::Ptr> m_Objects;
+       multimap<string, Object::Ptr> m_Objects;
+       ObjectSet::Ptr m_Parent;
+       ObjectKeyGetter m_KeyGetter;
+
+       void AddObject(const Object::Ptr& object);
+       void RemoveObject(const Object::Ptr& object);
+       void CheckObject(const Object::Ptr& object);
 
-       void RegisterObject(DynamicObject::Ptr object);
-       void UnregisterObject(DynamicObject::Ptr object);
+       int ObjectAddedHandler(const ObjectSetEventArgs& ea);
+       int ObjectCommittedHandler(const ObjectSetEventArgs& ea);
+       int ObjectRemovedHandler(const ObjectSetEventArgs& ea);
 };
 
 }
 
-#endif /* OBJECTSPACE_H */
+#endif OBJECTMAP_H
diff --git a/dyn/objectset.cpp b/dyn/objectset.cpp
new file mode 100644 (file)
index 0000000..9f08898
--- /dev/null
@@ -0,0 +1,124 @@
+/******************************************************************************
+ * 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;
+
+ObjectSet::ObjectSet(void)
+       : m_Parent(), m_Filter()
+{
+}
+
+ObjectSet::ObjectSet(const ObjectSet::Ptr& parent, ObjectPredicate filter)
+       : m_Parent(parent), m_Filter(filter)
+{
+}
+
+void ObjectSet::Start(void)
+{
+       if (m_Parent) {
+               m_Parent->OnObjectCommitted += bind_weak(&ObjectSet::ObjectCommittedHandler, shared_from_this());
+               m_Parent->OnObjectRemoved += bind_weak(&ObjectSet::ObjectRemovedHandler, shared_from_this());
+
+               for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
+                       CheckObject(*it);
+       }
+}
+
+void ObjectSet::AddObject(const Object::Ptr& object)
+{
+       m_Objects.insert(object);
+
+       ObjectSetEventArgs ea;
+       ea.Source = shared_from_this();
+       ea.Object = object;
+       OnObjectAdded(ea);
+}
+
+void ObjectSet::RemoveObject(const Object::Ptr& object)
+{
+       ObjectSet::Iterator it = m_Objects.find(object);
+
+       if (it != m_Objects.end()) {
+               m_Objects.erase(it);
+
+               ObjectSetEventArgs ea;
+               ea.Source = shared_from_this();
+               ea.Object = object;
+               OnObjectRemoved(ea);
+       }
+}
+
+bool ObjectSet::Contains(const Object::Ptr& object) const
+{
+       ObjectSet::Iterator it = m_Objects.find(object);
+
+       return !(it == m_Objects.end());
+}
+
+void ObjectSet::CheckObject(const Object::Ptr& object)
+{
+       if (m_Filter && !m_Filter(object))
+               RemoveObject(object);
+       else {
+               if (!Contains(object))
+                       AddObject(object);
+               else {
+                       ObjectSetEventArgs ea;
+                       ea.Source = shared_from_this();
+                       ea.Object = object;
+                       OnObjectCommitted(ea);
+               }
+       }
+}
+
+int ObjectSet::ObjectCommittedHandler(const ObjectSetEventArgs& ea)
+{
+       CheckObject(ea.Object);
+       return 0;
+}
+
+int ObjectSet::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
+{
+       RemoveObject(ea.Object);
+       return 0;
+}
+
+ObjectSet::Iterator ObjectSet::Begin(void)
+{
+       return m_Objects.begin();
+}
+
+ObjectSet::Iterator ObjectSet::End(void)
+{
+       return m_Objects.end();
+}
+
+ObjectSet::Ptr ObjectSet::GetAllObjects(void)
+{
+       static ObjectSet::Ptr allObjects;
+
+       if (!allObjects) {
+               allObjects = make_shared<ObjectSet>();
+               allObjects->Start();
+       }
+
+       return allObjects;
+}
\ No newline at end of file
diff --git a/dyn/objectset.h b/dyn/objectset.h
new file mode 100644 (file)
index 0000000..e277f4b
--- /dev/null
@@ -0,0 +1,73 @@
+/******************************************************************************
+ * 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 OBJECTSET_H
+#define OBJECTSET_H
+
+namespace icinga
+{
+
+struct ObjectSetEventArgs : public EventArgs
+{
+       Object::Ptr Object;
+};
+
+typedef function<bool (const Object::Ptr&)> ObjectPredicate;
+
+class I2_DYN_API ObjectSet : public Object
+{
+public:
+       typedef shared_ptr<ObjectSet> Ptr;
+       typedef weak_ptr<ObjectSet> WeakPtr;
+
+       typedef set<Object::Ptr>::iterator Iterator;
+
+       ObjectSet(void);
+       ObjectSet(const ObjectSet::Ptr& parent, ObjectPredicate filter);
+
+       void Start(void);
+
+       void AddObject(const Object::Ptr& object);
+       void RemoveObject(const Object::Ptr& object);
+       bool Contains(const Object::Ptr& object) const;
+
+       void CheckObject(const Object::Ptr& object);
+
+       Observable<ObjectSetEventArgs> OnObjectAdded;
+       Observable<ObjectSetEventArgs> OnObjectCommitted;
+       Observable<ObjectSetEventArgs> OnObjectRemoved;
+
+       Iterator Begin(void);
+       Iterator End(void);
+
+       static ObjectSet::Ptr GetAllObjects(void);
+
+private:
+       set<Object::Ptr> m_Objects;
+
+       ObjectSet::Ptr m_Parent;
+       ObjectPredicate m_Filter;
+
+       int ObjectCommittedHandler(const ObjectSetEventArgs& ea);
+       int ObjectRemovedHandler(const ObjectSetEventArgs& ea);
+};
+
+}
+
+#endif /* OBJECTSET_H */
\ No newline at end of file
diff --git a/dyn/objectspace.cpp b/dyn/objectspace.cpp
deleted file mode 100644 (file)
index 6dd41d3..0000000
+++ /dev/null
@@ -1,91 +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;
-
-void ObjectSpace::RegisterClass(string name, DynamicObjectFactory factory)
-{
-       m_Classes[name] = factory;
-}
-
-void ObjectSpace::UnregisterClass(string name)
-{
-       map<string, DynamicObjectFactory>::iterator ci = m_Classes.find(name);
-
-       if (ci != m_Classes.end())
-               m_Classes.erase(ci);
-}
-
-void ObjectSpace::RegisterObject(DynamicObject::Ptr object)
-{
-       m_Objects.insert(object);
-}
-
-void ObjectSpace::UnregisterObject(DynamicObject::Ptr object)
-{
-       set<DynamicObject::Ptr>::iterator di = m_Objects.find(object);
-
-       if (di != m_Objects.end())
-               m_Objects.erase(di);
-}
-
-Dictionary::Ptr ObjectSpace::SerializeObject(DynamicObject::Ptr object)
-{
-       DynamicDictionary::Ptr properties = object->GetProperties();
-       if (!properties)
-               throw InvalidArgumentException();
-
-       Dictionary::Ptr data = make_shared<Dictionary>();
-       data->SetProperty("type", object->GetType());
-
-       Dictionary::Ptr serializedProperties = properties->Serialize();
-       data->SetProperty("properties", serializedProperties);
-       return data;
-}
-
-DynamicObject::Ptr ObjectSpace::UnserializeObject(Dictionary::Ptr data)
-{
-       string type;
-       if (!data->GetProperty("type", &type))
-               throw InvalidArgumentException();
-
-       Dictionary::Ptr serializedProperties;
-       if (!data->GetProperty("properties", &serializedProperties))
-               throw InvalidArgumentException();
-       DynamicDictionary::Ptr properties = make_shared<DynamicDictionary>(serializedProperties);
-
-       map<string, DynamicObjectFactory>::iterator di = m_Classes.find(type);
-       DynamicObject::Ptr object;
-       if (di != m_Classes.end())
-               object = di->second();
-       else
-               object = make_shared<DynamicObject>();
-
-       object->SetProperties(properties);
-       object->Commit();
-
-       return object;
-}
-
-vector<DynamicObject::Ptr> FindObjects(function<bool (DynamicObject::Ptr)> predicate)
-{
-       return vector<DynamicObject::Ptr>();
-}
diff --git a/dyntest/dyntest.cpp b/dyntest/dyntest.cpp
new file mode 100644 (file)
index 0000000..4870d07
--- /dev/null
@@ -0,0 +1,37 @@
+#include <i2-dyn.h>
+
+using namespace icinga;
+
+bool foogetter(const Object::Ptr& object, string *key)
+{
+       DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(object);
+       return dobj->GetConfig()->GetProperty("foo", key);
+}
+
+bool foo(const Object::Ptr& object)
+{
+       DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(object);
+
+       string value;
+       return dobj->GetConfig()->GetProperty("foo", &value);
+}
+
+int main(int argc, char **argv)
+{
+       for (int i = 0; i < 1000000; i++) {
+               DynamicObject::Ptr dobj = make_shared<DynamicObject>();
+               dobj->GetConfig()->SetProperty("foo", "bar");
+               dobj->Commit();
+       }
+
+       ObjectSet::Ptr filtered = make_shared<ObjectSet>(ObjectSet::GetAllObjects(), &foo);
+       filtered->Start();
+
+       ObjectMap::Ptr m = make_shared<ObjectMap>(ObjectSet::GetAllObjects(), &foogetter);
+       m->Start();
+
+       ObjectMap::Range range = m->GetRange("bar");
+       cout << distance(range.first, range.second) << " elements" << endl;
+
+       return 0;
+}
diff --git a/dyntest/dyntest.vcxproj b/dyntest/dyntest.vcxproj
new file mode 100644 (file)
index 0000000..4a7d9f7
--- /dev/null
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{E6FA740D-0939-4711-AFBC-3D9E913510A1}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>dyntest</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
+    <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
+    <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>base.lib;dyn.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>base.lib;dyn.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="dyntest.cpp" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
index 594522256e8547835588f5271d57be68a266d6f8..f9766e2d60ba3bd70fe453e76346ec6ed818d400 100644 (file)
@@ -1,6 +1,6 @@
 
 Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual C++ Express 2010
+# Visual Studio 2010
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base", "base\base.vcxproj", "{9C92DA90-FD53-43A9-A244-90F2E8AF9677}"
        ProjectSection(ProjectDependencies) = postProject
                {19CBCE06-3F5C-479A-BD75-E2AB6215D345} = {19CBCE06-3F5C-479A-BD75-E2AB6215D345}
@@ -12,8 +12,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jsonrpc", "jsonrpc\jsonrpc.
                {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
        EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cJSON", "cJSON\cJSON.vcxproj", "{66BED474-C33F-48F9-90BA-BBCFEDC006B8}"
-EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga", "icinga\icinga.vcxproj", "{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}"
        ProjectSection(ProjectDependencies) = postProject
                {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
@@ -49,13 +47,20 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "discovery", "components\dis
                {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
        EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mmatch", "mmatch\mmatch.vcxproj", "{19CBCE06-3F5C-479A-BD75-E2AB6215D345}"
-EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dyn", "dyn\dyn.vcxproj", "{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}"
        ProjectSection(ProjectDependencies) = postProject
                {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
        EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cJSON", "third-party\cJSON\cJSON.vcxproj", "{66BED474-C33F-48F9-90BA-BBCFEDC006B8}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mmatch", "third-party\mmatch\mmatch.vcxproj", "{19CBCE06-3F5C-479A-BD75-E2AB6215D345}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dyntest", "dyntest\dyntest.vcxproj", "{E6FA740D-0939-4711-AFBC-3D9E913510A1}"
+       ProjectSection(ProjectDependencies) = postProject
+               {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
+       EndProjectSection
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Win32 = Debug|Win32
@@ -70,10 +75,6 @@ Global
                {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}.Debug|Win32.Build.0 = Debug|Win32
                {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}.Release|Win32.ActiveCfg = Release|Win32
                {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}.Release|Win32.Build.0 = Release|Win32
-               {66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Debug|Win32.ActiveCfg = Debug|Win32
-               {66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Debug|Win32.Build.0 = Debug|Win32
-               {66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Release|Win32.ActiveCfg = Release|Win32
-               {66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Release|Win32.Build.0 = Release|Win32
                {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}.Debug|Win32.ActiveCfg = Debug|Win32
                {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}.Debug|Win32.Build.0 = Debug|Win32
                {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}.Release|Win32.ActiveCfg = Release|Win32
@@ -98,14 +99,22 @@ Global
                {EAD41628-BB96-4F99-9070-8A9676801295}.Debug|Win32.Build.0 = Debug|Win32
                {EAD41628-BB96-4F99-9070-8A9676801295}.Release|Win32.ActiveCfg = Release|Win32
                {EAD41628-BB96-4F99-9070-8A9676801295}.Release|Win32.Build.0 = Release|Win32
-               {19CBCE06-3F5C-479A-BD75-E2AB6215D345}.Debug|Win32.ActiveCfg = Debug|Win32
-               {19CBCE06-3F5C-479A-BD75-E2AB6215D345}.Debug|Win32.Build.0 = Debug|Win32
-               {19CBCE06-3F5C-479A-BD75-E2AB6215D345}.Release|Win32.ActiveCfg = Release|Win32
-               {19CBCE06-3F5C-479A-BD75-E2AB6215D345}.Release|Win32.Build.0 = Release|Win32
                {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}.Debug|Win32.ActiveCfg = Debug|Win32
                {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}.Debug|Win32.Build.0 = Debug|Win32
                {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}.Release|Win32.ActiveCfg = Release|Win32
                {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}.Release|Win32.Build.0 = Release|Win32
+               {66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Debug|Win32.ActiveCfg = Debug|Win32
+               {66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Debug|Win32.Build.0 = Debug|Win32
+               {66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Release|Win32.ActiveCfg = Release|Win32
+               {66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Release|Win32.Build.0 = Release|Win32
+               {19CBCE06-3F5C-479A-BD75-E2AB6215D345}.Debug|Win32.ActiveCfg = Debug|Win32
+               {19CBCE06-3F5C-479A-BD75-E2AB6215D345}.Debug|Win32.Build.0 = Debug|Win32
+               {19CBCE06-3F5C-479A-BD75-E2AB6215D345}.Release|Win32.ActiveCfg = Release|Win32
+               {19CBCE06-3F5C-479A-BD75-E2AB6215D345}.Release|Win32.Build.0 = Release|Win32
+               {E6FA740D-0939-4711-AFBC-3D9E913510A1}.Debug|Win32.ActiveCfg = Debug|Win32
+               {E6FA740D-0939-4711-AFBC-3D9E913510A1}.Debug|Win32.Build.0 = Debug|Win32
+               {E6FA740D-0939-4711-AFBC-3D9E913510A1}.Release|Win32.ActiveCfg = Release|Win32
+               {E6FA740D-0939-4711-AFBC-3D9E913510A1}.Release|Win32.Build.0 = Release|Win32
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
index 9cd579651f817efeb296cfedba1146db0d22de7f..de1f80346c01cb7aacb6085d94daddfc24873817 100644 (file)
   </ImportGroup>
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\cJSON;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\third-party\cJSON;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\cJSON;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)\base;$(SolutionDir)\third-party\cJSON;$(IncludePath)</IncludePath>
     <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">