summaryrefslogtreecommitdiffstats
path: root/src/Common/Backends
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-10-03 01:30:27 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-10-03 01:30:27 +0200
commit426d60a6992259ca80431c59e916073cc31f5261 (patch)
treece88e01006e91ce4c159afc645777f9b458110b3 /src/Common/Backends
parent2f5eba3ce1bddf30b23444042f955adc10d84855 (diff)
downloadmad-426d60a6992259ca80431c59e916073cc31f5261.tar
mad-426d60a6992259ca80431c59e916073cc31f5261.zip
Callback-basierte SystemBackends f?r h?here Flexibilit?t
Diffstat (limited to 'src/Common/Backends')
-rw-r--r--src/Common/Backends/SystemBackendPosix.cpp2
-rw-r--r--src/Common/Backends/SystemBackendPosix.h7
-rw-r--r--src/Common/Backends/SystemBackendProc.cpp52
-rw-r--r--src/Common/Backends/SystemBackendProc.h6
4 files changed, 36 insertions, 31 deletions
diff --git a/src/Common/Backends/SystemBackendPosix.cpp b/src/Common/Backends/SystemBackendPosix.cpp
index b1e088d..3ddf67d 100644
--- a/src/Common/Backends/SystemBackendPosix.cpp
+++ b/src/Common/Backends/SystemBackendPosix.cpp
@@ -69,7 +69,7 @@ void SystemBackendPosix::childHandler(int) {
setChildHandler();
}
-bool SystemBackendPosix::exec(sigc::slot<void, int> resultHandler, const std::string &filename, const std::vector<std::string> &argv, const std::vector<std::string> &env) {
+bool SystemBackendPosix::exec(const sigc::slot<void, int>& resultHandler, const std::string &filename, const std::vector<std::string> &argv, const std::vector<std::string> &env) {
pid_t pid;
char **argvp, **envp;
diff --git a/src/Common/Backends/SystemBackendPosix.h b/src/Common/Backends/SystemBackendPosix.h
index 9efd59f..4a2c572 100644
--- a/src/Common/Backends/SystemBackendPosix.h
+++ b/src/Common/Backends/SystemBackendPosix.h
@@ -28,6 +28,7 @@
#include <sys/types.h>
#include <sigc++/signal.h>
+#include <sigc++/hide.h>
namespace Mad {
namespace Common {
@@ -47,8 +48,8 @@ class SystemBackendPosix : public SystemBackend {
}
protected:
- virtual bool doShutdown() {return exec(sigc::slot<void, int>(), "/sbin/halt");}
- virtual bool doReboot() {return exec(sigc::slot<void, int>(), "/sbin/reboot");}
+ virtual bool doShutdown(const sigc::slot<void> &callback) {return exec(sigc::hide(callback), "/sbin/halt");}
+ virtual bool doReboot(const sigc::slot<void> &callback) {return exec(sigc::hide(callback), "/sbin/reboot");}
public:
~SystemBackendPosix();
@@ -61,7 +62,7 @@ class SystemBackendPosix : public SystemBackend {
SystemBackend::unregisterBackend(&backend);
}
- static bool exec(sigc::slot<void, int> resultHandler, const std::string &filename, const std::vector<std::string> &argv = std::vector<std::string>(),
+ static bool exec(const sigc::slot<void, int> &resultHandler, const std::string &filename, const std::vector<std::string> &argv = std::vector<std::string>(),
const std::vector<std::string> &env = std::vector<std::string>());
};
diff --git a/src/Common/Backends/SystemBackendProc.cpp b/src/Common/Backends/SystemBackendProc.cpp
index 37bfaf3..134998f 100644
--- a/src/Common/Backends/SystemBackendProc.cpp
+++ b/src/Common/Backends/SystemBackendProc.cpp
@@ -28,37 +28,37 @@ namespace Backends {
SystemBackendProc SystemBackendProc::backend;
-SystemBackend::UptimeInfo SystemBackendProc::uptimeInfo() {
- UptimeInfo uptime = {0, 0};
+bool SystemBackendProc::uptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback) {
+ unsigned long uptime = 0, idleTime = 0;
uptimeFile.seekg(0, std::ios::beg);
if(!uptimeFile.good())
- return uptime;
+ return false;
float f;
uptimeFile >> f;
if(!uptimeFile.good())
- return uptime;
+ return false;
- uptime.uptime = (unsigned long)f;
+ uptime = (unsigned long)f;
uptimeFile >> f;
- if(!uptimeFile.good())
- return uptime;
+ if(uptimeFile.good())
+ idleTime = (unsigned long)f;
- uptime.idleTime = (unsigned long)f;
+ callback(uptime, idleTime);
- return uptime;
+ return true;
}
-SystemBackend::MemoryInfo SystemBackendProc::memoryInfo() {
- MemoryInfo memInfo = {0, 0, 0, 0};
+bool SystemBackendProc::memoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback) {
+ unsigned long totalMem = 0, freeMem = 0, totalSwap = 0, freeSwap = 0;
meminfoFile.seekg(0, std::ios::beg);
if(!meminfoFile.good())
- return memInfo;
+ return false;
while(!meminfoFile.eof() && meminfoFile.good()) {
std::string line;
@@ -69,42 +69,46 @@ SystemBackend::MemoryInfo SystemBackendProc::memoryInfo() {
if(std::sscanf(line.c_str(), "%s %lu", name, &value) == 2) {
if(std::strcmp(name, "MemTotal:") == 0)
- memInfo.totalMem = value;
+ totalMem = value;
else if(std::strcmp(name, "MemFree:") == 0)
- memInfo.freeMem = value;
+ freeMem = value;
else if(std::strcmp(name, "SwapTotal:") == 0)
- memInfo.totalSwap = value;
+ totalSwap = value;
else if(std::strcmp(name, "SwapFree:") == 0)
- memInfo.freeSwap = value;
+ freeSwap = value;
}
delete [] name;
- if(memInfo.totalMem && memInfo.freeMem && memInfo.totalSwap && memInfo.freeSwap)
+ if(totalMem && freeMem && totalSwap && freeSwap)
break;
}
+ callback(totalMem, freeMem, totalSwap, freeSwap);
- return memInfo;
+ return true;
}
-SystemBackend::LoadInfo SystemBackendProc::loadInfo() {
- LoadInfo loadInfo = {0, 0, 0, 0, 0};
+bool SystemBackendProc::loadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback) {
+ unsigned long currentLoad = 0, nProcesses = 0;
+ float loadAvg1 = 0, loadAvg5 = 0, loadAvg15 = 0;
loadFile.seekg(0, std::ios::beg);
if(!loadFile.good())
- return loadInfo;
+ return false;
std::string line;
std::getline(loadFile, line);
if(line.empty())
- return loadInfo;
+ return false;
+
+ std::sscanf(line.c_str(), "%f %f %f %lu/%lu", &loadAvg1, &loadAvg5, &loadAvg15, &currentLoad, &nProcesses);
- std::sscanf(line.c_str(), "%f %f %f %lu/%lu", &loadInfo.loadAvg1, &loadInfo.loadAvg5, &loadInfo.loadAvg15, &loadInfo.currentLoad, &loadInfo.nProcesses);
+ callback(currentLoad, nProcesses, loadAvg1, loadAvg5, loadAvg15);
- return loadInfo;
+ return true;
}
}
diff --git a/src/Common/Backends/SystemBackendProc.h b/src/Common/Backends/SystemBackendProc.h
index 619c996..79ff6c5 100644
--- a/src/Common/Backends/SystemBackendProc.h
+++ b/src/Common/Backends/SystemBackendProc.h
@@ -47,9 +47,9 @@ class SystemBackendProc : public SystemBackend {
SystemBackend::unregisterBackend(&backend);
}
- virtual UptimeInfo uptimeInfo();
- virtual MemoryInfo memoryInfo();
- virtual LoadInfo loadInfo();
+ virtual bool uptimeInfo(const sigc::slot<void, unsigned long, unsigned long> &callback);
+ virtual bool memoryInfo(const sigc::slot<void, unsigned long, unsigned long, unsigned long, unsigned long> &callback);
+ virtual bool loadInfo(const sigc::slot<void, unsigned long, unsigned long, float, float, float> &callback);
};
}