From 3086f10f53ced17ab4a237ab57da62395d259f0a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Sep 2008 18:16:20 +0200 Subject: InformationManager zur Verwaltung der Host-Liste hinzugef?gt --- src/Client/CommandParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Client/CommandParser.cpp') diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 1a5a96c..663c214 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -40,7 +40,7 @@ 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 [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand}, {{"reboot", 0}, "reboot host", "Reboots a host", "Reboots a host.", &CommandParser::rebootCommand}, - {{"shutdown", 0}, "shutdown host", "Shuts a host down", "Shuts a host down.", &CommandParser::shutdownCommand}, + {{"shutdown", "halt", 0}, "shutdown host", "Shuts a host down", "Shuts a host down.", &CommandParser::shutdownCommand}, {{"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} -- cgit v1.2.3 From d803fa64b8ecc94425043b4551c79273b6fee11e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Sep 2008 19:26:02 +0200 Subject: Benutzte InformationManager zur Auflistung der Hosts --- src/Client/CommandParser.cpp | 50 +++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'src/Client/CommandParser.cpp') diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 663c214..4f1cb99 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -18,9 +18,9 @@ */ #include "CommandParser.h" +#include "InformationManager.h" #include "Requests/CoreStatusRequest.h" #include "Requests/DaemonCommandRequest.h" -#include "Requests/DaemonListRequest.h" #include "Requests/DaemonStatusRequest.h" #include #include @@ -95,36 +95,48 @@ void CommandParser::helpCommand(const std::vector &args) { } void CommandParser::listHostsCommand(const std::vector &args) { + const std::map& hosts = InformationManager::getInformationManager()->getDaemons(); + if(args.size() == 1) { - Common::RequestManager::getRequestManager()->sendRequest(connection, - std::auto_ptr( - new Requests::DaemonListRequest( - sigc::bind(sigc::mem_fun(commandManager, &CommandManager::daemonListRequestFinished), false) - ) - ) - ); + if(hosts.empty()) { + std::cout << "The host list is empty." << std::endl << std::endl; + return; + } + + bool output = false; + + for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { + if(host->second.getStatus() == Common::HostInfo::INACTIVE) + continue; + + if(!output) { + std::cout << "Active hosts:" << std::endl; + output = true; + } + + std::cout << " " << host->first << std::endl; + } } else if(args.size() > 2) { Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); printUsage("list_hosts"); - return; } else if(args[1] == "-a") { - Common::RequestManager::getRequestManager()->sendRequest(connection, - std::auto_ptr( - new Requests::DaemonListRequest( - sigc::bind(sigc::mem_fun(commandManager, &CommandManager::daemonListRequestFinished), true) - ) - ) - ); + if(hosts.empty()) { + std::cout << "The host list is empty." << std::endl << std::endl; + return; + } + + std::cout << "Host list:" << std::endl; + + for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { + std::cout << " " << host->first << " (" << (host->second.getStatus() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")" << std::endl; + } } else { Common::Logger::logf(Common::Logger::ERROR, "%s: Don't unterstand argument '%s'.", args[0].c_str(), args[1].c_str()); printUsage("list_hosts"); - return; } - - commandManager.activeRequests++; } void CommandParser::rebootCommand(const std::vector &args) { -- cgit v1.2.3 From cc617dba41d5acfc43552847cdd747e7ea8c67da Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Sep 2008 20:11:24 +0200 Subject: Schreibfehler korrigiert --- src/Client/CommandParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Client/CommandParser.cpp') diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 4f1cb99..a271a7e 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -134,7 +134,7 @@ void CommandParser::listHostsCommand(const std::vector &args) { } } else { - Common::Logger::logf(Common::Logger::ERROR, "%s: Don't unterstand argument '%s'.", args[0].c_str(), args[1].c_str()); + Common::Logger::logf(Common::Logger::ERROR, "%s: Don't understand argument '%s'.", args[0].c_str(), args[1].c_str()); printUsage("list_hosts"); } } -- cgit v1.2.3 From 07768a871691433e2f3c490aa14c45cde40e00b4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Sep 2008 20:28:26 +0200 Subject: Status in HostInfo hei?t jetzt State --- src/Client/CommandParser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Client/CommandParser.cpp') diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index a271a7e..bc179fa 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -106,7 +106,7 @@ void CommandParser::listHostsCommand(const std::vector &args) { bool output = false; for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { - if(host->second.getStatus() == Common::HostInfo::INACTIVE) + if(host->second.getState() == Common::HostInfo::INACTIVE) continue; if(!output) { @@ -130,7 +130,7 @@ void CommandParser::listHostsCommand(const std::vector &args) { std::cout << "Host list:" << std::endl; for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { - std::cout << " " << host->first << " (" << (host->second.getStatus() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")" << std::endl; + std::cout << " " << host->first << " (" << (host->second.getState() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")" << std::endl; } } else { -- cgit v1.2.3 From 13fd1bb4f19e4791e000cb71cca2065820184bdb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Sep 2008 22:25:04 +0200 Subject: Daemon-Liste wird jetzt vom Core aktualisiert --- src/Client/CommandParser.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/Client/CommandParser.cpp') diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index bc179fa..1ba986f 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -116,6 +116,11 @@ void CommandParser::listHostsCommand(const std::vector &args) { std::cout << " " << host->first << std::endl; } + + if(!output) + std::cout << "No active hosts." << std::endl; + + std::cout << std::endl; } else if(args.size() > 2) { Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); @@ -132,6 +137,8 @@ void CommandParser::listHostsCommand(const std::vector &args) { for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { std::cout << " " << host->first << " (" << (host->second.getState() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")" << std::endl; } + + std::cout << std::endl; } else { Common::Logger::logf(Common::Logger::ERROR, "%s: Don't understand argument '%s'.", args[0].c_str(), args[1].c_str()); -- cgit v1.2.3