summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.cpp20
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.h6
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.cpp41
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.h6
-rw-r--r--src/Common/RequestManager.cpp4
-rw-r--r--src/Common/Requests/DisconnectRequest.cpp11
-rw-r--r--src/Common/Requests/DisconnectRequest.h8
-rw-r--r--src/Common/Requests/FSInfoRequest.cpp11
-rw-r--r--src/Common/Requests/FSInfoRequest.h9
-rw-r--r--src/Common/XmlPacket.h1
10 files changed, 78 insertions, 39 deletions
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
index 6a5ca99..346b6de 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
@@ -18,24 +18,34 @@
*/
#include "DisconnectRequestHandler.h"
+#include "../Exception.h"
#include "../Logger.h"
+#include "../XmlPacket.h"
#include <Net/Connection.h>
-#include <Net/Packets/ErrorPacket.h>
namespace Mad {
namespace Common {
namespace RequestHandlers {
-void DisconnectRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::DISCONNECT) {
+void DisconnectRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) {
+ if(packet.getType() != "Disconnect") {
Logger::log(Logger::ERROR, "Received an unexpected packet.");
- connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
+
+ XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+
+ connection->send(ret.encode(requestId));
signalFinished().emit();
return;
}
- connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()));
+ XmlPacket ret;
+ ret.setType("OK");
+
+ connection->send(ret.encode(requestId));
+
connection->disconnect();
signalFinished().emit();
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h
index f0ca85f..23d07dc 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.h
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h
@@ -20,15 +20,15 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_DISCONNECTREQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLERS_DISCONNECTREQUESTHANDLER_H_
-#include "../RequestHandler.h"
+#include "../XmlRequestHandler.h"
namespace Mad {
namespace Common {
namespace RequestHandlers {
-class DisconnectRequestHandler : public RequestHandler {
+class DisconnectRequestHandler : public XmlRequestHandler {
protected:
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet);
public:
DisconnectRequestHandler() {}
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();
}
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h
index 8de89ce..32e7a08 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.h
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h
@@ -20,7 +20,7 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
-#include "../RequestHandler.h"
+#include "../XmlRequestHandler.h"
#include "../SystemBackend.h"
#include <stdint.h>
@@ -29,7 +29,7 @@ namespace Mad {
namespace Common {
namespace RequestHandlers {
-class FSInfoRequestHandler : public RequestHandler {
+class FSInfoRequestHandler : public XmlRequestHandler {
private:
Net::Connection *connection;
uint16_t requestId;
@@ -37,7 +37,7 @@ class FSInfoRequestHandler : public RequestHandler {
void fsInfoHandler(const std::vector<SystemBackend::FSInfo> &info);
protected:
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *con, uint16_t rid, const XmlPacket &packet);
public:
FSInfoRequestHandler() {}
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index 6b1bf8f..afcfa4b 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -256,11 +256,11 @@ void RequestManager::unregisterPacketType(const std::string &type) {
}
RequestManager::RequestManager() : core(false), requestId(-1) {
- registerPacketType<RequestHandlers::DisconnectRequestHandler>(Net::Packet::DISCONNECT);
+ registerPacketType<RequestHandlers::DisconnectRequestHandler>("Disconnect");
}
RequestManager::~RequestManager() {
- unregisterPacketType(Net::Packet::DISCONNECT);
+ unregisterPacketType("Disconnect");
for(std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.begin(); it != requestMaps.end(); ++it)
delete it->second;
diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp
index d8e7ee9..afab8ed 100644
--- a/src/Common/Requests/DisconnectRequest.cpp
+++ b/src/Common/Requests/DisconnectRequest.cpp
@@ -25,18 +25,21 @@ namespace Common {
namespace Requests {
void DisconnectRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- connection->send(Net::Packet(Net::Packet::DISCONNECT, requestId));
+ XmlPacket packet;
+ packet.setType("Disconnect");
+
+ connection->send(packet.encode(requestId));
}
-void DisconnectRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::OK) {
+void DisconnectRequest::handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet) {
+ if(packet.getType() != "OK") {
finishWithError(Exception(Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
connection->disconnect();
- finish();
+ finish(packet);
}
}
diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h
index 602505a..4f2cdf5 100644
--- a/src/Common/Requests/DisconnectRequest.h
+++ b/src/Common/Requests/DisconnectRequest.h
@@ -20,19 +20,19 @@
#ifndef MAD_COMMON_REQUESTS_DISCONNECTREQUEST_H_
#define MAD_COMMON_REQUESTS_DISCONNECTREQUEST_H_
-#include "../Request.h"
+#include "../XmlRequest.h"
namespace Mad {
namespace Common {
namespace Requests {
-class DisconnectRequest : public Request<> {
+class DisconnectRequest : public XmlRequest {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet);
public:
- DisconnectRequest(slot_type slot) : Request<>(slot) {}
+ DisconnectRequest(slot_type slot) : XmlRequest(slot) {}
};
}
diff --git a/src/Common/Requests/FSInfoRequest.cpp b/src/Common/Requests/FSInfoRequest.cpp
index c8492ff..7b5574d 100644
--- a/src/Common/Requests/FSInfoRequest.cpp
+++ b/src/Common/Requests/FSInfoRequest.cpp
@@ -27,16 +27,19 @@ namespace Common {
namespace Requests {
void FSInfoRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- connection->send(Net::Packet(Net::Packet::FS_INFO, requestId));
+ XmlPacket packet;
+ packet.setType("FSInfo");
+
+ connection->send(packet.encode(requestId));
}
-void FSInfoRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::OK) {
+void FSInfoRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
+ if(packet.getType() != "OK") {
finishWithError(Exception(Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
- finish(Net::Packets::FSInfoPacket(packet));
+ finish(packet);
}
}
diff --git a/src/Common/Requests/FSInfoRequest.h b/src/Common/Requests/FSInfoRequest.h
index 9ae7673..9a6ba14 100644
--- a/src/Common/Requests/FSInfoRequest.h
+++ b/src/Common/Requests/FSInfoRequest.h
@@ -20,20 +20,19 @@
#ifndef MAD_COMMON_REQUESTS_FSINFOREQUEST_H_
#define MAD_COMMON_REQUESTS_FSINFOREQUEST_H_
-#include "../Request.h"
-#include <Net/Packets/FSInfoPacket.h>
+#include "../XmlRequest.h"
namespace Mad {
namespace Common {
namespace Requests {
-class FSInfoRequest : public Request<Net::Packets::FSInfoPacket> {
+class FSInfoRequest : public XmlRequest {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
- FSInfoRequest(slot_type slot) : Request<Net::Packets::FSInfoPacket>(slot) {}
+ FSInfoRequest(slot_type slot) : XmlRequest(slot) {}
};
}
diff --git a/src/Common/XmlPacket.h b/src/Common/XmlPacket.h
index e80a266..e32893a 100644
--- a/src/Common/XmlPacket.h
+++ b/src/Common/XmlPacket.h
@@ -234,7 +234,6 @@ class XmlPacket {
static Element nilElement;
- private:
bool add(const std::string &name, const std::string &value, const char *type) {
if(!entryNode)
return false;