From fcdd58703e3f5a0f6e77fd74e0304038e7cd4d3e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 6 Jun 2009 17:43:47 +0200 Subject: RequestHandler-Klassen vereinfacht --- .../RequestHandlers/CommandRequestHandler.cpp | 41 ++++------------------ src/Daemon/RequestHandlers/CommandRequestHandler.h | 11 +++--- 2 files changed, 13 insertions(+), 39 deletions(-) (limited to 'src/Daemon/RequestHandlers') diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp index 208d6e0..d00c415 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp @@ -18,53 +18,24 @@ */ #include "CommandRequestHandler.h" -#include -#include #include namespace Mad { namespace Daemon { namespace RequestHandlers { -void CommandRequestHandler::handlePacket(boost::shared_ptr packet) { - if(packet->getType() != "Command") { - Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); - - Common::XmlPacket ret; - ret.setType("Error"); - ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET); - - sendPacket(ret); - - signalFinished(); - return; - } - +void CommandRequestHandler::handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret) { // TODO Require authentication // TODO Error handling std::string command = (*packet)["command"]; - Common::XmlPacket ret; - - try { - if(command == "reboot") - Common::SystemManager::get()->shutdown(); - else - Common::SystemManager::get()->reboot(); - - ret.setType("OK"); - } - catch(Net::Exception e) { - ret.setType("Error"); - ret.add("ErrorCode", e.getErrorCode()); - ret.add("SubCode", e.getSubCode()); - ret.add("SubSubCode", e.getSubSubCode()); - ret.add("Where", e.getWhere()); - } + if(command == "reboot") + Common::SystemManager::get()->reboot(); + else + Common::SystemManager::get()->shutdown(); - sendPacket(ret); - signalFinished(); + ret->setType("OK"); } } diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h index be560f7..22c7a4b 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.h +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h @@ -20,15 +20,18 @@ #ifndef MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_ #define MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_ -#include +#include namespace Mad { namespace Daemon { namespace RequestHandlers { -class CommandRequestHandler : public Common::RequestHandler { - protected: - virtual void handlePacket(boost::shared_ptr packet); +class CommandRequestHandler : public Common::RequestHandlers::SimpleRequestHandler { + private: + static void handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret); + + public: + CommandRequestHandler() : Common::RequestHandlers::SimpleRequestHandler("Command", &CommandRequestHandler::handleRequest) {} }; } -- cgit v1.2.3