summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp28
-rw-r--r--src/Client/InformationManager.cpp13
-rw-r--r--src/Client/InformationManager.h9
-rw-r--r--src/Client/Requests/DaemonCommandRequest.cpp6
-rw-r--r--src/Client/Requests/DaemonCommandRequest.h7
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.cpp5
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.h5
-rw-r--r--src/Client/Requests/DaemonListRequest.h3
-rw-r--r--src/Client/Requests/DaemonStatusRequest.cpp5
-rw-r--r--src/Client/Requests/DaemonStatusRequest.h5
10 files changed, 42 insertions, 44 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 27aac78..7e3a90e 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::Request>(new Common::Requests::FSInfoRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::fsInfoRequestFinished))));
+ Common::RequestManager::get()->sendRequest<Common::Requests::FSInfoRequest>(connection, sigc::mem_fun(CommandManager::get(), &CommandManager::fsInfoRequestFinished));
else if(args.size() == 2)
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::Request>(new Requests::DaemonFSInfoRequest(args[1], sigc::mem_fun(CommandManager::get(), &CommandManager::daemonFSInfoRequestFinished))));
+ Common::RequestManager::get()->sendRequest<Requests::DaemonFSInfoRequest>(connection, sigc::mem_fun(CommandManager::get(), &CommandManager::daemonFSInfoRequestFinished), args[1]);
else {
Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str());
printUsage("fsinfo");
@@ -213,9 +213,9 @@ 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::Request>(
- new Requests::DaemonCommandRequest(host->first, true, sigc::mem_fun(CommandManager::get(), &CommandManager::daemonCommandRequestFinished))
- ));
+ Common::RequestManager::get()->sendRequest<Requests::DaemonCommandRequest>(connection,
+ sigc::mem_fun(CommandManager::get(), &CommandManager::daemonCommandRequestFinished), host->first, true
+ );
++CommandManager::get()->activeRequests;
}
@@ -231,9 +231,9 @@ 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::Request>(
- new Requests::DaemonCommandRequest(host->first, false, sigc::mem_fun(CommandManager::get(), &CommandManager::daemonCommandRequestFinished))
- ));
+ Common::RequestManager::get()->sendRequest<Requests::DaemonCommandRequest>(connection,
+ sigc::mem_fun(CommandManager::get(), &CommandManager::daemonCommandRequestFinished), host->first, false
+ );
++CommandManager::get()->activeRequests;
}
@@ -241,9 +241,11 @@ void CommandParser::shutdownCommand(const std::vector<std::string> &args) {
void CommandParser::statusCommand(const std::vector<std::string> &args) {
if(args.size() == 1)
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::Request>(new Common::Requests::StatusRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::statusRequestFinished))));
+ Common::RequestManager::get()->sendRequest<Common::Requests::StatusRequest>(connection,
+ sigc::mem_fun(CommandManager::get(), &CommandManager::statusRequestFinished));
else if(args.size() == 2)
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::Request>(new Requests::DaemonStatusRequest(args[1], sigc::mem_fun(CommandManager::get(), &CommandManager::daemonStatusRequestFinished))));
+ Common::RequestManager::get()->sendRequest<Requests::DaemonStatusRequest>(connection,
+ sigc::mem_fun(CommandManager::get(), &CommandManager::daemonStatusRequestFinished), args[1]);
else {
Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str());
printUsage("status");
@@ -256,13 +258,15 @@ void CommandParser::statusCommand(const std::vector<std::string> &args) {
void CommandParser::listUsersCommand(const std::vector<std::string>&) {
++CommandManager::get()->activeRequests;
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::Request>(new Common::Requests::UserListRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::userListRequestFinished))));
+ Common::RequestManager::get()->sendRequest<Common::Requests::UserListRequest>(connection,
+ sigc::mem_fun(CommandManager::get(), &CommandManager::userListRequestFinished));
}
void CommandParser::exitCommand(const std::vector<std::string>&) {
++CommandManager::get()->activeRequests;
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::Request>(new Common::Requests::DisconnectRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::disconnectRequestFinished))));
+ Common::RequestManager::get()->sendRequest<Common::Requests::DisconnectRequest>(connection,
+ sigc::mem_fun(CommandManager::get(), &CommandManager::disconnectRequestFinished));
}
bool CommandParser::parse(const std::string &cmd) {
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp
index cafe2fa..4c9800b 100644
--- a/src/Client/InformationManager.cpp
+++ b/src/Client/InformationManager.cpp
@@ -29,7 +29,7 @@ namespace Client {
InformationManager InformationManager::informationManager;
-void InformationManager::DaemonStateUpdateRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+void InformationManager::DaemonStateUpdateRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "UpdateHostState") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -37,7 +37,7 @@ void InformationManager::DaemonStateUpdateRequestHandler::handlePacket(Net::Conn
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -53,7 +53,7 @@ void InformationManager::DaemonStateUpdateRequestHandler::handlePacket(Net::Conn
Common::XmlPacket ret;
ret.setType("OK");
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
}
@@ -71,11 +71,8 @@ void InformationManager::updateDaemonList(Net::Connection *con) {
if(updating)
return;
- Common::RequestManager::get()->sendRequest(con,
- std::auto_ptr<Common::Request>(
- new Requests::DaemonListRequest(sigc::mem_fun(this, &InformationManager::daemonListRequestFinished))
- )
- );
+ Common::RequestManager::get()->sendRequest<Requests::DaemonListRequest>(con,
+ sigc::mem_fun(this, &InformationManager::daemonListRequestFinished));
updating = true;
}
diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h
index 566eaf6..369eefd 100644
--- a/src/Client/InformationManager.h
+++ b/src/Client/InformationManager.h
@@ -32,10 +32,6 @@ namespace Mad {
namespace Net {
class Connection;
-namespace Packets {
-class HostListPacket;
-}
-
}
namespace Client {
@@ -44,10 +40,11 @@ class InformationManager : public Common::Initializable {
private:
class DaemonStateUpdateRequestHandler : public Common::RequestHandler {
protected:
- virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet);
+ virtual void handlePacket(const Common::XmlPacket &packet);
public:
- DaemonStateUpdateRequestHandler() {}
+ DaemonStateUpdateRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
static InformationManager informationManager;
diff --git a/src/Client/Requests/DaemonCommandRequest.cpp b/src/Client/Requests/DaemonCommandRequest.cpp
index 7b444cd..45a346b 100644
--- a/src/Client/Requests/DaemonCommandRequest.cpp
+++ b/src/Client/Requests/DaemonCommandRequest.cpp
@@ -18,20 +18,18 @@
*/
#include "DaemonCommandRequest.h"
-#include <Common/XmlPacket.h>
-#include <Net/Connection.h>
namespace Mad {
namespace Client {
namespace Requests {
-void DaemonCommandRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void DaemonCommandRequest::sendRequest() {
Common::XmlPacket packet;
packet.setType("DaemonCommand");
packet.add("command", reboot ? "reboot" : "shutdown");
packet.add("daemon", daemon);
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
}
diff --git a/src/Client/Requests/DaemonCommandRequest.h b/src/Client/Requests/DaemonCommandRequest.h
index fa1e436..4e9e2d1 100644
--- a/src/Client/Requests/DaemonCommandRequest.h
+++ b/src/Client/Requests/DaemonCommandRequest.h
@@ -20,7 +20,7 @@
#ifndef MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_
#define MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_
-#include <Common/Requests/SimpleRequest.h>
+#include <Common/Request.h>
#include <string>
namespace Mad {
@@ -33,10 +33,11 @@ class DaemonCommandRequest : public Common::Request {
bool reboot;
protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void sendRequest();
public:
- DaemonCommandRequest(const std::string &daemon0, bool reboot0, slot_type slot) : Common::Request(slot), daemon(daemon0), reboot(reboot0) {}
+ DaemonCommandRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &daemon0, bool reboot0)
+ : Common::Request(connection, requestId, slot), daemon(daemon0), reboot(reboot0) {}
};
}
diff --git a/src/Client/Requests/DaemonFSInfoRequest.cpp b/src/Client/Requests/DaemonFSInfoRequest.cpp
index acd1179..5d77850 100644
--- a/src/Client/Requests/DaemonFSInfoRequest.cpp
+++ b/src/Client/Requests/DaemonFSInfoRequest.cpp
@@ -18,18 +18,17 @@
*/
#include "DaemonFSInfoRequest.h"
-#include <Net/Connection.h>
namespace Mad {
namespace Client {
namespace Requests {
-void DaemonFSInfoRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void DaemonFSInfoRequest::sendRequest() {
Common::XmlPacket packet;
packet.setType("DaemonFSInfo");
packet.add("daemon", daemon);
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
}
diff --git a/src/Client/Requests/DaemonFSInfoRequest.h b/src/Client/Requests/DaemonFSInfoRequest.h
index ac29a8b..2e6a68f 100644
--- a/src/Client/Requests/DaemonFSInfoRequest.h
+++ b/src/Client/Requests/DaemonFSInfoRequest.h
@@ -33,10 +33,11 @@ class DaemonFSInfoRequest : public Common::Request {
std::string daemon;
protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void sendRequest();
public:
- DaemonFSInfoRequest(const std::string &daemon0, slot_type slot) : Common::Request(slot), daemon(daemon0) {}
+ DaemonFSInfoRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &daemon0)
+ : Common::Request(connection, requestId, slot), daemon(daemon0) {}
};
}
diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h
index 2387387..017d355 100644
--- a/src/Client/Requests/DaemonListRequest.h
+++ b/src/Client/Requests/DaemonListRequest.h
@@ -28,7 +28,8 @@ namespace Requests {
class DaemonListRequest : public Common::Requests::SimpleRequest {
public:
- DaemonListRequest(slot_type slot) : SimpleRequest("ListHosts", slot) {}
+ DaemonListRequest(Net::Connection *connection, uint16_t requestId, slot_type slot)
+ : SimpleRequest(connection, requestId, slot, "ListHosts") {}
};
}
diff --git a/src/Client/Requests/DaemonStatusRequest.cpp b/src/Client/Requests/DaemonStatusRequest.cpp
index 7611d30..9f0a9a0 100644
--- a/src/Client/Requests/DaemonStatusRequest.cpp
+++ b/src/Client/Requests/DaemonStatusRequest.cpp
@@ -18,18 +18,17 @@
*/
#include "DaemonStatusRequest.h"
-#include <Net/Connection.h>
namespace Mad {
namespace Client {
namespace Requests {
-void DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void DaemonStatusRequest::sendRequest() {
Common::XmlPacket packet;
packet.setType("GetDaemonStatus");
packet.add("daemonName", daemon);
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
}
diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h
index bf8b7bf..83cba67 100644
--- a/src/Client/Requests/DaemonStatusRequest.h
+++ b/src/Client/Requests/DaemonStatusRequest.h
@@ -33,10 +33,11 @@ class DaemonStatusRequest : public Common::Request {
std::string daemon;
protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void sendRequest();
public:
- DaemonStatusRequest(const std::string &daemon0, slot_type slot) : Common::Request(slot), daemon(daemon0) {}
+ DaemonStatusRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &daemon0)
+ : Common::Request(connection, requestId, slot), daemon(daemon0) {}
};
}