summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp27
-rw-r--r--src/Client/CommandParser.h3
-rw-r--r--src/Client/Requests/CoreStatusRequest.cpp3
-rw-r--r--src/Client/Requests/DaemonListRequest.cpp66
-rw-r--r--src/Client/Requests/DaemonListRequest.h55
-rw-r--r--src/Client/Requests/Makefile.am4
-rw-r--r--src/Client/Requests/Makefile.in7
7 files changed, 157 insertions, 8 deletions
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 <Common/Requests/DisconnectRequest.h>
#include <Net/Packets/HostStatusPacket.h>
+#include <Net/Packets/NameListPacket.h>
#include <iostream>
#include <cstdio>
@@ -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<std::string> &args) {
}
}
+void CommandParser::listHostsCommand(const std::vector<std::string>&) {
+ activeRequests++;
+
+ Requests::DaemonListRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonListRequestFinished));
+}
+
void CommandParser::statusCommand(const std::vector<std::string>&) {
activeRequests++;
@@ -153,6 +162,24 @@ void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPack
requestFinished();
}
+void CommandParser::daemonListRequestFinished(const Net::Packets::NameListPacket &packet) {
+ const std::vector<std::string>& 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<std::string>::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<std::string> &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<std::string> &args);
+ void listHostsCommand(const std::vector<std::string>&);
void statusCommand(const std::vector<std::string>&);
void exitCommand(const std::vector<std::string>&);
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 <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 $@ $<