diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-29 22:25:04 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-29 22:25:04 +0200 |
commit | 13fd1bb4f19e4791e000cb71cca2065820184bdb (patch) | |
tree | 147254923044d6842a803b20b48ed607e76fa28d /src/Client | |
parent | 07768a871691433e2f3c490aa14c45cde40e00b4 (diff) | |
download | mad-13fd1bb4f19e4791e000cb71cca2065820184bdb.tar mad-13fd1bb4f19e4791e000cb71cca2065820184bdb.zip |
Daemon-Liste wird jetzt vom Core aktualisiert
Diffstat (limited to 'src/Client')
-rw-r--r-- | src/Client/CommandParser.cpp | 7 | ||||
-rw-r--r-- | src/Client/InformationManager.cpp | 34 | ||||
-rw-r--r-- | src/Client/InformationManager.h | 10 |
3 files changed, 51 insertions, 0 deletions
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<std::string> &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<std::string> &args) { for(std::map<std::string, Common::HostInfo>::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 <Common/Logger.h> #include <Common/RequestManager.h> +#include <Net/Packets/ErrorPacket.h> +#include <Net/Packets/HostStatePacket.h> namespace Mad { @@ -28,12 +30,44 @@ namespace Client { std::auto_ptr<InformationManager> 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<std::string, Common::HostInfo>::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<Common::RequestBase>( new Requests::DaemonListRequest(sigc::mem_fun(this, &InformationManager::daemonListRequestFinished)) ) ); + + Common::RequestManager::getRequestManager()->registerPacketType<DaemonStateUpdateRequest>(Net::Packet::DAEMON_STATE_UPDATE); +} + +InformationManager::~InformationManager() { + Common::RequestManager::getRequestManager()->unregisterPacketType(Net::Packet::DAEMON_STATE_UPDATE); } void InformationManager::daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &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> informationManager; std::map<std::string, Common::HostInfo> daemons; @@ -55,6 +63,8 @@ class InformationManager { void daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request); public: + ~InformationManager(); + static InformationManager* getInformationManager() { return informationManager.get(); } |