diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-06-06 17:43:47 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-06-06 17:43:47 +0200 |
commit | fcdd58703e3f5a0f6e77fd74e0304038e7cd4d3e (patch) | |
tree | 6956263f5ee93680ba730bb6b522e195000b2543 /src/Daemon | |
parent | 454cfccd51e2b9ad453fe79df04360fcd6eeb742 (diff) | |
download | mad-fcdd58703e3f5a0f6e77fd74e0304038e7cd4d3e.tar mad-fcdd58703e3f5a0f6e77fd74e0304038e7cd4d3e.zip |
RequestHandler-Klassen vereinfacht
Diffstat (limited to 'src/Daemon')
-rw-r--r-- | src/Daemon/RequestHandlers/CommandRequestHandler.cpp | 41 | ||||
-rw-r--r-- | src/Daemon/RequestHandlers/CommandRequestHandler.h | 11 |
2 files changed, 13 insertions, 39 deletions
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 <Net/Exception.h> -#include <Common/Logger.h> #include <Common/SystemManager.h> namespace Mad { namespace Daemon { namespace RequestHandlers { -void CommandRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> 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<const Common::XmlPacket> 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 <Common/RequestHandler.h> +#include <Common/RequestHandlers/SimpleRequestHandler.h> namespace Mad { namespace Daemon { namespace RequestHandlers { -class CommandRequestHandler : public Common::RequestHandler { - protected: - virtual void handlePacket(boost::shared_ptr<const Common::XmlPacket> packet); +class CommandRequestHandler : public Common::RequestHandlers::SimpleRequestHandler { + private: + static void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); + + public: + CommandRequestHandler() : Common::RequestHandlers::SimpleRequestHandler("Command", &CommandRequestHandler::handleRequest) {} }; } |