From a49876a1aea0d7a2f228883ac13a9692dfe5d4e4 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 1 Apr 2012 09:30:38 +0200 Subject: [PATCH] Auto-load components when component config objects are created. --- icinga/icingaapplication.cpp | 25 +++++++++++++++++++++---- icinga/icingaapplication.h | 3 +++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/icinga/icingaapplication.cpp b/icinga/icingaapplication.cpp index d5e4b839f..b7a6c6677 100644 --- a/icinga/icingaapplication.cpp +++ b/icinga/icingaapplication.cpp @@ -14,16 +14,15 @@ IcingaApplication::IcingaApplication(void) int IcingaApplication::Main(const vector& args) { + GetConfigHive()->OnObjectCreated.bind(bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this())); + GetConfigHive()->OnObjectRemoved.bind(bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this())); + ConfigObject::RefType fileComponentConfig = new_object(); fileComponentConfig->SetName("configfilecomponent"); fileComponentConfig->SetType("component"); fileComponentConfig->SetProperty("filename", "icinga.conf"); GetConfigHive()->AddObject(fileComponentConfig); - LoadComponent("configfilecomponent"); - - LoadComponent("configrpccomponent"); - RunEventLoop(); return 0; @@ -34,4 +33,22 @@ ConnectionManager::RefType IcingaApplication::GetConnectionManager(void) return m_ConnectionManager; } +int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType ea) +{ + if (ea->ConfigObject->GetType() == "component") { + LoadComponent(ea->ConfigObject->GetName()); + } + + return 0; +} + +int IcingaApplication::ConfigObjectRemovedHandler(ConfigHiveEventArgs::RefType ea) +{ + if (ea->ConfigObject->GetType() == "component") { + UnloadComponent(ea->ConfigObject->GetName()); + } + + return 0; +} + SET_START_CLASS(icinga::IcingaApplication); diff --git a/icinga/icingaapplication.h b/icinga/icingaapplication.h index 0bc0092d1..209e6b655 100644 --- a/icinga/icingaapplication.h +++ b/icinga/icingaapplication.h @@ -9,6 +9,9 @@ class IcingaApplication : public Application private: ConnectionManager::RefType m_ConnectionManager; + int ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType ea); + int ConfigObjectRemovedHandler(ConfigHiveEventArgs::RefType ea); + public: typedef shared_ptr RefType; typedef weak_ptr WeakRefType; -- 2.40.0