summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-04-25 16:27:03 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-04-25 16:27:03 +0200
commit71dc41a9b7b0e939314a886383daa6fb2e297a55 (patch)
tree583d3b0ef8aeb01b94cb9b3297a3976705f99e6a
parentc6f8a170e642b5b1a28bd85857f715846bbadbb4 (diff)
downloadmad-71dc41a9b7b0e939314a886383daa6fb2e297a55.tar
mad-71dc41a9b7b0e939314a886383daa6fb2e297a55.zip
SystemBackend und UserBackend in Backend und Manager aufgeteilt
-rw-r--r--src/Common/Makefile.am5
-rw-r--r--src/Common/Makefile.in9
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.cpp6
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.h4
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.cpp6
-rw-r--r--src/Common/SystemBackend.h60
-rw-r--r--src/Common/SystemManager.cpp (renamed from src/Common/SystemBackend.cpp)39
-rw-r--r--src/Common/SystemManager.h82
-rw-r--r--src/Core/Makefile.am4
-rw-r--r--src/Core/Makefile.in8
-rw-r--r--src/Core/RequestHandlers/UserInfoRequestHandler.cpp4
-rw-r--r--src/Core/RequestHandlers/UserListRequestHandler.cpp4
-rw-r--r--src/Core/UserBackend.h39
-rw-r--r--src/Core/UserManager.cpp (renamed from src/Core/UserBackend.cpp)36
-rw-r--r--src/Core/UserManager.h73
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.cpp6
-rw-r--r--src/modules/SystemBackendPosix.cpp8
-rw-r--r--src/modules/SystemBackendPosix.h12
-rw-r--r--src/modules/SystemBackendProc.cpp6
-rw-r--r--src/modules/SystemBackendProc.h10
-rw-r--r--src/modules/UserBackendMysql.cpp13
-rw-r--r--src/modules/UserBackendMysql.h7
22 files changed, 283 insertions, 158 deletions
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index 51593d7..dd27afe 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -3,11 +3,12 @@ SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = ActionManager.cpp ClientConnection.cpp ConfigEntry.cpp ConfigManager.cpp \
Connection.cpp Exception.cpp Initializable.cpp Logger.cpp LogManager.cpp \
- ModuleManager.cpp Request.cpp RequestManager.cpp SystemBackend.cpp \
+ ModuleManager.cpp Request.cpp RequestManager.cpp SystemManager.cpp \
Tokenizer.cpp XmlPacket.cpp
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
noinst_HEADERS = ActionManager.h ClientConnection.h ConfigEntry.h ConfigManager.h \
Configurable.h Connection.h Exception.h HostInfo.h Initializable.h Logger.h \
LoggerBase.h LogManager.h ModuleManager.h RemoteLogger.h Request.h \
- RequestHandler.h RequestManager.h SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h
+ RequestHandler.h RequestManager.h SystemBackend.h SystemManager.h Tokenizer.h \
+ UserInfo.h XmlPacket.h
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index 8b6b7ef..a17d8a1 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -56,7 +56,7 @@ libcommon_la_DEPENDENCIES = Requests/librequests.la \
am_libcommon_la_OBJECTS = ActionManager.lo ClientConnection.lo \
ConfigEntry.lo ConfigManager.lo Connection.lo Exception.lo \
Initializable.lo Logger.lo LogManager.lo ModuleManager.lo \
- Request.lo RequestManager.lo SystemBackend.lo Tokenizer.lo \
+ Request.lo RequestManager.lo SystemManager.lo Tokenizer.lo \
XmlPacket.lo
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@@ -244,14 +244,15 @@ SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = ActionManager.cpp ClientConnection.cpp ConfigEntry.cpp ConfigManager.cpp \
Connection.cpp Exception.cpp Initializable.cpp Logger.cpp LogManager.cpp \
- ModuleManager.cpp Request.cpp RequestManager.cpp SystemBackend.cpp \
+ ModuleManager.cpp Request.cpp RequestManager.cpp SystemManager.cpp \
Tokenizer.cpp XmlPacket.cpp
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
noinst_HEADERS = ActionManager.h ClientConnection.h ConfigEntry.h ConfigManager.h \
Configurable.h Connection.h Exception.h HostInfo.h Initializable.h Logger.h \
LoggerBase.h LogManager.h ModuleManager.h RemoteLogger.h Request.h \
- RequestHandler.h RequestManager.h SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h
+ RequestHandler.h RequestManager.h SystemBackend.h SystemManager.h Tokenizer.h \
+ UserInfo.h XmlPacket.h
all: all-recursive
@@ -316,7 +317,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ModuleManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Request.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestManager.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackend.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Tokenizer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/XmlPacket.Plo@am__quote@
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
index aaa4d9e..7421ad2 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
@@ -41,7 +41,7 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) {
// TODO Require authentication
- if(!SystemBackend::getFSInfo(sigc::mem_fun(this, &FSInfoRequestHandler::fsInfoHandler))) {
+ if(!SystemManager::get()->getFSInfo(sigc::mem_fun(this, &FSInfoRequestHandler::fsInfoHandler))) {
XmlPacket ret;
ret.setType("Error");
ret.add("ErrorCode", Exception::NOT_IMPLEMENTED);
@@ -52,12 +52,12 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) {
}
}
-void FSInfoRequestHandler::fsInfoHandler(const std::vector<SystemBackend::FSInfo> &info) {
+void FSInfoRequestHandler::fsInfoHandler(const std::vector<SystemManager::FSInfo> &info) {
XmlPacket ret;
ret.setType("OK");
ret.addList("filesystems");
- for(std::vector<SystemBackend::FSInfo>::const_iterator fs = info.begin(); fs != info.end(); ++fs) {
+ for(std::vector<SystemManager::FSInfo>::const_iterator fs = info.begin(); fs != info.end(); ++fs) {
ret["filesystems"].addEntry();
XmlPacket::Entry &entry = ret["filesystems"].back();
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h
index 0eda797..a4ed92c 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.h
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h
@@ -21,7 +21,7 @@
#define MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
#include "../RequestHandler.h"
-#include "../SystemBackend.h"
+#include "../SystemManager.h"
#include <stdint.h>
@@ -31,7 +31,7 @@ namespace RequestHandlers {
class FSInfoRequestHandler : public RequestHandler {
private:
- void fsInfoHandler(const std::vector<SystemBackend::FSInfo> &info);
+ void fsInfoHandler(const std::vector<SystemManager::FSInfo> &info);
protected:
virtual void handlePacket(const XmlPacket &packet);
diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp
index e03c345..1464f71 100644
--- a/src/Common/RequestHandlers/StatusRequestHandler.cpp
+++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp
@@ -42,11 +42,11 @@ void StatusRequestHandler::handlePacket(const XmlPacket &packet) {
// TODO Require authentication
- if(!SystemBackend::getUptimeInfo(sigc::mem_fun(this, &StatusRequestHandler::uptimeHandler)))
+ if(!SystemManager::get()->getUptimeInfo(sigc::mem_fun(this, &StatusRequestHandler::uptimeHandler)))
needUptime = false;
- if(!SystemBackend::getMemoryInfo(sigc::mem_fun(this, &StatusRequestHandler::memoryHandler)))
+ if(!SystemManager::get()->getMemoryInfo(sigc::mem_fun(this, &StatusRequestHandler::memoryHandler)))
needMemory = false;
- if(!SystemBackend::getLoadInfo(sigc::mem_fun(this, &StatusRequestHandler::loadHandler)))
+ if(!SystemManager::get()->getLoadInfo(sigc::mem_fun(this, &StatusRequestHandler::loadHandler)))
needLoad = false;
send();
diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h
index 944f195..9c3eaa2 100644
--- a/src/Common/SystemBackend.h
+++ b/src/Common/SystemBackend.h
@@ -20,82 +20,44 @@
#ifndef MAD_COMMON_SYSTEMBACKEND_H_
#define MAD_COMMON_SYSTEMBACKEND_H_
-#include <set>
-#include <string>
-#include <vector>
+#include <config.h>
-#include <sigc++/signal.h>
+#include "SystemManager.h"
namespace Mad {
namespace Common {
class SystemBackend {
- private:
- struct Compare {
- bool operator() (const SystemBackend *b1, const SystemBackend *b2) {
- if(b1->getPriority() == b2->getPriority())
- return (b1 > b2);
- else
- return (b1->getPriority() > b2->getPriority());
- }
- };
-
- static std::set<SystemBackend*, Compare> backends;
-
- public:
- struct FSInfo {
- std::string fsName;
- std::string mountedOn;
- long long total;
- long long used;
- long long available;
- };
-
protected:
- SystemBackend() {}
+ friend class SystemManager;
- static void registerBackend(SystemBackend *backend) {
- backends.insert(backend);
+ virtual bool getUptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback _UNUSED_PARAMETER_) {
+ return false;
}
- static void unregisterBackend(SystemBackend *backend) {
- backends.erase(backend);
+ virtual bool getMemoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback _UNUSED_PARAMETER_) {
+ return false;
}
- virtual bool uptimeInfo(const sigc::slot<void, unsigned long, unsigned long>&) {
+ virtual bool getLoadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback _UNUSED_PARAMETER_) {
return false;
}
- virtual bool memoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long>&) {
+ virtual bool getFSInfo(const sigc::slot<void, const std::vector<SystemManager::FSInfo>& > &callback _UNUSED_PARAMETER_) {
return false;
}
- virtual bool loadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float>&) {
+ virtual bool shutdown(const sigc::slot<void> &callback _UNUSED_PARAMETER_) {
return false;
}
- virtual bool fsInfo(const sigc::slot<void, const std::vector<FSInfo>& >&) {
+ virtual bool reboot(const sigc::slot<void> &callback _UNUSED_PARAMETER_) {
return false;
}
- virtual bool doShutdown(const sigc::slot<void>&) {return false;}
- virtual bool doReboot(const sigc::slot<void>&) {return false;}
-
virtual int getPriority() const {
return 0;
}
-
- public:
- virtual ~SystemBackend() {}
-
- static bool getUptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback);
- static bool getMemoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback);
- static bool getLoadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback);
-
- static bool getFSInfo(const sigc::slot<void, const std::vector<FSInfo>& > &callback);
-
- static bool shutdown(const sigc::slot<void> &callback);
- static bool reboot(const sigc::slot<void> &callback);
};
}
diff --git a/src/Common/SystemBackend.cpp b/src/Common/SystemManager.cpp
index 2370b89..a037bd6 100644
--- a/src/Common/SystemBackend.cpp
+++ b/src/Common/SystemManager.cpp
@@ -1,7 +1,7 @@
/*
- * SystemBackend.cpp
+ * SystemManager.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,62 +17,71 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "SystemManager.h"
#include "SystemBackend.h"
namespace Mad {
namespace Common {
-std::set<SystemBackend*, SystemBackend::Compare> SystemBackend::backends;
+SystemManager SystemManager::systemManager;
-bool SystemBackend::getUptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback) {
+bool SystemManager::Compare::operator() (const SystemBackend *b1, const SystemBackend *b2) {
+ if(b1->getPriority() == b2->getPriority())
+ return (b1 > b2);
+ else
+ return (b1->getPriority() > b2->getPriority());
+}
+
+
+bool SystemManager::getUptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback) {
for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->uptimeInfo(callback))
+ if((*backend)->getUptimeInfo(callback))
return true;
}
return false;
}
-bool SystemBackend::getMemoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback) {
+bool SystemManager::getMemoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback) {
for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->memoryInfo(callback))
+ if((*backend)->getMemoryInfo(callback))
return true;
}
return false;
}
-bool SystemBackend::getLoadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback) {
+bool SystemManager::getLoadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback) {
for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->loadInfo(callback))
+ if((*backend)->getLoadInfo(callback))
return true;
}
return false;
}
-bool SystemBackend::getFSInfo(const sigc::slot<void, const std::vector<FSInfo>& > &callback) {
+bool SystemManager::getFSInfo(const sigc::slot<void, const std::vector<FSInfo>& > &callback) {
for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->fsInfo(callback))
+ if((*backend)->getFSInfo(callback))
return true;
}
return false;
}
-bool SystemBackend::shutdown(const sigc::slot<void> &callback) {
+bool SystemManager::shutdown(const sigc::slot<void> &callback) {
for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->doShutdown(callback))
+ if((*backend)->shutdown(callback))
return true;
}
return false;
}
-bool SystemBackend::reboot(const sigc::slot<void> &callback) {
+bool SystemManager::reboot(const sigc::slot<void> &callback) {
for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->doReboot(callback))
+ if((*backend)->reboot(callback))
return true;
}
diff --git a/src/Common/SystemManager.h b/src/Common/SystemManager.h
new file mode 100644
index 0000000..5de7180
--- /dev/null
+++ b/src/Common/SystemManager.h
@@ -0,0 +1,82 @@
+/*
+ * SystemManager.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_COMMON_SYSTEMMANAGER_H_
+#define MAD_COMMON_SYSTEMMANAGER_H_
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include <sigc++/slot.h>
+
+namespace Mad {
+namespace Common {
+
+class SystemBackend;
+
+class SystemManager {
+ private:
+ struct Compare {
+ bool operator() (const SystemBackend *b1, const SystemBackend *b2);
+ };
+
+ static SystemManager systemManager;
+
+ std::set<SystemBackend*, Compare> backends;
+
+ public:
+ struct FSInfo {
+ std::string fsName;
+ std::string mountedOn;
+ long long total;
+ long long used;
+ long long available;
+ };
+
+ private:
+ SystemManager() {}
+
+ public:
+ void registerBackend(SystemBackend *backend) {
+ backends.insert(backend);
+ }
+
+ void unregisterBackend(SystemBackend *backend) {
+ backends.erase(backend);
+ }
+
+ bool getUptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback);
+ bool getMemoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback);
+ bool getLoadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback);
+
+ bool getFSInfo(const sigc::slot<void, const std::vector<FSInfo>& > &callback);
+
+ bool shutdown(const sigc::slot<void> &callback);
+ bool reboot(const sigc::slot<void> &callback);
+
+ static SystemManager *get() {
+ return &systemManager;
+ }
+};
+
+}
+}
+
+#endif /* MAD_COMMON_SYSTEMMANAGER_H_ */
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index adc4d29..a5e780b 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -2,7 +2,7 @@ SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcore.la
-libcore_la_SOURCES = ConnectionManager.cpp UserBackend.cpp
+libcore_la_SOURCES = ConnectionManager.cpp UserManager.cpp
libcore_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la
-noinst_HEADERS = ConnectionManager.h UserBackend.h
+noinst_HEADERS = ConnectionManager.h UserBackend.h UserManager.h
diff --git a/src/Core/Makefile.in b/src/Core/Makefile.in
index 4e3ef5a..c65470c 100644
--- a/src/Core/Makefile.in
+++ b/src/Core/Makefile.in
@@ -53,7 +53,7 @@ CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libcore_la_DEPENDENCIES = Requests/librequests.la \
RequestHandlers/librequesthandlers.la
-am_libcore_la_OBJECTS = ConnectionManager.lo UserBackend.lo
+am_libcore_la_OBJECTS = ConnectionManager.lo UserManager.lo
libcore_la_OBJECTS = $(am_libcore_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -238,9 +238,9 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcore.la
-libcore_la_SOURCES = ConnectionManager.cpp UserBackend.cpp
+libcore_la_SOURCES = ConnectionManager.cpp UserManager.cpp
libcore_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la
-noinst_HEADERS = ConnectionManager.h UserBackend.h
+noinst_HEADERS = ConnectionManager.h UserBackend.h UserManager.h
all: all-recursive
.SUFFIXES:
@@ -293,7 +293,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConnectionManager.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserBackend.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserManager.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/Core/RequestHandlers/UserInfoRequestHandler.cpp b/src/Core/RequestHandlers/UserInfoRequestHandler.cpp
index d3a8aca..68356f8 100644
--- a/src/Core/RequestHandlers/UserInfoRequestHandler.cpp
+++ b/src/Core/RequestHandlers/UserInfoRequestHandler.cpp
@@ -18,7 +18,7 @@
*/
#include "UserInfoRequestHandler.h"
-#include "../UserBackend.h"
+#include "../UserManager.h"
#include <Common/Exception.h>
#include <Common/Logger.h>
@@ -42,7 +42,7 @@ void UserInfoRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- if(!UserBackend::getUserInfo(packet["uid"], sigc::mem_fun(this, &UserInfoRequestHandler::userInfoHandler))) {
+ if(!UserManager::get()->getUserInfo(packet["uid"], sigc::mem_fun(this, &UserInfoRequestHandler::userInfoHandler))) {
Common::XmlPacket ret;
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::NOT_IMPLEMENTED);
diff --git a/src/Core/RequestHandlers/UserListRequestHandler.cpp b/src/Core/RequestHandlers/UserListRequestHandler.cpp
index bb67df9..8a61cbd 100644
--- a/src/Core/RequestHandlers/UserListRequestHandler.cpp
+++ b/src/Core/RequestHandlers/UserListRequestHandler.cpp
@@ -18,7 +18,7 @@
*/
#include "UserListRequestHandler.h"
-#include "../UserBackend.h"
+#include "../UserManager.h"
#include <Common/Exception.h>
#include <Common/Logger.h>
@@ -42,7 +42,7 @@ void UserListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- if(!UserBackend::getUserList(sigc::mem_fun(this, &UserListRequestHandler::userListHandler))) {
+ if(!UserManager::get()->getUserList(sigc::mem_fun(this, &UserListRequestHandler::userListHandler))) {
Common::XmlPacket ret;
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::NOT_IMPLEMENTED);
diff --git a/src/Core/UserBackend.h b/src/Core/UserBackend.h
index aad9ace..415f6bf 100644
--- a/src/Core/UserBackend.h
+++ b/src/Core/UserBackend.h
@@ -20,12 +20,12 @@
#ifndef MAD_CORE_USERBACKEND_H_
#define MAD_CORE_USERBACKEND_H_
+#include <config.h>
+
#include <Common/UserInfo.h>
#include <map>
-#include <set>
#include <string>
-#include <vector>
#include <sigc++/signal.h>
@@ -33,39 +33,27 @@
namespace Mad {
namespace Core {
-class UserBackend {
- private:
- struct Compare {
- bool operator() (const UserBackend *b1, const UserBackend *b2) {
- if(b1->getPriority() == b2->getPriority())
- return (b1 > b2);
- else
- return (b1->getPriority() > b2->getPriority());
- }
- };
-
- static std::set<UserBackend*, Compare> backends;
+class UserManager;
+class UserBackend {
protected:
- UserBackend() {}
+ friend class UserManager;
- static void registerBackend(UserBackend *backend) {
- backends.insert(backend);
- }
+ UserBackend() {}
- static void unregisterBackend(UserBackend *backend) {
- backends.erase(backend);
+ virtual bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback _UNUSED_PARAMETER_) {
+ return false;
}
- virtual bool userList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& >&) {
+ virtual bool getUserInfo(unsigned long uid _UNUSED_PARAMETER_, const sigc::slot<void, const Common::UserInfo&> &callback _UNUSED_PARAMETER_) {
return false;
}
- virtual bool userInfo(unsigned long, const sigc::slot<void, const Common::UserInfo&>&) {
+ virtual bool setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string&, const sigc::slot<void, bool> &callback _UNUSED_PARAMETER_) {
return false;
}
- virtual bool password(unsigned long, const std::string&, const sigc::slot<void, bool>&) {
+ virtual bool addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_, const sigc::slot<void, bool> &callback _UNUSED_PARAMETER_) {
return false;
}
@@ -75,11 +63,6 @@ class UserBackend {
public:
virtual ~UserBackend() {}
-
- static bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
- static bool getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
-
- static bool setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback);
};
}
diff --git a/src/Core/UserBackend.cpp b/src/Core/UserManager.cpp
index de8b943..d560586 100644
--- a/src/Core/UserBackend.cpp
+++ b/src/Core/UserManager.cpp
@@ -1,7 +1,7 @@
/*
- * UserBackend.cpp
+ * UserManager.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,35 +17,53 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "UserManager.h"
#include "UserBackend.h"
namespace Mad {
namespace Core {
-std::set<UserBackend*, UserBackend::Compare> UserBackend::backends;
+UserManager UserManager::userManager;
-bool UserBackend::getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
+bool UserManager::Compare::operator() (const UserBackend *b1, const UserBackend *b2) {
+ if(b1->getPriority() == b2->getPriority())
+ return (b1 > b2);
+ else
+ return (b1->getPriority() > b2->getPriority());
+}
+
+
+bool UserManager::getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
+ for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ if((*backend)->getUserList(callback))
+ return true;
+ }
+
+ return false;
+}
+
+bool UserManager::getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->userList(callback))
+ if((*backend)->getUserInfo(uid, callback))
return true;
}
return false;
}
-bool UserBackend::getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
+bool UserManager::setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->userInfo(uid, callback))
+ if((*backend)->setPassword(uid, password, callback))
return true;
}
return false;
}
-bool UserBackend::setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback) {
+bool UserManager::addUser(const Common::UserInfo &userInfo, const sigc::slot<void, bool> &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->password(uid, password, callback))
+ if((*backend)->addUser(userInfo, callback))
return true;
}
diff --git a/src/Core/UserManager.h b/src/Core/UserManager.h
new file mode 100644
index 0000000..a925bbe
--- /dev/null
+++ b/src/Core/UserManager.h
@@ -0,0 +1,73 @@
+/*
+ * UserManager.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_CORE_USERMANAGER_H_
+#define MAD_CORE_USERMANAGER_H_
+
+#include <Common/UserInfo.h>
+
+#include <map>
+#include <set>
+
+#include <sigc++/slot.h>
+
+namespace Mad {
+namespace Core {
+
+class UserBackend;
+
+class UserManager {
+ private:
+ struct Compare {
+ bool operator() (const UserBackend *b1, const UserBackend *b2);
+ };
+
+ static UserManager userManager;
+
+ std::set<UserBackend*, Compare> backends;
+
+ UserManager() {}
+
+ public:
+ void registerBackend(UserBackend *backend) {
+ backends.insert(backend);
+ }
+
+ void unregisterBackend(UserBackend *backend) {
+ backends.erase(backend);
+ }
+
+
+ bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
+ bool getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
+
+ bool setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback);
+
+ bool addUser(const Common::UserInfo &userInfo, const sigc::slot<void, bool> &callback);
+
+
+ static UserManager *get() {
+ return &userManager;
+ }
+};
+
+}
+}
+
+#endif /* MAD_CORE_USERMANAGER_H_ */
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
index b0856c1..ad5908a 100644
--- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
+++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
@@ -20,7 +20,7 @@
#include "CommandRequestHandler.h"
#include <Common/Exception.h>
#include <Common/Logger.h>
-#include <Common/SystemBackend.h>
+#include <Common/SystemManager.h>
namespace Mad {
namespace Daemon {
@@ -46,11 +46,11 @@ void CommandRequestHandler::handlePacket(const Common::XmlPacket &packet) {
std::string command = packet["command"];
if(command == "reboot") {
- if(Common::SystemBackend::shutdown(sigc::mem_fun(this, &CommandRequestHandler::sendReply)))
+ if(Common::SystemManager::get()->shutdown(sigc::mem_fun(this, &CommandRequestHandler::sendReply)))
return;
}
else {
- if(Common::SystemBackend::reboot(sigc::mem_fun(this, &CommandRequestHandler::sendReply)))
+ if(Common::SystemManager::get()->reboot(sigc::mem_fun(this, &CommandRequestHandler::sendReply)))
return;
}
diff --git a/src/modules/SystemBackendPosix.cpp b/src/modules/SystemBackendPosix.cpp
index c8135a3..21e5c75 100644
--- a/src/modules/SystemBackendPosix.cpp
+++ b/src/modules/SystemBackendPosix.cpp
@@ -70,8 +70,8 @@ SystemBackendPosix::~SystemBackendPosix() {
}
-void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const sigc::slot<void, const std::vector<FSInfo>& > &callback) {
- std::vector<FSInfo> ret;
+void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const sigc::slot<void, const std::vector<Common::SystemManager::FSInfo>& > &callback) {
+ std::vector<Common::SystemManager::FSInfo> ret;
std::istringstream stream(output);
std::string str;
@@ -83,7 +83,7 @@ void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const si
char *fsName = new char[str.length()+1];
char *mountedOn = new char[str.length()+1];
- FSInfo info;
+ Common::SystemManager::FSInfo info;
if(std::sscanf(str.c_str(), "%s %lld %lld %lld %*d%% %s", fsName, &info.total, &info.used, &info.available, mountedOn) == 5) {
info.fsName = fsName;
@@ -99,7 +99,7 @@ void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const si
callback(ret);
}
-bool SystemBackendPosix::fsInfo(const sigc::slot<void, const std::vector<FSInfo>& > &callback) {
+bool SystemBackendPosix::getFSInfo(const sigc::slot<void, const std::vector<Common::SystemManager::FSInfo>& > &callback) {
std::vector<std::string> argv;
argv.push_back("/bin/df");
diff --git a/src/modules/SystemBackendPosix.h b/src/modules/SystemBackendPosix.h
index a307f22..b12af6b 100644
--- a/src/modules/SystemBackendPosix.h
+++ b/src/modules/SystemBackendPosix.h
@@ -55,13 +55,13 @@ class SystemBackendPosix : private Common::SystemBackend {
setChildHandler();
}
- void fsInfoCallback(int, const std::string &output, const sigc::slot<void, const std::vector<FSInfo>& > &callback);
+ void fsInfoCallback(int, const std::string &output, const sigc::slot<void, const std::vector<Common::SystemManager::FSInfo>& > &callback);
protected:
- virtual bool fsInfo(const sigc::slot<void, const std::vector<FSInfo>& > &callback);
+ virtual bool getFSInfo(const sigc::slot<void, const std::vector<Common::SystemManager::FSInfo>& > &callback);
- virtual bool doShutdown(const sigc::slot<void> &callback) {return exec(sigc::hide(callback), "/sbin/halt");}
- virtual bool doReboot(const sigc::slot<void> &callback) {return exec(sigc::hide(callback), "/sbin/reboot");}
+ virtual bool shutdown(const sigc::slot<void> &callback) {return exec(sigc::hide(callback), "/sbin/halt");}
+ virtual bool reboot(const sigc::slot<void> &callback) {return exec(sigc::hide(callback), "/sbin/reboot");}
public:
~SystemBackendPosix();
@@ -71,14 +71,14 @@ class SystemBackendPosix : private Common::SystemBackend {
return;
backend = new SystemBackendPosix();
- SystemBackend::registerBackend(backend);
+ Common::SystemManager::get()->registerBackend(backend);
}
static void unregisterBackend() {
if(!backend)
return;
- SystemBackend::unregisterBackend(backend);
+ Common::SystemManager::get()->unregisterBackend(backend);
delete backend;
backend = 0;
}
diff --git a/src/modules/SystemBackendProc.cpp b/src/modules/SystemBackendProc.cpp
index 3a0d33d..501f779 100644
--- a/src/modules/SystemBackendProc.cpp
+++ b/src/modules/SystemBackendProc.cpp
@@ -34,7 +34,7 @@ namespace Modules {
SystemBackendProc *SystemBackendProc::backend = 0;
-bool SystemBackendProc::uptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback) {
+bool SystemBackendProc::getUptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback) {
unsigned long uptime = 0, idleTime = 0;
uptimeFile.seekg(0, std::ios::beg);
@@ -58,7 +58,7 @@ bool SystemBackendProc::uptimeInfo(const sigc::slot<void, unsigned long, unsigne
return true;
}
-bool SystemBackendProc::memoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback) {
+bool SystemBackendProc::getMemoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback) {
unsigned long totalMem = 0, freeMem = 0, totalSwap = 0, freeSwap = 0;
meminfoFile.seekg(0, std::ios::beg);
@@ -95,7 +95,7 @@ bool SystemBackendProc::memoryInfo(const sigc::slot<void, unsigned long, unsigne
return true;
}
-bool SystemBackendProc::loadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback) {
+bool SystemBackendProc::getLoadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback) {
unsigned long currentLoad = 0, nProcesses = 0;
float loadAvg1 = 0, loadAvg5 = 0, loadAvg15 = 0;
diff --git a/src/modules/SystemBackendProc.h b/src/modules/SystemBackendProc.h
index bd4767d..7174551 100644
--- a/src/modules/SystemBackendProc.h
+++ b/src/modules/SystemBackendProc.h
@@ -38,9 +38,9 @@ class SystemBackendProc : private Common::SystemBackend {
SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {}
protected:
- virtual bool uptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback);
- virtual bool memoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback);
- virtual bool loadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback);
+ virtual bool getUptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback);
+ virtual bool getMemoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback);
+ virtual bool getLoadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback);
public:
static void registerBackend() {
@@ -48,14 +48,14 @@ class SystemBackendProc : private Common::SystemBackend {
return;
backend = new SystemBackendProc();
- SystemBackend::registerBackend(backend);
+ Common::SystemManager::get()->registerBackend(backend);
}
static void unregisterBackend() {
if(!backend)
return;
- SystemBackend::unregisterBackend(backend);
+ Common::SystemManager::get()->unregisterBackend(backend);
delete backend;
backend = 0;
}
diff --git a/src/modules/UserBackendMysql.cpp b/src/modules/UserBackendMysql.cpp
index db3c32b..39b0652 100644
--- a/src/modules/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql.cpp
@@ -22,6 +22,7 @@
#include "UserBackendMysql.h"
#include <Common/ActionManager.h>
#include <Common/ConfigEntry.h>
+#include <Common/ConfigManager.h>
#include <Common/Logger.h>
#include <sstream>
@@ -130,11 +131,11 @@ void UserBackendMysql::configFinished() {
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);
- UserBackend::registerBackend(backend);
+ Core::UserManager::get()->registerBackend(backend);
}
-bool UserBackendMysql::userList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
+bool UserBackendMysql::getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
mysql_ping(mysql);
mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length());
@@ -159,7 +160,7 @@ bool UserBackendMysql::userList(const sigc::slot<void, const std::map<unsigned l
return true;
}
-bool UserBackendMysql::userInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
+bool UserBackendMysql::getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
mysql_ping(mysql);
std::string query = queryUserById;
@@ -196,10 +197,6 @@ bool UserBackendMysql::userInfo(unsigned long uid, const sigc::slot<void, const
return true;
}
-bool UserBackendMysql::password(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_, const sigc::slot<void, bool> &callback _UNUSED_PARAMETER_) {
- return false;
-}
-
void UserBackendMysql::registerBackend() {
if(backend)
@@ -214,7 +211,7 @@ void UserBackendMysql::unregisterBackend() {
return;
Common::ConfigManager::get()->unregisterConfigurable(backend);
- UserBackend::unregisterBackend(backend);
+ Core::UserManager::get()->unregisterBackend(backend);
delete backend;
backend = 0;
diff --git a/src/modules/UserBackendMysql.h b/src/modules/UserBackendMysql.h
index 60b2bd9..ac82d67 100644
--- a/src/modules/UserBackendMysql.h
+++ b/src/modules/UserBackendMysql.h
@@ -21,8 +21,8 @@
#define MAD_MODULES_USERBACKENDMYSQL_H_
#include <Core/UserBackend.h>
+#include <Core/UserManager.h>
#include <Common/Configurable.h>
-#include <Common/ConfigManager.h>
#include <mysql/mysql.h>
@@ -50,9 +50,8 @@ class UserBackendMysql : private Core::UserBackend, private Common::Configurable
virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool);
virtual void configFinished();
- virtual bool userList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
- virtual bool userInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
- virtual bool password(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback);
+ virtual bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
+ virtual bool getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
public:
virtual ~UserBackendMysql() {