summaryrefslogtreecommitdiffstats
path: root/src/Daemon
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-10-03 01:30:27 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-10-03 01:30:27 +0200
commit426d60a6992259ca80431c59e916073cc31f5261 (patch)
treece88e01006e91ce4c159afc645777f9b458110b3 /src/Daemon
parent2f5eba3ce1bddf30b23444042f955adc10d84855 (diff)
downloadmad-426d60a6992259ca80431c59e916073cc31f5261.tar
mad-426d60a6992259ca80431c59e916073cc31f5261.zip
Callback-basierte SystemBackends f?r h?here Flexibilit?t
Diffstat (limited to 'src/Daemon')
-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);