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 +++++++++++++++++++ 9 files changed, 201 insertions(+), 146 deletions(-) delete mode 100644 src/Common/SystemBackend.cpp create mode 100644 src/Common/SystemManager.cpp create mode 100644 src/Common/SystemManager.h (limited to 'src/Common') 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_ */ -- cgit v1.2.3