summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-03-12 20:26:36 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-03-12 20:26:36 +0100
commit03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e (patch)
tree863952edd85e56578e0810adbdccea3a1bf47e61
parentde5fa3867791bf4bf84a52de8cd09821f9ce28ab (diff)
downloadmad-03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e.tar
mad-03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e.zip
Request-Klassen vereinfacht
-rw-r--r--src/Client/Requests/DaemonCommandRequest.cpp13
-rw-r--r--src/Client/Requests/DaemonCommandRequest.h3
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.cpp13
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.h1
-rw-r--r--src/Client/Requests/DaemonListRequest.cpp45
-rw-r--r--src/Client/Requests/DaemonListRequest.h12
-rw-r--r--src/Client/Requests/DaemonStatusRequest.cpp9
-rw-r--r--src/Client/Requests/DaemonStatusRequest.h1
-rw-r--r--src/Client/Requests/Makefile.am2
-rw-r--r--src/Client/Requests/Makefile.in6
-rw-r--r--src/Common/Makefile.am2
-rw-r--r--src/Common/Makefile.in5
-rw-r--r--src/Common/Request.cpp (renamed from src/Common/Requests/UserListRequest.cpp)22
-rw-r--r--src/Common/Request.h1
-rw-r--r--src/Common/Requests/FSInfoRequest.h10
-rw-r--r--src/Common/Requests/Makefile.am4
-rw-r--r--src/Common/Requests/Makefile.in12
-rw-r--r--src/Common/Requests/SimpleRequest.cpp (renamed from src/Common/Requests/StatusRequest.cpp)20
-rw-r--r--src/Common/Requests/SimpleRequest.h (renamed from src/Common/Requests/FSInfoRequest.cpp)32
-rw-r--r--src/Common/Requests/StatusRequest.h10
-rw-r--r--src/Common/Requests/UserListRequest.h10
-rw-r--r--src/Core/Requests/CommandRequest.cpp13
-rw-r--r--src/Core/Requests/CommandRequest.h1
-rw-r--r--src/Core/Requests/DaemonStateUpdateRequest.cpp9
-rw-r--r--src/Core/Requests/DaemonStateUpdateRequest.h1
-rw-r--r--src/Daemon/Requests/IdentifyRequest.cpp9
-rw-r--r--src/Daemon/Requests/IdentifyRequest.h1
-rw-r--r--src/Daemon/Requests/LogRequest.cpp9
-rw-r--r--src/Daemon/Requests/LogRequest.h1
29 files changed, 58 insertions, 219 deletions
diff --git a/src/Client/Requests/DaemonCommandRequest.cpp b/src/Client/Requests/DaemonCommandRequest.cpp
index 6e82c60..7b444cd 100644
--- a/src/Client/Requests/DaemonCommandRequest.cpp
+++ b/src/Client/Requests/DaemonCommandRequest.cpp
@@ -34,19 +34,6 @@ void DaemonCommandRequest::sendRequest(Net::Connection *connection, uint16_t req
connection->send(packet.encode(requestId));
}
-void DaemonCommandRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() == "Error") {
- finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
- return;
- }
- else if(packet.getType() != "OK") {
- finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
}
}
}
diff --git a/src/Client/Requests/DaemonCommandRequest.h b/src/Client/Requests/DaemonCommandRequest.h
index 13a6da6..fa1e436 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/Request.h>
+#include <Common/Requests/SimpleRequest.h>
#include <string>
namespace Mad {
@@ -34,7 +34,6 @@ class DaemonCommandRequest : public Common::Request {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
DaemonCommandRequest(const std::string &daemon0, bool reboot0, slot_type slot) : Common::Request(slot), daemon(daemon0), reboot(reboot0) {}
diff --git a/src/Client/Requests/DaemonFSInfoRequest.cpp b/src/Client/Requests/DaemonFSInfoRequest.cpp
index 919a8f8..acd1179 100644
--- a/src/Client/Requests/DaemonFSInfoRequest.cpp
+++ b/src/Client/Requests/DaemonFSInfoRequest.cpp
@@ -32,19 +32,6 @@ void DaemonFSInfoRequest::sendRequest(Net::Connection *connection, uint16_t requ
connection->send(packet.encode(requestId));
}
-void DaemonFSInfoRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() == "Error") {
- finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
- return;
- }
- else if(packet.getType() != "OK") {
- finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
}
}
}
diff --git a/src/Client/Requests/DaemonFSInfoRequest.h b/src/Client/Requests/DaemonFSInfoRequest.h
index a42d85a..ac29a8b 100644
--- a/src/Client/Requests/DaemonFSInfoRequest.h
+++ b/src/Client/Requests/DaemonFSInfoRequest.h
@@ -34,7 +34,6 @@ class DaemonFSInfoRequest : public Common::Request {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
DaemonFSInfoRequest(const std::string &daemon0, slot_type slot) : Common::Request(slot), daemon(daemon0) {}
diff --git a/src/Client/Requests/DaemonListRequest.cpp b/src/Client/Requests/DaemonListRequest.cpp
deleted file mode 100644
index ec80828..0000000
--- a/src/Client/Requests/DaemonListRequest.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * DaemonListRequest.cpp
- *
- * Copyright (C) 2008 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 "DaemonListRequest.h"
-#include <Net/Connection.h>
-
-namespace Mad {
-namespace Client {
-namespace Requests {
-
-void DaemonListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- Common::XmlPacket packet;
-
- packet.setType("ListHosts");
- connection->send(packet.encode(requestId));
-}
-
-void DaemonListRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() != "OK") {
- finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
-}
-}
-}
diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h
index 3b561d2..a09894e 100644
--- a/src/Client/Requests/DaemonListRequest.h
+++ b/src/Client/Requests/DaemonListRequest.h
@@ -20,19 +20,15 @@
#ifndef MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
#define MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
-#include <Common/Request.h>
+#include <Common/Requests/SimpleRequest.h>
namespace Mad {
namespace Client {
namespace Requests {
-class DaemonListRequest : public Common::Request {
- protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
-
- public:
- DaemonListRequest(slot_type slot) : Common::Request(slot) {}
+class DaemonListRequest : public Common::Requests::SimpleRequest {
+ public:
+ DaemonListRequest(slot_type slot) : SimpleRequest("ListDaemons", slot) {}
};
}
diff --git a/src/Client/Requests/DaemonStatusRequest.cpp b/src/Client/Requests/DaemonStatusRequest.cpp
index f088fcc..7611d30 100644
--- a/src/Client/Requests/DaemonStatusRequest.cpp
+++ b/src/Client/Requests/DaemonStatusRequest.cpp
@@ -32,15 +32,6 @@ void DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requ
connection->send(packet.encode(requestId));
}
-void DaemonStatusRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() != "OK") {
- finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
}
}
}
diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h
index 2ccc9b2..bf8b7bf 100644
--- a/src/Client/Requests/DaemonStatusRequest.h
+++ b/src/Client/Requests/DaemonStatusRequest.h
@@ -34,7 +34,6 @@ class DaemonStatusRequest : public Common::Request {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
DaemonStatusRequest(const std::string &daemon0, slot_type slot) : Common::Request(slot), daemon(daemon0) {}
diff --git a/src/Client/Requests/Makefile.am b/src/Client/Requests/Makefile.am
index a96b265..fe09d38 100644
--- a/src/Client/Requests/Makefile.am
+++ b/src/Client/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DaemonCommandRequest.cpp DaemonFSInfoRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp
+librequests_la_SOURCES = DaemonCommandRequest.cpp DaemonFSInfoRequest.cpp DaemonStatusRequest.cpp
noinst_HEADERS = DaemonCommandRequest.h DaemonFSInfoRequest.h DaemonListRequest.h DaemonStatusRequest.h
diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in
index 6558799..0e70532 100644
--- a/src/Client/Requests/Makefile.in
+++ b/src/Client/Requests/Makefile.in
@@ -53,8 +53,7 @@ CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
am_librequests_la_OBJECTS = DaemonCommandRequest.lo \
- DaemonFSInfoRequest.lo DaemonListRequest.lo \
- DaemonStatusRequest.lo
+ DaemonFSInfoRequest.lo DaemonStatusRequest.lo
librequests_la_OBJECTS = $(am_librequests_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -225,7 +224,7 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DaemonCommandRequest.cpp DaemonFSInfoRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp
+librequests_la_SOURCES = DaemonCommandRequest.cpp DaemonFSInfoRequest.cpp DaemonStatusRequest.cpp
noinst_HEADERS = DaemonCommandRequest.h DaemonFSInfoRequest.h DaemonListRequest.h DaemonStatusRequest.h
all: all-am
@@ -280,7 +279,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonCommandRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonFSInfoRequest.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequest.Plo@am__quote@
.cpp.o:
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index e1c22b9..f0a0ad7 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -2,7 +2,7 @@ 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 RequestManager.cpp \
+ Logger.cpp LogManager.cpp ModuleManager.cpp Request.cpp RequestManager.cpp \
SystemBackend.cpp Tokenizer.cpp XmlPacket.cpp
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index d70edc7..9841291 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -55,7 +55,7 @@ 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 RequestManager.lo \
+ LogManager.lo ModuleManager.lo Request.lo RequestManager.lo \
SystemBackend.lo Tokenizer.lo XmlPacket.lo
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@@ -239,7 +239,7 @@ 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 RequestManager.cpp \
+ Logger.cpp LogManager.cpp ModuleManager.cpp Request.cpp RequestManager.cpp \
SystemBackend.cpp Tokenizer.cpp XmlPacket.cpp
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
@@ -307,6 +307,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogManager.Plo@am__quote@
@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)/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/Requests/UserListRequest.cpp b/src/Common/Request.cpp
index 2545677..0b8715e 100644
--- a/src/Common/Requests/UserListRequest.cpp
+++ b/src/Common/Request.cpp
@@ -1,5 +1,5 @@
/*
- * UserListRequest.cpp
+ * Request.cpp
*
* Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
*
@@ -17,21 +17,18 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "UserListRequest.h"
-#include <Net/Connection.h>
+#include <config.h>
+
+#include "Request.h"
namespace Mad {
namespace Common {
-namespace Requests {
-
-void UserListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- XmlPacket packet;
- packet.setType("ListUsers");
-
- connection->send(packet.encode(requestId));
-}
-void UserListRequest::handlePacket(Net::Connection*, uint16_t, const XmlPacket &packet) {
+void Request::handlePacket(Net::Connection *connection _UNUSED_PARAMETER_, uint16_t requestId _UNUSED_PARAMETER_, const XmlPacket &packet) {
+ if(packet.getType() == "Error") {
+ finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
+ return;
+ }
if(packet.getType() != "OK") {
finishWithError(Exception(Exception::UNEXPECTED_PACKET));
return; // TODO Logging
@@ -42,4 +39,3 @@ void UserListRequest::handlePacket(Net::Connection*, uint16_t, const XmlPacket &
}
}
-}
diff --git a/src/Common/Request.h b/src/Common/Request.h
index b0e6777..ef84194 100644
--- a/src/Common/Request.h
+++ b/src/Common/Request.h
@@ -53,6 +53,7 @@ class Request : public RequestHandler {
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);
public:
const XmlPacket& getResult() const throw(Exception) {
diff --git a/src/Common/Requests/FSInfoRequest.h b/src/Common/Requests/FSInfoRequest.h
index 39759ab..27a38ed 100644
--- a/src/Common/Requests/FSInfoRequest.h
+++ b/src/Common/Requests/FSInfoRequest.h
@@ -20,19 +20,15 @@
#ifndef MAD_COMMON_REQUESTS_FSINFOREQUEST_H_
#define MAD_COMMON_REQUESTS_FSINFOREQUEST_H_
-#include "../Request.h"
+#include "SimpleRequest.h"
namespace Mad {
namespace Common {
namespace Requests {
-class FSInfoRequest : public Request {
- protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
-
+class FSInfoRequest : public SimpleRequest {
public:
- FSInfoRequest(slot_type slot) : Request(slot) {}
+ FSInfoRequest(slot_type slot) : SimpleRequest("FSInfo", slot) {}
};
}
diff --git a/src/Common/Requests/Makefile.am b/src/Common/Requests/Makefile.am
index eae8669..b5c3bec 100644
--- a/src/Common/Requests/Makefile.am
+++ b/src/Common/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DisconnectRequest.cpp FSInfoRequest.cpp GSSAPIAuthRequest.cpp StatusRequest.cpp UserListRequest.cpp
+librequests_la_SOURCES = DisconnectRequest.cpp GSSAPIAuthRequest.cpp SimpleRequest.cpp
-noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h StatusRequest.h UserListRequest.h
+noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h SimpleRequest.h StatusRequest.h UserListRequest.h
diff --git a/src/Common/Requests/Makefile.in b/src/Common/Requests/Makefile.in
index f8b1bc6..8533102 100644
--- a/src/Common/Requests/Makefile.in
+++ b/src/Common/Requests/Makefile.in
@@ -52,8 +52,8 @@ CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
-am_librequests_la_OBJECTS = DisconnectRequest.lo FSInfoRequest.lo \
- GSSAPIAuthRequest.lo StatusRequest.lo UserListRequest.lo
+am_librequests_la_OBJECTS = DisconnectRequest.lo GSSAPIAuthRequest.lo \
+ SimpleRequest.lo
librequests_la_OBJECTS = $(am_librequests_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -224,8 +224,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DisconnectRequest.cpp FSInfoRequest.cpp GSSAPIAuthRequest.cpp StatusRequest.cpp UserListRequest.cpp
-noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h StatusRequest.h UserListRequest.h
+librequests_la_SOURCES = DisconnectRequest.cpp GSSAPIAuthRequest.cpp SimpleRequest.cpp
+noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h SimpleRequest.h StatusRequest.h UserListRequest.h
all: all-am
.SUFFIXES:
@@ -278,10 +278,8 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DisconnectRequest.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FSInfoRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequest.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StatusRequest.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserListRequest.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleRequest.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/Common/Requests/StatusRequest.cpp b/src/Common/Requests/SimpleRequest.cpp
index 3526e23..018ac39 100644
--- a/src/Common/Requests/StatusRequest.cpp
+++ b/src/Common/Requests/SimpleRequest.cpp
@@ -1,7 +1,7 @@
/*
- * CoreStatusRequest.cpp
+ * SimpleRequest.cpp
*
- * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ * 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
@@ -17,29 +17,21 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "StatusRequest.h"
+#include "SimpleRequest.h"
+
#include <Net/Connection.h>
namespace Mad {
namespace Common {
namespace Requests {
-void StatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+void SimpleRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
XmlPacket packet;
- packet.setType("GetStatus");
+ packet.setType(type);
connection->send(packet.encode(requestId));
}
-void StatusRequest::handlePacket(Net::Connection*, uint16_t, const XmlPacket &packet) {
- if(packet.getType() != "OK") {
- finishWithError(Exception(Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
}
}
}
diff --git a/src/Common/Requests/FSInfoRequest.cpp b/src/Common/Requests/SimpleRequest.h
index 7b5574d..0426910 100644
--- a/src/Common/Requests/FSInfoRequest.cpp
+++ b/src/Common/Requests/SimpleRequest.h
@@ -1,7 +1,7 @@
/*
- * FSInfoRequest.cpp
+ * SimpleRequest.h
*
- * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ * 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
@@ -17,32 +17,28 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "FSInfoRequest.h"
-#include <Net/Connection.h>
+#ifndef MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_
+#define MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_
-#include <iostream>
+#include "../Request.h"
+
+#include <string>
namespace Mad {
namespace Common {
namespace Requests {
-void FSInfoRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- XmlPacket packet;
- packet.setType("FSInfo");
-
- connection->send(packet.encode(requestId));
-}
+class SimpleRequest : public Request {
+ protected:
+ const std::string type;
-void FSInfoRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() != "OK") {
- finishWithError(Exception(Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
+ virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- finish(packet);
-}
+ SimpleRequest(const std::string &type0, slot_type slot) : Request(slot), type(type0) {}
+};
}
}
}
+#endif /* MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_ */
diff --git a/src/Common/Requests/StatusRequest.h b/src/Common/Requests/StatusRequest.h
index eb24305..d557358 100644
--- a/src/Common/Requests/StatusRequest.h
+++ b/src/Common/Requests/StatusRequest.h
@@ -20,19 +20,15 @@
#ifndef MAD_COMMON_REQUESTS_STATUSREQUEST_H_
#define MAD_COMMON_REQUESTS_STATUSREQUEST_H_
-#include "../Request.h"
+#include "SimpleRequest.h"
namespace Mad {
namespace Common {
namespace Requests {
-class StatusRequest : public Request {
- protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet);
-
+class StatusRequest : public SimpleRequest {
public:
- StatusRequest(slot_type slot) : Request(slot) {}
+ StatusRequest(slot_type slot) : SimpleRequest("GetStatus", slot) {}
};
}
diff --git a/src/Common/Requests/UserListRequest.h b/src/Common/Requests/UserListRequest.h
index bcd9578..918925c 100644
--- a/src/Common/Requests/UserListRequest.h
+++ b/src/Common/Requests/UserListRequest.h
@@ -20,19 +20,15 @@
#ifndef MAD_COMMON_REQUESTS_USERLISTREQUEST_H_
#define MAD_COMMON_REQUESTS_USERLISTREQUEST_H_
-#include "../Request.h"
+#include "SimpleRequest.h"
namespace Mad {
namespace Common {
namespace Requests {
-class UserListRequest : public Request {
- protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet);
-
+class UserListRequest : public SimpleRequest {
public:
- UserListRequest(slot_type slot) : Request(slot) {}
+ UserListRequest(slot_type slot) : SimpleRequest("ListUsers", slot) {}
};
}
diff --git a/src/Core/Requests/CommandRequest.cpp b/src/Core/Requests/CommandRequest.cpp
index 8fdd4c2..a280bc5 100644
--- a/src/Core/Requests/CommandRequest.cpp
+++ b/src/Core/Requests/CommandRequest.cpp
@@ -32,19 +32,6 @@ void CommandRequest::sendRequest(Net::Connection *connection, uint16_t requestId
connection->send(packet.encode(requestId));
}
-void CommandRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() == "Error") {
- finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
- return;
- }
- else if(packet.getType() != "OK") {
- finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
}
}
}
diff --git a/src/Core/Requests/CommandRequest.h b/src/Core/Requests/CommandRequest.h
index 9c6c70d..aece5ae 100644
--- a/src/Core/Requests/CommandRequest.h
+++ b/src/Core/Requests/CommandRequest.h
@@ -32,7 +32,6 @@ class CommandRequest : public Common::Request {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
CommandRequest(bool reboot0, slot_type slot) : Common::Request(slot), reboot(reboot0) {}
diff --git a/src/Core/Requests/DaemonStateUpdateRequest.cpp b/src/Core/Requests/DaemonStateUpdateRequest.cpp
index c00468e..abf51de 100644
--- a/src/Core/Requests/DaemonStateUpdateRequest.cpp
+++ b/src/Core/Requests/DaemonStateUpdateRequest.cpp
@@ -33,15 +33,6 @@ void DaemonStateUpdateRequest::sendRequest(Net::Connection *connection, uint16_t
connection->send(packet.encode(requestId));
}
-void DaemonStateUpdateRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() != "OK") {
- finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
}
}
}
diff --git a/src/Core/Requests/DaemonStateUpdateRequest.h b/src/Core/Requests/DaemonStateUpdateRequest.h
index f1466b2..3f15e9b 100644
--- a/src/Core/Requests/DaemonStateUpdateRequest.h
+++ b/src/Core/Requests/DaemonStateUpdateRequest.h
@@ -34,7 +34,6 @@ class DaemonStateUpdateRequest : public Common::Request {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
DaemonStateUpdateRequest(const std::string &name0, Common::HostInfo::State state0) : Common::Request(slot_type()), name(name0), state(state0) {}
diff --git a/src/Daemon/Requests/IdentifyRequest.cpp b/src/Daemon/Requests/IdentifyRequest.cpp
index 6334f00..1ae9372 100644
--- a/src/Daemon/Requests/IdentifyRequest.cpp
+++ b/src/Daemon/Requests/IdentifyRequest.cpp
@@ -33,15 +33,6 @@ void IdentifyRequest::sendRequest(Net::Connection *connection, uint16_t requestI
connection->send(packet.encode(requestId));
}
-void IdentifyRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() != "OK") {
- finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
}
}
}
diff --git a/src/Daemon/Requests/IdentifyRequest.h b/src/Daemon/Requests/IdentifyRequest.h
index 5009374..b3f48ab 100644
--- a/src/Daemon/Requests/IdentifyRequest.h
+++ b/src/Daemon/Requests/IdentifyRequest.h
@@ -33,7 +33,6 @@ class IdentifyRequest : public Common::Request {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
IdentifyRequest(const std::string &hostname0, slot_type slot) : Common::Request(slot), hostname(hostname0) {}
diff --git a/src/Daemon/Requests/LogRequest.cpp b/src/Daemon/Requests/LogRequest.cpp
index f7a498d..a7c4d03 100644
--- a/src/Daemon/Requests/LogRequest.cpp
+++ b/src/Daemon/Requests/LogRequest.cpp
@@ -37,15 +37,6 @@ void LogRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
connection->send(packet.encode(requestId));
}
-void LogRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
- if(packet.getType() != "OK") {
- finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
- return; // TODO Logging
- }
-
- finish(packet);
-}
-
}
}
}
diff --git a/src/Daemon/Requests/LogRequest.h b/src/Daemon/Requests/LogRequest.h
index 1045a2f..7cceade 100644
--- a/src/Daemon/Requests/LogRequest.h
+++ b/src/Daemon/Requests/LogRequest.h
@@ -37,7 +37,6 @@ class LogRequest : public Common::Request {
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
LogRequest(Common::Logger::MessageCategory category0, Common::Logger::MessageLevel level0, time_t messageTimestamp0, const std::string &message0, slot_type slot)