From 03e7a5b2fefa08d49ef34e70bfb1d52f0a7d828e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 12 Mar 2009 20:26:36 +0100 Subject: Request-Klassen vereinfacht --- src/Common/Requests/FSInfoRequest.cpp | 48 --------------------------------- src/Common/Requests/FSInfoRequest.h | 10 +++---- src/Common/Requests/Makefile.am | 4 +-- src/Common/Requests/Makefile.in | 12 ++++----- src/Common/Requests/SimpleRequest.cpp | 37 +++++++++++++++++++++++++ src/Common/Requests/SimpleRequest.h | 44 ++++++++++++++++++++++++++++++ src/Common/Requests/StatusRequest.cpp | 45 ------------------------------- src/Common/Requests/StatusRequest.h | 10 +++---- src/Common/Requests/UserListRequest.cpp | 45 ------------------------------- src/Common/Requests/UserListRequest.h | 10 +++---- 10 files changed, 97 insertions(+), 168 deletions(-) delete mode 100644 src/Common/Requests/FSInfoRequest.cpp create mode 100644 src/Common/Requests/SimpleRequest.cpp create mode 100644 src/Common/Requests/SimpleRequest.h delete mode 100644 src/Common/Requests/StatusRequest.cpp delete mode 100644 src/Common/Requests/UserListRequest.cpp (limited to 'src/Common/Requests') 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 - * - * 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 . - */ - -#include "FSInfoRequest.h" -#include - -#include - -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/SimpleRequest.cpp b/src/Common/Requests/SimpleRequest.cpp new file mode 100644 index 0000000..018ac39 --- /dev/null +++ b/src/Common/Requests/SimpleRequest.cpp @@ -0,0 +1,37 @@ +/* + * SimpleRequest.cpp + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 . + */ + +#include "SimpleRequest.h" + +#include + +namespace Mad { +namespace Common { +namespace Requests { + +void SimpleRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + XmlPacket packet; + packet.setType(type); + + connection->send(packet.encode(requestId)); +} + +} +} +} diff --git a/src/Common/Requests/SimpleRequest.h b/src/Common/Requests/SimpleRequest.h new file mode 100644 index 0000000..0426910 --- /dev/null +++ b/src/Common/Requests/SimpleRequest.h @@ -0,0 +1,44 @@ +/* + * SimpleRequest.h + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 . + */ + +#ifndef MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_ +#define MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_ + +#include "../Request.h" + +#include + +namespace Mad { +namespace Common { +namespace Requests { + +class SimpleRequest : public Request { + protected: + const std::string type; + + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + + 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.cpp b/src/Common/Requests/StatusRequest.cpp deleted file mode 100644 index 3526e23..0000000 --- a/src/Common/Requests/StatusRequest.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * CoreStatusRequest.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "StatusRequest.h" -#include - -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)); -} - -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/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.cpp b/src/Common/Requests/UserListRequest.cpp deleted file mode 100644 index 2545677..0000000 --- a/src/Common/Requests/UserListRequest.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * UserListRequest.cpp - * - * Copyright (C) 2009 Matthias Schiffer - * - * 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 . - */ - -#include "UserListRequest.h" -#include - -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) { - if(packet.getType() != "OK") { - finishWithError(Exception(Exception::UNEXPECTED_PACKET)); - return; // TODO Logging - } - - finish(packet); -} - -} -} -} 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) {} }; } -- cgit v1.2.3