diff options
Diffstat (limited to 'src/Client/Requests')
-rw-r--r-- | src/Client/Requests/CoreStatusRequest.cpp | 3 | ||||
-rw-r--r-- | src/Client/Requests/DaemonListRequest.cpp | 66 | ||||
-rw-r--r-- | src/Client/Requests/DaemonListRequest.h | 55 | ||||
-rw-r--r-- | src/Client/Requests/Makefile.am | 4 | ||||
-rw-r--r-- | src/Client/Requests/Makefile.in | 7 |
5 files changed, 127 insertions, 8 deletions
diff --git a/src/Client/Requests/CoreStatusRequest.cpp b/src/Client/Requests/CoreStatusRequest.cpp index 6d0f634..af34752 100644 --- a/src/Client/Requests/CoreStatusRequest.cpp +++ b/src/Client/Requests/CoreStatusRequest.cpp @@ -18,12 +18,9 @@ */ #include "CoreStatusRequest.h" - #include <Common/RequestManager.h> #include <Net/Packets/HostStatusPacket.h> -#include <sigc++/signal.h> - namespace Mad { namespace Client { namespace Requests { diff --git a/src/Client/Requests/DaemonListRequest.cpp b/src/Client/Requests/DaemonListRequest.cpp new file mode 100644 index 0000000..a0e4cf1 --- /dev/null +++ b/src/Client/Requests/DaemonListRequest.cpp @@ -0,0 +1,66 @@ +/* + * 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 <Common/RequestManager.h> +#include <Net/Packets/NameListPacket.h> + +namespace Mad { +namespace Client { +namespace Requests { + +bool DaemonListRequest::send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::NameListPacket&> &callback) { + DaemonListRequest *request = new DaemonListRequest(); + + request->finished.connect(callback); + + if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) + return true; + + delete request; + return false; +} + +bool DaemonListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + if(isSent()) + return false; + + if(!connection->send(Net::Packet(Net::Packet::LIST_DAEMONS, requestId))) + return false; + + setSent(); + return true; +} + +bool DaemonListRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::OK) + return false; // TODO Logging + + finished(Net::Packets::NameListPacket(packet)); + + setFinished(); + return true; +} + +} +} +} diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h new file mode 100644 index 0000000..1a820d7 --- /dev/null +++ b/src/Client/Requests/DaemonListRequest.h @@ -0,0 +1,55 @@ +/* + * DaemonListRequest.h + * + * 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/>. + */ + +#ifndef MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_ +#define MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_ + +#include <Common/Request.h> + +#include <sigc++/signal.h> + +namespace Mad { + +namespace Net { +namespace Packets { +class NameListPacket; +} +} + +namespace Client { +namespace Requests { + +class DaemonListRequest : public Common::Request { + private: + sigc::signal<void,const Net::Packets::NameListPacket&> finished; + + DaemonListRequest() {} + + public: + static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::NameListPacket&> &callback); + + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); + virtual bool handlePacket(Net::Connection*, const Net::Packet &packet); +}; + +} +} +} + +#endif /* MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_ */ diff --git a/src/Client/Requests/Makefile.am b/src/Client/Requests/Makefile.am index 4ba72b6..bf15a08 100644 --- a/src/Client/Requests/Makefile.am +++ b/src/Client/Requests/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = CoreStatusRequest.cpp +librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp -noinst_HEADERS = CoreStatusRequest.h +noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in index 174e64f..81f6cec 100644 --- a/src/Client/Requests/Makefile.in +++ b/src/Client/Requests/Makefile.in @@ -45,7 +45,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequests_la_LIBADD = -am_librequests_la_OBJECTS = CoreStatusRequest.lo +am_librequests_la_OBJECTS = CoreStatusRequest.lo DaemonListRequest.lo librequests_la_OBJECTS = $(am_librequests_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -184,8 +184,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = CoreStatusRequest.cpp -noinst_HEADERS = CoreStatusRequest.h +librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp +noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h all: all-am .SUFFIXES: @@ -238,6 +238,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CoreStatusRequest.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequest.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< |