]> granicus.if.org Git - icinga2/commitdiff
Implement additional attributes for the Host class
authorGunnar Beutner <gunnar@beutner.name>
Mon, 9 Feb 2015 07:50:17 +0000 (08:50 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 9 Feb 2015 07:50:17 +0000 (08:50 +0100)
refs #7564

17 files changed:
lib/base/dynamicobject.cpp
lib/base/dynamicobject.ti
lib/checker/checkercomponent.cpp
lib/config/configitem.cpp
lib/icinga/dependency-apply.cpp
lib/icinga/host.hpp
lib/icinga/host.ti
lib/icinga/notification-apply.cpp
lib/icinga/scheduleddowntime-apply.cpp
lib/icinga/service-apply.cpp
lib/icinga/service.ti
lib/remote/apilistener.cpp
lib/remote/zone.cpp
tools/mkclass/class_lexer.ll
tools/mkclass/class_parser.yy
tools/mkclass/classcompiler.cpp
tools/mkclass/classcompiler.hpp

index 957ac75658118faefa18ff3ec51ce5e462d2cc16..ff78cd3d18d450ccd6010560777af31a83ec7b95 100644 (file)
@@ -53,7 +53,7 @@ DynamicObject::DynamicObject(void)
 
 DynamicType::Ptr DynamicObject::GetType(void) const
 {
-       return DynamicType::GetByName(GetTypeName());
+       return DynamicType::GetByName(GetTypeNameV());
 }
 
 DebugInfo DynamicObject::GetDebugInfo(void) const
index fba2fb4c514de4348ebf23e4b33ddfd61eaf4c40..b541820ad84fef5aa642c8b02bc842e24a067a57 100644 (file)
@@ -44,8 +44,8 @@ abstract class DynamicObject
                                return m_ShortName;
                }}}
        };
-       [config, internal, get_protected] String type (TypeName);
-       [config] String zone;
+       [config, internal, get_protected] String type (TypeNameV);
+       [config] String zone (ZoneName);
        [config, internal, get_protected] Array::Ptr templates;
        [get_protected] bool active;
        [get_protected] bool paused {
index f91a5db2b85bb615f6786579483eab13db650de6..ca74315f8b5a60c925ed60869e79aa379de5ea00 100644 (file)
@@ -258,7 +258,7 @@ void CheckerComponent::ObjectHandler(const DynamicObject::Ptr& object)
 
        Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
 
-       Zone::Ptr zone = Zone::GetByName(checkable->GetZone());
+       Zone::Ptr zone = Zone::GetByName(checkable->GetZoneName());
        bool same_zone = (!zone || Zone::GetLocalZone() == zone);
 
        {
index 0bfcddf9420a0d5996e95d34ffbc33d93254ea30..69e7e2d1be4fd37ad8f5f2af2171917554013fdd 100644 (file)
@@ -160,8 +160,8 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
        DynamicObject::Ptr dobj = static_pointer_cast<DynamicObject>(type->Instantiate());
 
        dobj->SetDebugInfo(m_DebugInfo);
-       dobj->SetTypeName(m_Type);
-       dobj->SetZone(m_Zone);
+       dobj->SetTypeNameV(m_Type);
+       dobj->SetZoneName(m_Zone);
        dobj->SetName(m_Name);
 
        DebugHint debugHints;
index a16c9c05916f9ff812106a8e2c1411e4e16e83fb..07ccf762a0cd4a3eb85b8bc1db875e738e3aa284 100644 (file)
@@ -66,7 +66,7 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
        if (service)
                builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "child_service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
 
-       String zone = checkable->GetZone();
+       String zone = checkable->GetZoneName();
 
        if (!zone.IsEmpty())
                builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));
index 96ecab05f4a841800f953ecd6d3b95c3a94280d7..7ff78f6fd7ef44bf527329146b652f47f5d31927 100644 (file)
@@ -51,9 +51,9 @@ public:
 
        static HostState CalculateState(ServiceState state);
 
-       HostState GetState(void) const;
-       HostState GetLastState(void) const;
-       HostState GetLastHardState(void) const;
+       virtual HostState GetState(void) const;
+       virtual HostState GetLastState(void) const;
+       virtual HostState GetLastHardState(void) const;
        double GetLastStateUp(void) const;
        double GetLastStateDown(void) const;
 
index 310e60a8b6045057a310918f0431f97cd97ace23..bf570f86c2a373c407d8f644ccf221473d5d84bc 100644 (file)
@@ -36,6 +36,17 @@ class Host : Checkable
 
        [config] String address;
        [config] String address6;
