diff options
Diffstat (limited to 'src/Common/RequestHandlers')
6 files changed, 22 insertions, 34 deletions
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp index 346b6de..031853a 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp @@ -20,14 +20,13 @@ #include "DisconnectRequestHandler.h" #include "../Exception.h" #include "../Logger.h" -#include "../XmlPacket.h" #include <Net/Connection.h> namespace Mad { namespace Common { namespace RequestHandlers { -void DisconnectRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) { +void DisconnectRequestHandler::handlePacket(const XmlPacket &packet) { if(packet.getType() != "Disconnect") { Logger::log(Logger::ERROR, "Received an unexpected packet."); @@ -35,7 +34,7 @@ void DisconnectRequestHandler::handlePacket(Net::Connection *connection, uint16_ ret.setType("Error"); ret.add("ErrorCode", Exception::UNEXPECTED_PACKET); - connection->send(ret.encode(requestId)); + sendPacket(ret); signalFinished().emit(); return; @@ -44,9 +43,10 @@ void DisconnectRequestHandler::handlePacket(Net::Connection *connection, uint16_ XmlPacket ret; ret.setType("OK"); - connection->send(ret.encode(requestId)); + sendPacket(ret); - connection->disconnect(); + + getConnection()->disconnect(); signalFinished().emit(); } diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h index 7544fd8..b90c96e 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.h +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h @@ -28,10 +28,11 @@ namespace RequestHandlers { class DisconnectRequestHandler : public RequestHandler { protected: - virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet); + virtual void handlePacket(const XmlPacket &packet); public: - DisconnectRequestHandler() {} + DisconnectRequestHandler(Net::Connection *connection, uint16_t requestId) + : RequestHandler(connection, requestId) {} }; } diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp index 878dd7c..aaa4d9e 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp @@ -20,14 +20,12 @@ #include "FSInfoRequestHandler.h" #include "../Exception.h" #include "../Logger.h" -#include "../XmlPacket.h" -#include <Net/Connection.h> namespace Mad { namespace Common { namespace RequestHandlers { -void FSInfoRequestHandler::handlePacket(Net::Connection *con, uint16_t rid, const XmlPacket &packet) { +void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) { if(packet.getType() != "FSInfo") { Logger::log(Logger::ERROR, "Received an unexpected packet."); @@ -35,7 +33,7 @@ void FSInfoRequestHandler::handlePacket(Net::Connection *con, uint16_t rid, cons ret.setType("Error"); ret.add("ErrorCode", Exception::UNEXPECTED_PACKET); - connection->send(ret.encode(rid)); + sendPacket(ret); signalFinished().emit(); return; @@ -43,15 +41,12 @@ void FSInfoRequestHandler::handlePacket(Net::Connection *con, uint16_t rid, cons // TODO Require authentication - connection = con; - requestId = rid; - if(!SystemBackend::getFSInfo(sigc::mem_fun(this, &FSInfoRequestHandler::fsInfoHandler))) { XmlPacket ret; ret.setType("Error"); ret.add("ErrorCode", Exception::NOT_IMPLEMENTED); - connection->send(ret.encode(requestId)); + sendPacket(ret); signalFinished().emit(); } @@ -73,7 +68,7 @@ void FSInfoRequestHandler::fsInfoHandler(const std::vector<SystemBackend::FSInfo entry.add("availableSize", fs->available); } - connection->send(ret.encode(requestId)); + sendPacket(ret); signalFinished().emit(); } diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h index a9ee120..6fcf524 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.h +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h @@ -31,16 +31,14 @@ namespace RequestHandlers { class FSInfoRequestHandler : public RequestHandler { private: - Net::Connection *connection; - uint16_t requestId; - void fsInfoHandler(const std::vector<SystemBackend::FSInfo> &info); protected: - virtual void handlePacket(Net::Connection *con, uint16_t rid, const XmlPacket &packet); + virtual void handlePacket(const XmlPacket &packet); public: - FSInfoRequestHandler() {} + FSInfoRequestHandler(Net::Connection *connection, uint16_t requestId) + : RequestHandler(connection, requestId) {} }; } diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index 86ed970..e03c345 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -21,14 +21,12 @@ #include "../Exception.h" #include "../SystemBackend.h" #include "../Logger.h" -#include "../XmlPacket.h" -#include <Net/Connection.h> namespace Mad { namespace Common { namespace RequestHandlers { -void StatusRequestHandler::handlePacket(Net::Connection *con, uint16_t requestId, const XmlPacket &packet) { +void StatusRequestHandler::handlePacket(const XmlPacket &packet) { if(packet.getType() != "GetStatus") { Logger::log(Logger::ERROR, "Received an unexpected packet."); @@ -36,7 +34,7 @@ void StatusRequestHandler::handlePacket(Net::Connection *con, uint16_t requestId ret.setType("Error"); ret.add("ErrorCode", Exception::UNEXPECTED_PACKET); - con->send(ret.encode(requestId)); + sendPacket(ret); signalFinished().emit(); return; @@ -44,9 +42,6 @@ void StatusRequestHandler::handlePacket(Net::Connection *con, uint16_t requestId // TODO Require authentication - connection = con; - rid = requestId; - if(!SystemBackend::getUptimeInfo(sigc::mem_fun(this, &StatusRequestHandler::uptimeHandler))) needUptime = false; if(!SystemBackend::getMemoryInfo(sigc::mem_fun(this, &StatusRequestHandler::memoryHandler))) @@ -77,7 +72,7 @@ void StatusRequestHandler::send() { packet.add("loadAvg5", loadAvg5); packet.add("loadAvg15", loadAvg15); - connection->send(packet.encode(rid)); + sendPacket(packet); sent = true; diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h index ce7ae6d..ddaaae4 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.h +++ b/src/Common/RequestHandlers/StatusRequestHandler.h @@ -29,9 +29,6 @@ namespace RequestHandlers { class StatusRequestHandler : public RequestHandler { private: - Net::Connection *connection; - uint16_t rid; - bool needUptime, needMemory, needLoad, sent; unsigned long uptime, idleTime; @@ -60,10 +57,12 @@ class StatusRequestHandler : public RequestHandler { void send(); protected: - virtual void handlePacket(Net::Connection *con, uint16_t requestId, const XmlPacket &packet); + virtual void handlePacket(const XmlPacket &packet); public: - StatusRequestHandler() : needUptime(true), needMemory(true), needLoad(true), sent(false), + StatusRequestHandler(Net::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) {} }; |