diff options
Diffstat (limited to 'src/modules/SystemBackendProc')
-rw-r--r-- | src/modules/SystemBackendProc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/modules/SystemBackendProc/Module.cpp | 28 | ||||
-rw-r--r-- | src/modules/SystemBackendProc/Module.h | 52 | ||||
-rw-r--r-- | src/modules/SystemBackendProc/SystemBackendProc.cpp | 21 | ||||
-rw-r--r-- | src/modules/SystemBackendProc/SystemBackendProc.h | 32 |
5 files changed, 94 insertions, 40 deletions
diff --git a/src/modules/SystemBackendProc/CMakeLists.txt b/src/modules/SystemBackendProc/CMakeLists.txt index ba5642c..42f7431 100644 --- a/src/modules/SystemBackendProc/CMakeLists.txt +++ b/src/modules/SystemBackendProc/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories(${INCLUDES}) add_library(SystemBackendProc MODULE + Module.cpp Module.h SystemBackendProc.cpp SystemBackendProc.h ) diff --git a/src/modules/SystemBackendProc/Module.cpp b/src/modules/SystemBackendProc/Module.cpp new file mode 100644 index 0000000..7dbbbb5 --- /dev/null +++ b/src/modules/SystemBackendProc/Module.cpp @@ -0,0 +1,28 @@ +/* + * Module.cpp + * + * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "Module.h" + +extern "C" { + +Mad::Common::Module* SystemBackendProc_create(Mad::Common::Application *application) { + return new Mad::Modules::SystemBackendProc::Module(application); +} + +} diff --git a/src/modules/SystemBackendProc/Module.h b/src/modules/SystemBackendProc/Module.h new file mode 100644 index 0000000..6cdbd73 --- /dev/null +++ b/src/modules/SystemBackendProc/Module.h @@ -0,0 +1,52 @@ +/* + * Module.h + * + * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_MODULES_SYSTEMBACKENDPROC_MODULE_H_ +#define MAD_MODULES_SYSTEMBACKENDPROC_MODULE_H_ + +#include "SystemBackendProc.h" + +#include <Common/Application.h> +#include <Common/Module.h> + +namespace Mad { +namespace Modules { +namespace SystemBackendProc { + +class Module : public Common::Module { + private: + Common::Application *application; + + boost::shared_ptr<SystemBackendProc> backend; + + public: + Module(Common::Application *application0) : application(application0), backend(new SystemBackendProc(application)) { + application->getSystemManager()->registerBackend(backend); + } + + virtual ~Module() { + application->getSystemManager()->unregisterBackend(backend); + } +}; + +} +} +} + +#endif /* MAD_MODULES_SYSTEMBACKENDPROC_MODULE_H_ */ diff --git a/src/modules/SystemBackendProc/SystemBackendProc.cpp b/src/modules/SystemBackendProc/SystemBackendProc.cpp index e8b45cd..daae55b 100644 --- a/src/modules/SystemBackendProc/SystemBackendProc.cpp +++ b/src/modules/SystemBackendProc/SystemBackendProc.cpp @@ -26,11 +26,10 @@ namespace Mad { namespace Modules { - -boost::shared_ptr<SystemBackendProc> SystemBackendProc::backend; +namespace SystemBackendProc { void SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); uptimeFile.seekg(0, std::ios::beg); @@ -51,7 +50,7 @@ void SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idle } void SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); if(totalMem) *totalMem = 0; @@ -93,7 +92,7 @@ void SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *fr } void SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); unsigned long currentLoadValue = 0, nProcessesValue = 0; float loadAvg1Value = 0, loadAvg5Value = 0, loadAvg15Value = 0; @@ -129,16 +128,4 @@ void SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *n } } - - -extern "C" { - -void SystemBackendProc_init() { - Mad::Modules::SystemBackendProc::registerBackend(); -} - -void SystemBackendProc_deinit() { - Mad::Modules::SystemBackendProc::unregisterBackend(); -} - } diff --git a/src/modules/SystemBackendProc/SystemBackendProc.h b/src/modules/SystemBackendProc/SystemBackendProc.h index 9a0cb71..a54d783 100644 --- a/src/modules/SystemBackendProc/SystemBackendProc.h +++ b/src/modules/SystemBackendProc/SystemBackendProc.h @@ -17,51 +17,37 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MAD_MODULES_SYSTEMBACKENDPROC_H_ -#define MAD_MODULES_SYSTEMBACKENDPROC_H_ +#ifndef MAD_MODULES_SYSTEMBACKENDPROC_SYSTEMBACKENDPROC_H_ +#define MAD_MODULES_SYSTEMBACKENDPROC_SYSTEMBACKENDPROC_H_ #include <Common/SystemBackend.h> +#include <Common/Application.h> #include <fstream> -#include <boost/noncopyable.hpp> namespace Mad { namespace Modules { +namespace SystemBackendProc { -class SystemBackendProc : public Common::SystemBackend, boost::noncopyable { +class SystemBackendProc : public Common::SystemBackend { private: - static boost::shared_ptr<SystemBackendProc> backend; + Common::Application *application; std::ifstream uptimeFile; std::ifstream meminfoFile; std::ifstream loadFile; - SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {} - protected: virtual void getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception); virtual void getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Core::Exception); virtual void getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Core::Exception); public: - static void registerBackend() { - if(backend) - return; - - backend.reset(new SystemBackendProc()); - Common::SystemManager::get()->registerBackend(backend); - } - - static void unregisterBackend() { - if(!backend) - return; - - Common::SystemManager::get()->unregisterBackend(backend); - backend.reset(); - } + SystemBackendProc(Common::Application *application0) : application(application0), uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {} }; } } +} -#endif /* MAD_MODULES_SYSTEMBACKENDPROC_H_ */ +#endif /* MAD_MODULES_SYSTEMBACKENDPROC_SYSTEMBACKENDPROC_H_ */ |