+
+       [enum, no_storage] HostState "state" {
+               get;
+       };
+       [enum, no_storage] HostState last_state {
+               get;
+       };
+       [enum, no_storage] HostState last_hard_state {
+               get;
+       };
+
 };
 
 }
index b6fe251b49deb2312a5b3772b42c461a8c524b39..16a8f9d096616d8c5f39caf731a3724e053c3835 100644 (file)
@@ -65,7 +65,7 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
        if (service)
                builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
 
-       String zone = checkable->GetZone();
+       String zone = checkable->GetZoneName();
 
        if (!zone.IsEmpty())
                builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));
index 33336e8526efb6bcc8fb05480ef918fc5f1dbe3c..9180ef4772917c4235c37d82105b558323a2182d 100644 (file)
@@ -64,7 +64,7 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
        if (service)
                builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
 
-       String zone = checkable->GetZone();
+       String zone = checkable->GetZoneName();
 
        if (!zone.IsEmpty())
                builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));
index 5c39e9cf02a56edc15a9313f0ed2972fdd3c1be6..8e28a50781a6b4be087850d77a8d8c80a4fe0cf8 100644 (file)
@@ -58,7 +58,7 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
 
        builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "name"), OpSetLiteral, MakeLiteral(name), di));
 
-       String zone = host->GetZone();
+       String zone = host->GetZoneName();
 
        if (!zone.IsEmpty())
                builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));
index bd21f718ca639f3fb138fdd5912befa9fe21e895..4533403f5c8720a74cf4ec41900b3c240d44c8cb 100644 (file)
@@ -44,17 +44,17 @@ class Service : Checkable < ServiceNameComposer
                }}}
        };
        [config] String host_name;
