From 71dc41a9b7b0e939314a886383daa6fb2e297a55 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 25 Apr 2009 16:27:03 +0200 Subject: SystemBackend und UserBackend in Backend und Manager aufgeteilt --- src/Common/Makefile.am | 5 +- src/Common/Makefile.in | 9 ++- .../RequestHandlers/FSInfoRequestHandler.cpp | 6 +- src/Common/RequestHandlers/FSInfoRequestHandler.h | 4 +- .../RequestHandlers/StatusRequestHandler.cpp | 6 +- src/Common/SystemBackend.cpp | 83 ------------------- src/Common/SystemBackend.h | 60 +++----------- src/Common/SystemManager.cpp | 92 ++++++++++++++++++++++ src/Common/SystemManager.h | 82 +++++++++++++++++++ src/Core/Makefile.am | 4 +- src/Core/Makefile.in | 8 +- .../RequestHandlers/UserInfoRequestHandler.cpp | 4 +- .../RequestHandlers/UserListRequestHandler.cpp | 4 +- src/Core/UserBackend.cpp | 56 ------------- src/Core/UserBackend.h | 39 +++------ src/Core/UserManager.cpp | 74 +++++++++++++++++ src/Core/UserManager.h | 73 +++++++++++++++++ .../RequestHandlers/CommandRequestHandler.cpp | 6 +- src/modules/SystemBackendPosix.cpp | 8 +- src/modules/SystemBackendPosix.h | 12 +-- src/modules/SystemBackendProc.cpp | 6 +- src/modules/SystemBackendProc.h | 10 +-- src/modules/UserBackendMysql.cpp | 13 ++- src/modules/UserBackendMysql.h | 7 +- 24 files changed, 398 insertions(+), 273 deletions(-) delete mode 100644 src/Common/SystemBackend.cpp create mode 100644 src/Common/SystemManager.cpp create mode 100644 src/Common/SystemManager.h delete mode 100644 src/Core/UserBackend.cpp create mode 100644 src/Core/UserManager.cpp create mode 100644 src/Core/UserManager.h (limited to 'src') 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 &info) { +void FSInfoRequestHandler::fsInfoHandler(const std::vector &info) { XmlPacket ret; ret.setType("OK"); ret.addList("filesystems"); - for(std::vector::const_iterator fs = info.begin(); fs != info.end(); ++fs) { + for(std::vector::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 @@ -31,7 +31,7 @@ namespace RequestHandlers { class FSInfoRequestHandler : public RequestHandler { private: - void fsInfoHandler(const std::vector &info); + void fsInfoHandler(const std::vector &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.cpp b/src/Common/SystemBackend.cpp deleted file mode 100644 index 2370b89..0000000 --- a/src/Common/SystemBackend.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SystemBackend.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "SystemBackend.h" - -namespace Mad { -namespace Common { - -std::set SystemBackend::backends; - - -bool SystemBackend::getUptimeInfo(const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->uptimeInfo(callback)) - return true; - } - - return false; -} - -bool SystemBackend::getMemoryInfo(const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->memoryInfo(callback)) - return true; - } - - return false; -} - -bool SystemBackend::getLoadInfo(const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->loadInfo(callback)) - return true; - } - - return false; -} - -bool SystemBackend::getFSInfo(const sigc::slot& > &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->fsInfo(callback)) - return true; - } - - return false; -} - -bool SystemBackend::shutdown(const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->doShutdown(callback)) - return true; - } - - return false; -} - -bool SystemBackend::reboot(const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->doReboot(callback)) - return true; - } - - return false; -} - -} -} 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 -#include -#include +#include -#include +#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 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 &callback _UNUSED_PARAMETER_) { + return false; } - static void unregisterBackend(SystemBackend *backend) { - backends.erase(backend); + virtual bool getMemoryInfo(const sigc::slot &callback _UNUSED_PARAMETER_) { + return false; } - virtual bool uptimeInfo(const sigc::slot&) { + virtual bool getLoadInfo(const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } - virtual bool memoryInfo(const sigc::slot&) { + virtual bool getFSInfo(const sigc::slot& > &callback _UNUSED_PARAMETER_) { return false; } - virtual bool loadInfo(const sigc::slot&) { + virtual bool shutdown(const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } - virtual bool fsInfo(const sigc::slot& >&) { + virtual bool reboot(const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } - virtual bool doShutdown(const sigc::slot&) {return false;} - virtual bool doReboot(const sigc::slot&) {return false;} - virtual int getPriority() const { return 0; } - - public: - virtual ~SystemBackend() {} - - static bool getUptimeInfo(const sigc::slot &callback); - static bool getMemoryInfo(const sigc::slot &callback); - static bool getLoadInfo(const sigc::slot &callback); - - static bool getFSInfo(const sigc::slot& > &callback); - - static bool shutdown(const sigc::slot &callback); - static bool reboot(const sigc::slot &callback); }; } diff --git a/src/Common/SystemManager.cpp b/src/Common/SystemManager.cpp new file mode 100644 index 0000000..a037bd6 --- /dev/null +++ b/src/Common/SystemManager.cpp @@ -0,0 +1,92 @@ +/* + * SystemManager.cpp + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 . + */ + +#include "SystemManager.h" +#include "SystemBackend.h" + +namespace Mad { +namespace Common { + +SystemManager SystemManager::systemManager; + + +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 &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->getUptimeInfo(callback)) + return true; + } + + return false; +} + +bool SystemManager::getMemoryInfo(const sigc::slot &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->getMemoryInfo(callback)) + return true; + } + + return false; +} + +bool SystemManager::getLoadInfo(const sigc::slot &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->getLoadInfo(callback)) + return true; + } + + return false; +} + +bool SystemManager::getFSInfo(const sigc::slot& > &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->getFSInfo(callback)) + return true; + } + + return false; +} + +bool SystemManager::shutdown(const sigc::slot &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->shutdown(callback)) + return true; + } + + return false; +} + +bool SystemManager::reboot(const sigc::slot &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->reboot(callback)) + return true; + } + + return false; +} + +} +} 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 + * + * 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 . + */ + +#ifndef MAD_COMMON_SYSTEMMANAGER_H_ +#define MAD_COMMON_SYSTEMMANAGER_H_ + +#include +#include +#include + +#include + +namespace Mad { +namespace Common { + +class SystemBackend; + +class SystemManager { + private: + struct Compare { + bool operator() (const SystemBackend *b1, const SystemBackend *b2); + }; + + static SystemManager systemManager; + + std::set 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 &callback); + bool getMemoryInfo(const sigc::slot &callback); + bool getLoadInfo(const sigc::slot &callback); + + bool getFSInfo(const sigc::slot& > &callback); + + bool shutdown(const sigc::slot &callback); + bool reboot(const sigc::slot &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 #include @@ -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 #include @@ -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.cpp b/src/Core/UserBackend.cpp deleted file mode 100644 index de8b943..0000000 --- a/src/Core/UserBackend.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * UserBackend.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "UserBackend.h" - -namespace Mad { -namespace Core { - -std::set UserBackend::backends; - - -bool UserBackend::getUserList(const sigc::slot& > &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->userList(callback)) - return true; - } - - return false; -} - -bool UserBackend::getUserInfo(unsigned long uid, const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->userInfo(uid, callback)) - return true; - } - - return false; -} - -bool UserBackend::setPassword(unsigned long uid, const std::string &password, const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->password(uid, password, callback)) - return true; - } - - return false; -} - -} -} 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 + #include #include -#include #include -#include #include @@ -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 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& > &callback _UNUSED_PARAMETER_) { + return false; } - virtual bool userList(const sigc::slot& >&) { + virtual bool getUserInfo(unsigned long uid _UNUSED_PARAMETER_, const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } - virtual bool userInfo(unsigned long, const sigc::slot&) { + virtual bool setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string&, const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } - virtual bool password(unsigned long, const std::string&, const sigc::slot&) { + virtual bool addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_, const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } @@ -75,11 +63,6 @@ class UserBackend { public: virtual ~UserBackend() {} - - static bool getUserList(const sigc::slot& > &callback); - static bool getUserInfo(unsigned long uid, const sigc::slot &callback); - - static bool setPassword(unsigned long uid, const std::string &password, const sigc::slot &callback); }; } diff --git a/src/Core/UserManager.cpp b/src/Core/UserManager.cpp new file mode 100644 index 0000000..d560586 --- /dev/null +++ b/src/Core/UserManager.cpp @@ -0,0 +1,74 @@ +/* + * UserManager.cpp + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 . + */ + +#include "UserManager.h" +#include "UserBackend.h" + +namespace Mad { +namespace Core { + +UserManager UserManager::userManager; + + +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& > &callback) { + for(std::set::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 &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->getUserInfo(uid, callback)) + return true; + } + + return false; +} + +bool UserManager::setPassword(unsigned long uid, const std::string &password, const sigc::slot &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->setPassword(uid, password, callback)) + return true; + } + + return false; +} + +bool UserManager::addUser(const Common::UserInfo &userInfo, const sigc::slot &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->addUser(userInfo, callback)) + return true; + } + + return false; +} + +} +} 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 + * + * 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 . + */ + +#ifndef MAD_CORE_USERMANAGER_H_ +#define MAD_CORE_USERMANAGER_H_ + +#include + +#include +#include + +#include + +namespace Mad { +namespace Core { + +class UserBackend; + +class UserManager { + private: + struct Compare { + bool operator() (const UserBackend *b1, const UserBackend *b2); + }; + + static UserManager userManager; + + std::set backends; + + UserManager() {} + + public: + void registerBackend(UserBackend *backend) { + backends.insert(backend); + } + + void unregisterBackend(UserBackend *backend) { + backends.erase(backend); + } + + + bool getUserList(const sigc::slot& > &callback); + bool getUserInfo(unsigned long uid, const sigc::slot &callback); + + bool setPassword(unsigned long uid, const std::string &password, const sigc::slot &callback); + + bool addUser(const Common::UserInfo &userInfo, const sigc::slot &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 #include -#include +#include 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& > &callback) { - std::vector ret; +void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const sigc::slot& > &callback) { + std::vector 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& > &callback) { +bool SystemBackendPosix::getFSInfo(const sigc::slot& > &callback) { std::vector 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& > &callback); + void fsInfoCallback(int, const std::string &output, const sigc::slot& > &callback); protected: - virtual bool fsInfo(const sigc::slot& > &callback); + virtual bool getFSInfo(const sigc::slot& > &callback); - virtual bool doShutdown(const sigc::slot &callback) {return exec(sigc::hide(callback), "/sbin/halt");} - virtual bool doReboot(const sigc::slot &callback) {return exec(sigc::hide(callback), "/sbin/reboot");} + virtual bool shutdown(const sigc::slot &callback) {return exec(sigc::hide(callback), "/sbin/halt");} + virtual bool reboot(const sigc::slot &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 &callback) { +bool SystemBackendProc::getUptimeInfo(const sigc::slot &callback) { unsigned long uptime = 0, idleTime = 0; uptimeFile.seekg(0, std::ios::beg); @@ -58,7 +58,7 @@ bool SystemBackendProc::uptimeInfo(const sigc::slot &callback) { +bool SystemBackendProc::getMemoryInfo(const sigc::slot &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 &callback) { +bool SystemBackendProc::getLoadInfo(const sigc::slot &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 &callback); - virtual bool memoryInfo(const sigc::slot &callback); - virtual bool loadInfo(const sigc::slot &callback); + virtual bool getUptimeInfo(const sigc::slot &callback); + virtual bool getMemoryInfo(const sigc::slot &callback); + virtual bool getLoadInfo(const sigc::slot &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 #include +#include #include #include @@ -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& > &callback) { +bool UserBackendMysql::getUserList(const sigc::slot& > &callback) { mysql_ping(mysql); mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length()); @@ -159,7 +160,7 @@ bool UserBackendMysql::userList(const sigc::slot &callback) { +bool UserBackendMysql::getUserInfo(unsigned long uid, const sigc::slot &callback) { mysql_ping(mysql); std::string query = queryUserById; @@ -196,10 +197,6 @@ bool UserBackendMysql::userInfo(unsigned long uid, const sigc::slot &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 +#include #include -#include #include @@ -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& > &callback); - virtual bool userInfo(unsigned long uid, const sigc::slot &callback); - virtual bool password(unsigned long uid, const std::string &password, const sigc::slot &callback); + virtual bool getUserList(const sigc::slot& > &callback); + virtual bool getUserInfo(unsigned long uid, const sigc::slot &callback); public: virtual ~UserBackendMysql() { -- cgit v1.2.3