Implemented loading components on *NIX.

This commit is contained in:
Gunnar Beutner 2012-04-01 13:22:30 +02:00
parent 43b38f5a85
commit b4a51c98c7
3 changed files with 34 additions and 9 deletions

View 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);

View 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 */

View 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();