-       [enum] ServiceState "state" {
+       [enum, no_storage] ServiceState "state" {
                get {{{
                        return GetStateRaw();
                }}}
        };
-       [enum] ServiceState last_state {
+       [enum, no_storage] ServiceState last_state {
                get {{{
                        return GetLastStateRaw();
                }}}
        };
-       [enum] ServiceState last_hard_state {
+       [enum, no_storage] ServiceState last_hard_state {
                get {{{
                        return GetLastHardStateRaw();
                }}}
index 9c962dc64afbdd5cca1db6c2d37916c65324b088..d7956eecbc469d171ff2e9b76ceaa3eda394c2af 100644 (file)
@@ -556,7 +556,7 @@ void ApiListener::SyncRelayMessage(const MessageOrigin& origin, const DynamicObj
 
                /* only relay the message to a) the same zone, b) the parent zone and c) direct child zones */
                if (target_zone != my_zone && target_zone != my_zone->GetParent() &&
-                   secobj->GetZone() != target_zone->GetName()) {
+                   secobj->GetZoneName() != target_zone->GetName()) {
                        skippedEndpoints.push_back(endpoint);
                        continue;
                }
index 472b05710b69cf087b55d8f92e791be06cd8997a..194292cdb1db3805755acc21d389ebc11ba22b88 100644 (file)
@@ -60,7 +60,7 @@ bool Zone::CanAccessObject(const DynamicObject::Ptr& object)
        if (dynamic_pointer_cast<Zone>(object))
                object_zone = static_pointer_cast<Zone>(object);
        else
-               object_zone = Zone::GetByName(object->GetZone());
+               object_zone = Zone::GetByName(object->GetZoneName());
 
        if (!object_zone)
                object_zone = Zone::GetLocalZone();
index 799a9924cce0df015fcc99e1aded1a5515a2e027..2d74276c3400e9eb1745fbc14b09644735635216 100644 (file)
@@ -141,6 +141,7 @@ get_protected                       { yylval->num = FAGetProtected; return T_FIELD_ATTRIBUTE; }
 set_protected                  { yylval->num = FASetProtected; return T_FIELD_ATTRIBUTE; }
 protected                      { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTRIBUTE; }
 internal                       { yylval->num = FAInternal; return T_FIELD_ATTRIBUTE; }
+no_storage                     { yylval->num = FANoStorage; return T_FIELD_ATTRIBUTE; }
 default                                { yylval->num = FTDefault; return T_FIELD_ACCESSOR_TYPE; }
 get                            { yylval->num = FTGet; return T_FIELD_ACCESSOR_TYPE; }
 set                            { yylval->num = FTSet; return T_FIELD_ACCESSOR_TYPE; }
index 5d064b42b63bdb4e1788096c93781aa407f2036c..5f60d92b3b0c180f2c11aef4fd8db39c74854945 100644 (file)
@@ -265,9 +265,11 @@ class_field: field_attribute_list identifier identifier alternative_name_specifi
                        switch (it->Type) {
                                case FTGet:
                                        field->GetAccessor = it->Accessor;
+                                       field->PureGetAccessor = it->Pure;
                                        break;
                                case FTSet:
                                        field->SetAccessor = it->Accessor;
+                                       field->PureSetAccessor = it->Pure;
                                        break;
                                case FTDefault:
                                        field->DefaultAccessor = it->Accessor;
@@ -339,9 +341,13 @@ field_accessors: /* empty */
 
 field_accessor: T_FIELD_ACCESSOR_TYPE T_STRING
        {
-               $$ = new FieldAccessor(static_cast<FieldAccessorType>($1), $2);
+               $$ = new FieldAccessor(static_cast<FieldAccessorType>($1), $2, false);
                std::free($2);
        }
+       | T_FIELD_ACCESSOR_TYPE ';'
+       {
+               $$ = new FieldAccessor(static_cast<FieldAccessorType>($1), "", true);
+       }
        ;
 
 identifier: T_IDENTIFIER
index 9fa8de744d96b039de408cab8b2f7aa458a3f96b..901a3835e11c24709055a44477d5f676c5217d2e 100644 (file)
@@ -454,15 +454,21 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
                                prot = "public";
 
                        std::cout << prot << ":" << std::endl
-                                         << "\t" << it->Type << " Get" << it->GetFriendlyName() << "(void) const" << std::endl
+                           << "\t" << "virtual " << it->Type << " Get" << it->GetFriendlyName() << "(void) const";
+
+                       if (it->PureGetAccessor) {
+                               std::cout << " = 0;" << std::endl;
+                       } else {
+                               std::cout << std::endl
                                          << "\t" << "{" << std::endl;
 
-                       if (it->GetAccessor.empty())
-                               std::cout << "\t\t" << "return m_" << it->GetFriendlyName() << ";" << std::endl;
-                       else
-                               std::cout << it->GetAccessor << std::endl;
+                               if (it->GetAccessor.empty() && !(it->Attributes & FANoStorage))
+                                       std::cout << "\t\t" << "return m_" << it->GetFriendlyName() << ";" << std::endl;
+                               else
+                                       std::cout << it->GetAccessor << std::endl;
 
-                       std::cout << "\t" << "}" << std::endl << std::endl;
+                               std::cout << "\t" << "}" << std::endl << std::endl;
+                       }
                }
 
                /* setters */
@@ -484,15 +490,20 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
                        else
                                std::cout << "const " << it->Type << "&";
 
-                       std::cout << " value)" << std::endl
-                                         << "\t" << "{" << std::endl;
+                       std::cout << " value)" << std::endl;
 
-                       if (it->SetAccessor.empty())
-                               std::cout << "\t\t" << "m_" << it->GetFriendlyName() << " = value;" << std::endl;
-                       else
-                               std::cout << it->SetAccessor << std::endl;
+                       if (it->PureSetAccessor) {
+                               std::cout << " = 0;" << std::endl;
+                       } else {
+                               std::cout << "\t" << "{" << std::endl;
+
+                               if (it->SetAccessor.empty() && !(it->Attributes & FANoStorage))
+                                       std::cout << "\t\t" << "m_" << it->GetFriendlyName() << " = value;" << std::endl;
+                               else
+                                       std::cout << it->SetAccessor << std::endl;
 
-                       std::cout << "\t" << "}" << std::endl << std::endl;
+                               std::cout << "\t" << "}" << std::endl << std::endl;
+                       }
                }
 
                /* default */
index 04994b6d8b04b4fe3c4524d6558e180c286042b6..138ea40ea718859da537b867520d95b67af7f0d9 100644 (file)
@@ -48,9 +48,10 @@ struct FieldAccessor
 {
        FieldAccessorType Type;
        std::string Accessor;
+       bool Pure;
 
-       FieldAccessor(FieldAccessorType type, const std::string& accessor)
-               : Type(type), Accessor(accessor)
+       FieldAccessor(FieldAccessorType type, const std::string& accessor, bool pure)
+               : Type(type), Accessor(accessor), Pure(pure)
        { }
 };
 
@@ -61,7 +62,8 @@ enum FieldAttribute
        FAEnum = 4,
        FAGetProtected = 8,
        FASetProtected = 16,
-       FAInternal = 32
+       FAInternal = 32,
+       FANoStorage = 64
 };
 
 struct Field
@@ -71,7 +73,9 @@ struct Field
        std::string Name;
        std::string AlternativeName;
        std::string GetAccessor;
+       bool PureGetAccessor;
        std::string SetAccessor;
+       bool PureSetAccessor;
        std::string DefaultAccessor;
 
        std::string GetFriendlyName(void) const