summaryrefslogtreecommitdiffstats
path: root/src/Client/Requests
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client/Requests')
-rw-r--r--src/Client/Requests/DaemonCommandRequest.cpp19
-rw-r--r--src/Client/Requests/DaemonCommandRequest.h8
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.cpp16
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.h9
4 files changed, 30 insertions, 22 deletions
diff --git a/src/Client/Requests/DaemonCommandRequest.cpp b/src/Client/Requests/DaemonCommandRequest.cpp
index d27c3fb..6e82c60 100644
--- a/src/Client/Requests/DaemonCommandRequest.cpp
+++ b/src/Client/Requests/DaemonCommandRequest.cpp
@@ -18,28 +18,33 @@
*/
#include "DaemonCommandRequest.h"
+#include <Common/XmlPacket.h>
#include <Net/Connection.h>
-#include <Net/Packets/ErrorPacket.h>
namespace Mad {
namespace Client {
namespace Requests {
void DaemonCommandRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- connection->send(Net::Packet(reboot ? Net::Packet::DAEMON_COMMAND_REBOOT : Net::Packet::DAEMON_COMMAND_SHUTDOWN, requestId, daemon.c_str(), daemon.length()));
+ Common::XmlPacket packet;
+ packet.setType("DaemonCommand");
+ packet.add("command", reboot ? "reboot" : "shutdown");
+ packet.add("daemon", daemon);
+
+ connection->send(packet.encode(requestId));
}
-void DaemonCommandRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(packet.getType() == Net::Packet::ERROR) {
- finishWithError(Net::Packets::ErrorPacket(packet).getException());
+void DaemonCommandRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
+ if(packet.getType() == "Error") {
+ finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
return;
}
- else if(packet.getType() != Net::Packet::OK) {
+ else if(packet.getType() != "OK") {
finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
- finish();
+ finish(packet);
}
}
diff --git a/src/Client/Requests/DaemonCommandRequest.h b/src/Client/Requests/DaemonCommandRequest.h
index 439462f..8575123 100644
--- a/src/Client/Requests/DaemonCommandRequest.h
+++ b/src/Client/Requests/DaemonCommandRequest.h
@@ -20,24 +20,24 @@
#ifndef MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_
#define MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_
-#include <Common/Request.h>
+#include <Common/XmlRequest.h>
#include <string>
namespace Mad {
namespace Client {
namespace Requests {
-class DaemonCommandRequest : public Common::Request<> {
+class DaemonCommandRequest : public Common::XmlRequest {
private:
std::string daemon;
bool reboot;
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:
- DaemonCommandRequest(const std::string &daemon0, bool reboot0, slot_type slot) : Common::Request<>(slot), daemon(daemon0), reboot(reboot0) {}
+ DaemonCommandRequest(const std::string &daemon0, bool reboot0, slot_type slot) : Common::XmlRequest(slot), daemon(daemon0), reboot(reboot0) {}
};
}
diff --git a/src/Client/Requests/DaemonFSInfoRequest.cpp b/src/Client/Requests/DaemonFSInfoRequest.cpp
index eb26cf4..e179f46 100644
--- a/src/Client/Requests/DaemonFSInfoRequest.cpp
+++ b/src/Client/Requests/DaemonFSInfoRequest.cpp
@@ -26,20 +26,24 @@ namespace Client {
namespace Requests {
void DaemonFSInfoRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- connection->send(Net::Packet(Net::Packet::DAEMON_FS_INFO, requestId, daemon.c_str(), daemon.length()));
+ Common::XmlPacket packet;
+ packet.setType("DaemonFSInfo");
+ packet.add("daemon", daemon);
+
+ connection->send(packet.encode(requestId));
}
-void DaemonFSInfoRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(packet.getType() == Net::Packet::ERROR) {
- finishWithError(Net::Packets::ErrorPacket(packet).getException());
+void DaemonFSInfoRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
+ if(packet.getType() == "Error") {
+ finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
return;
}
- else if(packet.getType() != Net::Packet::OK) {
+ else if(packet.getType() != "OK") {
finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
- finish(Net::Packets::FSInfoPacket(packet));
+ finish(packet);
}
}
diff --git a/src/Client/Requests/DaemonFSInfoRequest.h b/src/Client/Requests/DaemonFSInfoRequest.h
index d966b8d..48a201f 100644
--- a/src/Client/Requests/DaemonFSInfoRequest.h
+++ b/src/Client/Requests/DaemonFSInfoRequest.h
@@ -20,8 +20,7 @@
#ifndef MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_
#define MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_
-#include <Common/Request.h>
-#include <Net/Packets/FSInfoPacket.h>
+#include <Common/XmlRequest.h>
#include <string>
@@ -29,16 +28,16 @@ namespace Mad {
namespace Client {
namespace Requests {
-class DaemonFSInfoRequest : public Common::Request<Net::Packets::FSInfoPacket> {
+class DaemonFSInfoRequest : public Common::XmlRequest {
private:
std::string daemon;
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:
- DaemonFSInfoRequest(const std::string &daemon0, slot_type slot) : Common::Request<Net::Packets::FSInfoPacket>(slot), daemon(daemon0) {}
+ DaemonFSInfoRequest(const std::string &daemon0, slot_type slot) : Common::XmlRequest(slot), daemon(daemon0) {}
};
}