Kind-of worked on the R-Tree; not really enough time to do much.
[aesalon.git] / src / monitor / MarshalWrapper.cpp
blob4e56cdd980c580392a86da6b63f306f4429e5d4f
1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/monitor/MarshalWrapper.cpp
8 */
10 #include <dlfcn.h>
12 #include "monitor/MarshalWrapper.h"
13 #include "config/GlobalVault.h"
14 #include "util/MessageSystem.h"
16 namespace Monitor {
18 MarshalWrapper::MarshalWrapper(const std::string &moduleName) : m_interface(NULL), m_handle(NULL) {
19 load(moduleName);
22 MarshalWrapper::MarshalWrapper(Marshal::Interface *interface) : m_interface(interface) {
26 MarshalWrapper::~MarshalWrapper() {
30 void MarshalWrapper::load(const std::string &moduleName) {
31 std::string moduleRoot = Config::GlobalVault::instance()->get(moduleName + ":root");
32 std::string marshalPath = Config::GlobalVault::instance()->get(moduleName + ":marshalPath");
34 /* Use RTLD_NOW so if there are any undefined symbols, they are caught now instead of later. */
35 m_handle = dlopen((moduleRoot + marshalPath).c_str(), RTLD_NOW | RTLD_LOCAL);
36 if(m_handle == NULL) {
37 Message(Warning, "Could not open marshal library for module \"" << moduleName << "\":" << dlerror());
38 return;
40 Marshal::Interface *(*instantiate)();
42 *(void **) (&instantiate) = dlsym(m_handle, "AM_Instantiate");
44 if(instantiate == NULL) {
45 Message(Warning, "Could not find AM_Instantiate in " << moduleName << "'s marshal.");
46 return;
49 m_interface = instantiate();
52 } // namespace Monitor