summaryrefslogtreecommitdiffstats
path: root/src/Common/ModuleManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/ModuleManager.cpp')
-rw-r--r--src/Common/ModuleManager.cpp48
1 files changed, 23 insertions, 25 deletions
diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp
index bec3618..738532f 100644
--- a/src/Common/ModuleManager.cpp
+++ b/src/Common/ModuleManager.cpp
@@ -21,10 +21,10 @@
#include <config.h>
#include "ModuleManager.h"
+#include "Application.h"
#include <Core/ConfigEntry.h>
-#include <Core/Logger.h>
-
+#include <Core/ConfigManager.h>
//extern const lt_dlsymlist lt_preloaded_symbols[];
@@ -32,24 +32,25 @@
namespace Mad {
namespace Common {
-ModuleManager ModuleManager::moduleManager;
-
-
-int ModuleManager::preopenCallback(lt_dlhandle handle) {
+/*int ModuleManager::preopenCallback(lt_dlhandle handle) {
moduleManager.modules.insert(std::make_pair(lt_dlgetinfo(handle)->name, std::make_pair(handle, false)));
return 0;
-}
+}*/
-void ModuleManager::doInit() {
+ModuleManager::ModuleManager(Application *application0) : application(application0) {
lt_dlinit();
//lt_dlpreload_default(lt_preloaded_symbols);
- lt_dlpreload(0);
- lt_dlpreload_open("@PROGRAM@", &ModuleManager::preopenCallback);
+ //lt_dlpreload(0);
+ //lt_dlpreload_open("@PROGRAM@", &ModuleManager::preopenCallback);
+
+ application->getConfigManager()->registerConfigurable(this);
}
-void ModuleManager::doDeinit() {
+ModuleManager::~ModuleManager() {
+ application->getConfigManager()->unregisterConfigurable(this);
+
while(!moduleOrder.empty()) {
unloadModule(moduleOrder.top());
moduleOrder.pop();
@@ -64,7 +65,7 @@ bool ModuleManager::handleConfigEntry(const Core::ConfigEntry &entry, bool handl
if(entry[0].getKey().matches("LoadModule")) {
if(!loadModule(entry[0][0].c_str()))
- Core::Logger::logf(Core::Logger::ERROR, "Can't load module '%s'.", entry[0][0].c_str());
+ application->logf(Core::LoggerBase::ERROR, "Can't load module '%s'.", entry[0][0].c_str());
return true;
}
@@ -73,7 +74,7 @@ bool ModuleManager::handleConfigEntry(const Core::ConfigEntry &entry, bool handl
}
lt_dlhandle ModuleManager::loadModule(const std::string &name) {
- std::map<std::string, std::pair<lt_dlhandle, bool> >::iterator mod = modules.find(name);
+ std::map<std::string, std::pair<lt_dlhandle, Module*> >::iterator mod = modules.find(name);
if(mod == modules.end()) {
lt_dlhandle handle = lt_dlopen((name + MODULE_SUFFIX).c_str());
@@ -81,28 +82,25 @@ lt_dlhandle ModuleManager::loadModule(const std::string &name) {
if(!handle)
return 0;
- mod = modules.insert(std::make_pair(lt_dlgetinfo(handle)->name, std::make_pair(handle, false))).first;
+ mod = modules.insert(std::make_pair(lt_dlgetinfo(handle)->name, std::make_pair(handle, (Module*)0))).first;
}
if(!mod->second.second) {
- void (*initFun)() = (void(*)())lt_dlsym(mod->second.first, (name + "_init").c_str());
+ ModuleLoadFunc loader = (ModuleLoadFunc)lt_dlsym(mod->second.first, (name + "_create").c_str());
+
+ if(!loader)
+ return 0;
- if(initFun)
- (*initFun)();
+ mod->second.second = loader(application);
- mod->second.second = true;
- moduleOrder.push(name);
+ if(mod->second.second)
+ moduleOrder.push(name);
}
return mod->second.first;
}
void ModuleManager::unloadModule(const std::string &name) {
- void (*deinitFun)();
- deinitFun = (void(*)())lt_dlsym(modules[name].first, (name + "_deinit").c_str());
-
- if(deinitFun)
- (*deinitFun)();
-
+ delete modules[name].second;
lt_dlclose(modules[name].first);
modules.erase(name);