]> granicus.if.org Git - icinga2/commitdiff
Added preliminary version of the dynamic object framework.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 25 May 2012 09:10:11 +0000 (11:10 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 25 May 2012 09:10:11 +0000 (11:10 +0200)
23 files changed:
base/configobject.cpp
base/configobject.h
base/dictionary.h
base/tcpsocket.cpp
base/variant.cpp
base/variant.h
components/configrpc/configrpccomponent.cpp
components/demo/demo.vcxproj.filters
components/discovery/discovery.vcxproj.filters
components/discovery/discoverycomponent.cpp
dyn/dyn.vcxproj [new file with mode: 0644]
dyn/dynamicdictionary.cpp [new file with mode: 0644]
dyn/dynamicdictionary.h [new file with mode: 0644]
dyn/dynamicobject.cpp [new file with mode: 0644]
dyn/dynamicobject.h [new file with mode: 0644]
dyn/i2-dyn.h [new file with mode: 0644]
dyn/objectspace.cpp [new file with mode: 0644]
dyn/objectspace.h [new file with mode: 0644]
icinga.sln
icinga/endpoint.cpp
icinga/endpoint.h
icinga/icingaapplication.cpp
jsonrpc/jsonrpc.vcxproj.filters

index 9e015da49dc1326b5ccfe4c2dc648a658ddb836b..65ac039416ff6cf2a267dd0df5ef2ae8d8726443 100644 (file)
@@ -112,7 +112,7 @@ void ConfigObject::SetReplicated(bool replicated)
  *
  * @returns Whether this object was replicated.
  */
-bool ConfigObject::GetReplicated(void) const
+bool ConfigObject::IsReplicated(void) const
 {
        return m_Replicated;
 }
index 5ecb6d0282e664c6391d5c756c3ebd92466107bf..8871d8c50a7fa261a165a5bc2b9ba331f874183b 100644 (file)
@@ -50,7 +50,7 @@ public:
        string GetType(void) const;
 
        void SetReplicated(bool replicated);
-       bool GetReplicated(void) const;
+       bool IsReplicated(void) const;
 
        void Commit(void);
 
index eef9587f39c0cb7e8017dc484e2fb2776ff38a59..5cf00ac9fc62ffdcd5051c80f55f4c70dcee066c 100644 (file)
@@ -57,6 +57,27 @@ public:
                return true;
        }
 
+       /**
+        * Retrieves a value from the dictionary.
+        *
+        * @param key The key.
+        * @param[out] value Pointer to the value.
+        * @returns true if the value was retrieved, false otherwise.
+        */
+       bool GetProperty(string key, Dictionary::Ptr *value)
+       {
+               Object::Ptr object;
+
+               if (!GetProperty(key, &object))
+                       return false;
+
+               *value = dynamic_pointer_cast<Dictionary>(object);
+               if (!*value)
+                       throw InvalidCastException();
+
+               return true;
+       }
+
        /**
         * Sets a value in the dictionary.
         *
index 3e3c00877c9e180509d699aca55d2d655d8e2424..97733e977a303921a8cd8997fa74630bce75b86c 100644 (file)
@@ -55,6 +55,7 @@ void TcpSocket::Bind(string service, int family)
 /**
  * Creates a socket and binds it to the specified node and service.
  *
+ * @param node The node.
  * @param service The service.
  * @param family The address family for the socket.
  */
index dcf148e5dc0f9342b8ac9ab2a4afd9c84283f457..b41f0b0c9615e775699884b19f18769496175f1d 100644 (file)
@@ -64,6 +64,18 @@ long Variant::GetInteger(void) const
        return m_IntegerValue;
 }
 
