summaryrefslogtreecommitdiffstats
path: root/src/modules/SystemBackendPosix
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-18 22:03:02 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-18 22:03:02 +0200
commit7234fe326d16d6bf9f4374a09ddc6ef790e6723f (patch)
tree437d4c40eeb1e9b34b369e4b82064a1572c7dac9 /src/modules/SystemBackendPosix
parentbf561f8226e97f4ace4f04bddf198175e91ee7f0 (diff)
downloadmad-7234fe326d16d6bf9f4374a09ddc6ef790e6723f.tar
mad-7234fe326d16d6bf9f4374a09ddc6ef790e6723f.zip
Globale Variablen durch Application-Klasse ersetzt
Diffstat (limited to 'src/modules/SystemBackendPosix')
-rw-r--r--src/modules/SystemBackendPosix/CMakeLists.txt1
-rw-r--r--src/modules/SystemBackendPosix/Module.cpp28
-rw-r--r--src/modules/SystemBackendPosix/Module.h52
-rw-r--r--src/modules/SystemBackendPosix/SystemBackendPosix.cpp21
-rw-r--r--src/modules/SystemBackendPosix/SystemBackendPosix.h35
5 files changed, 93 insertions, 44 deletions
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 <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* 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 <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_SYSTEMBACKENDPOSIX_MODULE_H_
+#define MAD_MODULES_SYSTEMBACKENDPOSIX_MODULE_H_
+
+#include "SystemBackendPosix.h"
+
+#include <Common/Application.h>
+#include <Common/Module.h>
+
+namespace Mad {
+namespace Modules {
+namespace SystemBackendPosix {
+
+class Module : public Common::Module {
+ private:
+ Common::Application *application;
+
+ boost::shared_ptr<SystemBackendPosix> 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> SystemBackendPosix::backend;
+namespace SystemBackendPosix {
void SystemBackendPosix::getFSInfo(std::vector<Common::SystemManager::FSInfo> *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<Common::SystemManager::FSInfo> *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 <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_H_
-#define MAD_MODULES_SYSTEMBACKENDPOSIX_H_
+#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_SYSTEMBACKENDPOSIX_H_
+#define MAD_MODULES_SYSTEMBACKENDPOSIX_SYSTEMBACKENDPOSIX_H_
#include <Common/SystemBackend.h>
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include <sys/types.h>
-
-#include <boost/bind.hpp>
+#include <Common/Application.h>
namespace Mad {
namespace Modules {
+namespace SystemBackendPosix {
class SystemBackendPosix : public Common::SystemBackend {
private:
- static boost::shared_ptr<SystemBackendPosix> backend;
+ Common::Application *application;
protected:
virtual void getFSInfo(std::vector<Common::SystemManager::FSInfo> *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_ */