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 +++++++ src/Client/InformationManager.cpp | 34 ++++++++++++++++++++++++++++++++++ src/Client/InformationManager.h | 10 ++++++++++ 3 files changed, 51 insertions(+) (limited to 'src/Client') 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()); diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index 3a8caab..8a3227c 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -21,6 +21,8 @@ #include "Requests/DaemonListRequest.h" #include #include +#include +#include namespace Mad { @@ -28,12 +30,44 @@ namespace Client { std::auto_ptr InformationManager::informationManager; + +void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::DAEMON_STATE_UPDATE) { + Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + signalFinished().emit(); + return; + } + + // TODO Require authentication + + Net::Packets::HostStatePacket hostStatePacket(packet); + + std::map::iterator host = informationManager->daemons.find(hostStatePacket.getName()); + if(host != informationManager->daemons.end()) + host->second.setState(hostStatePacket.getState()); + else + Common::Logger::log(Common::Logger::WARNING, "Received a state update for an unknown host."); + + connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())); + + signalFinished().emit(); +} + + InformationManager::InformationManager(Net::Connection *connection) : initFinished(false) { Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr( new Requests::DaemonListRequest(sigc::mem_fun(this, &InformationManager::daemonListRequestFinished)) ) ); + + Common::RequestManager::getRequestManager()->registerPacketType(Net::Packet::DAEMON_STATE_UPDATE); +} + +InformationManager::~InformationManager() { + Common::RequestManager::getRequestManager()->unregisterPacketType(Net::Packet::DAEMON_STATE_UPDATE); } void InformationManager::daemonListRequestFinished(const Common::Request &request) { diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h index 5670f8f..bf2d67a 100644 --- a/src/Client/InformationManager.h +++ b/src/Client/InformationManager.h @@ -41,6 +41,14 @@ namespace Client { class InformationManager { private: + class DaemonStateUpdateRequest : public Common::RequestHandler { + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + DaemonStateUpdateRequest() {} + }; + static std::auto_ptr informationManager; std::map daemons; @@ -55,6 +63,8 @@ class InformationManager { void daemonListRequestFinished(const Common::Request &request); public: + ~InformationManager(); + static InformationManager* getInformationManager() { return informationManager.get(); } -- cgit v1.2.3