summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.cpp11
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.cpp11
-rw-r--r--src/Common/SystemBackend.h24
-rw-r--r--src/Common/SystemManager.cpp96
-rw-r--r--src/Common/SystemManager.h14
5 files changed, 107 insertions, 49 deletions
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
index 663e512..94756b5 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
@@ -47,7 +47,9 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) {
XmlPacket ret;
- if(SystemManager::get()->getFSInfo(&fsInfo)) {
+ try {
+ SystemManager::get()->getFSInfo(&fsInfo);
+
ret.setType("OK");
ret.addList("filesystems");
@@ -62,9 +64,12 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) {
entry.add("availableSize", fs->available);
}
}
- else {
+ catch(Net::Exception e) {
ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
+ ret.add("ErrorCode", e.getErrorCode());
+ ret.add("SubCode", e.getSubCode());
+ ret.add("SubSubCode", e.getSubSubCode());
+ ret.add("Where", e.getWhere());
}
sendPacket(ret);
diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp
index 94ec5b2..c564680 100644
--- a/src/Common/RequestHandlers/StatusRequestHandler.cpp
+++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp
@@ -50,12 +50,15 @@ void StatusRequestHandler::handlePacket(const XmlPacket &packet) {
float loadAvg1, loadAvg5, loadAvg15;
+ XmlPacket ret;
- SystemManager::get()->getUptimeInfo(&uptime, &idleTime);
- SystemManager::get()->getMemoryInfo(&totalMem, &freeMem, &totalSwap, &freeSwap);
- SystemManager::get()->getLoadInfo(&currentLoad, &nProcesses, &loadAvg1, &loadAvg5, &loadAvg15);
+ try {
+ SystemManager::get()->getUptimeInfo(&uptime, &idleTime);
+ SystemManager::get()->getMemoryInfo(&totalMem, &freeMem, &totalSwap, &freeSwap);
+ SystemManager::get()->getLoadInfo(&currentLoad, &nProcesses, &loadAvg1, &loadAvg5, &loadAvg15);
+ }
+ catch(Net::Exception e) {}
- XmlPacket ret;
ret.setType("OK");
ret.add("uptime", uptime);
diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h
index 7b9ee04..1543207 100644
--- a/src/Common/SystemBackend.h
+++ b/src/Common/SystemBackend.h
@@ -31,28 +31,28 @@ class SystemBackend {
protected:
friend class SystemManager;
- virtual bool getUptimeInfo(unsigned long *uptime _UNUSED_PARAMETER_, unsigned long *idleTime _UNUSED_PARAMETER_) {
- return false;
+ virtual void getUptimeInfo(unsigned long *uptime _UNUSED_PARAMETER_, unsigned long *idleTime _UNUSED_PARAMETER_) throw(Net::Exception) {
+ throw Net::Exception(Net::Exception::NOT_IMPLEMENTED);
}
- virtual bool getMemoryInfo(unsigned long *totalMem _UNUSED_PARAMETER_, unsigned long *freeMem _UNUSED_PARAMETER_, unsigned long *totalSwap _UNUSED_PARAMETER_, unsigned long *freeSwap _UNUSED_PARAMETER_) {
- return false;
+ virtual void getMemoryInfo(unsigned long *totalMem _UNUSED_PARAMETER_, unsigned long *freeMem _UNUSED_PARAMETER_, unsigned long *totalSwap _UNUSED_PARAMETER_, unsigned long *freeSwap _UNUSED_PARAMETER_) throw(Net::Exception) {
+ throw Net::Exception(Net::Exception::NOT_IMPLEMENTED);
}
- virtual bool getLoadInfo(unsigned long *currentLoad _UNUSED_PARAMETER_, unsigned long *nProcesses _UNUSED_PARAMETER_, float *loadAvg1 _UNUSED_PARAMETER_, float *loadAvg5 _UNUSED_PARAMETER_, float *loadAvg15 _UNUSED_PARAMETER_) {
- return false;
+ virtual void getLoadInfo(unsigned long *currentLoad _UNUSED_PARAMETER_, unsigned long *nProcesses _UNUSED_PARAMETER_, float *loadAvg1 _UNUSED_PARAMETER_, float *loadAvg5 _UNUSED_PARAMETER_, float *loadAvg15 _UNUSED_PARAMETER_) throw(Net::Exception) {
+ throw Net::Exception(Net::Exception::NOT_IMPLEMENTED);
}
- virtual bool getFSInfo(std::vector<SystemManager::FSInfo> *fsInfo _UNUSED_PARAMETER_) {
- return false;
+ virtual void getFSInfo(std::vector<SystemManager::FSInfo> *fsInfo _UNUSED_PARAMETER_) throw(Net::Exception) {
+ throw Net::Exception(Net::Exception::NOT_IMPLEMENTED);
}
- virtual bool shutdown() {
- return false;
+ virtual void shutdown() throw(Net::Exception) {
+ throw Net::Exception(Net::Exception::NOT_IMPLEMENTED);
}
- virtual bool reboot() {
- return false;
+ virtual void reboot() throw(Net::Exception) {
+ throw Net::Exception(Net::Exception::NOT_IMPLEMENTED);
}
virtual int getPriority() const {
diff --git a/src/Common/SystemManager.cpp b/src/Common/SystemManager.cpp
index c5eac0e..3c89a33 100644
--- a/src/Common/SystemManager.cpp
+++ b/src/Common/SystemManager.cpp
@@ -34,58 +34,106 @@ bool SystemManager::Compare::operator() (boost::shared_ptr<SystemBackend> b1, bo
}
-bool SystemManager::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) {
+void SystemManager::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->getUptimeInfo(uptime, idleTime))
- return true;
+ try {
+ (*backend)->getUptimeInfo(uptime, idleTime);
+ return;
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return false;
+ throw e;
}
-bool SystemManager::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) {
+void SystemManager::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->getMemoryInfo(totalMem, freeMem, totalSwap, freeSwap))
- return true;
+ try {
+ (*backend)->getMemoryInfo(totalMem, freeMem, totalSwap, freeSwap);
+ return;
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return false;
+ throw e;
}
-bool SystemManager::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) {
+void SystemManager::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->getLoadInfo(currentLoad, nProcesses, loadAvg1, loadAvg5, loadAvg15))
- return true;
+ try {
+ (*backend)->getLoadInfo(currentLoad, nProcesses, loadAvg1, loadAvg5, loadAvg15);
+ return;
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return false;
+ throw e;
}
-bool SystemManager::getFSInfo(std::vector<FSInfo> *fsInfo) {
+void SystemManager::getFSInfo(std::vector<FSInfo> *fsInfo) throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->getFSInfo(fsInfo))
- return true;
+ try {
+ (*backend)->getFSInfo(fsInfo);
+ return;
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return false;
+ throw e;
}
-bool SystemManager::shutdown() {
+void SystemManager::shutdown() throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->shutdown())
- return true;
+ try {
+ (*backend)->shutdown();
+ return;
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return false;
+ throw e;
}
-bool SystemManager::reboot() {
+void SystemManager::reboot() throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->reboot())
- return true;
+ try {
+ (*backend)->reboot();
+ return;
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return false;
+ throw e;
}
}
diff --git a/src/Common/SystemManager.h b/src/Common/SystemManager.h
index ef66db8..9252b2b 100644
--- a/src/Common/SystemManager.h
+++ b/src/Common/SystemManager.h
@@ -26,6 +26,8 @@
#include <boost/smart_ptr.hpp>
+#include <Net/Exception.h>
+
namespace Mad {
namespace Common {
@@ -60,14 +62,14 @@ class SystemManager {
backends.erase(backend);
}
- bool getUptimeInfo(unsigned long *uptime, unsigned long *idleTime);
- bool getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap);
- bool getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15);
+ void getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Net::Exception);
+ void getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Net::Exception);
+ void getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Net::Exception);
- bool getFSInfo(std::vector<FSInfo> *fsInfo);
+ void getFSInfo(std::vector<FSInfo> *fsInfo) throw(Net::Exception);
- bool shutdown();
- bool reboot();
+ void shutdown() throw(Net::Exception);
+ void reboot() throw(Net::Exception);
static SystemManager *get() {
return &systemManager;