summaryrefslogtreecommitdiffstats
path: root/src/Common/RequestHandlers
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-16 01:20:43 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-16 01:20:43 +0200
commitcc35771abf4fc7e0dd472bd818ff2b4962c7e204 (patch)
tree682bc38ffbf5954a93b1967a700f40bd78038ee4 /src/Common/RequestHandlers
parent2226256eedb2849f387ff566893a91bf5da3cdc9 (diff)
downloadmad-cc35771abf4fc7e0dd472bd818ff2b4962c7e204.tar
mad-cc35771abf4fc7e0dd472bd818ff2b4962c7e204.zip
Bessere Fehlerbehandlung
Diffstat (limited to 'src/Common/RequestHandlers')
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.cpp18
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.h2
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.cpp21
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.h2
4 files changed, 26 insertions, 17 deletions
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
index aa98c04..010f1e7 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
@@ -19,23 +19,27 @@
#include "DisconnectRequestHandler.h"
#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
+
+#include <iostream>
namespace Mad {
namespace Common {
namespace RequestHandlers {
-bool DisconnectRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::DISCONNECT)
- return false; // TODO Logging
+void DisconnectRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::DISCONNECT) {
+ std::cerr << "Received an unexpected packet." << std::endl;
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
- if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())))
- return false;
+ signalFinished().emit();
+ return;
+ }
+ connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()));
connection->disconnect();
signalFinished().emit();
-
- return true;
}
}
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h
index 784700d..b4da634 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.h
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h
@@ -30,7 +30,7 @@ class DisconnectRequestHandler : public RequestHandler {
public:
DisconnectRequestHandler() {}
- virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
};
}
diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp
index 0a437fa..bcff6b6 100644
--- a/src/Common/RequestHandlers/StatusRequestHandler.cpp
+++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp
@@ -20,28 +20,33 @@
#include "StatusRequestHandler.h"
#include "../SystemBackend.h"
#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
#include <Net/Packets/HostStatusPacket.h>
+#include <iostream>
+
namespace Mad {
namespace Common {
namespace RequestHandlers {
-bool StatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::STATUS)
- return false; // TODO Logging
+void StatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::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
SystemBackend::UptimeInfo uptimeInfo = SystemBackend::getBackend()->getUptimeInfo();
SystemBackend::MemoryInfo memInfo = SystemBackend::getBackend()->getMemoryInfo();
- if(!connection->send(Net::Packets::HostStatusPacket(Net::Packet::OK, packet.getRequestId(), uptimeInfo.uptime, uptimeInfo.idleTime,
- memInfo.totalMem, memInfo.freeMem, memInfo.totalSwap, memInfo.freeSwap)))
- return false;
+ connection->send(Net::Packets::HostStatusPacket(Net::Packet::OK, packet.getRequestId(), uptimeInfo.uptime, uptimeInfo.idleTime,
+ memInfo.totalMem, memInfo.freeMem, memInfo.totalSwap, memInfo.freeSwap));
signalFinished().emit();
-
- return true;
}
}
diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h
index db2176a..f98a9a4 100644
--- a/src/Common/RequestHandlers/StatusRequestHandler.h
+++ b/src/Common/RequestHandlers/StatusRequestHandler.h
@@ -30,7 +30,7 @@ class StatusRequestHandler : public RequestHandler {
public:
StatusRequestHandler() {}
- virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
};
}