From 7234fe326d16d6bf9f4374a09ddc6ef790e6723f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Jun 2009 22:03:02 +0200 Subject: Globale Variablen durch Application-Klasse ersetzt --- src/Common/ModuleManager.cpp | 48 +++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'src/Common/ModuleManager.cpp') 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 #include "ModuleManager.h" +#include "Application.h" #include -#include - +#include //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 >::iterator mod = modules.find(name); + std::map >::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); -- cgit v1.2.3