]> granicus.if.org Git - icinga2/commitdiff
Auto-load components when component config objects are created.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 1 Apr 2012 07:30:38 +0000 (09:30 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 1 Apr 2012 07:30:38 +0000 (09:30 +0200)
icinga/icingaapplication.cpp
icinga/icingaapplication.h

index d5e4b839f8b28e3792f0fc3d99bd250f65326a15..b7a6c6677849bf083f5d8035a630ee118016d8b3 100644 (file)
@@ -14,16 +14,15 @@ IcingaApplication::IcingaApplication(void)
 
 int IcingaApplication::Main(const vector<string>& 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<ConfigObject>();
        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);
index 0bc0092d107efd8e345a6a9255f29bbeb4e49f3c..209e6b655a80f73df0d908f677d861dee9624c42 100644 (file)
@@ -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<IcingaApplication> RefType;
        typedef weak_ptr<IcingaApplication> WeakRefType;