summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-29 19:26:02 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-29 19:26:02 +0200
commitd803fa64b8ecc94425043b4551c79273b6fee11e (patch)
tree09ab81d9e259f6c962090d0c45fb83aa276dc440 /src
parent3086f10f53ced17ab4a237ab57da62395d259f0a (diff)
downloadmad-d803fa64b8ecc94425043b4551c79273b6fee11e.tar
mad-d803fa64b8ecc94425043b4551c79273b6fee11e.zip
Benutzte InformationManager zur Auflistung der Hosts
Diffstat (limited to 'src')
-rw-r--r--src/Client/CommandManager.cpp40
-rw-r--r--src/Client/CommandManager.h1
-rw-r--r--src/Client/CommandParser.cpp50
3 files changed, 31 insertions, 60 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp
index 8a82a82..2a20b29 100644
--- a/src/Client/CommandManager.cpp
+++ b/src/Client/CommandManager.cpp
@@ -106,46 +106,6 @@ void CommandManager::daemonCommandRequestFinished(const Common::Request<> &reque
requestFinished();
}
-void CommandManager::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 << "The host list is empty." << std::endl << std::endl;
- }
- else {
- 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;
- }
-
- if(!output)
- std::cout << "No active hosts." << std::endl;
-
- std::cout << std::endl;
- }
- }
- catch(Common::Exception &exception) {
- Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str());
- }
-
- requestFinished();
-}
-
void CommandManager::daemonStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request) {
try {
const Net::Packets::HostStatusPacket &packet = request.getResult();
diff --git a/src/Client/CommandManager.h b/src/Client/CommandManager.h
index 6aea724..f93d07f 100644
--- a/src/Client/CommandManager.h
+++ b/src/Client/CommandManager.h
@@ -53,7 +53,6 @@ class CommandManager {
void coreStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
void daemonCommandRequestFinished(const Common::Request<> &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);
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) {