summaryrefslogtreecommitdiffstats
path: root/src/Daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/Daemon')
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.cpp41
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.h11
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) {}
};
}