diff options
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Makefile.am | 5 | ||||
-rw-r--r-- | src/Common/Makefile.in | 9 | ||||
-rw-r--r-- | src/Common/RequestHandlers/FSInfoRequestHandler.cpp | 6 | ||||
-rw-r--r-- | src/Common/RequestHandlers/FSInfoRequestHandler.h | 4 | ||||
-rw-r--r-- | src/Common/RequestHandlers/StatusRequestHandler.cpp | 6 | ||||
-rw-r--r-- | src/Common/SystemBackend.h | 60 | ||||
-rw-r--r-- | src/Common/SystemManager.cpp (renamed from src/Common/SystemBackend.cpp) | 39 | ||||
-rw-r--r-- | src/Common/SystemManager.h | 82 |
8 files changed, 133 insertions, 78 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_ */ |