diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-11-27 22:15:00 +0100 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-11-27 22:15:00 +0100 |
commit | ad7ee8df8ac73ef7754ccf1d5fb442ec23c879f1 (patch) | |
tree | 5f2253e72172091127f15284fb75a579b5302314 /src/Common | |
parent | e0de95864892d1e119f91936d8b1294542ab2316 (diff) | |
download | mad-ad7ee8df8ac73ef7754ccf1d5fb442ec23c879f1.tar mad-ad7ee8df8ac73ef7754ccf1d5fb442ec23c879f1.zip |
SystemBackendProc zum Modul gemacht
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Backends/Makefile.am | 4 | ||||
-rw-r--r-- | src/Common/Backends/Makefile.in | 52 | ||||
-rw-r--r-- | src/Common/Backends/SystemBackendProc.cpp | 116 | ||||
-rw-r--r-- | src/Common/Backends/SystemBackendProc.h | 59 |
4 files changed, 14 insertions, 217 deletions
diff --git a/src/Common/Backends/Makefile.am b/src/Common/Backends/Makefile.am index 83e5b2f..ab20072 100644 --- a/src/Common/Backends/Makefile.am +++ b/src/Common/Backends/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = libbackends.la -libbackends_la_SOURCES = SystemBackendProc.cpp +libbackends_la_SOURCES = -noinst_HEADERS = ConsoleLogger.h FileLogger.h SystemBackendProc.h +noinst_HEADERS = ConsoleLogger.h FileLogger.h diff --git a/src/Common/Backends/Makefile.in b/src/Common/Backends/Makefile.in index fd44c4d..e57b0e2 100644 --- a/src/Common/Backends/Makefile.in +++ b/src/Common/Backends/Makefile.in @@ -49,19 +49,17 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libbackends_la_LIBADD = -am_libbackends_la_OBJECTS = SystemBackendProc.lo +am_libbackends_la_OBJECTS = libbackends_la_OBJECTS = $(am_libbackends_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/config/depcomp -am__depfiles_maybe = depfiles -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -CXXLD = $(CXX) -CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(libbackends_la_SOURCES) DIST_SOURCES = $(libbackends_la_SOURCES) @@ -207,12 +205,11 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = libbackends.la -libbackends_la_SOURCES = SystemBackendProc.cpp -noinst_HEADERS = ConsoleLogger.h FileLogger.h SystemBackendProc.h +libbackends_la_SOURCES = +noinst_HEADERS = ConsoleLogger.h FileLogger.h all: all-am .SUFFIXES: -.SUFFIXES: .cpp .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -252,7 +249,7 @@ clean-noinstLTLIBRARIES: rm -f "$${dir}/so_locations"; \ done libbackends.la: $(libbackends_la_OBJECTS) $(libbackends_la_DEPENDENCIES) - $(CXXLINK) $(libbackends_la_OBJECTS) $(libbackends_la_LIBADD) $(LIBS) + $(LINK) $(libbackends_la_OBJECTS) $(libbackends_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -260,29 +257,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackendProc.Plo@am__quote@ - -.cpp.o: -@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< - -.cpp.obj: -@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.cpp.lo: -@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< - mostlyclean-libtool: -rm -f *.lo @@ -396,7 +370,6 @@ clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ mostlyclean-am distclean: distclean-am - -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -430,7 +403,6 @@ install-ps: install-ps-am installcheck-am: maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic diff --git a/src/Common/Backends/SystemBackendProc.cpp b/src/Common/Backends/SystemBackendProc.cpp deleted file mode 100644 index 134998f..0000000 --- a/src/Common/Backends/SystemBackendProc.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * SystemBackendProc.cpp - * - * Copyright (C) 2008 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 "SystemBackendProc.h" - -#include <cstdio> -#include <cstring> - -namespace Mad { -namespace Common { -namespace Backends { - -SystemBackendProc SystemBackendProc::backend; - -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 false; - - float f; - uptimeFile >> f; - if(!uptimeFile.good()) - return false; - - uptime = (unsigned long)f; - - uptimeFile >> f; - if(uptimeFile.good()) - idleTime = (unsigned long)f; - - callback(uptime, idleTime); - - return true; -} - -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 false; - - while(!meminfoFile.eof() && meminfoFile.good()) { - std::string line; - std::getline(meminfoFile, line); - - char *name = new char[line.length()+1]; // is always long enough - unsigned long value; - - if(std::sscanf(line.c_str(), "%s %lu", name, &value) == 2) { - if(std::strcmp(name, "MemTotal:") == 0) - totalMem = value; - else if(std::strcmp(name, "MemFree:") == 0) - freeMem = value; - else if(std::strcmp(name, "SwapTotal:") == 0) - totalSwap = value; - else if(std::strcmp(name, "SwapFree:") == 0) - freeSwap = value; - } - - delete [] name; - - if(totalMem && freeMem && totalSwap && freeSwap) - break; - } - - callback(totalMem, freeMem, totalSwap, freeSwap); - - return true; -} - -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 false; - - std::string line; - std::getline(loadFile, line); - - if(line.empty()) - return false; - - std::sscanf(line.c_str(), "%f %f %f %lu/%lu", &loadAvg1, &loadAvg5, &loadAvg15, ¤tLoad, &nProcesses); - - callback(currentLoad, nProcesses, loadAvg1, loadAvg5, loadAvg15); - - return true; -} - -} -} -} diff --git a/src/Common/Backends/SystemBackendProc.h b/src/Common/Backends/SystemBackendProc.h deleted file mode 100644 index 79ff6c5..0000000 --- a/src/Common/Backends/SystemBackendProc.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SystemBackendProc.h - * - * Copyright (C) 2008 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_COMMON_BACKENDS_SYSTEMBACKENDPROC_H_ -#define MAD_COMMON_BACKENDS_SYSTEMBACKENDPROC_H_ - -#include "../SystemBackend.h" - -#include <fstream> - -namespace Mad { -namespace Common { -namespace Backends { - -class SystemBackendProc : public SystemBackend { - private: - static SystemBackendProc backend; - - std::ifstream uptimeFile; - std::ifstream meminfoFile; - std::ifstream loadFile; - - SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {} - - public: - static void registerBackend() { - SystemBackend::registerBackend(&backend); - } - - static void unregisterBackend() { - SystemBackend::unregisterBackend(&backend); - } - - 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); -}; - -} -} -} - -#endif /* MAD_COMMON_BACKENDS_SYSTEMBACKENDPROC_H_ */ |