summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-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);