summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-03-01 00:51:00 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-03-01 00:51:00 +0100
commit63907817cb057f497f03a28016d408885cbe41ea (patch)
treea9ad6b0b19bff7722b21375137ba6e53c8869c91 /src/Client
parent46c110f7a14e4b5d0e8bd27259f7744ae8a36382 (diff)
downloadmad-63907817cb057f497f03a28016d408885cbe41ea.tar
mad-63907817cb057f497f03a28016d408885cbe41ea.zip
Alle uebrigen Requests ausser GSSAPIAuthRequest in XmlRequests umgewandelt
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandManager.cpp31
-rw-r--r--src/Client/CommandManager.h18
-rw-r--r--src/Client/CommandParser.cpp10
-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
7 files changed, 57 insertions, 54 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp
index d98b041..59de7c4 100644
--- a/src/Client/CommandManager.cpp
+++ b/src/Client/CommandManager.cpp
@@ -21,7 +21,6 @@
#include <Common/HostInfo.h>
#include <Common/Logger.h>
#include <Common/XmlRequest.h>
-#include <Net/Packets/FSInfoPacket.h>
#include <cmath>
#include <iostream>
@@ -34,19 +33,19 @@ namespace Client {
CommandManager CommandManager::commandManager;
-void CommandManager::printFSInfo(const Net::Packets::FSInfoPacket &packet) {
+void CommandManager::printFSInfo(const Common::XmlPacket &packet) {
const std::string units[] = {
"kB", "MB", "GB", "TB", ""
};
- const std::vector<Common::SystemBackend::FSInfo>& fsList = packet.getFSInfo();
+ for(size_t i = 0; i < packet["filesystems"].getSize(); ++i) {
+ const Common::XmlPacket::Entry &fs = packet["filesystems"][i];
- for(std::vector<Common::SystemBackend::FSInfo>::const_iterator fs = fsList.begin(); fs != fsList.end(); ++fs) {
unsigned usedUnit = 0, totalUnit = 0;
- float used = fs->used;
- float total = fs->total;
- float available = fs->available;
+ float used = fs["usedSize"];
+ float total = fs["totalSize"];
+ float available = fs["availableSize"];
while(used >= 1024 && !units[usedUnit+1].empty()) {
++usedUnit;
@@ -59,7 +58,11 @@ void CommandManager::printFSInfo(const Net::Packets::FSInfoPacket &packet) {
total /= 1024;
}
- std::string nameString = fs->mountedOn + " (" + fs->fsName + ")";
+
+ std::string name = fs["name"];
+ std::string mountedOn = fs["mountedOn"];
+
+ std::string nameString = mountedOn + " (" + name + ")";
if(nameString.length() < 32) {
nameString.resize(32, ' ');
@@ -133,7 +136,7 @@ void CommandManager::printHostStatus(const Common::XmlPacket &packet) {
}
-void CommandManager::daemonCommandRequestFinished(const Common::Request<> &request) {
+void CommandManager::daemonCommandRequestFinished(const Common::XmlRequest &request) {
try {
request.getResult();
}
@@ -144,9 +147,9 @@ void CommandManager::daemonCommandRequestFinished(const Common::Request<> &reque
requestFinished();
}
-void CommandManager::daemonFSInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request) {
+void CommandManager::daemonFSInfoRequestFinished(const Common::XmlRequest &request) {
try {
- const Net::Packets::FSInfoPacket &packet = request.getResult();
+ const Common::XmlPacket &packet = request.getResult();
std::cout << "Host file system usage:" << std::endl;
printFSInfo(packet);
}
@@ -170,7 +173,7 @@ void CommandManager::daemonStatusRequestFinished(const Common::XmlRequest &reque
requestFinished();
}
-void CommandManager::disconnectRequestFinished(const Common::Request<> &request) {
+void CommandManager::disconnectRequestFinished(const Common::XmlRequest &request) {
try {
request.getResult();
disconnect = true;
@@ -182,9 +185,9 @@ void CommandManager::disconnectRequestFinished(const Common::Request<> &request)
requestFinished();
}
-void CommandManager::fsInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request) {
+void CommandManager::fsInfoRequestFinished(const Common::XmlRequest &request) {
try {
- const Net::Packets::FSInfoPacket &packet = request.getResult();
+ const Common::XmlPacket &packet = request.getResult();
std::cout << "Server file system usage:" << std::endl;
printFSInfo(packet);
}
diff --git a/src/Client/CommandManager.h b/src/Client/CommandManager.h
index fb90070..e2e5ff4 100644
--- a/src/Client/CommandManager.h
+++ b/src/Client/CommandManager.h
@@ -29,14 +29,6 @@ class XmlPacket;
class XmlRequest;
}
-namespace Net {
-namespace Packets {
-class FSInfoPacket;
-class HostStatusPacket;
-class HostListPacket;
-}
-}
-
namespace Client {
class CommandManager {
@@ -57,14 +49,14 @@ class CommandManager {
finished();
}
- void printFSInfo(const Net::Packets::FSInfoPacket &packet);
+ void printFSInfo(const Common::XmlPacket &packet);
void printHostStatus(const Common::XmlPacket &packet);
- void daemonCommandRequestFinished(const Common::Request<> &request);
- void daemonFSInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request);
+ void daemonCommandRequestFinished(const Common::XmlRequest &request);
+ void daemonFSInfoRequestFinished(const Common::XmlRequest &request);
void daemonStatusRequestFinished(const Common::XmlRequest &request);
- void disconnectRequestFinished(const Common::Request<> &request);
- void fsInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request);
+ void disconnectRequestFinished(const Common::XmlRequest &request);
+ void fsInfoRequestFinished(const Common::XmlRequest &request);
void statusRequestFinished(const Common::XmlRequest &request);
void userListRequestFinished(const Common::XmlRequest &request);
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 878e413..526f434 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -110,9 +110,9 @@ std::map<std::string, Common::HostInfo> CommandParser::parseHostList(const std::
void CommandParser::fsinfoCommand(const std::vector<std::string> &args) {
if(args.size() == 1)
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::FSInfoRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::fsInfoRequestFinished))));
+ Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::XmlRequest>(new Common::Requests::FSInfoRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::fsInfoRequestFinished))));
else if(args.size() == 2)
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonFSInfoRequest(args[1], sigc::mem_fun(CommandManager::get(), &CommandManager::daemonFSInfoRequestFinished))));
+ Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::XmlRequest>(new Requests::DaemonFSInfoRequest(args[1], sigc::mem_fun(CommandManager::get(), &CommandManager::daemonFSInfoRequestFinished))));
else {
Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str());
printUsage("fsinfo");
@@ -213,7 +213,7 @@ void CommandParser::rebootCommand(const std::vector<std::string> &args) {
std::map<std::string, Common::HostInfo> hosts = parseHostList(std::vector<std::string>(args.begin()+1, args.end()), true);
for(std::map<std::string, Common::HostInfo>::iterator host = hosts.begin(); host != hosts.end(); ++host) {
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(
+ Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::XmlRequest>(
new Requests::DaemonCommandRequest(host->first, true, sigc::mem_fun(CommandManager::get(), &CommandManager::daemonCommandRequestFinished))
));
@@ -231,7 +231,7 @@ void CommandParser::shutdownCommand(const std::vector<std::string> &args) {
std::map<std::string, Common::HostInfo> hosts = parseHostList(std::vector<std::string>(args.begin()+1, args.end()), true);
for(std::map<std::string, Common::HostInfo>::iterator host = hosts.begin(); host != hosts.end(); ++host) {
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(
+ Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::XmlRequest>(
new Requests::DaemonCommandRequest(host->first, false, sigc::mem_fun(CommandManager::get(), &CommandManager::daemonCommandRequestFinished))
));
@@ -262,7 +262,7 @@ void CommandParser::listUsersCommand(const std::vector<std::string>&) {
void CommandParser::exitCommand(const std::vector<std::string>&) {
++CommandManager::get()->activeRequests;
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::DisconnectRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::disconnectRequestFinished))));
+ Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::XmlRequest>(new Common::Requests::DisconnectRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::disconnectRequestFinished))));
}
bool CommandParser::parse(const std::string &cmd) {
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) {}
};
}