]> granicus.if.org Git - icinga2/commitdiff
Implemented loading components on *NIX.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 1 Apr 2012 11:22:30 +0000 (13:22 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 1 Apr 2012 11:23:32 +0000 (13:23 +0200)
base/application.cpp
base/unix.h
configrpccomponent/configrpccomponent.cpp

index a56019d0ab130a10a9121a6a59cee2835fecebcb..62b3f13e1d2432481e9f329e731b7da181b03eb5 100644 (file)
@@ -190,7 +190,6 @@ Component::RefType Application::LoadComponent(string name)
 
        string path = componentConfig->GetProperty("path", name);
 
-#ifdef _WIN32
        HMODULE hModule = LoadLibrary(path.c_str());
 
        if (hModule == INVALID_HANDLE_VALUE)
@@ -201,10 +200,6 @@ Component::RefType Application::LoadComponent(string name)
        if (pCreateComponent == NULL)
                throw exception(/*"Module does not contain CreateComponent function"*/);
 
-#else /* _WIN32 */
-       // TODO: implement
-#endif /* _WIN32 */
-
        component = Component::RefType(pCreateComponent());
        component->SetApplication(static_pointer_cast<Application>(shared_from_this()));
        component->SetConfig(componentConfig);
index cde7fdb1ab02afb33177cc6ac24044f90df367fd..727b7e318d32b589437981e968884d83dc12b78e 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef I2_UNIX_H
 #define I2_UNIX_H
 
+#include <ltdl.h>
 #include <execinfo.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -32,4 +33,33 @@ inline void closesocket(int fd)
 #define I2_EXPORT
 #define I2_IMPORT
 
+typedef lt_dlhandle HMODULE;
+
+#define INVALID_HANDLE_VALUE NULL
+
+inline HMODULE LoadLibrary(const char *filename)
+{
+       lt_dlhandle handle = 0;
+    lt_dladvise advise;
+
+    if (!lt_dladvise_init(&advise) && !lt_dladvise_global(&advise)) {
+            handle = lt_dlopenadvise(filename, advise);
+    }
+
+    lt_dladvise_destroy(&advise);
+
+       return handle;
+}
+
+inline void FreeLibrary(HMODULE module)
+{
+       if (module)
+               lt_dlclose(module);
+}
+
+inline void *GetProcAddress(HMODULE module, const char *function)
+{
+       return lt_dlsym(module, function);
+}
+
 #endif /* I2_UNIX_H */
\ No newline at end of file
index efb651af1a1a4304e6d52329389f095e5e64ecbb..ce741692fc9fc2630a71b9245bb54b4f3c602b28 100644 (file)
@@ -81,7 +81,7 @@ int ConfigRpcComponent::FetchObjectsHandler(NewMessageEventArgs::RefType ea)
 int ConfigRpcComponent::LocalObjectCreatedHandler(ConfigHiveEventArgs::RefType ea)
 {
        ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
-       connectionManager->SendMessage(MakeObjectMessage(ea->Object, "config::ObjectCreated", true));
+       connectionManager->SendMessage(MakeObjectMessage(ea->ConfigObject, "config::ObjectCreated", true));
 
        return 0;
 }
@@ -89,17 +89,17 @@ int ConfigRpcComponent::LocalObjectCreatedHandler(ConfigHiveEventArgs::RefType e
 int ConfigRpcComponent::LocalObjectRemovedHandler(ConfigHiveEventArgs::RefType ea)
 {
        ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
-       connectionManager->SendMessage(MakeObjectMessage(ea->Object, "config::ObjectRemoved", false));
+       connectionManager->SendMessage(MakeObjectMessage(ea->ConfigObject, "config::ObjectRemoved", false));
 
        return 0;
 }
 
 int ConfigRpcComponent::LocalPropertyChangedHandler(ConfigHiveEventArgs::RefType ea)
 {
-       JsonRpcMessage::RefType msg = MakeObjectMessage(ea->Object, "config::ObjectRemoved", false);
+       JsonRpcMessage::RefType msg = MakeObjectMessage(ea->ConfigObject, "config::ObjectRemoved", false);
        cJSON *params = msg->GetParams();
        cJSON_AddStringToObject(params, "property", ea->Property.c_str());
-       string value = ea->Object->GetProperty(ea->Property);
+       string value = ea->ConfigObject->GetProperty(ea->Property);
        cJSON_AddStringToObject(params, "value", value.c_str());
 
        ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();