summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-07-02 08:45:10 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-07-02 08:45:10 +0200
commit2008ccc79e21962ffb5e327c2aba4ea7c8da76a1 (patch)
treea74c0d30d3d98f53a933abcc6146bd6bef4b860c /src/Common
parentfd68c0f047bbd40d02cad5a84584cc74979c993a (diff)
downloadmad-2008ccc79e21962ffb5e327c2aba4ea7c8da76a1.tar
mad-2008ccc79e21962ffb5e327c2aba4ea7c8da76a1.zip
Module können wieder statisch gelinkt werden
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/CMakeLists.txt2
-rw-r--r--src/Common/ModuleManager.cpp43
-rw-r--r--src/Common/ModuleManager.h2
3 files changed, 30 insertions, 17 deletions
diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt
index 6076561..1ac7e69 100644
--- a/src/Common/CMakeLists.txt
+++ b/src/Common/CMakeLists.txt
@@ -26,4 +26,4 @@ add_library(Common
UserManager.cpp UserManager.h
XmlPacket.cpp XmlPacket.h
)
-target_link_libraries(Common Backends RequestHandlers Requests Net ${LIBXML2_LIBRARIES} ${DL_LIBRARY})
+target_link_libraries(Common Backends RequestHandlers Requests Net modules ${LIBXML2_LIBRARIES} ${DL_LIBRARY})
diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp
index 74c424d..67a1b14 100644
--- a/src/Common/ModuleManager.cpp
+++ b/src/Common/ModuleManager.cpp
@@ -26,12 +26,16 @@
#include <Core/ConfigEntry.h>
#include <Core/ConfigManager.h>
+#include <modules/modules.h>
+
#include <dlfcn.h>
namespace Mad {
namespace Common {
+const ModuleManager::ModuleHandle ModuleManager::STATIC_MODULE = 0;
+
ModuleManager::ModuleManager(Application *application0) : application(application0) {
application->getConfigManager()->registerConfigurable(this);
}
@@ -73,26 +77,31 @@ bool ModuleManager::loadModule(const std::string &name) {
return true;
}
- ModuleHandle handle = dlopen((name + MODULE_SUFFIX).c_str(), RTLD_NOW | RTLD_GLOBAL);
+ ModuleHandle handle = STATIC_MODULE;
+ Module *mod = Modules::loadStaticModule(application, name);
- if(!handle) {
- application->log(Core::LoggerBase::VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror()));
- return false;
- }
+ if(!mod) {
+ handle = dlopen((name + MODULE_SUFFIX).c_str(), RTLD_NOW | RTLD_GLOBAL);
- ModuleLoadFunc loader;
- *(void**)&loader = dlsym(handle, (name + "_create").c_str());
+ if(!handle) {
+ application->log(Core::LoggerBase::VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror()));
+ return false;
+ }
- if(!loader) {
- application->log(Core::LoggerBase::VERBOSE, "loadModule: Can't open module: Invalid module");
- return false;
- }
+ ModuleLoadFunc loader;
+ *(void**)&loader = dlsym(handle, (name + "_create").c_str());
- Module *mod = loader(application);
+ if(!loader) {
+ application->log(Core::LoggerBase::VERBOSE, "loadModule: Can't open module: Invalid module");
+ return false;
+ }
- if(!mod) {
- application->log(Core::LoggerBase::VERBOSE, "loadModule: Can't open module: Internal module error");
- return false;
+ Module *mod = loader(application);
+
+ if(!mod) {
+ application->log(Core::LoggerBase::VERBOSE, "loadModule: Can't open module: Internal module error");
+ return false;
+ }
}
modules.insert(std::make_pair(name, std::make_pair(handle, mod))).first;
@@ -111,7 +120,9 @@ void ModuleManager::unloadModule(const std::string &name) {
boost::upgrade_to_unique_lock<boost::shared_mutex> upgradeLock(lock);
delete mod->second.second;
- dlclose(mod->second.first);
+
+ if(mod->second.first != STATIC_MODULE)
+ dlclose(mod->second.first);
modules.erase(mod);
}
diff --git a/src/Common/ModuleManager.h b/src/Common/ModuleManager.h
index 9d722c4..8149824 100644
--- a/src/Common/ModuleManager.h
+++ b/src/Common/ModuleManager.h
@@ -41,6 +41,8 @@ class ModuleManager : public Core::Configurable, private boost::noncopyable {
typedef void *ModuleHandle;
typedef Module *(*ModuleLoadFunc)(Application*);
+ static const ModuleHandle STATIC_MODULE;
+
Application *application;
std::map<std::string, std::pair<ModuleHandle, Module*> > modules;