diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-03-12 20:26:36 +0100 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-03-12 20:26:36 +0100 |
commit | 03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e (patch) | |
tree | 863952edd85e56578e0810adbdccea3a1bf47e61 /src/Common | |
parent | de5fa3867791bf4bf84a52de8cd09821f9ce28ab (diff) | |
download | mad-03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e.tar mad-03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e.zip |
Request-Klassen vereinfacht
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Makefile.am | 2 | ||||
-rw-r--r-- | src/Common/Makefile.in | 5 | ||||
-rw-r--r-- | src/Common/Request.cpp (renamed from src/Common/Requests/UserListRequest.cpp) | 22 | ||||
-rw-r--r-- | src/Common/Request.h | 1 | ||||
-rw-r--r-- | src/Common/Requests/FSInfoRequest.h | 10 | ||||
-rw-r--r-- | src/Common/Requests/Makefile.am | 4 | ||||
-rw-r--r-- | src/Common/Requests/Makefile.in | 12 | ||||
-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.h | 10 | ||||
-rw-r--r-- | src/Common/Requests/UserListRequest.h | 10 |
11 files changed, 50 insertions, 78 deletions
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) {} }; } |