summaryrefslogtreecommitdiffstats
path: root/src/Core/RequestHandlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core/RequestHandlers')
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.cpp30
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.h6
2 files changed, 27 insertions, 9 deletions
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
index dcf9f53..c20627f 100644
--- a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
+++ b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
@@ -20,18 +20,22 @@
#include "DaemonListRequestHandler.h"
#include "../ConnectionManager.h"
#include <Common/Logger.h>
+#include <Common/XmlPacket.h>
#include <Net/Connection.h>
-#include <Net/Packets/ErrorPacket.h>
-#include <Net/Packets/HostListPacket.h>
namespace Mad {
namespace Core {
namespace RequestHandlers {
-void DaemonListRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::LIST_DAEMONS) {
+void DaemonListRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+ if(packet.getType() != "ListHosts") {
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(requestId));
signalFinished().emit();
return;
@@ -39,7 +43,21 @@ void DaemonListRequestHandler::handlePacket(Net::Connection *connection, const N
// TODO Require authentication
- connection->send(Net::Packets::HostListPacket(Net::Packet::OK, packet.getRequestId(), ConnectionManager::get()->getDaemonList()));
+ Common::XmlPacket ret;
+ ret.setType("OK");
+ ret.addList("hosts");
+
+ std::vector<Common::HostInfo> daemons = ConnectionManager::get()->getDaemonList();
+
+ for(std::vector<Common::HostInfo>::iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) {
+ ret["hosts"].addEntry();
+
+ ret["hosts"].back().add("name", daemon->getName());
+ ret["hosts"].back().add("address", daemon->getIP());
+ ret["hosts"].back().add("state", daemon->getState());
+ }
+
+ connection->send(ret.encode(requestId));
signalFinished().emit();
}
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.h b/src/Core/RequestHandlers/DaemonListRequestHandler.h
index 205ad02..6fe2517 100644
--- a/src/Core/RequestHandlers/DaemonListRequestHandler.h
+++ b/src/Core/RequestHandlers/DaemonListRequestHandler.h
@@ -20,15 +20,15 @@
#ifndef MAD_CORE_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_
#define MAD_CORE_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_
-#include <Common/RequestHandler.h>
+#include <Common/XmlRequestHandler.h>
namespace Mad {
namespace Core {
namespace RequestHandlers {
-class DaemonListRequestHandler : public Common::RequestHandler {
+class DaemonListRequestHandler : public Common::XmlRequestHandler {
protected:
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet);
public:
DaemonListRequestHandler() {}