summaryrefslogtreecommitdiffstats
path: root/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core/RequestHandlers/DaemonListRequestHandler.cpp')
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.cpp30
1 files changed, 24 insertions, 6 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();
}