From 426d60a6992259ca80431c59e916073cc31f5261 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 3 Oct 2008 01:30:27 +0200 Subject: Callback-basierte SystemBackends f?r h?here Flexibilit?t --- .../RequestHandlers/CommandRequestHandler.cpp | 23 +++++++++++++--------- src/Daemon/RequestHandlers/CommandRequestHandler.h | 4 ++++ 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src/Daemon') 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 #include +#include + 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 +#include 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); -- cgit v1.2.3