summaryrefslogtreecommitdiffstats
path: root/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp')
-rw-r--r--src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
index 0179ecc..bb5d45f 100644
--- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
+++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
@@ -20,15 +20,24 @@
#include "DaemonStatusRequestHandler.h"
#include "../ConnectionManager.h"
#include <Core/Requests/DaemonStatusRequest.h>
+#include <Net/Packets/ErrorPacket.h>
#include <Net/Packets/HostStatusPacket.h>
+#include <iostream>
+
+
namespace Mad {
namespace Core {
namespace RequestHandlers {
-bool DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::DAEMON_STATUS)
- return false; // TODO Logging
+void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::DAEMON_STATUS) {
+ std::cerr << "Received an unexpected packet." << std::endl;
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
+
+ signalFinished().emit();
+ return;
+ }
// TODO Require authentication
@@ -37,13 +46,13 @@ bool DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const
std::string daemonName((char*)packet.getData(), packet.getLength());
- Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName);
- if(!daemonCon)
- return false;
-
- Requests::DaemonStatusRequest::send(daemonCon, sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished));
-
- return true;
+ try {
+ Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName);
+ Requests::DaemonStatusRequest::send(daemonCon, sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished));
+ }
+ catch(Common::Exception &e) {
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e));
+ }
}
void DaemonStatusRequestHandler::requestFinished(const Net::Packets::HostStatusPacket &packet) {