summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-03-16 19:13:42 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-03-16 19:13:42 +0100
commit8f098fc3070f791302ec1f497588fab6ed409980 (patch)
tree6cff9f7bb973342344a22636a5d9ef26c7a0d940
parentaef0f2e7a5085b8da3aa2e97565215d182d3dd2d (diff)
downloadmad-8f098fc3070f791302ec1f497588fab6ed409980.tar
mad-8f098fc3070f791302ec1f497588fab6ed409980.zip
Request- und RequestHandler-Interfaces vereinfacht
-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
-rw-r--r--src/Common/Makefile.am10
-rw-r--r--src/Common/Makefile.in15
-rw-r--r--src/Common/Request.cpp6
-rw-r--r--src/Common/Request.h8
-rw-r--r--src/Common/RequestHandler.cpp31
-rw-r--r--src/Common/RequestHandler.h20
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.cpp10
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.h5
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.cpp13
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.h8
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.cpp11
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.h9
-rw-r--r--src/Common/RequestManager.cpp32
-rw-r--r--src/Common/RequestManager.h117
-rw-r--r--src/Common/Requests/DisconnectRequest.cpp14
-rw-r--r--src/Common/Requests/DisconnectRequest.h7
-rw-r--r--src/Common/Requests/FSInfoRequest.h3
-rw-r--r--src/Common/Requests/GSSAPIAuthRequest.cpp15
-rw-r--r--src/Common/Requests/GSSAPIAuthRequest.h8
-rw-r--r--src/Common/Requests/SimpleRequest.cpp6
-rw-r--r--src/Common/Requests/SimpleRequest.h5
-rw-r--r--src/Common/Requests/StatusRequest.h3
-rw-r--r--src/Common/Requests/UserListRequest.h3
-rw-r--r--src/Core/ConnectionManager.cpp4
-rw-r--r--src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp20
-rw-r--r--src/Core/RequestHandlers/DaemonCommandRequestHandler.h8
-rw-r--r--src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp17
-rw-r--r--src/Core/RequestHandlers/DaemonFSInfoRequestHandler.h15
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.cpp8
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.h5
-rw-r--r--src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp17
-rw-r--r--src/Core/RequestHandlers/DaemonStatusRequestHandler.h15
-rw-r--r--src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp11
-rw-r--r--src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h5
-rw-r--r--src/Core/RequestHandlers/IdentifyRequestHandler.cpp12
-rw-r--r--src/Core/RequestHandlers/IdentifyRequestHandler.h5
-rw-r--r--src/Core/RequestHandlers/LogRequestHandler.cpp10
-rw-r--r--src/Core/RequestHandlers/LogRequestHandler.h5
-rw-r--r--src/Core/RequestHandlers/UserListRequestHandler.cpp13
-rw-r--r--src/Core/RequestHandlers/UserListRequestHandler.h8
-rw-r--r--src/Core/Requests/CommandRequest.cpp5
-rw-r--r--src/Core/Requests/CommandRequest.h5
-rw-r--r--src/Core/Requests/DaemonStateUpdateRequest.cpp5
-rw-r--r--src/Core/Requests/DaemonStateUpdateRequest.h5
-rw-r--r--src/Daemon/Backends/NetworkLogger.h6
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.cpp18
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.h7
-rw-r--r--src/Daemon/Requests/IdentifyRequest.cpp6
-rw-r--r--src/Daemon/Requests/IdentifyRequest.h5
-rw-r--r--src/Daemon/Requests/LogRequest.cpp5
-rw-r--r--src/Daemon/Requests/LogRequest.h6
-rw-r--r--src/mad-core.cpp2
-rw-r--r--src/mad.cpp4
63 files changed, 387 insertions, 315 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) {}
};
}
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index f0a0ad7..9f31371 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -2,11 +2,11 @@ SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = ActionManager.cpp ConfigEntry.cpp ConfigManager.cpp Exception.cpp Initializable.cpp \
- Logger.cpp LogManager.cpp ModuleManager.cpp Request.cpp RequestManager.cpp \
- SystemBackend.cpp Tokenizer.cpp XmlPacket.cpp
+ Logger.cpp LogManager.cpp ModuleManager.cpp Request.cpp RequestHandler.cpp \
+ RequestManager.cpp SystemBackend.cpp Tokenizer.cpp XmlPacket.cpp
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
-noinst_HEADERS = ActionManager.h ConfigEntry.h ConfigManager.h Configurable.h Exception.h HostInfo.h \
- Initializable.h Logger.h LoggerBase.h LogManager.h ModuleManager.h \
- RemoteLogger.h Request.h RequestHandler.h RequestManager.h \
+noinst_HEADERS = ActionManager.h ConfigEntry.h ConfigManager.h Configurable.h \
+ Exception.h HostInfo.h Initializable.h Logger.h LoggerBase.h LogManager.h \
+ ModuleManager.h RemoteLogger.h Request.h RequestHandler.h RequestManager.h \
SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index 9841291..6f2595f 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -55,8 +55,8 @@ libcommon_la_DEPENDENCIES = Requests/librequests.la \
RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
am_libcommon_la_OBJECTS = ActionManager.lo ConfigEntry.lo \
ConfigManager.lo Exception.lo Initializable.lo Logger.lo \
- LogManager.lo ModuleManager.lo Request.lo RequestManager.lo \
- SystemBackend.lo Tokenizer.lo XmlPacket.lo
+ LogManager.lo ModuleManager.lo Request.lo RequestHandler.lo \
+ RequestManager.lo SystemBackend.lo Tokenizer.lo XmlPacket.lo
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -239,13 +239,13 @@ top_srcdir = @top_srcdir@
SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = ActionManager.cpp ConfigEntry.cpp ConfigManager.cpp Exception.cpp Initializable.cpp \
- Logger.cpp LogManager.cpp ModuleManager.cpp Request.cpp RequestManager.cpp \
- SystemBackend.cpp Tokenizer.cpp XmlPacket.cpp
+ Logger.cpp LogManager.cpp ModuleManager.cpp Request.cpp RequestHandler.cpp \
+ RequestManager.cpp SystemBackend.cpp Tokenizer.cpp XmlPacket.cpp
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
-noinst_HEADERS = ActionManager.h ConfigEntry.h ConfigManager.h Configurable.h Exception.h HostInfo.h \
- Initializable.h Logger.h LoggerBase.h LogManager.h ModuleManager.h \
- RemoteLogger.h Request.h RequestHandler.h RequestManager.h \
+noinst_HEADERS = ActionManager.h ConfigEntry.h ConfigManager.h Configurable.h \
+ Exception.h HostInfo.h Initializable.h Logger.h LoggerBase.h LogManager.h \
+ ModuleManager.h RemoteLogger.h Request.h RequestHandler.h RequestManager.h \
SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h
all: all-recursive
@@ -308,6 +308,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Logger.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ModuleManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Request.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackend.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Tokenizer.Plo@am__quote@
diff --git a/src/Common/Request.cpp b/src/Common/Request.cpp
index 0b8715e..bc37708 100644
--- a/src/Common/Request.cpp
+++ b/src/Common/Request.cpp
@@ -17,19 +17,17 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
-
#include "Request.h"
namespace Mad {
namespace Common {
-void Request::handlePacket(Net::Connection *connection _UNUSED_PARAMETER_, uint16_t requestId _UNUSED_PARAMETER_, const XmlPacket &packet) {
+void Request::handlePacket(const XmlPacket &packet) {
if(packet.getType() == "Error") {
finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
return;
}
- if(packet.getType() != "OK") {
+ else if(packet.getType() != "OK") {
finishWithError(Exception(Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
diff --git a/src/Common/Request.h b/src/Common/Request.h
index ef84194..2c6c8d4 100644
--- a/src/Common/Request.h
+++ b/src/Common/Request.h
@@ -20,7 +20,6 @@
#ifndef MAD_COMMON_XMLREQUEST_H_
#define MAD_COMMON_XMLREQUEST_H_
-#include "XmlPacket.h"
#include "RequestHandler.h"
#include "Exception.h"
@@ -43,7 +42,8 @@ class Request : public RequestHandler {
typedef sigc::slot<void,const Request&> slot_type;
protected:
- Request(slot_type slot) : exp(Exception::NOT_FINISHED) {
+ Request(Net::Connection *connection, uint16_t requestId, slot_type slot)
+ : RequestHandler(connection, requestId), exp(Exception::NOT_FINISHED) {
finished.connect(slot);
finished.connect(sigc::hide(signalFinished().make_slot()));
}
@@ -52,8 +52,8 @@ class Request : public RequestHandler {
void finish(const XmlPacket& result) {res.reset(new XmlPacket(result)); finished(*this);}
void finishWithError(const Exception &e) {exp = e; finished(*this);}
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId) = 0;
- virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet);
+ virtual void sendRequest() = 0;
+ virtual void handlePacket(const XmlPacket &packet);
public:
const XmlPacket& getResult() const throw(Exception) {
diff --git a/src/Common/RequestHandler.cpp b/src/Common/RequestHandler.cpp
new file mode 100644
index 0000000..3e0eabc
--- /dev/null
+++ b/src/Common/RequestHandler.cpp
@@ -0,0 +1,31 @@
+/*
+ * RequestHandler.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "RequestHandler.h"
+#include <Net/Connection.h>
+
+namespace Mad {
+namespace Common {
+
+bool RequestHandler::sendPacket(const XmlPacket &packet) {
+ return connection->send(packet.encode(requestId));
+}
+
+}
+}
diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h
index b909e81..f36aae5 100644
--- a/src/Common/RequestHandler.h
+++ b/src/Common/RequestHandler.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_XMLREQUESTHANDLER_H_
#define MAD_COMMON_XMLREQUESTHANDLER_H_
+#include "XmlPacket.h"
+
#include <sigc++/signal.h>
#include <stdint.h>
@@ -32,22 +34,34 @@ class Connection;
namespace Common {
class RequestManager;
-class XmlPacket;
class RequestHandler {
private:
sigc::signal<void> finished;
+ Net::Connection *connection;
+ uint16_t requestId;
+
// Prevent shallow copy
RequestHandler(const RequestHandler &o);
RequestHandler& operator=(const RequestHandler &o);
protected:
- RequestHandler() {}
+ RequestHandler(Net::Connection *connection0, uint16_t requestId0) : connection(connection0), requestId(requestId0) {}
sigc::signal<void> signalFinished() {return finished;}
- virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) = 0;
+ Net::Connection* getConnection() const {
+ return connection;
+ }
+
+ uint16_t getRequestId() const {
+ return requestId;
+ }
+
+ bool sendPacket(const XmlPacket &packet);
+
+ virtual void handlePacket(const XmlPacket &packet) = 0;
public:
virtual ~RequestHandler() {}
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
index 346b6de..031853a 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
@@ -20,14 +20,13 @@
#include "DisconnectRequestHandler.h"
#include "../Exception.h"
#include "../Logger.h"
-#include "../XmlPacket.h"
#include <Net/Connection.h>
namespace Mad {
namespace Common {
namespace RequestHandlers {
-void DisconnectRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) {
+void DisconnectRequestHandler::handlePacket(const XmlPacket &packet) {
if(packet.getType() != "Disconnect") {
Logger::log(Logger::ERROR, "Received an unexpected packet.");
@@ -35,7 +34,7 @@ void DisconnectRequestHandler::handlePacket(Net::Connection *connection, uint16_
ret.setType("Error");
ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -44,9 +43,10 @@ void DisconnectRequestHandler::handlePacket(Net::Connection *connection, uint16_
XmlPacket ret;
ret.setType("OK");
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
- connection->disconnect();
+
+ getConnection()->disconnect();
signalFinished().emit();
}
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h
index 7544fd8..b90c96e 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.h
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h
@@ -28,10 +28,11 @@ namespace RequestHandlers {
class DisconnectRequestHandler : public RequestHandler {
protected:
- virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet);
+ virtual void handlePacket(const XmlPacket &packet);
public:
- DisconnectRequestHandler() {}
+ DisconnectRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
index 878dd7c..aaa4d9e 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
@@ -20,14 +20,12 @@
#include "FSInfoRequestHandler.h"
#include "../Exception.h"
#include "../Logger.h"
-#include "../XmlPacket.h"
-#include <Net/Connection.h>
namespace Mad {
namespace Common {
namespace RequestHandlers {
-void FSInfoRequestHandler::handlePacket(Net::Connection *con, uint16_t rid, const XmlPacket &packet) {
+void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) {
if(packet.getType() != "FSInfo") {
Logger::log(Logger::ERROR, "Received an unexpected packet.");
@@ -35,7 +33,7 @@ void FSInfoRequestHandler::handlePacket(Net::Connection *con, uint16_t rid, cons
ret.setType("Error");
ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(rid));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -43,15 +41,12 @@ void FSInfoRequestHandler::handlePacket(Net::Connection *con, uint16_t rid, cons
// TODO Require authentication
- connection = con;
- requestId = rid;
-
if(!SystemBackend::getFSInfo(sigc::mem_fun(this, &FSInfoRequestHandler::fsInfoHandler))) {
XmlPacket ret;
ret.setType("Error");
ret.add("ErrorCode", Exception::NOT_IMPLEMENTED);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
}
@@ -73,7 +68,7 @@ void FSInfoRequestHandler::fsInfoHandler(const std::vector<SystemBackend::FSInfo
entry.add("availableSize", fs->available);
}
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
}
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h
index a9ee120..6fcf524 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.h
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h
@@ -31,16 +31,14 @@ namespace RequestHandlers {
class FSInfoRequestHandler : public RequestHandler {
private:
- Net::Connection *connection;
- uint16_t requestId;
-
void fsInfoHandler(const std::vector<SystemBackend::FSInfo> &info);
protected:
- virtual void handlePacket(Net::Connection *con, uint16_t rid, const XmlPacket &packet);
+ virtual void handlePacket(const XmlPacket &packet);
public:
- FSInfoRequestHandler() {}
+ FSInfoRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp
index 86ed970..e03c345 100644
--- a/src/Common/RequestHandlers/StatusRequestHandler.cpp
+++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp
@@ -21,14 +21,12 @@
#include "../Exception.h"
#include "../SystemBackend.h"
#include "../Logger.h"
-#include "../XmlPacket.h"
-#include <Net/Connection.h>
namespace Mad {
namespace Common {
namespace RequestHandlers {
-void StatusRequestHandler::handlePacket(Net::Connection *con, uint16_t requestId, const XmlPacket &packet) {
+void StatusRequestHandler::handlePacket(const XmlPacket &packet) {
if(packet.getType() != "GetStatus") {
Logger::log(Logger::ERROR, "Received an unexpected packet.");
@@ -36,7 +34,7 @@ void StatusRequestHandler::handlePacket(Net::Connection *con, uint16_t requestId
ret.setType("Error");
ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
- con->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -44,9 +42,6 @@ void StatusRequestHandler::handlePacket(Net::Connection *con, uint16_t requestId
// TODO Require authentication
- connection = con;
- rid = requestId;
-
if(!SystemBackend::getUptimeInfo(sigc::mem_fun(this, &StatusRequestHandler::uptimeHandler)))
needUptime = false;
if(!SystemBackend::getMemoryInfo(sigc::mem_fun(this, &StatusRequestHandler::memoryHandler)))
@@ -77,7 +72,7 @@ void StatusRequestHandler::send() {
packet.add("loadAvg5", loadAvg5);
packet.add("loadAvg15", loadAvg15);
- connection->send(packet.encode(rid));
+ sendPacket(packet);
sent = true;
diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h
index ce7ae6d..ddaaae4 100644
--- a/src/Common/RequestHandlers/StatusRequestHandler.h
+++ b/src/Common/RequestHandlers/StatusRequestHandler.h
@@ -29,9 +29,6 @@ namespace RequestHandlers {
class StatusRequestHandler : public RequestHandler {
private:
- Net::Connection *connection;
- uint16_t rid;
-
bool needUptime, needMemory, needLoad, sent;
unsigned long uptime, idleTime;
@@ -60,10 +57,12 @@ class StatusRequestHandler : public RequestHandler {
void send();
protected:
- virtual void handlePacket(Net::Connection *con, uint16_t requestId, const XmlPacket &packet);
+ virtual void handlePacket(const XmlPacket &packet);
public:
- StatusRequestHandler() : needUptime(true), needMemory(true), needLoad(true), sent(false),
+ StatusRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId),
+ needUptime(true), needMemory(true), needLoad(true), sent(false),
uptime(0), idleTime(0), totalMem(0), freeMem(0), totalSwap(0), freeSwap(0),
currentLoad(0), nProcesses(0), loadAvg1(0), loadAvg5(0), loadAvg15(0) {}
};
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index ac1909b..9d50865 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -18,11 +18,11 @@
*/
#include "RequestManager.h"
-#include "Request.h"
-#include "XmlPacket.h"
#include "RequestHandlers/DisconnectRequestHandler.h"
#include "Logger.h"
+#include <Net/Connection.h>
+
#include <sigc++/bind.h>
#include <sigc++/retype_return.h>
@@ -81,48 +81,44 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack
RequestHandler *request = requestMap->findRequest(packet.getRequestId());
if(request) {
- request->handlePacket(connection, packet.getRequestId(), xmlPacket);
+ request->handlePacket(xmlPacket);
return;
}
std::map<std::string,RequestHandlerFactory*>::iterator factoryIt = requestHandlerFactories.find(xmlPacket.getType());
if(factoryIt != requestHandlerFactories.end()) {
- request = factoryIt->second->createRequestHandler();
+ request = factoryIt->second->createRequestHandler(connection, packet.getRequestId());
+
requestMap->addRequest(packet.getRequestId(), request);
- request->handlePacket(connection, packet.getRequestId(), xmlPacket);
+ request->handlePacket(xmlPacket);
return;
}
- Logger::log(Logger::ERROR, "Received an unexpected packet.");
+ Logger::logf(Logger::ERROR, "Received an unexpected packet with type '%s'.", xmlPacket.getType().c_str());
XmlPacket ret;
ret.setType("Error");
ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(requestId));
+ connection->send(ret.encode(packet.getRequestId()));
}
-bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptr<Request> request) {
+RequestManager::RequestMap* RequestManager::getUnusedRequestId(Net::Connection *connection, uint16_t *requestId) {
std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.find(connection);
if(it == requestMaps.end()) {
Logger::log(Logger::CRITICAL, "Trying to send a request over an unregistered connecion.");
- return false;
+ return 0;
}
RequestMap *requestMap = it->second;
- uint16_t id;
do {
- id = getRequestId();
- } while(requestMap->findRequest(id));
+ *requestId = getRequestId();
+ } while(requestMap->findRequest(*requestId));
- request->sendRequest(connection, id);
-
- requestMap->addRequest(id, request.release());
-
- return true;
+ return requestMap;
}
void RequestManager::registerConnection(Net::Connection *connection) {
@@ -151,7 +147,7 @@ void RequestManager::unregisterPacketType(const std::string &type) {
requestHandlerFactories.erase(it);
}
-RequestManager::RequestManager() : core(false), requestId(-1) {
+RequestManager::RequestManager() : core(false), lastRequestId(-1) {
registerPacketType<RequestHandlers::DisconnectRequestHandler>("Disconnect");
}
diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h
index ee4f4d1..c38435b 100644
--- a/src/Common/RequestManager.h
+++ b/src/Common/RequestManager.h
@@ -20,16 +20,22 @@
#ifndef MAD_COMMON_REQUESTMANAGER_H_
#define MAD_COMMON_REQUESTMANAGER_H_
-#include <Net/Connection.h>
+#include "Request.h"
#include <map>
#include <memory>
+#include <string>
+
+#include <stdint.h>
namespace Mad {
-namespace Common {
-class Request;
-class RequestHandler;
+namespace Net {
+class Connection;
+class Packet;
+}
+
+namespace Common {
class RequestManager {
private:
@@ -53,14 +59,14 @@ class RequestManager {
RequestHandlerFactory() {}
public:
- virtual RequestHandler* createRequestHandler() = 0;
+ virtual RequestHandler* createRequestHandler(Net::Connection *connection, int16_t requestId) = 0;
virtual ~RequestHandlerFactory() {}
};
template<class T> class SpecificRequestHandlerFactory : public RequestHandlerFactory {
public:
- virtual RequestHandler* createRequestHandler() {
- return new T();
+ virtual RequestHandler* createRequestHandler(Net::Connection *connection, int16_t requestId) {
+ return new T(connection, requestId);
}
};
@@ -68,12 +74,12 @@ class RequestManager {
std::map<Net::Connection*,RequestMap*> requestMaps;
bool core;
- uint16_t requestId;
+ uint16_t lastRequestId;
std::map<std::string,RequestHandlerFactory*> requestHandlerFactories;
uint16_t getRequestId() {
- return requestId+=2;
+ return lastRequestId+=2;
}
// Prevent shallow copy
@@ -82,6 +88,10 @@ class RequestManager {
void receiveHandler(Net::Connection *connection, const Net::Packet &packet);
+ RequestMap* getUnusedRequestId(Net::Connection *connection, uint16_t *requestId);
+
+ bool send(Request *request);
+
RequestManager();
public:
@@ -94,9 +104,9 @@ class RequestManager {
core = newCore;
if(core)
- requestId &= ~0x01;
+ lastRequestId &= ~0x01;
else
- requestId |= 0x01;
+ lastRequestId |= 0x01;
}
void registerConnection(Net::Connection *connection);
@@ -108,7 +118,90 @@ class RequestManager {
void unregisterPacketType(const std::string &type);
- bool sendRequest(Net::Connection *connection, std::auto_ptr<Request> request);
+ template <class T>
+ bool sendRequest(Net::Connection *connection, Request::slot_type slot) {
+ RequestMap *requestMap;
+ uint16_t requestId;
+
+ requestMap = getUnusedRequestId(connection, &requestId);
+
+ if(!requestMap)
+ return false;
+
+ Request *request = new T(connection, requestId, slot);
+ request->sendRequest();
+ requestMap->addRequest(requestId, request);
+
+ return true;
+ }
+
+ template <class T, typename T1>
+ bool sendRequest(Net::Connection *connection, Request::slot_type slot, T1 t1) {
+ RequestMap *requestMap;
+ uint16_t requestId;
+
+ requestMap = getUnusedRequestId(connection, &requestId);
+
+ if(!requestMap)
+ return false;
+
+ Request *request = new T(connection, requestId, slot, t1);
+ request->sendRequest();
+ requestMap->addRequest(requestId, request);
+
+ return true;
+ }
+
+ template <class T, typename T1, typename T2>
+ bool sendRequest(Net::Connection *connection, Request::slot_type slot, T1 t1, T2 t2) {
+ RequestMap *requestMap;
+ uint16_t requestId;
+
+ requestMap = getUnusedRequestId(connection, &requestId);
+
+ if(!requestMap)
+ return false;
+
+ Request *request = new T(connection, requestId, slot, t1, t2);
+ request->sendRequest();
+ requestMap->addRequest(requestId, request);
+
+ return true;
+ }
+
+ template <class T, typename T1, typename T2, typename T3>
+ bool sendRequest(Net::Connection *connection, Request::slot_type slot, T1 t1, T2 t2, T3 t3) {
+ RequestMap *requestMap;
+ uint16_t requestId;
+
+ requestMap = getUnusedRequestId(connection, &requestId);
+
+ if(!requestMap)
+ return false;
+
+ Request *request = new T(connection, requestId, slot, t1, t2, t3);
+ request->sendRequest();
+ requestMap->addRequest(requestId, request);
+
+ return true;
+ }
+
+ template <class T, typename T1, typename T2, typename T3, typename T4>
+ bool sendRequest(Net::Connection *connection, Request::slot_type slot, T1 t1, T2 t2, T3 t3, T4 t4) {
+ RequestMap *requestMap;
+ uint16_t requestId;
+
+ requestMap = getUnusedRequestId(connection, &requestId);
+
+ if(!requestMap)
+ return false;
+
+ Request *request = new T(connection, requestId, slot, t1, t2, t3, t4);
+ request->sendRequest();
+ requestMap->addRequest(requestId, request);
+
+ return true;
+ }
virtual ~RequestManager();
};
diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp
index afab8ed..ec8719d 100644
--- a/src/Common/Requests/DisconnectRequest.cpp
+++ b/src/Common/Requests/DisconnectRequest.cpp
@@ -24,20 +24,24 @@ namespace Mad {
namespace Common {
namespace Requests {
-void DisconnectRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void DisconnectRequest::sendRequest() {
XmlPacket packet;
packet.setType("Disconnect");
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
-void DisconnectRequest::handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet) {
- if(packet.getType() != "OK") {
+void DisconnectRequest::handlePacket(const XmlPacket &packet) {
+ if(packet.getType() == "Error") {
+ finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
+ return;
+ }
+ else if(packet.getType() != "OK") {
finishWithError(Exception(Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
- connection->disconnect();
+ getConnection()->disconnect();
finish(packet);
}
diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h
index af7cca5..22ff16b 100644
--- a/src/Common/Requests/DisconnectRequest.h
+++ b/src/Common/Requests/DisconnectRequest.h
@@ -28,11 +28,12 @@ namespace Requests {
class DisconnectRequest : public Request {
protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet);
+ virtual void sendRequest();
+ virtual void handlePacket(const XmlPacket &packet);
public:
- DisconnectRequest(slot_type slot) : Request(slot) {}
+ DisconnectRequest(Net::Connection *connection, uint16_t requestId, slot_type slot)
+ : Request(connection, requestId, slot) {}
};
}
diff --git a/src/Common/Requests/FSInfoRequest.h b/src/Common/Requests/FSInfoRequest.h
index 27a38ed..285f662 100644
--- a/src/Common/Requests/FSInfoRequest.h
+++ b/src/Common/Requests/FSInfoRequest.h
@@ -28,7 +28,8 @@ namespace Requests {
class FSInfoRequest : public SimpleRequest {
public:
- FSInfoRequest(slot_type slot) : SimpleRequest("FSInfo", slot) {}
+ FSInfoRequest(Net::Connection *connection, uint16_t requestId, slot_type slot)
+ : SimpleRequest(connection, requestId, slot, "FSInfo") {}
};
}
diff --git a/src/Common/Requests/GSSAPIAuthRequest.cpp b/src/Common/Requests/GSSAPIAuthRequest.cpp
index 7f4617a..07e516f 100644
--- a/src/Common/Requests/GSSAPIAuthRequest.cpp
+++ b/src/Common/Requests/GSSAPIAuthRequest.cpp
@@ -19,7 +19,6 @@
#include "GSSAPIAuthRequest.h"
#include "../Logger.h"
-#include "../XmlPacket.h"
#include <Net/Connection.h>
#include <cstring>
@@ -37,7 +36,7 @@ GSSAPIAuthRequest::~GSSAPIAuthRequest() {
gss_release_name(&minStat, &gssServiceName);
}
-void GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void GSSAPIAuthRequest::sendRequest() {
OM_uint32 majStat, minStat;
gss_buffer_desc buffer;
@@ -70,7 +69,7 @@ void GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t reques
ret.setType("AuthGSSAPI");
ret.addBinary("authToken", buffer.value, buffer.length);
- if(!connection->send(ret.encode(requestId))) {
+ if(!sendPacket(ret)) {
gss_release_buffer(&minStat, &buffer);
return;
}
@@ -78,7 +77,7 @@ void GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t reques
gss_release_buffer(&minStat, &buffer);
}
-void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) {
+void GSSAPIAuthRequest::handlePacket(const XmlPacket &packet) {
if(packet.getType() != "AuthGSSAPI") {
finishWithError(Exception(Exception::UNEXPECTED_PACKET));
return; // TODO Logging
@@ -114,7 +113,7 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t reque
ret.setType("AuthGSSAPI");
ret.addBinary("authToken", sendBuffer.value, sendBuffer.length);
- if(!connection->send(ret.encode(requestId))) {
+ if(!sendPacket(ret)) {
gss_release_buffer(&minStat, &sendBuffer);
return;
}
@@ -128,7 +127,7 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t reque
recvBuffer.value = std::malloc(recvBuffer.length);
std::memcpy(recvBuffer.value, pkgData, recvBuffer.length);
- const gnutls_datum_t *cert = connection->getPeerCertificate();
+ const gnutls_datum_t *cert = getConnection()->getPeerCertificate();
sendBuffer.length = cert->size;
sendBuffer.value = cert->data;
@@ -140,7 +139,7 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t reque
if(majStat != GSS_S_COMPLETE)
return;
- connection->setAuthenticated();
+ getConnection()->setAuthenticated();
Logger::log(Logger::VERBOSE, "Authentication complete.");
majStat = gss_delete_sec_context(&minStat, &gssContext, &sendBuffer);
@@ -154,7 +153,7 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t reque
ret.setType("AuthGSSAPI");
ret.addBinary("authToken", sendBuffer.value, sendBuffer.length);
- if(!connection->send(ret.encode(requestId))) {
+ if(!sendPacket(ret)) {
gss_release_buffer(&minStat, &sendBuffer);
return;
}
diff --git a/src/Common/Requests/GSSAPIAuthRequest.h b/src/Common/Requests/GSSAPIAuthRequest.h
index ca6195b..104af0c 100644
--- a/src/Common/Requests/GSSAPIAuthRequest.h
+++ b/src/Common/Requests/GSSAPIAuthRequest.h
@@ -38,12 +38,12 @@ class GSSAPIAuthRequest : public Request {
bool gssContinue;
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet);
+ virtual void sendRequest();
+ virtual void handlePacket(const XmlPacket &packet);
public:
- GSSAPIAuthRequest(const std::string &serviceName0, slot_type slot)
- : Request(slot), serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {}
+ GSSAPIAuthRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &serviceName0)
+ : Request(connection, requestId, slot), serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {}
virtual ~GSSAPIAuthRequest();
};
diff --git a/src/Common/Requests/SimpleRequest.cpp b/src/Common/Requests/SimpleRequest.cpp
index 018ac39..97426ae 100644
--- a/src/Common/Requests/SimpleRequest.cpp
+++ b/src/Common/Requests/SimpleRequest.cpp
@@ -19,17 +19,15 @@
#include "SimpleRequest.h"
-#include <Net/Connection.h>
-
namespace Mad {
namespace Common {
namespace Requests {
-void SimpleRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void SimpleRequest::sendRequest() {
XmlPacket packet;
packet.setType(type);
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
}
diff --git a/src/Common/Requests/SimpleRequest.h b/src/Common/Requests/SimpleRequest.h
index 0426910..ca95eca 100644
--- a/src/Common/Requests/SimpleRequest.h
+++ b/src/Common/Requests/SimpleRequest.h
@@ -32,9 +32,10 @@ class SimpleRequest : public Request {
protected:
const std::string type;
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void sendRequest();
- SimpleRequest(const std::string &type0, slot_type slot) : Request(slot), type(type0) {}
+ SimpleRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &type0)
+ : Request(connection, requestId, slot), type(type0) {}
};
}
diff --git a/src/Common/Requests/StatusRequest.h b/src/Common/Requests/StatusRequest.h
index d557358..ad89ec4 100644
--- a/src/Common/Requests/StatusRequest.h
+++ b/src/Common/Requests/StatusRequest.h
@@ -28,7 +28,8 @@ namespace Requests {
class StatusRequest : public SimpleRequest {
public:
- StatusRequest(slot_type slot) : SimpleRequest("GetStatus", slot) {}
+ StatusRequest(Net::Connection *connection, uint16_t requestId, slot_type slot)
+ : SimpleRequest(connection, requestId, slot, "GetStatus") {}
};
}
diff --git a/src/Common/Requests/UserListRequest.h b/src/Common/Requests/UserListRequest.h
index 918925c..69b0f05 100644
--- a/src/Common/Requests/UserListRequest.h
+++ b/src/Common/Requests/UserListRequest.h
@@ -28,7 +28,8 @@ namespace Requests {
class UserListRequest : public SimpleRequest {
public:
- UserListRequest(slot_type slot) : SimpleRequest("ListUsers", slot) {}
+ UserListRequest(Net::Connection *connection, uint16_t requestId, slot_type slot)
+ : SimpleRequest(connection, requestId, slot, "ListUsers") {}
};
}
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index a6d80d0..3ce52fc 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -50,9 +50,7 @@ void ConnectionManager::updateState(const std::string &name, Common::HostInfo::S
daemonInfo[name].setState(state);
for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con) {
- Common::RequestManager::get()->sendRequest(*con, std::auto_ptr<Common::Request>(
- new Requests::DaemonStateUpdateRequest(name, state)
- ));
+ Common::RequestManager::get()->sendRequest<Requests::DaemonStateUpdateRequest>(*con, Common::Request::slot_type(), name, state);
}
}
diff --git a/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp b/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp
index 1bfe3e4..c9a4530 100644
--- a/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp
+++ b/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp
@@ -26,7 +26,7 @@ namespace Mad {
namespace Core {
namespace RequestHandlers {
-void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t rid, const Common::XmlPacket &packet) {
+void DaemonCommandRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "DaemonCommand") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -34,7 +34,7 @@ void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, uint
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(rid));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -42,16 +42,12 @@ void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, uint
// TODO Require authentication
- con = connection;
- requestId = rid;
-
std::string command = packet["command"];
try {
Net::Connection *daemonCon = ConnectionManager::get()->getDaemonConnection(packet["daemon"]);
- Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr<Common::Request>(
- new Requests::CommandRequest(command == "reboot", sigc::mem_fun(this, &DaemonCommandRequestHandler::requestFinished))
- ));
+ Common::RequestManager::get()->sendRequest<Requests::CommandRequest>(daemonCon,
+ sigc::mem_fun(this, &DaemonCommandRequestHandler::requestFinished), command == "reboot");
}
catch(Common::Exception &e) {
Common::XmlPacket ret;
@@ -61,15 +57,13 @@ void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, uint
ret.add("SubSubCode", e.getSubSubCode());
ret.add("Where", e.getWhere());
- con->send(ret.encode(requestId));
+ sendPacket(ret);
}
}
void DaemonCommandRequestHandler::requestFinished(const Common::Request &request) {
try {
- const Common::XmlPacket &packet = request.getResult();
-
- con->send(packet.encode(requestId));
+ sendPacket(request.getResult());
}
catch(Common::Exception &e) {
Common::XmlPacket ret;
@@ -79,7 +73,7 @@ void DaemonCommandRequestHandler::requestFinished(const Common::Request &request
ret.add("SubSubCode", e.getSubSubCode());
ret.add("Where", e.getWhere());
- con->send(ret.encode(requestId));
+ sendPacket(ret);
}
signalFinished().emit();
diff --git a/src/Core/RequestHandlers/DaemonCommandRequestHandler.h b/src/Core/RequestHandlers/DaemonCommandRequestHandler.h
index 4ab7a3f..9e089e3 100644
--- a/src/Core/RequestHandlers/DaemonCommandRequestHandler.h
+++ b/src/Core/RequestHandlers/DaemonCommandRequestHandler.h
@@ -30,16 +30,14 @@ namespace RequestHandlers {
class DaemonCommandRequestHandler : public Common::RequestHandler {
private:
- Net::Connection *con;
- uint16_t requestId;
-
void requestFinished(const Common::Request &request);
protected:
- virtual void handlePacket(Net::Connection *connection, uint16_t rid, const Common::XmlPacket &packet);
+ virtual void handlePacket(const Common::XmlPacket &packet);
public:
- DaemonCommandRequestHandler() {}
+ DaemonCommandRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp
index b9dc030..ae12a8e 100644
--- a/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp
+++ b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp
@@ -27,7 +27,7 @@ namespace Mad {
namespace Core {
namespace RequestHandlers {
-void DaemonFSInfoRequestHandler::handlePacket(Net::Connection *connection, uint16_t rid, const Common::XmlPacket &packet) {
+void DaemonFSInfoRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "DaemonFSInfo") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -35,7 +35,7 @@ void DaemonFSInfoRequestHandler::handlePacket(Net::Connection *connection, uint1
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(rid));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -43,12 +43,10 @@ void DaemonFSInfoRequestHandler::handlePacket(Net::Connection *connection, uint1
// TODO Require authentication
- con = connection;
- requestId = rid;
-
try {
Net::Connection *daemonCon = ConnectionManager::get()->getDaemonConnection(packet["daemon"]);
- Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr<Common::Request>(new Common::Requests::FSInfoRequest(sigc::mem_fun(this, &DaemonFSInfoRequestHandler::requestFinished))));
+ Common::RequestManager::get()->sendRequest<Common::Requests::FSInfoRequest>(daemonCon,
+ sigc::mem_fun(this, &DaemonFSInfoRequestHandler::requestFinished));
}
catch(Common::Exception &e) {
Common::XmlPacket ret;
@@ -58,14 +56,13 @@ void DaemonFSInfoRequestHandler::handlePacket(Net::Connection *connection, uint1
ret.add("SubSubCode", e.getSubSubCode());
ret.add("Where", e.getWhere());
- con->send(ret.encode(requestId));
+ sendPacket(ret);
}
}
void DaemonFSInfoRequestHandler::requestFinished(const Common::Request &request) {
try {
- const Common::XmlPacket &packet = request.getResult();
- con->send(packet.encode(requestId));
+ sendPacket(request.getResult());
}
catch(Common::Exception &e) {
Common::XmlPacket ret;
@@ -75,7 +72,7 @@ void DaemonFSInfoRequestHandler::requestFinished(const Common::Request &request)
ret.add("SubSubCode", e.getSubSubCode());
ret.add("Where", e.getWhere());
- con->send(ret.encode(requestId));
+ sendPacket(ret);
}
signalFinished().emit();
diff --git a/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.h b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.h
index 820ef69..6a70c5e 100644
--- a/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.h
+++ b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.h
@@ -25,28 +25,19 @@
#include <stdint.h>
namespace Mad {
-
-namespace Net {
-namespace Packets {
-class FSInfoPacket;
-}
-}
-
namespace Core {
namespace RequestHandlers {
class DaemonFSInfoRequestHandler : public Common::RequestHandler {
private:
- Net::Connection *con;
- uint16_t requestId;
-
void requestFinished(const Common::Request &request);
protected:
- virtual void handlePacket(Net::Connection *connection, uint16_t rid, const Common::XmlPacket &packet);
+ virtual void handlePacket(const Common::XmlPacket &packet);
public:
- DaemonFSInfoRequestHandler() {}
+ DaemonFSInfoRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
index c20627f..84d3207 100644
--- a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
+++ b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
@@ -20,14 +20,12 @@
#include "DaemonListRequestHandler.h"
#include "../ConnectionManager.h"
#include <Common/Logger.h>
-#include <Common/XmlPacket.h>
-#include <Net/Connection.h>
namespace Mad {
namespace Core {
namespace RequestHandlers {
-void DaemonListRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+void DaemonListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "ListHosts") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -35,7 +33,7 @@ void DaemonListRequestHandler::handlePacket(Net::Connection *connection, uint16_
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -57,7 +55,7 @@ void DaemonListRequestHandler::handlePacket(Net::Connection *connection, uint16_
ret["hosts"].back().add("state", daemon->getState());
}
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
}
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.h b/src/Core/RequestHandlers/DaemonListRequestHandler.h
index 26c46f8..07badae 100644
--- a/src/Core/RequestHandlers/DaemonListRequestHandler.h
+++ b/src/Core/RequestHandlers/DaemonListRequestHandler.h
@@ -28,10 +28,11 @@ namespace RequestHandlers {
class DaemonListRequestHandler : 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:
- DaemonListRequestHandler() {}
+ DaemonListRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
index 35daae4..66c3aa1 100644
--- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
+++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
@@ -27,7 +27,7 @@ namespace Mad {
namespace Core {
namespace RequestHandlers {
-void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+void DaemonStatusRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "GetDaemonStatus") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -35,7 +35,7 @@ void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, uint1
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- con->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -43,14 +43,12 @@ void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, uint1
// TODO Require authentication
- con = connection;
- rid = requestId;
-
std::string daemonName = packet["daemonName"];
try {
Net::Connection *daemonCon = ConnectionManager::get()->getDaemonConnection(daemonName);
- Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr<Common::Request>(new Common::Requests::StatusRequest(sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished))));
+ Common::RequestManager::get()->sendRequest<Common::Requests::StatusRequest>(daemonCon,
+ sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished));
}
catch(Common::Exception &e) {
Common::XmlPacket ret;
@@ -60,14 +58,13 @@ void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, uint1
ret.add("SubSubCode", e.getSubSubCode());
ret.add("Where", e.getWhere());
- con->send(ret.encode(rid));
+ sendPacket(ret);
}
}
void DaemonStatusRequestHandler::requestFinished(const Common::Request &request) {
try {
- const Common::XmlPacket &packet = request.getResult();
- con->send(packet.encode(rid));
+ sendPacket(request.getResult());
}
catch(Common::Exception &e) {
Common::XmlPacket ret;
@@ -77,7 +74,7 @@ void DaemonStatusRequestHandler::requestFinished(const Common::Request &request)
ret.add("SubSubCode", e.getSubSubCode());
ret.add("Where", e.getWhere());
- con->send(ret.encode(rid));
+ sendPacket(ret);
}
signalFinished().emit();
diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h
index 92dac2f..f232649 100644
--- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h
+++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h
@@ -25,28 +25,19 @@
#include <stdint.h>
namespace Mad {
-
-namespace Net {
-namespace Packets {
-class HostStatusPacket;
-}
-}
-
namespace Core {
namespace RequestHandlers {
class DaemonStatusRequestHandler : public Common::RequestHandler {
private:
- Net::Connection *con;
- uint16_t rid;
-
void requestFinished(const Common::Request &request);
protected:
- virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet);
+ virtual void handlePacket(const Common::XmlPacket &packet);
public:
- DaemonStatusRequestHandler() {}
+ DaemonStatusRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp
index d9694c8..ad0a293 100644
--- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp
+++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp
@@ -20,7 +20,6 @@
#include "GSSAPIAuthRequestHandler.h"
#include <Common/Exception.h>
#include <Common/Logger.h>
-#include <Common/XmlPacket.h>
#include <Net/Connection.h>
#include <cstring>
@@ -31,7 +30,7 @@ namespace RequestHandlers {
// TODO Error handling
-void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+void GSSAPIAuthRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "AuthGSSAPI") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -39,7 +38,7 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, uint16_
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -74,7 +73,7 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, uint16_
ret.setType("AuthGSSAPI");
ret.addBinary("authToken", sendBuffer.value, sendBuffer.length);
- if(!connection->send(ret.encode(requestId))) {
+ if(!sendPacket(ret)) {
gss_release_buffer(&minStat, &sendBuffer);
return;
}
@@ -85,7 +84,7 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, uint16_
if(!packet["binary"].isEmpty())
return;
- const gnutls_datum_t *cert = connection->getCertificate();
+ const gnutls_datum_t *cert = getConnection()->getCertificate();
recvBuffer.length = cert->size;
recvBuffer.value = cert->data;
@@ -101,7 +100,7 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, uint16_
ret.setType("AuthGSSAPI");
ret.addBinary("certMic", sendBuffer.value, sendBuffer.length);
- if(!connection->send(ret.encode(requestId))) {
+ if(!sendPacket(ret)) {
gss_release_buffer(&minStat, &sendBuffer);
return;
}
diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
index 7f29804..06c1886 100644
--- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
+++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
@@ -34,10 +34,11 @@ class GSSAPIAuthRequestHandler : public Common::RequestHandler {
bool gssContinue, sentSignature;
protected:
- virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet);
+ virtual void handlePacket(const Common::XmlPacket &packet);
public:
- GSSAPIAuthRequestHandler() : gssContext(GSS_C_NO_CONTEXT), gssContinue(true), sentSignature(false) {}
+ GSSAPIAuthRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId), gssContext(GSS_C_NO_CONTEXT), gssContinue(true), sentSignature(false) {}
};
}
diff --git a/src/Core/RequestHandlers/IdentifyRequestHandler.cpp b/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
index 4bf921e..235569c 100644
--- a/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
+++ b/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
@@ -20,15 +20,13 @@
#include "IdentifyRequestHandler.h"
#include "../ConnectionManager.h"
#include <Common/Logger.h>
-#include <Common/XmlPacket.h>
-#include <Net/Connection.h>
namespace Mad {
namespace Core {
namespace RequestHandlers {
-void IdentifyRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+void IdentifyRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "Identify") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -36,7 +34,7 @@ void IdentifyRequestHandler::handlePacket(Net::Connection *connection, uint16_t
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -44,11 +42,11 @@ void IdentifyRequestHandler::handlePacket(Net::Connection *connection, uint16_t
// TODO Require authentication
try {
- ConnectionManager::get()->identifyDaemonConnection(connection, packet["hostname"]);
+ ConnectionManager::get()->identifyDaemonConnection(getConnection(), packet["hostname"]);
Common::XmlPacket ret;
ret.setType("OK");
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
}
catch(Common::Exception &e) {
Common::XmlPacket ret;
@@ -58,7 +56,7 @@ void IdentifyRequestHandler::handlePacket(Net::Connection *connection, uint16_t
ret.add("SubSubCode", e.getSubSubCode());
ret.add("Where", e.getWhere());
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
}
signalFinished().emit();
diff --git a/src/Core/RequestHandlers/IdentifyRequestHandler.h b/src/Core/RequestHandlers/IdentifyRequestHandler.h
index 7bc5d7c..37aa74b 100644
--- a/src/Core/RequestHandlers/IdentifyRequestHandler.h
+++ b/src/Core/RequestHandlers/IdentifyRequestHandler.h
@@ -28,10 +28,11 @@ namespace RequestHandlers {
class IdentifyRequestHandler : 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:
- IdentifyRequestHandler() {}
+ IdentifyRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Core/RequestHandlers/LogRequestHandler.cpp b/src/Core/RequestHandlers/LogRequestHandler.cpp
index 77be876..aeec7da 100644
--- a/src/Core/RequestHandlers/LogRequestHandler.cpp
+++ b/src/Core/RequestHandlers/LogRequestHandler.cpp
@@ -20,15 +20,13 @@
#include "LogRequestHandler.h"
#include <Common/Logger.h>
#include <Common/LogManager.h>
-#include <Common/XmlPacket.h>
#include "../ConnectionManager.h"
-#include <Net/Connection.h>
namespace Mad {
namespace Core {
namespace RequestHandlers {
-void LogRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+void LogRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "Log") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -36,7 +34,7 @@ void LogRequestHandler::handlePacket(Net::Connection *connection, uint16_t reque
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -46,7 +44,7 @@ void LogRequestHandler::handlePacket(Net::Connection *connection, uint16_t reque
try {
Common::LogManager::get()->log(packet["category"], packet["level"], packet["timestamp"], packet["message"],
- ConnectionManager::get()->getDaemonName(connection));
+ ConnectionManager::get()->getDaemonName(getConnection()));
}
catch(Common::Exception &e) {
Common::Logger::logf(Common::Logger::ERROR, "Can't determine daemon name: %s", e.strerror().c_str());
@@ -55,7 +53,7 @@ void LogRequestHandler::handlePacket(Net::Connection *connection, uint16_t reque
Common::XmlPacket ret;
ret.setType("OK");
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
}
diff --git a/src/Core/RequestHandlers/LogRequestHandler.h b/src/Core/RequestHandlers/LogRequestHandler.h
index 4a0f9cb..9cf63ec 100644
--- a/src/Core/RequestHandlers/LogRequestHandler.h
+++ b/src/Core/RequestHandlers/LogRequestHandler.h
@@ -28,10 +28,11 @@ namespace RequestHandlers {
class LogRequestHandler : 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:
- LogRequestHandler() {}
+ LogRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Core/RequestHandlers/UserListRequestHandler.cpp b/src/Core/RequestHandlers/UserListRequestHandler.cpp
index 176fde9..bb67df9 100644
--- a/src/Core/RequestHandlers/UserListRequestHandler.cpp
+++ b/src/Core/RequestHandlers/UserListRequestHandler.cpp
@@ -21,14 +21,12 @@
#include "../UserBackend.h"
#include <Common/Exception.h>
#include <Common/Logger.h>
-#include <Common/XmlPacket.h>
-#include <Net/Connection.h>
namespace Mad {
namespace Core {
namespace RequestHandlers {
-void UserListRequestHandler::handlePacket(Net::Connection *con, uint16_t requestId, const Common::XmlPacket &packet) {
+void UserListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "ListUsers") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -36,7 +34,7 @@ void UserListRequestHandler::handlePacket(Net::Connection *con, uint16_t request
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- con->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -44,15 +42,12 @@ void UserListRequestHandler::handlePacket(Net::Connection *con, uint16_t request
// TODO Require authentication
- connection = con;
- rid = requestId;
-
if(!UserBackend::getUserList(sigc::mem_fun(this, &UserListRequestHandler::userListHandler))) {
Common::XmlPacket ret;
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::NOT_IMPLEMENTED);
- con->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
}
}
@@ -72,7 +67,7 @@ void UserListRequestHandler::userListHandler(const std::map<unsigned long, Commo
entry.add("fullName", user->second.getFullName());
}
- connection->send(ret.encode(rid));
+ sendPacket(ret);
signalFinished().emit();
}
diff --git a/src/Core/RequestHandlers/UserListRequestHandler.h b/src/Core/RequestHandlers/UserListRequestHandler.h
index a9c8ac6..8eae11e 100644
--- a/src/Core/RequestHandlers/UserListRequestHandler.h
+++ b/src/Core/RequestHandlers/UserListRequestHandler.h
@@ -32,16 +32,14 @@ namespace RequestHandlers {
class UserListRequestHandler : public Common::RequestHandler {
private:
- Net::Connection *connection;
- uint16_t rid;
-
void userListHandler(const std::map<unsigned long, Common::UserInfo> &info);
protected:
- virtual void handlePacket(Net::Connection *con, uint16_t requestId, const Common::XmlPacket &packet);
+ virtual void handlePacket(const Common::XmlPacket &packet);
public:
- UserListRequestHandler() {}
+ UserListRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Core/Requests/CommandRequest.cpp b/src/Core/Requests/CommandRequest.cpp
index a280bc5..78bb650 100644
--- a/src/Core/Requests/CommandRequest.cpp
+++ b/src/Core/Requests/CommandRequest.cpp
@@ -18,18 +18,17 @@
*/
#include "CommandRequest.h"
-#include <Net/Connection.h>
namespace Mad {
namespace Core {
namespace Requests {
-void CommandRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void CommandRequest::sendRequest() {
Common::XmlPacket packet;
packet.setType("Command");
packet.add("command", reboot ? "reboot" : "shutdown");
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
}
diff --git a/src/Core/Requests/CommandRequest.h b/src/Core/Requests/CommandRequest.h
index aece5ae..2214a29 100644
--- a/src/Core/Requests/CommandRequest.h
+++ b/src/Core/Requests/CommandRequest.h
@@ -31,10 +31,11 @@ class CommandRequest : public Common::Request {
bool reboot;
protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void sendRequest();
public:
- CommandRequest(bool reboot0, slot_type slot) : Common::Request(slot), reboot(reboot0) {}
+ CommandRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, bool reboot0)
+ : Common::Request(connection, requestId, slot), reboot(reboot0) {}
};
}
diff --git a/src/Core/Requests/DaemonStateUpdateRequest.cpp b/src/Core/Requests/DaemonStateUpdateRequest.cpp
index abf51de..c8a813b 100644
--- a/src/Core/Requests/DaemonStateUpdateRequest.cpp
+++ b/src/Core/Requests/DaemonStateUpdateRequest.cpp
@@ -18,19 +18,18 @@
*/
#include "DaemonStateUpdateRequest.h"
-#include <Net/Connection.h>
namespace Mad {
namespace Core {
namespace Requests {
-void DaemonStateUpdateRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void DaemonStateUpdateRequest::sendRequest() {
Common::XmlPacket packet;
packet.setType("UpdateHostState");
packet.add("name", name);
packet.add("state", state);
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
}
diff --git a/src/Core/Requests/DaemonStateUpdateRequest.h b/src/Core/Requests/DaemonStateUpdateRequest.h
index 3f15e9b..f310119 100644
--- a/src/Core/Requests/DaemonStateUpdateRequest.h
+++ b/src/Core/Requests/DaemonStateUpdateRequest.h
@@ -33,10 +33,11 @@ class DaemonStateUpdateRequest : public Common::Request {
Common::HostInfo::State state;
protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void sendRequest();
public:
- DaemonStateUpdateRequest(const std::string &name0, Common::HostInfo::State state0) : Common::Request(slot_type()), name(name0), state(state0) {}
+ DaemonStateUpdateRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &name0, Common::HostInfo::State state0)
+ : Common::Request(connection, requestId, slot), name(name0), state(state0) {}
};
}
diff --git a/src/Daemon/Backends/NetworkLogger.h b/src/Daemon/Backends/NetworkLogger.h
index 857d27c..8dc34b9 100644
--- a/src/Daemon/Backends/NetworkLogger.h
+++ b/src/Daemon/Backends/NetworkLogger.h
@@ -23,7 +23,6 @@
#include <Common/Logger.h>
#include <Common/RequestManager.h>
#include <Daemon/Requests/LogRequest.h>
-#include <Net/Connection.h>
#include <ctime>
namespace Mad {
@@ -36,9 +35,8 @@ class NetworkLogger : public Common::Logger {
protected:
virtual void logMessage(Common::Logger::MessageCategory category, Common::Logger::MessageLevel level, time_t messageTimestamp, const std::string &message) {
- Common::RequestManager::get()->sendRequest(connection,
- std::auto_ptr<Common::Request>(new Requests::LogRequest(category, level, messageTimestamp, message, Requests::LogRequest::slot_type()))
- );
+ Common::RequestManager::get()->sendRequest<Requests::LogRequest>(connection, Common::Request::slot_type(),
+ category, level, messageTimestamp, message);
}
public:
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
index 3f4ef17..b0856c1 100644
--- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
+++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
@@ -21,16 +21,12 @@
#include <Common/Exception.h>
#include <Common/Logger.h>
#include <Common/SystemBackend.h>
-#include <Common/XmlPacket.h>
-#include <Net/Connection.h>
-
-#include <sigc++/bind.h>
namespace Mad {
namespace Daemon {
namespace RequestHandlers {
-void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+void CommandRequestHandler::handlePacket(const Common::XmlPacket &packet) {
if(packet.getType() != "Command") {
Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
@@ -38,7 +34,7 @@ void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t r
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
return;
@@ -50,11 +46,11 @@ void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t r
std::string command = packet["command"];
if(command == "reboot") {
- if(Common::SystemBackend::shutdown(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, requestId)))
+ if(Common::SystemBackend::shutdown(sigc::mem_fun(this, &CommandRequestHandler::sendReply)))
return;
}
else {
- if(Common::SystemBackend::reboot(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, requestId)))
+ if(Common::SystemBackend::reboot(sigc::mem_fun(this, &CommandRequestHandler::sendReply)))
return;
}
@@ -62,16 +58,16 @@ void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t r
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::NOT_IMPLEMENTED);
- connection->send(ret.encode(requestId));
+ sendPacket(ret);
signalFinished().emit();
}
-void CommandRequestHandler::sendReply(Net::Connection *connection, uint16_t requestId) {
+void CommandRequestHandler::sendReply() {
Common::XmlPacket packet;
packet.setType("OK");
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
signalFinished().emit();
}
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h
index 408dbcf..230a8f5 100644
--- a/src/Daemon/RequestHandlers/CommandRequestHandler.h
+++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h
@@ -29,13 +29,14 @@ namespace RequestHandlers {
class CommandRequestHandler : public Common::RequestHandler {
private:
- void sendReply(Net::Connection *connection, uint16_t requestId);
+ void sendReply();
protected:
- virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet);
+ virtual void handlePacket(const Common::XmlPacket &packet);
public:
- CommandRequestHandler() {}
+ CommandRequestHandler(Net::Connection *connection, uint16_t requestId)
+ : RequestHandler(connection, requestId) {}
};
}
diff --git a/src/Daemon/Requests/IdentifyRequest.cpp b/src/Daemon/Requests/IdentifyRequest.cpp
index 1ae9372..ba0adef 100644
--- a/src/Daemon/Requests/IdentifyRequest.cpp
+++ b/src/Daemon/Requests/IdentifyRequest.cpp
@@ -18,19 +18,17 @@
*/
#include "IdentifyRequest.h"
-#include <Net/Connection.h>
-#include <Common/XmlPacket.h>
namespace Mad {
namespace Daemon {
namespace Requests {
-void IdentifyRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void IdentifyRequest::sendRequest() {
Common::XmlPacket packet;
packet.setType("Identify");
packet.add("hostname", hostname);
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
}
diff --git a/src/Daemon/Requests/IdentifyRequest.h b/src/Daemon/Requests/IdentifyRequest.h
index b3f48ab..75ecd6e 100644
--- a/src/Daemon/Requests/IdentifyRequest.h
+++ b/src/Daemon/Requests/IdentifyRequest.h
@@ -32,10 +32,11 @@ class IdentifyRequest : public Common::Request {
std::string hostname;
protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void sendRequest();
public:
- IdentifyRequest(const std::string &hostname0, slot_type slot) : Common::Request(slot), hostname(hostname0) {}
+ IdentifyRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &hostname0)
+ : Common::Request(connection, requestId, slot), hostname(hostname0) {}
};
}
diff --git a/src/Daemon/Requests/LogRequest.cpp b/src/Daemon/Requests/LogRequest.cpp
index a7c4d03..0741168 100644
--- a/src/Daemon/Requests/LogRequest.cpp
+++ b/src/Daemon/Requests/LogRequest.cpp
@@ -18,13 +18,12 @@
*/
#include "LogRequest.h"
-#include <Net/Connection.h>
namespace Mad {
namespace Daemon {
namespace Requests {
-void LogRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void LogRequest::sendRequest() {
Common::XmlPacket packet;
packet.setType("Log");
@@ -34,7 +33,7 @@ void LogRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
packet.add("timestamp", messageTimestamp);
packet.add("message", message);
- connection->send(packet.encode(requestId));
+ sendPacket(packet);
}
}
diff --git a/src/Daemon/Requests/LogRequest.h b/src/Daemon/Requests/LogRequest.h
index 7cceade..9e22b64 100644
--- a/src/Daemon/Requests/LogRequest.h
+++ b/src/Daemon/Requests/LogRequest.h
@@ -36,11 +36,11 @@ class LogRequest : public Common::Request {
std::string message;
protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void sendRequest();
public:
- LogRequest(Common::Logger::MessageCategory category0, Common::Logger::MessageLevel level0, time_t messageTimestamp0, const std::string &message0, slot_type slot)
- : Common::Request(slot), category(category0), level(level0), messageTimestamp(messageTimestamp0), message(message0) {}
+ LogRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, Common::Logger::MessageCategory category0, Common::Logger::MessageLevel level0, time_t messageTimestamp0, const std::string &message0)
+ : Common::Request(connection, requestId, slot), category(category0), level(level0), messageTimestamp(messageTimestamp0), message(message0) {}
};
}
diff --git a/src/mad-core.cpp b/src/mad-core.cpp
index b5f6999..d5693ea 100644
--- a/src/mad-core.cpp
+++ b/src/mad-core.cpp
@@ -23,8 +23,6 @@
#include "Common/ModuleManager.h"
#include "Core/ConnectionManager.h"
-#include "Common/XmlPacket.h"
-
#include <signal.h>
using namespace Mad;
diff --git a/src/mad.cpp b/src/mad.cpp
index 3dfe379..eba4125 100644
--- a/src/mad.cpp
+++ b/src/mad.cpp
@@ -69,8 +69,8 @@ int main() {
//char hostname[256];
//gethostname(hostname, sizeof(hostname));
- //Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::XmlRequest>(new Daemon::Requests::IdentifyRequest(hostname, sigc::ptr_fun(requestFinished))));
- Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::Request>(new Daemon::Requests::IdentifyRequest("test", sigc::ptr_fun(requestFinished))));
+ //Common::RequestManager::get()->sendRequest<Daemon::Requests::IdentifyRequest>(connection, sigc::ptr_fun(requestFinished), hostname);
+ Common::RequestManager::get()->sendRequest<Daemon::Requests::IdentifyRequest>(connection, sigc::ptr_fun(requestFinished), "test");
while(connection->isConnected())
Net::FdManager::get()->run();