]> granicus.if.org Git - icinga2/commitdiff
Fix compiler warnings w/ config validators
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 20 Apr 2015 12:16:19 +0000 (14:16 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 20 Apr 2015 12:16:19 +0000 (14:16 +0200)
fixes #9015

lib/icinga/checkable.cpp
lib/icinga/checkable.ti
lib/icinga/host.ti
lib/icinga/service.ti
tools/mkclass/classcompiler.cpp

index 75561bed1a205a826c9010f15edf2de84cea12b9..6ec3294c3c8842b27af3bdb5c701e0dd113cd2d3 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "icinga/checkable.hpp"
 #include "icinga/checkable.tcpp"
+#include "icinga/host.hpp"
+#include "icinga/service.hpp"
 #include "base/objectlock.hpp"
 #include "base/utility.hpp"
 #include "base/exception.hpp"
@@ -81,7 +83,13 @@ void Checkable::AddGroup(const String& name)
 {
        boost::mutex::scoped_lock lock(m_CheckableMutex);
 
-       Array::Ptr groups = GetGroups();
+       Array::Ptr groups;
+       Host *host = dynamic_cast<Host *>(this);
+
+       if (host)
+               groups = host->GetGroups();
+       else
+               groups = static_cast<Service *>(this)->GetGroups();
 
        if (groups && groups->Contains(name))
                return;
index 6c868300e46a0c4e4a04caa14b4149e289b1f3c3..749a26748e2dc6b6e473c8a4dc9028a27289eefd 100644 (file)
@@ -40,9 +40,6 @@ enum AcknowledgementType
 
 abstract class Checkable : CustomVarObject
 {
-       [config] Array::Ptr groups {
-               default {{{ return new Array(); }}}
-       };
        [config, protected, required] name(CheckCommand) check_command (CheckCommandRaw);
        [config] int max_check_attempts (MaxCheckAttemptsRaw) {
                default {{{ return 3; }}}
index 670f0b3173b35454174c0642067737195df0982d..d0fde790224aea3ff899bbea73e042603cb01b73 100644 (file)
@@ -25,6 +25,10 @@ namespace icinga
 
 class Host : Checkable
 {
+       [config] Array::Ptr groups {
+               default {{{ return new Array(); }}}
+       };
+
        [config] String display_name {
                get {{{
                        if (m_DisplayName.IsEmpty())
index a516fac7ea059f62e37766ff25b3d83a91ebdbff..0f92ee6a8928082be34838eb9336074f429857cd 100644 (file)
@@ -37,6 +37,10 @@ class Service : Checkable < ServiceNameComposer
 {
        load_after Host;
 
+       [config] Array::Ptr groups {
+               default {{{ return new Array(); }}}
+       };
+
        [config] String display_name {
                get {{{
                        if (m_DisplayName.IsEmpty())
index 1cd9b05148a6e6c9124267b41f285eee244e5a37..1c1a6e6113c1c5ea2d384d319edd9bbc821139f0 100644 (file)
@@ -645,14 +645,10 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string&
        if (validatorType != ValidatorField)
                m_Impl << "const String& key, ";
 
-       bool static_known_attribute = false;
-
        m_Impl << fieldType.GetArgumentType() << " value, std::vector<String>& location, const ValidationUtils& utils)" << std::endl
               << "{" << std::endl;
 
        if (validatorType == ValidatorField) {
-               static_known_attribute = true;
-
                bool required = false;
 
                for (std::vector<Rule>::size_type i = 0; i < rules.size(); i++) {
@@ -679,7 +675,7 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string&
                }
        }
 
-       if (!static_known_attribute)
+       if (validatorType != ValidatorField)
                m_Impl << "\t" << "bool known_attribute = false;" << std::endl;
 
        bool type_check = false;
@@ -703,11 +699,9 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string&
                                        m_Impl << "\t\t" << "if (key != \"" << rule.Pattern << "\")" << std::endl;
 
                                m_Impl << "\t\t\t" << "break;" << std::endl;
-                       } else
-                               static_known_attribute = true;
+                       }
 
-                       if (!static_known_attribute)
-                               m_Impl << "\t\t" << "known_attribute = true;" << std::endl;
+                       m_Impl << "\t\t" << "known_attribute = true;" << std::endl;
                }
 
                if (rule.IsName) {
@@ -824,12 +818,13 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string&
        }
 
        if (type_check || validatorType != ValidatorField) {
-               if (!static_known_attribute)
+               if (validatorType != ValidatorField) {
                        m_Impl << "\t" << "if (!known_attribute)" << std::endl
                               << "\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast<DynamicObject>(object), location, \"Invalid attribute: \" + key));" << std::endl
                               << "\t" << "else" << std::endl;
+               }
 
-               m_Impl << (!static_known_attribute ? "\t" : "") << "\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast<DynamicObject>(object), location, \"Invalid type.\"));" << std::endl;
+               m_Impl << (validatorType != ValidatorField ? "\t" : "") << "\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast<DynamicObject>(object), location, \"Invalid type.\"));" << std::endl;
        }
 
        m_Impl << "}" << std::endl << std::endl;