summaryrefslogtreecommitdiffstats
path: root/src/Daemon
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 /src/Daemon
parentaef0f2e7a5085b8da3aa2e97565215d182d3dd2d (diff)
downloadmad-8f098fc3070f791302ec1f497588fab6ed409980.tar
mad-8f098fc3070f791302ec1f497588fab6ed409980.zip
Request- und RequestHandler-Interfaces vereinfacht
Diffstat (limited to 'src/Daemon')
-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
7 files changed, 23 insertions, 30 deletions
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) {}
};
}