+/**
+ * Retrieves the variant's value as a bool.
+ *
+ * @returns The variant's value as a bool.
+ */
+long Variant::GetBool(void) const
+{
+       Convert(VariantInteger);
+
+       return (m_IntegerValue != 0);
+}
+
 /**
  * Retrieves the variant's value as a string.
  *
@@ -108,6 +120,16 @@ Variant::operator long(void) const
        return GetInteger();
 }
 
+/**
+ * Retrieves the variant's value as a bool.
+ *
+ * @returns The variant's value as a bool.
+ */
+Variant::operator bool(void) const
+{
+       return GetBool();
+}
+
 /**
  * Retrieves the variant's value as a string.
  *
index 4545e1daee3fd1f15a6162f226e297378881d344..b2e24382e4b5a740e1b91413b65e000b637253e9 100644 (file)
@@ -50,6 +50,9 @@ public:
        inline Variant(int value)
            : m_Type(VariantInteger), m_IntegerValue(value) { }
 
+       inline Variant(bool value)
+           : m_Type(VariantInteger), m_IntegerValue(value ? 1 : 0) { }
+
        inline Variant(long value)
            : m_Type(VariantInteger), m_IntegerValue(value) { }
 
@@ -66,12 +69,14 @@ public:
        VariantType GetType(void) const;
 
        long GetInteger(void) const;
+       long GetBool(void) const;
        string GetString(void) const;
        Object::Ptr GetObject(void) const;
 
        bool IsEmpty(void) const;
 
        operator long(void) const;
+       operator bool(void) const;
        operator string(void) const;
        operator Object::Ptr(void) const;
 
index 91c7767d3268c06efa2fc6f0b88f22ee4a928265..37c2c36974edaa7620c29b8c7a2f84d6bd770c05 100644 (file)
@@ -219,7 +219,7 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea
        if (!object)
                return 0;
 
-       if (object->GetReplicated())
+       if (object->IsReplicated())
                configHive->RemoveObject(object);
 
        return 0;
index 51b6a0536da1fdecf76a3dc6cb74afdb47d274b7..e02ed2da941ac813ff3bbbcaf40434623f195e2e 100644 (file)
@@ -1,10 +1,24 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
-    <ClInclude Include="i2-demo.h" />
-    <ClInclude Include="democomponent.h" />
+    <ClInclude Include="democomponent.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="i2-demo.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="democomponent.cpp" />
+    <Filter Include="Headerdateien">
+      <UniqueIdentifier>{11a495bf-a705-4766-b3d3-9b5db266a6ef}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Quelldateien">
+      <UniqueIdentifier>{1fb6337f-a17f-46ea-9316-2d800a94b53d}</UniqueIdentifier>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="democomponent.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 36941f15769e3be4118398d150ac76bc34ec28c0..a356d8a9217b97734af5e4b9ceadf5e4d744a9c5 100644 (file)
@@ -1,12 +1,30 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
-    <ClCompile Include="discoverycomponent.cpp" />
-    <ClCompile Include="discoverymessage.cpp" />
+    <ClCompile Include="discoverycomponent.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="discoverymessage.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="discoverycomponent.h" />
-    <ClInclude Include="i2-discovery.h" />
-    <ClInclude Include="discoverymessage.h" />
+    <ClInclude Include="discoverycomponent.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="i2-discovery.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="discoverymessage.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <Filter Include="Headerdateien">
+      <UniqueIdentifier>{53341f7e-6bad-4cf1-92cf-be906efe1704}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Quelldateien">
+      <UniqueIdentifier>{c7b2deba-743b-4449-ae46-0b7ba1b1350a}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 3ceb622113ebc1aaef81d9434ffeee22e7b59a57..815f35557e5168f7da7be817e720503b298692f8 100644 (file)
@@ -254,12 +254,12 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
 {
        Endpoint::Ptr endpoint = nrea.Sender;
 
-       if (endpoint->GetReceivedWelcome())
+       if (endpoint->HasReceivedWelcome())
                return 0;
 
        endpoint->SetReceivedWelcome(true);
 
-       if (endpoint->GetSentWelcome()) {
+       if (endpoint->HasSentWelcome()) {
                EventArgs ea;
                ea.Source = endpoint;
                endpoint->OnSessionEstablished(ea);
@@ -277,7 +277,7 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
  */
 void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
 {
-       if (endpoint->GetSentWelcome())
+       if (endpoint->HasSentWelcome())
                return;
 
        // we assume the other component _always_ wants
@@ -289,7 +289,7 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
 
        endpoint->SetSentWelcome(true);
 
-       if (endpoint->GetReceivedWelcome()) {
+       if (endpoint->HasReceivedWelcome()) {
                EventArgs ea;
                ea.Source = endpoint;
                endpoint->OnSessionEstablished(ea);
diff --git a/dyn/dyn.vcxproj b/dyn/dyn.vcxproj
new file mode 100644 (file)
index 0000000..50d64aa
--- /dev/null
@@ -0,0 +1,94 @@
+<?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>
+  <ItemGroup>
+    <ClInclude Include="dynamicdictionary.h" />
+    <ClInclude Include="dynamicobject.h" />
+    <ClInclude Include="i2-dyn.h" />
+    <ClInclude Include="objectspace.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="dynamicdictionary.cpp" />
+    <ClCompile Include="dynamicobject.cpp" />
+    <ClCompile Include="objectspace.cpp" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>dyn</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</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'">
+    <IncludePath>$(SolutionDir)\base;$(IncludePath)</IncludePath>
+    <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <IncludePath>$(SolutionDir)\base;$(IncludePath)</IncludePath>
+    <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>base.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;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>base.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/dyn/dynamicdictionary.cpp b/dyn/dynamicdictionary.cpp
new file mode 100644 (file)
index 0000000..5a7b05f
--- /dev/null
@@ -0,0 +1,22 @@
+/******************************************************************************
+ * 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;
diff --git a/dyn/dynamicdictionary.h b/dyn/dynamicdictionary.h
new file mode 100644 (file)
index 0000000..30aafe7
--- /dev/null
@@ -0,0 +1,79 @@
+/******************************************************************************
+ * 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 DYNAMICDICTIONARY_H
+#define DYNAMICDICTIONARY_H
+
+namespace icinga
+{
+
+enum DynamicDictionaryOperator
+{
+       OperatorSet,
+       OperatorPlus,
+       OperatorMinus,
+       OperatorMultiply,
+       OperatorDivide
+};
+
+struct DynamicDictionaryValue
+{
+       Variant Value;
+       DynamicDictionaryOperator Operator;
+};
+
+class DynamicDictionary : public Object
+{
+public:
+       typedef shared_ptr<DynamicDictionary> Ptr;
+       typedef weak_ptr<DynamicDictionary> WeakPtr;
+
+       DynamicDictionary(void);
+       DynamicDictionary(Dictionary::Ptr serializedDictionary);
+
+       void AddParent(DynamicDictionary::Ptr parent);
+       void ClearParents(void);
+
+       template<typename T>
+       bool GetProperty(string name, T *value, DynamicDictionaryOperator *op) const
+       {
+               map<string, DynamicDictionaryValue>::const_iterator di;
+
+               di = m_Values.find(name);
+               if (di == m_Values.end())
+                       return false;
+
+               return di->second.op;
+       }
+
+       template<typename T>
+       void SetProperty(string name, const T& value, DynamicDictionaryOperator op);
+
+       Dictionary::Ptr ToFlatDictionary(void) const;
+
+       Dictionary::Ptr Serialize(void);
+
+private:
+       set<DynamicDictionary::Ptr> m_Parents;
+       map<string, DynamicDictionaryValue> m_Values;
+};
+
+}
+
+#endif /* DYNAMICDICTIONARY_H */
diff --git a/dyn/dynamicobject.cpp b/dyn/dynamicobject.cpp
new file mode 100644 (file)
index 0000000..e61d3dd
--- /dev/null
@@ -0,0 +1,90 @@
+/******************************************************************************
+ * 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;
+
+DynamicDictionary::Ptr DynamicObject::GetProperties(void) const
+{
+       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)
+{
+       m_Type = type;
+}
+
+bool DynamicObject::IsLocal(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;
+}
+
+void DynamicObject::Commit(void)
+{
+       // TODO: link properties to parent objects
+
+       Dictionary::Ptr resolvedProperties = m_Properties->ToFlatDictionary();
+       Reload(resolvedProperties);
+}
+
+void DynamicObject::Reload(Dictionary::Ptr resolvedProperties)
+{
+       resolvedProperties->GetProperty("__name", &m_Name);
+       resolvedProperties->GetProperty("__type", &m_Type);
+       resolvedProperties->GetProperty("__local", &m_Local);
+       resolvedProperties->GetProperty("__abstract", &m_Abstract);
+}
diff --git a/dyn/dynamicobject.h b/dyn/dynamicobject.h
new file mode 100644 (file)
index 0000000..8608896
--- /dev/null
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * 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 DynamicObject : public Object
+{
+public:
+       typedef shared_ptr<DynamicObject> Ptr;
+       typedef weak_ptr<DynamicObject> WeakPtr;
+
+       void AddParentObject(DynamicObject::Ptr parent);
+       void RemoveParentObject(DynamicObject::Ptr parent);
+
+       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;
+
+       void Commit(void);
+
+protected:
+       virtual void Reload(Dictionary::Ptr resolvedProperties);
+
+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);
+};
+
+}
+
+#endif /* DYNAMICOBJECT_H */
diff --git a/dyn/i2-dyn.h b/dyn/i2-dyn.h
new file mode 100644 (file)
index 0000000..806d4bc
--- /dev/null
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * 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 I2DYN_H
+#define I2DYN_H
+
+/**
+ * @defgroup dyn Dynamic object library
+ *
+ * The dynamic object library implements serializable objects which support
+ * inheritance.
+ */
+
+#include <i2-base.h>
+
+#include "dynamicdictionary.h"
+#include "dynamicobject.h"
+#include "objectspace.h"
+
+#endif /* I2DYN_H */
diff --git a/dyn/objectspace.cpp b/dyn/objectspace.cpp
new file mode 100644 (file)
index 0000000..6dd41d3
--- /dev/null
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * 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/dyn/objectspace.h b/dyn/objectspace.h
new file mode 100644 (file)
index 0000000..de3f24a
--- /dev/null
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * 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 OBJECTSPACE_H
+#define OBJECTSPACE_H
+
+namespace icinga
+{
+
+typedef function<DynamicObject::Ptr()> DynamicObjectFactory;
+
+class ObjectSpace : public Object
+{
+public:
+       void RegisterClass(string name, DynamicObjectFactory factory);
+       void UnregisterClass(string name);
+
+       Dictionary::Ptr SerializeObject(DynamicObject::Ptr object);
+       DynamicObject::Ptr UnserializeObject(Dictionary::Ptr serializedObject);
+
+       vector<DynamicObject::Ptr> FindObjects(function<bool (DynamicObject::Ptr)> predicate);
+
+private:
+       map<string, DynamicObjectFactory> m_Classes;
+       set<DynamicObject::Ptr> m_Objects;
+
+       void RegisterObject(DynamicObject::Ptr object);
+       void UnregisterObject(DynamicObject::Ptr object);
+};
+
+}
+
+#endif /* OBJECTSPACE_H */
index 21ee272eea9ce6a77e36e698fb328aaa4f8f2271..594522256e8547835588f5271d57be68a266d6f8 100644 (file)
@@ -51,6 +51,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "discovery", "components\dis
 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
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Win32 = Debug|Win32
@@ -97,6 +102,10 @@ Global
                {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
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
index e00ffff94e9becfb9b8d2ce54792e43ec428a4f3..94c015e7aeecffa6b1a3c3b45e4adba974240c1c 100644 (file)
@@ -207,7 +207,7 @@ void Endpoint::SetReceivedWelcome(bool value)
  *
  * @returns Whether we've received a welcome message.
  */
-bool Endpoint::GetReceivedWelcome(void) const
+bool Endpoint::HasReceivedWelcome(void) const
 {
        return m_ReceivedWelcome;
 }
@@ -227,7 +227,7 @@ void Endpoint::SetSentWelcome(bool value)
  *
  * @returns Whether we've sent a welcome message.
  */
-bool Endpoint::GetSentWelcome(void) const
+bool Endpoint::HasSentWelcome(void) const
 {
        return m_SentWelcome;
 }
index a6b2453304678d963a9f10d0e0aa3d74d17dda74..b1cd5982c22a3a25c175a155b5beeddf53adf810 100644 (file)
@@ -46,10 +46,10 @@ public:
        void SetIdentity(string identity);
 
        void SetReceivedWelcome(bool value);
-       bool GetReceivedWelcome(void) const;
+       bool HasReceivedWelcome(void) const;
 
        void SetSentWelcome(bool value);
-       bool GetSentWelcome(void) const;
+       bool HasSentWelcome(void) const;
 
        shared_ptr<EndpointManager> GetEndpointManager(void) const;
        void SetEndpointManager(weak_ptr<EndpointManager> manager);
index a1ed1e4ee3e25d0cba515dd2000cd514ddbc307f..6cb33299c55b014ab5b44ec06ff8a7a9c9967e7e 100644 (file)
@@ -108,7 +108,7 @@ int IcingaApplication::NewComponentHandler(const EventArgs& ea)
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        
        /* don't allow replicated config objects */
-       if (object->GetReplicated())
+       if (object->IsReplicated())
                return 0;
 
        string path;
@@ -140,7 +140,7 @@ int IcingaApplication::NewIcingaConfigHandler(const EventArgs& ea)
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        
        /* don't allow replicated config objects */
-       if (object->GetReplicated())
+       if (object->IsReplicated())
                return 0;
 
        string privkey;
index 055198b6c102b7bc171aa201a620208000369644..6878f2c8ade83eb8a723c684232bc360c9012881 100644 (file)
@@ -1,20 +1,54 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
-    <ClCompile Include="jsonrpcclient.cpp" />
-    <ClCompile Include="jsonrpcserver.cpp" />
-    <ClCompile Include="netstring.cpp" />
-    <ClCompile Include="messagepart.cpp" />
-    <ClCompile Include="requestmessage.cpp" />
-    <ClCompile Include="responsemessage.cpp" />
+    <ClCompile Include="jsonrpcclient.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="responsemessage.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="jsonrpcserver.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="messagepart.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="netstring.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="requestmessage.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="i2-jsonrpc.h" />
-    <ClInclude Include="jsonrpcclient.h" />
-    <ClInclude Include="jsonrpcserver.h" />
-    <ClInclude Include="netstring.h" />
-    <ClInclude Include="messagepart.h" />
-    <ClInclude Include="requestmessage.h" />
-    <ClInclude Include="responsemessage.h" />
+    <ClInclude Include="i2-jsonrpc.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="jsonrpcclient.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="jsonrpcserver.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="messagepart.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="netstring.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="requestmessage.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="responsemessage.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <Filter Include="Headerdateien">
+      <UniqueIdentifier>{796f79ec-5628-4c91-9e2b-3d603ab2acfc}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Quelldateien">
+      <UniqueIdentifier>{0457f937-d12b-4328-818b-77359de2425f}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
 </Project>
\ No newline at end of file