From b4a51c98c7b6d0929e682a1c9797dc6df2a3c8b5 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 1 Apr 2012 13:22:30 +0200 Subject: [PATCH] Implemented loading components on *NIX. --- base/application.cpp | 5 ---- base/unix.h | 30 +++++++++++++++++++++++ configrpccomponent/configrpccomponent.cpp | 8 +++--- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/base/application.cpp b/base/application.cpp index a56019d0a..62b3f13e1 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -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(shared_from_this())); component->SetConfig(componentConfig); diff --git a/base/unix.h b/base/unix.h index cde7fdb1a..727b7e318 100644 --- a/base/unix.h +++ b/base/unix.h @@ -1,6 +1,7 @@ #ifndef I2_UNIX_H #define I2_UNIX_H +#include #include #include #include @@ -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 diff --git a/configrpccomponent/configrpccomponent.cpp b/configrpccomponent/configrpccomponent.cpp index efb651af1..ce741692f 100644 --- a/configrpccomponent/configrpccomponent.cpp +++ b/configrpccomponent/configrpccomponent.cpp @@ -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();