diff options
Diffstat (limited to 'src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp')
-rw-r--r-- | src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp index 3d371a9..c0e4b9f 100644 --- a/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp +++ b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp @@ -21,18 +21,21 @@ #include "../ConnectionManager.h" #include <Common/Logger.h> #include <Common/Requests/FSInfoRequest.h> -#include <Net/Packets/ErrorPacket.h> -#include <Net/Packets/FSInfoPacket.h> namespace Mad { namespace Core { namespace RequestHandlers { -void DaemonFSInfoRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::DAEMON_FS_INFO) { +void DaemonFSInfoRequestHandler::handlePacket(Net::Connection *connection, uint16_t rid, const Common::XmlPacket &packet) { + if(packet.getType() != "DaemonFSInfo") { Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); - connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + Common::XmlPacket ret; + ret.setType("Error"); + ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET); + + connection->send(ret.encode(rid)); signalFinished().emit(); return; @@ -41,26 +44,38 @@ void DaemonFSInfoRequestHandler::handlePacket(Net::Connection *connection, const // TODO Require authentication con = connection; - requestId = packet.getRequestId(); - - std::string daemonName((char*)packet.getData(), packet.getLength()); + requestId = rid; try { - Net::Connection *daemonCon = ConnectionManager::get()->getDaemonConnection(daemonName); - Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr<Common::RequestBase>(new Common::Requests::FSInfoRequest(sigc::mem_fun(this, &DaemonFSInfoRequestHandler::requestFinished)))); + Net::Connection *daemonCon = ConnectionManager::get()->getDaemonConnection(packet["daemon"]); + Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr<Common::XmlRequest>(new Common::Requests::FSInfoRequest(sigc::mem_fun(this, &DaemonFSInfoRequestHandler::requestFinished)))); } catch(Common::Exception &e) { - connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e)); + 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()); + + con->send(ret.encode(requestId)); } } -void DaemonFSInfoRequestHandler::requestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request) { +void DaemonFSInfoRequestHandler::requestFinished(const Common::XmlRequest &request) { try { - const Net::Packet &packet = request.getResult(); - con->send(Net::Packet(Net::Packet::OK, requestId, packet.getData(), packet.getLength())); + const Common::XmlPacket &packet = request.getResult(); + con->send(packet.encode(requestId)); } catch(Common::Exception &e) { - con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, requestId, e)); + 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()); + + con->send(ret.encode(requestId)); } signalFinished().emit(); |