summaryrefslogtreecommitdiffstats
path: root/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/RequestHandlers/FSInfoRequestHandler.cpp')
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.cpp41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
index 5d71277..878dd7c 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
@@ -18,19 +18,24 @@
*/
#include "FSInfoRequestHandler.h"
+#include "../Exception.h"
#include "../Logger.h"
+#include "../XmlPacket.h"
#include <Net/Connection.h>
-#include <Net/Packets/ErrorPacket.h>
-#include <Net/Packets/FSInfoPacket.h>
namespace Mad {
namespace Common {
namespace RequestHandlers {
-void FSInfoRequestHandler::handlePacket(Net::Connection *con, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::FS_INFO) {
+void FSInfoRequestHandler::handlePacket(Net::Connection *con, uint16_t rid, const XmlPacket &packet) {
+ if(packet.getType() != "FSInfo") {
Logger::log(Logger::ERROR, "Received an unexpected packet.");
- con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::UNEXPECTED_PACKET)));
+
+ XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+
+ connection->send(ret.encode(rid));
signalFinished().emit();
return;
@@ -39,16 +44,36 @@ void FSInfoRequestHandler::handlePacket(Net::Connection *con, const Net::Packet
// TODO Require authentication
connection = con;
- requestId = packet.getRequestId();
+ requestId = rid;
if(!SystemBackend::getFSInfo(sigc::mem_fun(this, &FSInfoRequestHandler::fsInfoHandler))) {
- con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::NOT_IMPLEMENTED)));
+ XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Exception::NOT_IMPLEMENTED);
+
+ connection->send(ret.encode(requestId));
+
signalFinished().emit();
}
}
void FSInfoRequestHandler::fsInfoHandler(const std::vector<SystemBackend::FSInfo> &info) {
- connection->send(Net::Packets::FSInfoPacket(Net::Packet::OK, requestId, info));
+ XmlPacket ret;
+ ret.setType("OK");
+ ret.addList("filesystems");
+
+ for(std::vector<SystemBackend::FSInfo>::const_iterator fs = info.begin(); fs != info.end(); ++fs) {
+ ret["filesystems"].addEntry();
+ XmlPacket::Entry &entry = ret["filesystems"].back();
+
+ entry.add("name", fs->fsName);
+ entry.add("mountedOn", fs->mountedOn);
+ entry.add("totalSize", fs->total);
+ entry.add("usedSize", fs->used);
+ entry.add("availableSize", fs->available);
+ }
+
+ connection->send(ret.encode(requestId));
signalFinished().emit();
}