summaryrefslogtreecommitdiffstats
path: root/src/Daemon/RequestHandlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/Daemon/RequestHandlers')
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.cpp23
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.h4
2 files changed, 18 insertions, 9 deletions
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
index e49b0f5..c6750ba 100644
--- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
+++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
@@ -24,6 +24,8 @@
#include <Net/Connection.h>
#include <Net/Packets/ErrorPacket.h>
+#include <sigc++/bind.h>
+
namespace Mad {
namespace Daemon {
namespace RequestHandlers {
@@ -31,15 +33,17 @@ namespace RequestHandlers {
void CommandRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
// TODO Require authentication
- bool ret = false;
-
switch(packet.getType()) {
case Net::Packet::COMMAND_SHUTDOWN:
- ret = Common::SystemBackend::shutdown();
+ if(Common::SystemBackend::shutdown(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, packet.getRequestId())))
+ return;
+
break;
case Net::Packet::COMMAND_REBOOT:
- ret = Common::SystemBackend::reboot();
+ if(Common::SystemBackend::reboot(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, packet.getRequestId())))
+ return;
+
break;
default:
@@ -50,12 +54,13 @@ void CommandRequestHandler::handlePacket(Net::Connection *connection, const Net:
return;
}
- if(ret)
- connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()));
- else {
- connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::NOT_IMPLEMENTED)));
- }
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::NOT_IMPLEMENTED)));
+
+ signalFinished().emit();
+}
+void CommandRequestHandler::sendReply(Net::Connection *connection, uint16_t requestId) {
+ connection->send(Net::Packet(Net::Packet::OK, requestId));
signalFinished().emit();
}
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h
index cff6c10..5066c1d 100644
--- a/src/Daemon/RequestHandlers/CommandRequestHandler.h
+++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h
@@ -21,12 +21,16 @@
#define MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_
#include <Common/RequestHandler.h>
+#include <stdint.h>
namespace Mad {
namespace Daemon {
namespace RequestHandlers {
class CommandRequestHandler : public Common::RequestHandler {
+ private:
+ void sendReply(Net::Connection *connection, uint16_t requestId);
+
protected:
virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);