From 7234fe326d16d6bf9f4374a09ddc6ef790e6723f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Jun 2009 22:03:02 +0200 Subject: Globale Variablen durch Application-Klasse ersetzt --- src/modules/SystemBackendProc/CMakeLists.txt | 1 + src/modules/SystemBackendProc/Module.cpp | 28 ++++++++++++ src/modules/SystemBackendProc/Module.h | 52 ++++++++++++++++++++++ .../SystemBackendProc/SystemBackendProc.cpp | 21 ++------- src/modules/SystemBackendProc/SystemBackendProc.h | 32 ++++--------- 5 files changed, 94 insertions(+), 40 deletions(-) create mode 100644 src/modules/SystemBackendProc/Module.cpp create mode 100644 src/modules/SystemBackendProc/Module.h (limited to 'src/modules/SystemBackendProc') 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 + * + * 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 "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 + * + * 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_MODULES_SYSTEMBACKENDPROC_MODULE_H_ +#define MAD_MODULES_SYSTEMBACKENDPROC_MODULE_H_ + +#include "SystemBackendProc.h" + +#include +#include + +namespace Mad { +namespace Modules { +namespace SystemBackendProc { + +class Module : public Common::Module { + private: + Common::Application *application; + + boost::shared_ptr 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::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 . */ -#ifndef MAD_MODULES_SYSTEMBACKENDPROC_H_ -#define MAD_MODULES_SYSTEMBACKENDPROC_H_ +#ifndef MAD_MODULES_SYSTEMBACKENDPROC_SYSTEMBACKENDPROC_H_ +#define MAD_MODULES_SYSTEMBACKENDPROC_SYSTEMBACKENDPROC_H_ #include +#include #include -#include namespace Mad { namespace Modules { +namespace SystemBackendProc { -class SystemBackendProc : public Common::SystemBackend, boost::noncopyable { +class SystemBackendProc : public Common::SystemBackend { private: - static boost::shared_ptr 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_ */ -- cgit v1.2.3