From 30bec92571ba23f1f2aa6b12149f6545a4ef0d7e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 15 Sep 2008 04:46:28 +0200 Subject: Hosts k?nnen jetzt aufgelistet werden --- src/Client/CommandParser.cpp | 27 +++++++++++++ src/Client/CommandParser.h | 3 ++ src/Client/Requests/CoreStatusRequest.cpp | 3 -- src/Client/Requests/DaemonListRequest.cpp | 66 +++++++++++++++++++++++++++++++ src/Client/Requests/DaemonListRequest.h | 55 ++++++++++++++++++++++++++ src/Client/Requests/Makefile.am | 4 +- src/Client/Requests/Makefile.in | 7 ++-- 7 files changed, 157 insertions(+), 8 deletions(-) create mode 100644 src/Client/Requests/DaemonListRequest.cpp create mode 100644 src/Client/Requests/DaemonListRequest.h (limited to 'src/Client') diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 9644d71..badbef7 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -19,8 +19,10 @@ #include "CommandParser.h" #include "Requests/CoreStatusRequest.h" +#include "Requests/DaemonListRequest.h" #include #include +#include #include #include @@ -30,6 +32,7 @@ namespace Client { const CommandParser::Command CommandParser::commands[] = { {{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand}, + {{"list_hosts", "hosts", 0}, "list_hosts", "Lists the currently active hosts", "Lists the currently active hosts", &CommandParser::listHostsCommand}, {{"status", "st", 0}, "status", "Displays server status information", "Displays server status information.", &CommandParser::statusCommand}, {{"exit", "quit", 0}, "exit", "Closes the connection and quits the client", "Closes the connection and quits the client.", &CommandParser::exitCommand}, {{0}, 0, 0, 0, 0} @@ -83,6 +86,12 @@ void CommandParser::helpCommand(const std::vector &args) { } } +void CommandParser::listHostsCommand(const std::vector&) { + activeRequests++; + + Requests::DaemonListRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonListRequestFinished)); +} + void CommandParser::statusCommand(const std::vector&) { activeRequests++; @@ -153,6 +162,24 @@ void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPack requestFinished(); } +void CommandParser::daemonListRequestFinished(const Net::Packets::NameListPacket &packet) { + const std::vector& hosts = packet.getNameList(); + + if(hosts.empty()) { + std::cout << "There aren't any active hosts." << std::endl << std::endl; + } + else { + std::cout << "Active hosts:" << std::endl; + + for(std::vector::const_iterator host = hosts.begin(); host != hosts.end(); ++host) + std::cout << "\t" << *host << std::endl; + + std::cout << std::endl; + } + + requestFinished(); +} + bool CommandParser::split(const std::string &str, std::vector &ret) { std::string temp; bool quoteSingle = false, quoteDouble = false, escape = false; diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index 69ed217..40d36a7 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -31,6 +31,7 @@ class Connection; namespace Packets { class HostStatusPacket; +class NameListPacket; } } @@ -63,10 +64,12 @@ class CommandParser { void printUsage(const std::string& command); void helpCommand(const std::vector &args); + void listHostsCommand(const std::vector&); void statusCommand(const std::vector&); void exitCommand(const std::vector&); void coreStatusRequestFinished(const Net::Packets::HostStatusPacket &packet); + void daemonListRequestFinished(const Net::Packets::NameListPacket &packet); void requestFinished() { activeRequests--; 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 #include -#include - 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 + * + * 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 "DaemonListRequest.h" +#include +#include + +namespace Mad { +namespace Client { +namespace Requests { + +bool DaemonListRequest::send(Net::Connection *connection, const sigc::slot &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 + * + * 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_CLIENT_REQUEST_DAEMONLISTREQUEST_H_ +#define MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_ + +#include + +#include + +namespace Mad { + +namespace Net { +namespace Packets { +class NameListPacket; +} +} + +namespace Client { +namespace Requests { + +class DaemonListRequest : public Common::Request { + private: + sigc::signal finished; + + DaemonListRequest() {} + + public: + static bool send(Net::Connection *connection, const sigc::slot &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 $@ $< -- cgit v1.2.3