summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-18 22:03:02 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-18 22:03:02 +0200
commit7234fe326d16d6bf9f4374a09ddc6ef790e6723f (patch)
tree437d4c40eeb1e9b34b369e4b82064a1572c7dac9 /src/modules
parentbf561f8226e97f4ace4f04bddf198175e91ee7f0 (diff)
downloadmad-7234fe326d16d6bf9f4374a09ddc6ef790e6723f.tar
mad-7234fe326d16d6bf9f4374a09ddc6ef790e6723f.zip
Globale Variablen durch Application-Klasse ersetzt
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/FileLogger/CMakeLists.txt3
-rw-r--r--src/modules/FileLogger/FileLogger.h40
-rw-r--r--src/modules/FileLogger/Module.cpp (renamed from src/modules/FileLogger/FileLogger.cpp)28
-rw-r--r--src/modules/FileLogger/Module.h67
-rw-r--r--src/modules/SystemBackendPosix/CMakeLists.txt1
-rw-r--r--src/modules/SystemBackendPosix/Module.cpp28
-rw-r--r--src/modules/SystemBackendPosix/Module.h52
-rw-r--r--src/modules/SystemBackendPosix/SystemBackendPosix.cpp21
-rw-r--r--src/modules/SystemBackendPosix/SystemBackendPosix.h35
-rw-r--r--src/modules/SystemBackendProc/CMakeLists.txt1
-rw-r--r--src/modules/SystemBackendProc/Module.cpp28
-rw-r--r--src/modules/SystemBackendProc/Module.h52
-rw-r--r--src/modules/SystemBackendProc/SystemBackendProc.cpp21
-rw-r--r--src/modules/SystemBackendProc/SystemBackendProc.h32
-rw-r--r--src/modules/UserBackendMysql/CMakeLists.txt1
-rw-r--r--src/modules/UserBackendMysql/Module.cpp28
-rw-r--r--src/modules/UserBackendMysql/Module.h59
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.cpp71
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.h27
19 files changed, 397 insertions, 198 deletions
diff --git a/src/modules/FileLogger/CMakeLists.txt b/src/modules/FileLogger/CMakeLists.txt
index 7d90028..555425d 100644
--- a/src/modules/FileLogger/CMakeLists.txt
+++ b/src/modules/FileLogger/CMakeLists.txt
@@ -1,5 +1,6 @@
include_directories(${INCLUDES})
add_library(FileLogger MODULE
- FileLogger.cpp FileLogger.h
+ FileLogger.h
+ Module.cpp Module.h
)
diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h
index 9b0f8e2..a24f747 100644
--- a/src/modules/FileLogger/FileLogger.h
+++ b/src/modules/FileLogger/FileLogger.h
@@ -17,31 +17,20 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_MODULES_FILELOGGER_H_
-#define MAD_MODULES_FILELOGGER_H_
-
-#include <Core/ConfigManager.h>
-#include <Core/Configurable.h>
-#include <Core/LogManager.h>
+#ifndef MAD_MODULES_FILELOGGER_FILELOGGER_H_
+#define MAD_MODULES_FILELOGGER_FILELOGGER_H_
#include <fstream>
+#include <Core/Logger.h>
+#include <Core/RemoteLogger.h>
+
namespace Mad {
namespace Modules {
+namespace FileLogger {
class FileLogger : public Core::Logger, public Core::RemoteLogger {
private:
- class ConfigHelper : public Core::Configurable {
- protected:
- virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled);
-
- public:
- virtual int getPriority() const {return 1;}
- };
-
- static ConfigHelper configHelper;
- static std::set<boost::shared_ptr<FileLogger> > loggers;
-
std::ofstream file;
protected:
@@ -55,23 +44,10 @@ class FileLogger : public Core::Logger, public Core::RemoteLogger {
public:
FileLogger(const std::string &filename)
: file(filename.c_str(), std::ios::out|std::ios::app) {}
-
- static void registerConfigHelper() {
- Core::ConfigManager::get()->registerConfigurable(&configHelper);
- }
-
- static void unregisterConfigHelper() {
- Core::ConfigManager::get()->unregisterConfigurable(&configHelper);
-
- for(std::set<boost::shared_ptr<FileLogger> >::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
- Core::LogManager::get()->unregisterLogger(boost::static_pointer_cast<Logger>(*logger));
- }
-
- loggers.clear();
- }
};
}
}
+}
-#endif /* MAD_MODULES_FILELOGGER_H_ */
+#endif /* MAD_MODULES_FILELOGGER_FILELOGGER_H_ */
diff --git a/src/modules/FileLogger/FileLogger.cpp b/src/modules/FileLogger/Module.cpp
index bdae536..829c429 100644
--- a/src/modules/FileLogger/FileLogger.cpp
+++ b/src/modules/FileLogger/Module.cpp
@@ -1,7 +1,7 @@
/*
- * FileLogger.cpp
+ * Module.cpp
*
- * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -17,19 +17,14 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "FileLogger.h"
-
+#include "Module.h"
#include <Core/ConfigEntry.h>
-
namespace Mad {
namespace Modules {
+namespace FileLogger {
-FileLogger::ConfigHelper FileLogger::configHelper;
-std::set<boost::shared_ptr<FileLogger> > FileLogger::loggers;
-
-
-bool FileLogger::ConfigHelper::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) {
+bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) {
if(handled)
return false;
@@ -40,10 +35,10 @@ bool FileLogger::ConfigHelper::handleConfigEntry(const Core::ConfigEntry &entry,
boost::shared_ptr<FileLogger> logger(new FileLogger(entry[0][1]));
loggers.insert(logger);
- Core::LogManager::get()->registerLogger(boost::static_pointer_cast<Logger>(logger));
+ application->getLogManager()->registerLogger(boost::static_pointer_cast<Core::Logger>(logger));
}
else {
- Logger::logf(Logger::WARNING, "FileLogger: no filename given.");
+ application->logf(Core::LoggerBase::WARNING, "FileLogger: no filename given.");
}
return true;
@@ -56,15 +51,12 @@ bool FileLogger::ConfigHelper::handleConfigEntry(const Core::ConfigEntry &entry,
}
}
+}
extern "C" {
-void FileLogger_init() {
- Mad::Modules::FileLogger::registerConfigHelper();
-}
-
-void FileLogger_deinit() {
- Mad::Modules::FileLogger::unregisterConfigHelper();
+Mad::Common::Module* FileLogger_create(Mad::Common::Application *application) {
+ return new Mad::Modules::FileLogger::Module(application);
}
}
diff --git a/src/modules/FileLogger/Module.h b/src/modules/FileLogger/Module.h
new file mode 100644
index 0000000..e800b69
--- /dev/null
+++ b/src/modules/FileLogger/Module.h
@@ -0,0 +1,67 @@
+/*
+ * Module.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_MODULES_FILELOGGER_MODULE_H_
+#define MAD_MODULES_FILELOGGER_MODULE_H_
+
+#include "FileLogger.h"
+
+#include <Core/Configurable.h>
+#include <Core/ConfigManager.h>
+#include <Core/LogManager.h>
+
+#include <Common/Application.h>
+#include <Common/Module.h>
+
+namespace Mad {
+namespace Modules {
+namespace FileLogger {
+
+class Module : public Common::Module, private Core::Configurable {
+ private:
+ Common::Application *application;
+
+ std::set<boost::shared_ptr<FileLogger> > loggers;
+
+ protected:
+ virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled);
+
+ public:
+ Module(Common::Application *application0) : application(application0) {
+ application->getConfigManager()->registerConfigurable(this);
+ }
+
+ virtual ~Module() {
+ application->getConfigManager()->unregisterConfigurable(this);
+
+ for(std::set<boost::shared_ptr<FileLogger> >::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
+ application->getLogManager()->unregisterLogger(boost::static_pointer_cast<Core::Logger>(*logger));
+ }
+
+ loggers.clear();
+ }
+
+ virtual int getPriority() const {return 1;}
+};
+
+}
+}
+}
+
+#endif /* MAD_MODULES_FILELOGGER_MODULE_H_ */
diff --git a/src/modules/SystemBackendPosix/CMakeLists.txt b/src/modules/SystemBackendPosix/CMakeLists.txt
index 223960b..83e8ea1 100644
--- a/src/modules/SystemBackendPosix/CMakeLists.txt
+++ b/src/modules/SystemBackendPosix/CMakeLists.txt
@@ -1,5 +1,6 @@
include_directories(${INCLUDES})
add_library(SystemBackendPosix MODULE
+ Module.cpp Module.h
SystemBackendPosix.cpp SystemBackendPosix.h
)
diff --git a/src/modules/SystemBackendPosix/Module.cpp b/src/modules/SystemBackendPosix/Module.cpp
new file mode 100644
index 0000000..230fef4
--- /dev/null
+++ b/src/modules/SystemBackendPosix/Module.cpp
@@ -0,0 +1,28 @@
+/*
+ * Module.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Module.h"
+
+extern "C" {
+
+Mad::Common::Module* SystemBackendPosix_create(Mad::Common::Application *application) {
+ return new Mad::Modules::SystemBackendPosix::Module(application);
+}
+
+}
diff --git a/src/modules/SystemBackendPosix/Module.h b/src/modules/SystemBackendPosix/Module.h
new file mode 100644
index 0000000..ee780f6
--- /dev/null
+++ b/src/modules/SystemBackendPosix/Module.h
@@ -0,0 +1,52 @@
+/*
+ * Module.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_MODULE_H_
+#define MAD_MODULES_SYSTEMBACKENDPOSIX_MODULE_H_
+
+#include "SystemBackendPosix.h"
+
+#include <Common/Application.h>
+#include <Common/Module.h>
+
+namespace Mad {
+namespace Modules {
+namespace SystemBackendPosix {
+
+class Module : public Common::Module {
+ private:
+ Common::Application *application;
+
+ boost::shared_ptr<SystemBackendPosix> backend;
+
+ public:
+ Module(Common::Application *application0) : application(application0), backend(new SystemBackendPosix(application)) {
+ application->getSystemManager()->registerBackend(backend);
+ }
+
+ virtual ~Module() {
+ application->getSystemManager()->unregisterBackend(backend);
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_MODULES_SYSTEMBACKENDPOSIX_MODULE_H_ */
diff --git a/src/modules/SystemBackendPosix/SystemBackendPosix.cpp b/src/modules/SystemBackendPosix/SystemBackendPosix.cpp
index 4eb5807..801fcd4 100644
--- a/src/modules/SystemBackendPosix/SystemBackendPosix.cpp
+++ b/src/modules/SystemBackendPosix/SystemBackendPosix.cpp
@@ -26,11 +26,10 @@
namespace Mad {
namespace Modules {
-
-boost::shared_ptr<SystemBackendPosix> SystemBackendPosix::backend;
+namespace SystemBackendPosix {
void SystemBackendPosix::getFSInfo(std::vector<Common::SystemManager::FSInfo> *fsInfo) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
FILE *pipe = popen("/bin/df -P -k", "r");
if(!pipe)
@@ -79,14 +78,14 @@ void SystemBackendPosix::getFSInfo(std::vector<Common::SystemManager::FSInfo> *f
}
void SystemBackendPosix::shutdown() throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
if(system("/sbin/halt") != 0)
throw(Core::Exception(Core::Exception::NOT_AVAILABLE));
}
void SystemBackendPosix::reboot() throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
if(system("/sbin/reboot") != 0)
throw(Core::Exception(Core::Exception::NOT_AVAILABLE));
@@ -94,16 +93,4 @@ void SystemBackendPosix::reboot() throw(Core::Exception) {
}
}
-
-
-extern "C" {
-
-void SystemBackendPosix_init() {
- Mad::Modules::SystemBackendPosix::registerBackend();
-}
-
-void SystemBackendPosix_deinit() {
- Mad::Modules::SystemBackendPosix::unregisterBackend();
-}
-
}
diff --git a/src/modules/SystemBackendPosix/SystemBackendPosix.h b/src/modules/SystemBackendPosix/SystemBackendPosix.h
index 4aec7dd..6c5ae06 100644
--- a/src/modules/SystemBackendPosix/SystemBackendPosix.h
+++ b/src/modules/SystemBackendPosix/SystemBackendPosix.h
@@ -17,25 +17,19 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_H_
-#define MAD_MODULES_SYSTEMBACKENDPOSIX_H_
+#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_SYSTEMBACKENDPOSIX_H_
+#define MAD_MODULES_SYSTEMBACKENDPOSIX_SYSTEMBACKENDPOSIX_H_
#include <Common/SystemBackend.h>
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include <sys/types.h>
-
-#include <boost/bind.hpp>
+#include <Common/Application.h>
namespace Mad {
namespace Modules {
+namespace SystemBackendPosix {
class SystemBackendPosix : public Common::SystemBackend {
private:
- static boost::shared_ptr<SystemBackendPosix> backend;
+ Common::Application *application;
protected:
virtual void getFSInfo(std::vector<Common::SystemManager::FSInfo> *fsInfo) throw(Core::Exception);
@@ -44,24 +38,11 @@ class SystemBackendPosix : public Common::SystemBackend {
virtual void reboot() throw(Core::Exception);
public:
- static void registerBackend() {
- if(backend)
- return;
-
- backend.reset(new SystemBackendPosix());
- Common::SystemManager::get()->registerBackend(backend);
- }
-
- static void unregisterBackend() {
- if(!backend)
- return;
-
- Common::SystemManager::get()->unregisterBackend(backend);
- backend.reset();
- }
+ SystemBackendPosix(Common::Application *application0) : application(application0) {}
};
}
}
+}
-#endif /* MAD_MODULES_SYSTEMBACKENDPOSIX_H_ */
+#endif /* MAD_MODULES_SYSTEMBACKENDPOSIX_SYSTEMBACKENDPOSIX_H_ */
diff --git a/src/modules/SystemBackendProc/CMakeLists.txt b/src/modules/SystemBackendProc/CMakeLists.txt
index ba5642c..42f7431 100644
--- a/src/modules/SystemBackendProc/CMakeLists.txt
+++ b/src/modules/SystemBackendProc/CMakeLists.txt
@@ -1,5 +1,6 @@
include_directories(${INCLUDES})
add_library(SystemBackendProc MODULE
+ Module.cpp Module.h
SystemBackendProc.cpp SystemBackendProc.h
)
diff --git a/src/modules/SystemBackendProc/Module.cpp b/src/modules/SystemBackendProc/Module.cpp
new file mode 100644
index 0000000..7dbbbb5
--- /dev/null
+++ b/src/modules/SystemBackendProc/Module.cpp
@@ -0,0 +1,28 @@
+/*
+ * Module.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Module.h"
+
+extern "C" {
+
+Mad::Common::Module* SystemBackendProc_create(Mad::Common::Application *application) {
+ return new Mad::Modules::SystemBackendProc::Module(application);
+}
+
+}
diff --git a/src/modules/SystemBackendProc/Module.h b/src/modules/SystemBackendProc/Module.h
new file mode 100644
index 0000000..6cdbd73
--- /dev/null
+++ b/src/modules/SystemBackendProc/Module.h
@@ -0,0 +1,52 @@
+/*
+ * Module.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_MODULES_SYSTEMBACKENDPROC_MODULE_H_
+#define MAD_MODULES_SYSTEMBACKENDPROC_MODULE_H_
+
+#include "SystemBackendProc.h"
+
+#include <Common/Application.h>
+#include <Common/Module.h>
+
+namespace Mad {
+namespace Modules {
+namespace SystemBackendProc {
+
+class Module : public Common::Module {
+ private:
+ Common::Application *application;
+
+ boost::shared_ptr<SystemBackendProc> backend;
+
+ public:
+ Module(Common::Application *application0) : application(application0), backend(new SystemBackendProc(application)) {
+ application->getSystemManager()->registerBackend(backend);
+ }
+
+ virtual ~Module() {
+ application->getSystemManager()->unregisterBackend(backend);
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_MODULES_SYSTEMBACKENDPROC_MODULE_H_ */
diff --git a/src/modules/SystemBackendProc/SystemBackendProc.cpp b/src/modules/SystemBackendProc/SystemBackendProc.cpp
index e8b45cd..daae55b 100644
--- a/src/modules/SystemBackendProc/SystemBackendProc.cpp
+++ b/src/modules/SystemBackendProc/SystemBackendProc.cpp
@@ -26,11 +26,10 @@
namespace Mad {
namespace Modules {
-
-boost::shared_ptr<SystemBackendProc> SystemBackendProc::backend;
+namespace SystemBackendProc {
void SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
uptimeFile.seekg(0, std::ios::beg);
@@ -51,7 +50,7 @@ void SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idle
}
void SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
if(totalMem)
*totalMem = 0;
@@ -93,7 +92,7 @@ void SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *fr
}
void SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
unsigned long currentLoadValue = 0, nProcessesValue = 0;
float loadAvg1Value = 0, loadAvg5Value = 0, loadAvg15Value = 0;
@@ -129,16 +128,4 @@ void SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *n
}
}
-
-
-extern "C" {
-
-void SystemBackendProc_init() {
- Mad::Modules::SystemBackendProc::registerBackend();
-}
-
-void SystemBackendProc_deinit() {
- Mad::Modules::SystemBackendProc::unregisterBackend();
-}
-
}
diff --git a/src/modules/SystemBackendProc/SystemBackendProc.h b/src/modules/SystemBackendProc/SystemBackendProc.h
index 9a0cb71..a54d783 100644
--- a/src/modules/SystemBackendProc/SystemBackendProc.h
+++ b/src/modules/SystemBackendProc/SystemBackendProc.h
@@ -17,51 +17,37 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_MODULES_SYSTEMBACKENDPROC_H_
-#define MAD_MODULES_SYSTEMBACKENDPROC_H_
+#ifndef MAD_MODULES_SYSTEMBACKENDPROC_SYSTEMBACKENDPROC_H_
+#define MAD_MODULES_SYSTEMBACKENDPROC_SYSTEMBACKENDPROC_H_
#include <Common/SystemBackend.h>
+#include <Common/Application.h>
#include <fstream>
-#include <boost/noncopyable.hpp>
namespace Mad {
namespace Modules {
+namespace SystemBackendProc {
-class SystemBackendProc : public Common::SystemBackend, boost::noncopyable {
+class SystemBackendProc : public Common::SystemBackend {
private:
- static boost::shared_ptr<SystemBackendProc> backend;
+ Common::Application *application;
std::ifstream uptimeFile;
std::ifstream meminfoFile;
std::ifstream loadFile;
- SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {}
-
protected:
virtual void getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception);
virtual void getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Core::Exception);
virtual void getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Core::Exception);
public:
- static void registerBackend() {
- if(backend)
- return;
-
- backend.reset(new SystemBackendProc());
- Common::SystemManager::get()->registerBackend(backend);
- }
-
- static void unregisterBackend() {
- if(!backend)
- return;
-
- Common::SystemManager::get()->unregisterBackend(backend);
- backend.reset();
- }
+ SystemBackendProc(Common::Application *application0) : application(application0), uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {}
};
}
}
+}
-#endif /* MAD_MODULES_SYSTEMBACKENDPROC_H_ */
+#endif /* MAD_MODULES_SYSTEMBACKENDPROC_SYSTEMBACKENDPROC_H_ */
diff --git a/src/modules/UserBackendMysql/CMakeLists.txt b/src/modules/UserBackendMysql/CMakeLists.txt
index b185c13..5f32d9c 100644
--- a/src/modules/UserBackendMysql/CMakeLists.txt
+++ b/src/modules/UserBackendMysql/CMakeLists.txt
@@ -1,6 +1,7 @@
include_directories(${INCLUDES} ${MYSQL_INCLUDE_DIR})
add_library(UserBackendMysql MODULE
+ Module.cpp Module.h
UserBackendMysql.cpp UserBackendMysql.h
)
diff --git a/src/modules/UserBackendMysql/Module.cpp b/src/modules/UserBackendMysql/Module.cpp
new file mode 100644
index 0000000..c29f65b
--- /dev/null
+++ b/src/modules/UserBackendMysql/Module.cpp
@@ -0,0 +1,28 @@
+/*
+ * Module.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Module.h"
+
+extern "C" {
+
+Mad::Common::Module* UserBackendMysql_create(Mad::Common::Application *application) {
+ return new Mad::Modules::UserBackendMysql::Module(application);
+}
+
+}
diff --git a/src/modules/UserBackendMysql/Module.h b/src/modules/UserBackendMysql/Module.h
new file mode 100644
index 0000000..31f6692
--- /dev/null
+++ b/src/modules/UserBackendMysql/Module.h
@@ -0,0 +1,59 @@
+/*
+ * Module.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_MODULES_USERBACKENDMYSQL_MODULE_H_
+#define MAD_MODULES_USERBACKENDMYSQL_MODULE_H_
+
+#include "UserBackendMysql.h"
+
+#include <Server/Application.h>
+#include <Server/UserManager.h>
+#include <Common/Module.h>
+
+namespace Mad {
+namespace Modules {
+namespace UserBackendMysql {
+
+class Module : public Common::Module {
+ private:
+ Common::Application *application;
+
+ boost::shared_ptr<UserBackendMysql> backend;
+
+ public:
+ Module(Common::Application *application0) : application(application0), backend(new UserBackendMysql(application)) {
+ Server::Application *app = dynamic_cast<Server::Application*>(application);
+
+ if(app)
+ app->getUserManager()->registerBackend(backend);
+ }
+
+ virtual ~Module() {
+ Server::Application *app = dynamic_cast<Server::Application*>(application);
+
+ if(app)
+ app->getUserManager()->unregisterBackend(backend);
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_MODULES_USERBACKENDMYSQL_MODULE_H_ */
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp
index f0e9b2e..904c9a6 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp
@@ -22,7 +22,6 @@
#include "UserBackendMysql.h"
#include <Core/ConfigEntry.h>
#include <Core/ConfigManager.h>
-#include <Core/Logger.h>
#include <Core/ThreadManager.h>
#include <sstream>
@@ -33,8 +32,8 @@
namespace Mad {
namespace Modules {
+namespace UserBackendMysql {
-boost::shared_ptr<UserBackendMysql> UserBackendMysql::backend;
bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) {
if(handled)
@@ -65,7 +64,7 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool ha
val = strtol(entry[1][0].c_str(), &endptr, 10);
if(endptr != 0 || val < 0 || val > 65535)
- Core::Logger::log(Core::Logger::WARNING, "UserBackendMysql: Invalid port");
+ application->log(Core::LoggerBase::WARNING, "UserBackendMysql: Invalid port");
else
port = val;
}
@@ -121,21 +120,19 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool ha
void UserBackendMysql::configFinished() {
if(db.empty()) {
- Core::Logger::log(Core::Logger::ERROR, "UserBackendMysql: No database name given");
+ application->log(Core::LoggerBase::ERROR, "UserBackendMysql: No database name given");
return;
}
mysql = mysql_init(0);
mysql_real_connect(mysql, host.c_str(), username.c_str(), passwd.c_str(), db.c_str(), port, unixSocket.empty() ? 0 : unixSocket.c_str(), 0);
-
- Server::UserManager::get()->registerBackend(backend);
}
boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql::getUserList() throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
- if(mysql_ping(mysql))
+ if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length());
@@ -159,9 +156,9 @@ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql::
}
boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long uid) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
- if(mysql_ping(mysql))
+ if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
std::string query = queryUserById;
@@ -196,9 +193,9 @@ boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long
}
boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfoByName(const std::string &name) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
- if(mysql_ping(mysql))
+ if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
boost::scoped_array<char> escapedName(new char[name.length()*2+1]);
@@ -230,9 +227,9 @@ boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfoByName(const st
}
boost::shared_ptr<std::set<unsigned long> > UserBackendMysql::getUserGroupList(unsigned long uid) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
- if(mysql_ping(mysql))
+ if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
std::ostringstream tmp;
@@ -258,9 +255,9 @@ boost::shared_ptr<std::set<unsigned long> > UserBackendMysql::getUserGroupList(u
boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserBackendMysql::getGroupList() throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
- if(mysql_ping(mysql))
+ if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
mysql_real_query(mysql, queryListGroups.c_str(), queryListGroups.length());
@@ -281,9 +278,9 @@ boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserBackendMysql:
}
std::string UserBackendMysql::getGroupName(unsigned long gid) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
- if(mysql_ping(mysql))
+ if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
std::string query = queryGroupById;
@@ -310,9 +307,9 @@ std::string UserBackendMysql::getGroupName(unsigned long gid) throw(Core::Except
}
unsigned long UserBackendMysql::getGroupId(const std::string &name) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
- if(mysql_ping(mysql))
+ if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
boost::scoped_array<char> escapedName(new char[name.length()*2+1]);
@@ -336,9 +333,9 @@ unsigned long UserBackendMysql::getGroupId(const std::string &name) throw(Core::
}
boost::shared_ptr<std::set<unsigned long> > UserBackendMysql::getGroupUserList(unsigned long gid) throw(Core::Exception) {
- Core::ThreadManager::get()->detach();
+ application->getThreadManager()->detach();
- if(mysql_ping(mysql))
+ if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
std::ostringstream tmp;
@@ -362,36 +359,6 @@ boost::shared_ptr<std::set<unsigned long> > UserBackendMysql::getGroupUserList(u
return users;
}
-
-void UserBackendMysql::registerBackend() {
- if(backend)
- return;
-
- backend.reset(new UserBackendMysql());
- Core::ConfigManager::get()->registerConfigurable(backend.get());
}
-
-void UserBackendMysql::unregisterBackend() {
- if(!backend)
- return;
-
- Core::ConfigManager::get()->unregisterConfigurable(backend.get());
- Server::UserManager::get()->unregisterBackend(backend);
-
- backend.reset();
}
-
-}
-}
-
-extern "C" {
-
-void UserBackendMysql_init() {
- Mad::Modules::UserBackendMysql::registerBackend();
-}
-
-void UserBackendMysql_deinit() {
- Mad::Modules::UserBackendMysql::unregisterBackend();
-}
-
}
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h
index 523806f..aa141da 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.h
+++ b/src/modules/UserBackendMysql/UserBackendMysql.h
@@ -17,22 +17,25 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_MODULES_USERBACKENDMYSQL_H_
-#define MAD_MODULES_USERBACKENDMYSQL_H_
+#ifndef MAD_MODULES_USERBACKENDMYSQL_USERBACKENDMYSQL_H_
+#define MAD_MODULES_USERBACKENDMYSQL_USERBACKENDMYSQL_H_
#include <Server/UserBackend.h>
-#include <Server/UserManager.h>
+
+#include <Common/Application.h>
+
#include <Core/Configurable.h>
+#include <Core/ConfigManager.h>
#include <mysql/mysql.h>
-
namespace Mad {
namespace Modules {
+namespace UserBackendMysql {
class UserBackendMysql : public Server::UserBackend, private Core::Configurable {
private:
- static boost::shared_ptr<UserBackendMysql> backend;
+ Common::Application *application;
std::string host, username, passwd, db, unixSocket;
uint16_t port;
@@ -44,8 +47,6 @@ class UserBackendMysql : public Server::UserBackend, private Core::Configurable
MYSQL *mysql;
- UserBackendMysql() : port(0), mysql(0) {}
-
protected:
virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool);
virtual void configFinished();
@@ -61,18 +62,22 @@ class UserBackendMysql : public Server::UserBackend, private Core::Configurable
virtual boost::shared_ptr<std::set<unsigned long> > getGroupUserList(unsigned long gid) throw(Core::Exception);
public:
+ UserBackendMysql(Common::Application *application0) : application(application0), port(0), mysql(0) {
+ application->getConfigManager()->registerConfigurable(this);
+ }
+
virtual ~UserBackendMysql() {
+ application->getConfigManager()->unregisterConfigurable(this);
+
if(mysql) {
mysql_close(mysql);
mysql = 0;
}
}
-
- static void registerBackend();
- static void unregisterBackend();
};
}
}
+}
-#endif /* MAD_MODULES_USERBACKENDMYSQL_H_ */
+#endif /* MAD_MODULES_USERBACKENDMYSQL_USERBACKENDMYSQL_H_ */