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/SystemBackendPosix/CMakeLists.txt | 1 + src/modules/SystemBackendPosix/Module.cpp | 28 ++++++++++++ src/modules/SystemBackendPosix/Module.h | 52 ++++++++++++++++++++++ .../SystemBackendPosix/SystemBackendPosix.cpp | 21 ++------- .../SystemBackendPosix/SystemBackendPosix.h | 35 ++++----------- 5 files changed, 93 insertions(+), 44 deletions(-) create mode 100644 src/modules/SystemBackendPosix/Module.cpp create mode 100644 src/modules/SystemBackendPosix/Module.h (limited to 'src/modules/SystemBackendPosix') diff --git a/src/modules/SystemBackendPosix/CMakeLists.txt b/src/modules/SystemBackendPosix/CMakeLists.txt index 223960b..83e8ea1 100644 --- a/src/modules/SystemBackendPosix/CMakeLists.txt +++ b/src/modules/SystemBackendPosix/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories(${INCLUDES}) add_library(SystemBackendPosix MODULE + Module.cpp Module.h SystemBackendPosix.cpp SystemBackendPosix.h ) diff --git a/src/modules/SystemBackendPosix/Module.cpp b/src/modules/SystemBackendPosix/Module.cpp new file mode 100644 index 0000000..230fef4 --- /dev/null +++ b/src/modules/SystemBackendPosix/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* SystemBackendPosix_create(Mad::Common::Application *application) { + return new Mad::Modules::SystemBackendPosix::Module(application); +} + +} diff --git a/src/modules/SystemBackendPosix/Module.h b/src/modules/SystemBackendPosix/Module.h new file mode 100644 index 0000000..ee780f6 --- /dev/null +++ b/src/modules/SystemBackendPosix/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_SYSTEMBACKENDPOSIX_MODULE_H_ +#define MAD_MODULES_SYSTEMBACKENDPOSIX_MODULE_H_ + +#include "SystemBackendPosix.h" + +#include +#include + +namespace Mad { +namespace Modules { +namespace SystemBackendPosix { + +class Module : public Common::Module { + private: + Common::Application *application; + + boost::shared_ptr backend; + + public: + Module(Common::Application *application0) : application(application0), backend(new SystemBackendPosix(application)) { + application->getSystemManager()->registerBackend(backend); + } + + virtual ~Module() { + application->getSystemManager()->unregisterBackend(backend); + } +}; + +} +} +} + +#endif /* MAD_MODULES_SYSTEMBACKENDPOSIX_MODULE_H_ */ diff --git a/src/modules/SystemBackendPosix/SystemBackendPosix.cpp b/src/modules/SystemBackendPosix/SystemBackendPosix.cpp index 4eb5807..801fcd4 100644 --- a/src/modules/SystemBackendPosix/SystemBackendPosix.cpp +++ b/src/modules/SystemBackendPosix/SystemBackendPosix.cpp @@ -26,11 +26,10 @@ namespace Mad { namespace Modules { - -boost::shared_ptr SystemBackendPosix::backend; +namespace SystemBackendPosix { void SystemBackendPosix::getFSInfo(std::vector *fsInfo) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); FILE *pipe = popen("/bin/df -P -k", "r"); if(!pipe) @@ -79,14 +78,14 @@ void SystemBackendPosix::getFSInfo(std::vector *f } void SystemBackendPosix::shutdown() throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); if(system("/sbin/halt") != 0) throw(Core::Exception(Core::Exception::NOT_AVAILABLE)); } void SystemBackendPosix::reboot() throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); if(system("/sbin/reboot") != 0) throw(Core::Exception(Core::Exception::NOT_AVAILABLE)); @@ -94,16 +93,4 @@ void SystemBackendPosix::reboot() throw(Core::Exception) { } } - - -extern "C" { - -void SystemBackendPosix_init() { - Mad::Modules::SystemBackendPosix::registerBackend(); -} - -void SystemBackendPosix_deinit() { - Mad::Modules::SystemBackendPosix::unregisterBackend(); -} - } diff --git a/src/modules/SystemBackendPosix/SystemBackendPosix.h b/src/modules/SystemBackendPosix/SystemBackendPosix.h index 4aec7dd..6c5ae06 100644 --- a/src/modules/SystemBackendPosix/SystemBackendPosix.h +++ b/src/modules/SystemBackendPosix/SystemBackendPosix.h @@ -17,25 +17,19 @@ * with this program. If not, see . */ -#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_H_ -#define MAD_MODULES_SYSTEMBACKENDPOSIX_H_ +#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_SYSTEMBACKENDPOSIX_H_ +#define MAD_MODULES_SYSTEMBACKENDPOSIX_SYSTEMBACKENDPOSIX_H_ #include - -#include -#include -#include - -#include - -#include +#include namespace Mad { namespace Modules { +namespace SystemBackendPosix { class SystemBackendPosix : public Common::SystemBackend { private: - static boost::shared_ptr backend; + Common::Application *application; protected: virtual void getFSInfo(std::vector *fsInfo) throw(Core::Exception); @@ -44,24 +38,11 @@ class SystemBackendPosix : public Common::SystemBackend { virtual void reboot() throw(Core::Exception); public: - static void registerBackend() { - if(backend) - return; - - backend.reset(new SystemBackendPosix()); - Common::SystemManager::get()->registerBackend(backend); - } - - static void unregisterBackend() { - if(!backend) - return; - - Common::SystemManager::get()->unregisterBackend(backend); - backend.reset(); - } + SystemBackendPosix(Common::Application *application0) : application(application0) {} }; +} } } -#endif /* MAD_MODULES_SYSTEMBACKENDPOSIX_H_ */ +#endif /* MAD_MODULES_SYSTEMBACKENDPOSIX_SYSTEMBACKENDPOSIX_H_ */ -- cgit v1.2.3