From 0b27c37fe95c6aced613d51a3624f8930a96ad3f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 4 Jun 2009 22:23:07 +0200 Subject: RequestHandler-Interface ?berarbeitet --- .../DaemonCommandRequestHandler.cpp | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/Server/RequestHandlers/DaemonCommandRequestHandler.cpp') diff --git a/src/Server/RequestHandlers/DaemonCommandRequestHandler.cpp b/src/Server/RequestHandlers/DaemonCommandRequestHandler.cpp index 0a7bd39..65592a1 100644 --- a/src/Server/RequestHandlers/DaemonCommandRequestHandler.cpp +++ b/src/Server/RequestHandlers/DaemonCommandRequestHandler.cpp @@ -27,8 +27,8 @@ namespace Mad { namespace Server { namespace RequestHandlers { -void DaemonCommandRequestHandler::handlePacket(const Common::XmlPacket &packet) { - if(packet.getType() != "DaemonCommand") { +void DaemonCommandRequestHandler::handlePacket(boost::shared_ptr packet) { + if(packet->getType() != "DaemonCommand") { Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); Common::XmlPacket ret; @@ -43,12 +43,14 @@ void DaemonCommandRequestHandler::handlePacket(const Common::XmlPacket &packet) // TODO Require authentication - std::string command = packet["command"]; + std::string command = (*packet)["command"]; try { - boost::shared_ptr daemonCon = ConnectionManager::get()->getDaemonConnection(packet["daemon"]); - Common::RequestManager::get()->sendRequest1(daemonCon.get(), - command == "reboot", boost::bind(&DaemonCommandRequestHandler::requestFinished, this, _1)); + boost::shared_ptr daemonCon = ConnectionManager::get()->getDaemonConnection((*packet)["daemon"]); + + boost::shared_ptr request(new Requests::CommandRequest(command == "reboot")); + request->connectSignalFinished(boost::bind(&DaemonCommandRequestHandler::requestFinished, this, _1, _2)); + Common::RequestManager::get()->sendRequest(daemonCon.get(), request); } catch(Net::Exception &e) { Common::XmlPacket ret; @@ -62,20 +64,20 @@ void DaemonCommandRequestHandler::handlePacket(const Common::XmlPacket &packet) } } -void DaemonCommandRequestHandler::requestFinished(Common::Request &request) { - try { - sendPacket(request.getResult()); - } - catch(Net::Exception &e) { +void DaemonCommandRequestHandler::requestFinished(boost::shared_ptr packet, Net::Exception error) { + if(error) { Common::XmlPacket ret; ret.setType("Error"); - ret.add("ErrorCode", e.getErrorCode()); - ret.add("SubCode", e.getSubCode()); - ret.add("SubSubCode", e.getSubSubCode()); - ret.add("Where", e.getWhere()); + ret.add("ErrorCode", error.getErrorCode()); + ret.add("SubCode", error.getSubCode()); + ret.add("SubSubCode", error.getSubSubCode()); + ret.add("Where", error.getWhere()); sendPacket(ret); } + else { + sendPacket(*packet); + } signalFinished(); } -- cgit v1.2.3