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/Requests | |
parent | de5fa3867791bf4bf84a52de8cd09821f9ce28ab (diff) | |
download | mad-03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e.tar mad-03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e.zip |
Request-Klassen vereinfacht
Diffstat (limited to 'src/Common/Requests')
-rw-r--r-- | src/Common/Requests/FSInfoRequest.cpp | 48 | ||||
-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/UserListRequest.cpp) | 18 | ||||
-rw-r--r-- | src/Common/Requests/SimpleRequest.h (renamed from src/Common/Requests/StatusRequest.cpp) | 33 | ||||
-rw-r--r-- | src/Common/Requests/StatusRequest.h | 10 | ||||
-rw-r--r-- | src/Common/Requests/UserListRequest.h | 10 |
8 files changed, 37 insertions, 108 deletions
diff --git a/src/Common/Requests/FSInfoRequest.cpp b/src/Common/Requests/FSInfoRequest.cpp deleted file mode 100644 index 7b5574d..0000000 --- a/src/Common/Requests/FSInfoRequest.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * FSInfoRequest.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 "FSInfoRequest.h" -#include <Net/Connection.h> - -#include <iostream> - -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)); -} - -void FSInfoRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) { - if(packet.getType() != "OK") { - finishWithError(Exception(Exception::UNEXPECTED_PACKET)); - return; // TODO Logging - } - - finish(packet); -} - -} -} -} - 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/UserListRequest.cpp b/src/Common/Requests/SimpleRequest.cpp index 2545677..018ac39 100644 --- a/src/Common/Requests/UserListRequest.cpp +++ b/src/Common/Requests/SimpleRequest.cpp @@ -1,5 +1,5 @@ /* - * UserListRequest.cpp + * SimpleRequest.cpp * * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> * @@ -17,29 +17,21 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "UserListRequest.h" +#include "SimpleRequest.h" + #include <Net/Connection.h> namespace Mad { namespace Common { namespace Requests { -void UserListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { +void SimpleRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { XmlPacket packet; - packet.setType("ListUsers"); + packet.setType(type); connection->send(packet.encode(requestId)); } -void UserListRequest::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/StatusRequest.cpp b/src/Common/Requests/SimpleRequest.h index 3526e23..0426910 100644 --- a/src/Common/Requests/StatusRequest.cpp +++ b/src/Common/Requests/SimpleRequest.h @@ -1,7 +1,7 @@ /* - * CoreStatusRequest.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,29 +17,28 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "StatusRequest.h" -#include <Net/Connection.h> +#ifndef MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_ +#define MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_ + +#include "../Request.h" + +#include <string> namespace Mad { namespace Common { namespace Requests { -void StatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { - XmlPacket packet; - packet.setType("GetStatus"); - - connection->send(packet.encode(requestId)); -} +class SimpleRequest : public Request { + protected: + const std::string type; -void StatusRequest::handlePacket(Net::Connection*, uint16_t, const 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) {} }; } |