mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 21:24:41 +02:00
Implemented loading components on *NIX.
This commit is contained in:
parent
43b38f5a85
commit
b4a51c98c7
@ -190,7 +190,6 @@ Component::RefType Application::LoadComponent(string name)
|
|||||||
|
|
||||||
string path = componentConfig->GetProperty("path", name);
|
string path = componentConfig->GetProperty("path", name);
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
HMODULE hModule = LoadLibrary(path.c_str());
|
HMODULE hModule = LoadLibrary(path.c_str());
|
||||||
|
|
||||||
if (hModule == INVALID_HANDLE_VALUE)
|
if (hModule == INVALID_HANDLE_VALUE)
|
||||||
@ -201,10 +200,6 @@ Component::RefType Application::LoadComponent(string name)
|
|||||||
if (pCreateComponent == NULL)
|
if (pCreateComponent == NULL)
|
||||||
throw exception(/*"Module does not contain CreateComponent function"*/);
|
throw exception(/*"Module does not contain CreateComponent function"*/);
|
||||||
|
|
||||||
#else /* _WIN32 */
|
|
||||||
// TODO: implement
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
|
|
||||||
component = Component::RefType(pCreateComponent());
|
component = Component::RefType(pCreateComponent());
|
||||||
component->SetApplication(static_pointer_cast<Application>(shared_from_this()));
|
component->SetApplication(static_pointer_cast<Application>(shared_from_this()));
|
||||||
component->SetConfig(componentConfig);
|
component->SetConfig(componentConfig);
|
||||||
|
30
base/unix.h
30
base/unix.h
@ -1,6 +1,7 @@
|
|||||||
#ifndef I2_UNIX_H
|
#ifndef I2_UNIX_H
|
||||||
#define I2_UNIX_H
|
#define I2_UNIX_H
|
||||||
|
|
||||||
|
#include <ltdl.h>
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -32,4 +33,33 @@ inline void closesocket(int fd)
|
|||||||
#define I2_EXPORT
|
#define I2_EXPORT
|
||||||
#define I2_IMPORT
|
#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 */
|
#endif /* I2_UNIX_H */
|
@ -81,7 +81,7 @@ int ConfigRpcComponent::FetchObjectsHandler(NewMessageEventArgs::RefType ea)
|
|||||||
int ConfigRpcComponent::LocalObjectCreatedHandler(ConfigHiveEventArgs::RefType ea)
|
int ConfigRpcComponent::LocalObjectCreatedHandler(ConfigHiveEventArgs::RefType ea)
|
||||||
{
|
{
|
||||||
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
|
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
|
||||||
connectionManager->SendMessage(MakeObjectMessage(ea->Object, "config::ObjectCreated", true));
|
connectionManager->SendMessage(MakeObjectMessage(ea->ConfigObject, "config::ObjectCreated", true));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -89,17 +89,17 @@ int ConfigRpcComponent::LocalObjectCreatedHandler(ConfigHiveEventArgs::RefType e
|
|||||||
int ConfigRpcComponent::LocalObjectRemovedHandler(ConfigHiveEventArgs::RefType ea)
|
int ConfigRpcComponent::LocalObjectRemovedHandler(ConfigHiveEventArgs::RefType ea)
|
||||||
{
|
{
|
||||||
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
|
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
|
||||||
connectionManager->SendMessage(MakeObjectMessage(ea->Object, "config::ObjectRemoved", false));
|
connectionManager->SendMessage(MakeObjectMessage(ea->ConfigObject, "config::ObjectRemoved", false));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::LocalPropertyChangedHandler(ConfigHiveEventArgs::RefType ea)
|
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 *params = msg->GetParams();
|
||||||
cJSON_AddStringToObject(params, "property", ea->Property.c_str());
|
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());
|
cJSON_AddStringToObject(params, "value", value.c_str());
|
||||||
|
|
||||||
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
|
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user