diff options
Diffstat (limited to 'src/modules/SystemBackendProc')
-rw-r--r-- | src/modules/SystemBackendProc/SystemBackendProc.cpp | 22 | ||||
-rw-r--r-- | src/modules/SystemBackendProc/SystemBackendProc.h | 6 |
2 files changed, 11 insertions, 17 deletions
diff --git a/src/modules/SystemBackendProc/SystemBackendProc.cpp b/src/modules/SystemBackendProc/SystemBackendProc.cpp index 1888227..ab074b2 100644 --- a/src/modules/SystemBackendProc/SystemBackendProc.cpp +++ b/src/modules/SystemBackendProc/SystemBackendProc.cpp @@ -29,18 +29,18 @@ namespace Modules { boost::shared_ptr<SystemBackendProc> SystemBackendProc::backend; -bool SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) { +void SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Net::Exception) { Net::ThreadManager::get()->detach(); uptimeFile.seekg(0, std::ios::beg); if(!uptimeFile.good()) - return false; + throw(Net::Exception(Net::Exception::NOT_AVAILABLE)); float f; uptimeFile >> f; if(!uptimeFile.good()) - return false; + throw(Net::Exception(Net::Exception::NOT_AVAILABLE)); if(uptime) *uptime = (unsigned long)f; @@ -48,11 +48,9 @@ bool SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idle uptimeFile >> f; if(uptimeFile.good() && idleTime) *idleTime = (unsigned long)f; - - return true; } -bool SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) { +void SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Net::Exception) { Net::ThreadManager::get()->detach(); if(totalMem) @@ -67,7 +65,7 @@ bool SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *fr meminfoFile.seekg(0, std::ios::beg); if(!meminfoFile.good()) - return false; + throw(Net::Exception(Net::Exception::NOT_AVAILABLE)); while(!meminfoFile.eof() && meminfoFile.good()) { std::string line; @@ -92,11 +90,9 @@ bool SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *fr if((!totalMem || *totalMem) && (!freeMem || *freeMem) && (!totalSwap || *totalSwap) && (!freeSwap || *freeSwap)) break; } - - return true; } -bool SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) { +void SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Net::Exception) { Net::ThreadManager::get()->detach(); unsigned long currentLoadValue = 0, nProcessesValue = 0; @@ -105,13 +101,13 @@ bool SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *n loadFile.seekg(0, std::ios::beg); if(!loadFile.good()) - return false; + throw(Net::Exception(Net::Exception::NOT_AVAILABLE)); std::string line; std::getline(loadFile, line); if(line.empty()) - return false; + throw(Net::Exception(Net::Exception::NOT_AVAILABLE)); std::sscanf(line.c_str(), "%f %f %f %lu/%lu", &loadAvg1Value, &loadAvg5Value, &loadAvg15Value, ¤tLoadValue, &nProcessesValue); @@ -129,8 +125,6 @@ bool SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *n if(loadAvg15) *loadAvg15 = loadAvg15Value; - - return true; } } diff --git a/src/modules/SystemBackendProc/SystemBackendProc.h b/src/modules/SystemBackendProc/SystemBackendProc.h index 9b36df4..eb2f8a6 100644 --- a/src/modules/SystemBackendProc/SystemBackendProc.h +++ b/src/modules/SystemBackendProc/SystemBackendProc.h @@ -39,9 +39,9 @@ class SystemBackendProc : public Common::SystemBackend, boost::noncopyable { SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {} protected: - virtual bool getUptimeInfo(unsigned long *uptime, unsigned long *idleTime); - virtual bool getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap); - virtual bool getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15); + virtual void getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Net::Exception); + virtual void getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Net::Exception); + virtual void getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Net::Exception); public: static void registerBackend() { |