diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-05-21 01:42:33 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-05-21 01:42:33 +0200 |
commit | 73667d1102735c42cf385442aeb2a1735bb67d6a (patch) | |
tree | f0044dc9324ab0c15e63926bb22910d34a684b46 /src/Common/RequestHandlers | |
parent | 9c076d2649ff8c6997c2dec1e1ef4f7359d404ec (diff) | |
download | mad-73667d1102735c42cf385442aeb2a1735bb67d6a.tar mad-73667d1102735c42cf385442aeb2a1735bb67d6a.zip |
SystemBackend-Interface ueberarbeitet
Diffstat (limited to 'src/Common/RequestHandlers')
-rw-r--r-- | src/Common/RequestHandlers/FSInfoRequestHandler.cpp | 39 | ||||
-rw-r--r-- | src/Common/RequestHandlers/FSInfoRequestHandler.h | 3 | ||||
-rw-r--r-- | src/Common/RequestHandlers/StatusRequestHandler.cpp | 49 | ||||
-rw-r--r-- | src/Common/RequestHandlers/StatusRequestHandler.h | 33 |
4 files changed, 40 insertions, 84 deletions
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp index ed70a8b..663e512 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp @@ -43,31 +43,28 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) { // TODO Require authentication - if(!SystemManager::get()->getFSInfo(boost::bind(&FSInfoRequestHandler::fsInfoHandler, this, _1))) { - XmlPacket ret; - ret.setType("Error"); - ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED); + std::vector<SystemManager::FSInfo> fsInfo; - sendPacket(ret); - - signalFinished()(); - } -} - -void FSInfoRequestHandler::fsInfoHandler(const std::vector<SystemManager::FSInfo> &info) { XmlPacket ret; - ret.setType("OK"); - ret.addList("filesystems"); - for(std::vector<SystemManager::FSInfo>::const_iterator fs = info.begin(); fs != info.end(); ++fs) { - ret["filesystems"].addEntry(); - XmlPacket::Entry &entry = ret["filesystems"].back(); + if(SystemManager::get()->getFSInfo(&fsInfo)) { + ret.setType("OK"); + ret.addList("filesystems"); + + for(std::vector<SystemManager::FSInfo>::const_iterator fs = fsInfo.begin(); fs != fsInfo.end(); ++fs) { + ret["filesystems"].addEntry(); + XmlPacket::Entry &entry = ret["filesystems"].back(); - entry.add("name", fs->fsName); - entry.add("mountedOn", fs->mountedOn); - entry.add("totalSize", fs->total); - entry.add("usedSize", fs->used); - entry.add("availableSize", fs->available); + entry.add("name", fs->fsName); + entry.add("mountedOn", fs->mountedOn); + entry.add("totalSize", fs->total); + entry.add("usedSize", fs->used); + entry.add("availableSize", fs->available); + } + } + else { + ret.setType("Error"); + ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED); } sendPacket(ret); diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h index a4ed92c..47fcbd8 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.h +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h @@ -30,9 +30,6 @@ namespace Common { namespace RequestHandlers { class FSInfoRequestHandler : public RequestHandler { - private: - void fsInfoHandler(const std::vector<SystemManager::FSInfo> &info); - protected: virtual void handlePacket(const XmlPacket &packet); diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index 0c13bd9..94ec5b2 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -44,40 +44,33 @@ void StatusRequestHandler::handlePacket(const XmlPacket &packet) { // TODO Require authentication - if(!SystemManager::get()->getUptimeInfo(boost::bind(&StatusRequestHandler::uptimeHandler, this, _1, _2))) - needUptime = false; - if(!SystemManager::get()->getMemoryInfo(boost::bind(&StatusRequestHandler::memoryHandler, this, _1, _2, _3, _4))) - needMemory = false; - if(!SystemManager::get()->getLoadInfo(boost::bind(&StatusRequestHandler::loadHandler, this, _1, _2, _3, _4, _5))) - needLoad = false; - - send(); -} - -void StatusRequestHandler::send() { - if(needUptime || needMemory || needLoad || sent) - return; + unsigned long uptime, idleTime; + unsigned long totalMem, freeMem, totalSwap, freeSwap; + unsigned long currentLoad, nProcesses; + float loadAvg1, loadAvg5, loadAvg15; - XmlPacket packet; - packet.setType("OK"); - packet.add("uptime", uptime); - packet.add("idleTime", idleTime); - packet.add("totalMem", totalMem); - packet.add("freeMem", freeMem); - packet.add("totalSwap", totalSwap); - packet.add("freeSwap", freeSwap); - packet.add("currentLoad", currentLoad); - packet.add("nProcesses", nProcesses); - packet.add("loadAvg1", loadAvg1); - packet.add("loadAvg5", loadAvg5); - packet.add("loadAvg15", loadAvg15); + SystemManager::get()->getUptimeInfo(&uptime, &idleTime); + SystemManager::get()->getMemoryInfo(&totalMem, &freeMem, &totalSwap, &freeSwap); + SystemManager::get()->getLoadInfo(¤tLoad, &nProcesses, &loadAvg1, &loadAvg5, &loadAvg15); - sendPacket(packet); + XmlPacket ret; + ret.setType("OK"); - sent = true; + ret.add("uptime", uptime); + ret.add("idleTime", idleTime); + ret.add("totalMem", totalMem); + ret.add("freeMem", freeMem); + ret.add("totalSwap", totalSwap); + ret.add("freeSwap", freeSwap); + ret.add("currentLoad", currentLoad); + ret.add("nProcesses", nProcesses); + ret.add("loadAvg1", loadAvg1); + ret.add("loadAvg5", loadAvg5); + ret.add("loadAvg15", loadAvg15); + sendPacket(ret); signalFinished()(); } diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h index 8c7d124..151852c 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.h +++ b/src/Common/RequestHandlers/StatusRequestHandler.h @@ -28,43 +28,12 @@ namespace Common { namespace RequestHandlers { class StatusRequestHandler : public RequestHandler { - private: - bool needUptime, needMemory, needLoad, sent; - - unsigned long uptime, idleTime; - unsigned long totalMem, freeMem, totalSwap, freeSwap; - unsigned long currentLoad, nProcesses; - float loadAvg1, loadAvg5, loadAvg15; - - void uptimeHandler(unsigned long uptime0, unsigned long idleTime0) { - uptime = uptime0; idleTime = idleTime0; - needUptime = false; - send(); - } - - void memoryHandler(unsigned long totalMem0, unsigned long freeMem0, unsigned long totalSwap0, unsigned long freeSwap0) { - totalMem = totalMem0; freeMem = freeMem0; totalSwap = totalSwap0; freeSwap = freeSwap0; - needMemory = false; - send(); - } - - void loadHandler(unsigned long currentLoad0, unsigned long nProcesses0, float loadAvg10, float loadAvg50, float loadAvg150) { - currentLoad = currentLoad0; nProcesses = nProcesses0; loadAvg1 = loadAvg10; loadAvg5 = loadAvg50; loadAvg15 = loadAvg150; - needLoad = false; - send(); - } - - void send(); - protected: virtual void handlePacket(const XmlPacket &packet); public: StatusRequestHandler(Connection *connection, uint16_t requestId) - : RequestHandler(connection, requestId), - needUptime(true), needMemory(true), needLoad(true), sent(false), - uptime(0), idleTime(0), totalMem(0), freeMem(0), totalSwap(0), freeSwap(0), - currentLoad(0), nProcesses(0), loadAvg1(0), loadAvg5(0), loadAvg15(0) {} + : RequestHandler(connection, requestId) {} }; } |