diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-29 19:26:02 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-29 19:26:02 +0200 |
commit | d803fa64b8ecc94425043b4551c79273b6fee11e (patch) | |
tree | 09ab81d9e259f6c962090d0c45fb83aa276dc440 /src/Client/CommandParser.cpp | |
parent | 3086f10f53ced17ab4a237ab57da62395d259f0a (diff) | |
download | mad-d803fa64b8ecc94425043b4551c79273b6fee11e.tar mad-d803fa64b8ecc94425043b4551c79273b6fee11e.zip |
Benutzte InformationManager zur Auflistung der Hosts
Diffstat (limited to 'src/Client/CommandParser.cpp')
-rw-r--r-- | src/Client/CommandParser.cpp | 50 |
1 files changed, 31 insertions, 19 deletions
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 <Common/Exception.h> #include <Common/Logger.h> @@ -95,36 +95,48 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) { } void CommandParser::listHostsCommand(const std::vector<std::string> &args) { + const std::map<std::string, Common::HostInfo>& hosts = InformationManager::getInformationManager()->getDaemons(); + if(args.size() == 1) { - Common::RequestManager::getRequestManager()->sendRequest(connection, - std::auto_ptr<Common::RequestBase>( - 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<std::string, Common::HostInfo>::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<Common::RequestBase>( - 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<std::string, Common::HostInfo>::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<std::string> &args) { |