diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-03-16 19:13:42 +0100 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-03-16 19:13:42 +0100 |
commit | 8f098fc3070f791302ec1f497588fab6ed409980 (patch) | |
tree | 6cff9f7bb973342344a22636a5d9ef26c7a0d940 /src/Daemon/RequestHandlers | |
parent | aef0f2e7a5085b8da3aa2e97565215d182d3dd2d (diff) | |
download | mad-8f098fc3070f791302ec1f497588fab6ed409980.tar mad-8f098fc3070f791302ec1f497588fab6ed409980.zip |
Request- und RequestHandler-Interfaces vereinfacht
Diffstat (limited to 'src/Daemon/RequestHandlers')
-rw-r--r-- | src/Daemon/RequestHandlers/CommandRequestHandler.cpp | 18 | ||||
-rw-r--r-- | src/Daemon/RequestHandlers/CommandRequestHandler.h | 7 |
2 files changed, 11 insertions, 14 deletions
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp index 3f4ef17..b0856c1 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp @@ -21,16 +21,12 @@ #include <Common/Exception.h> #include <Common/Logger.h> #include <Common/SystemBackend.h> -#include <Common/XmlPacket.h> -#include <Net/Connection.h> - -#include <sigc++/bind.h> namespace Mad { namespace Daemon { namespace RequestHandlers { -void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) { +void CommandRequestHandler::handlePacket(const Common::XmlPacket &packet) { if(packet.getType() != "Command") { Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); @@ -38,7 +34,7 @@ void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t r ret.setType("Error"); ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET); - connection->send(ret.encode(requestId)); + sendPacket(ret); signalFinished().emit(); return; @@ -50,11 +46,11 @@ void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t r std::string command = packet["command"]; if(command == "reboot") { - if(Common::SystemBackend::shutdown(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, requestId))) + if(Common::SystemBackend::shutdown(sigc::mem_fun(this, &CommandRequestHandler::sendReply))) return; } else { - if(Common::SystemBackend::reboot(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, requestId))) + if(Common::SystemBackend::reboot(sigc::mem_fun(this, &CommandRequestHandler::sendReply))) return; } @@ -62,16 +58,16 @@ void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t r ret.setType("Error"); ret.add("ErrorCode", Common::Exception::NOT_IMPLEMENTED); - connection->send(ret.encode(requestId)); + sendPacket(ret); signalFinished().emit(); } -void CommandRequestHandler::sendReply(Net::Connection *connection, uint16_t requestId) { +void CommandRequestHandler::sendReply() { Common::XmlPacket packet; packet.setType("OK"); - connection->send(packet.encode(requestId)); + sendPacket(packet); signalFinished().emit(); } diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h index 408dbcf..230a8f5 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.h +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h @@ -29,13 +29,14 @@ namespace RequestHandlers { class CommandRequestHandler : public Common::RequestHandler { private: - void sendReply(Net::Connection *connection, uint16_t requestId); + void sendReply(); protected: - virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet); + virtual void handlePacket(const Common::XmlPacket &packet); public: - CommandRequestHandler() {} + CommandRequestHandler(Net::Connection *connection, uint16_t requestId) + : RequestHandler(connection, requestId) {} }; } |