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
12 #include "monitor/MarshalWrapper.h"
13 #include "config/GlobalVault.h"
14 #include "util/MessageSystem.h"
18 MarshalWrapper::MarshalWrapper(const std::string
&moduleName
) : m_interface(NULL
), m_handle(NULL
) {
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());
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.");
49 m_interface
= instantiate();
52 } // namespace Monitor