summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-18 21:31:28 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-18 21:31:28 +0200
commit793a0789858734141dfa12d2ab3dd6ea3ed293e8 (patch)
tree8a1259eca5cff868c58c21dc140975175dcca0fa /src
parentb503a70fca019368399038cde649b3ef8df85bb9 (diff)
downloadmad-793a0789858734141dfa12d2ab3dd6ea3ed293e8.tar
mad-793a0789858734141dfa12d2ab3dd6ea3ed293e8.zip
list_hosts zeigt entweder alle oder nur aktive Hosts an
Diffstat (limited to 'src')
-rw-r--r--src/Client/CommandParser.cpp63
-rw-r--r--src/Client/CommandParser.h4
2 files changed, 56 insertions, 11 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 76178dc..34c7e4f 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -30,13 +30,14 @@
#include <iostream>
#include <cstdio>
+#include <sigc++/bind.h>
namespace Mad {
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},
+ {{"list_hosts", "hosts", 0}, "list_hosts [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand},
{{"status", "st", 0}, "status [host]", "Displays status information", "Displays host status information. If no host is given, server status information is displayed.", &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}
@@ -143,10 +144,37 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) {
}
}
-void CommandParser::listHostsCommand(const std::vector<std::string>&) {
- activeRequests++;
+void CommandParser::listHostsCommand(const std::vector<std::string> &args) {
+ if(args.size() == 1) {
+ Common::RequestManager::getRequestManager()->sendRequest(connection,
+ std::auto_ptr<Common::RequestBase>(
+ new Requests::DaemonListRequest(
+ sigc::bind(sigc::mem_fun(this, &CommandParser::daemonListRequestFinished), false)
+ )
+ )
+ );
+ }
+ else if(args.size() > 2) {
+ Common::Logger::log(Common::Logger::ERROR, args[0] + ": Too many arguments.");
+ printUsage("list_hosts");
+ return;
+ }
+ else if(args[1] == "-a") {
+ Common::RequestManager::getRequestManager()->sendRequest(connection,
+ std::auto_ptr<Common::RequestBase>(
+ new Requests::DaemonListRequest(
+ sigc::bind(sigc::mem_fun(this, &CommandParser::daemonListRequestFinished), true)
+ )
+ )
+ );
+ }
+ else {
+ Common::Logger::log(Common::Logger::ERROR, args[0] + ": Don't unterstand argument '" + args[1] + "'.");
+ printUsage("list_hosts");
+ return;
+ }
- Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonListRequest(sigc::mem_fun(this, &CommandParser::daemonListRequestFinished))));
+ activeRequests++;
}
void CommandParser::statusCommand(const std::vector<std::string> &args) {
@@ -182,18 +210,35 @@ void CommandParser::coreStatusRequestFinished(const Common::Request<Net::Packets
requestFinished();
}
-void CommandParser::daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request) {
+void CommandParser::daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request, bool all) {
try {
const std::vector<Common::HostInfo>& hosts = request.getResult().getHostInfo();
if(hosts.empty()) {
- std::cout << "There aren't any active hosts." << std::endl << std::endl;
+ std::cout << "The host list is empty." << std::endl << std::endl;
}
else {
- std::cout << "Host list:" << std::endl;
+ bool output = false;
+
+ for(std::vector<Common::HostInfo>::const_iterator host = hosts.begin(); host != hosts.end(); ++host) {
+ if(host->getStatus() == Common::HostInfo::INACTIVE && !all)
+ continue;
+
+ if(!output) {
+ std::cout << (all ? "Host list:" : "Active hosts:") << std::endl;
+ output = true;
+ }
+
+ std::cout << " " << host->getName();
+
+ if(all)
+ std::cout << " (" << (host->getStatus() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")";
+
+ std::cout << std::endl;
+ }
- for(std::vector<Common::HostInfo>::const_iterator host = hosts.begin(); host != hosts.end(); ++host)
- std::cout << "\t" << host->getName() << " (" << (host->getStatus() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")" << std::endl;
+ if(!output)
+ std::cout << "No active hosts." << std::endl;
std::cout << std::endl;
}
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 16d7e34..28abb12 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -71,12 +71,12 @@ class CommandParser {
void printHostStatus(const Net::Packets::HostStatusPacket &packet);
void helpCommand(const std::vector<std::string> &args);
- void listHostsCommand(const std::vector<std::string>&);
+ void listHostsCommand(const std::vector<std::string> &args);
void statusCommand(const std::vector<std::string> &args);
void exitCommand(const std::vector<std::string>&);
void coreStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
- void daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request);
+ void daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request, bool all);
void daemonStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
void disconnectRequestFinished(const Common::Request<> &request);