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/InformationManager.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/Client/InformationManager.cpp') 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) { -- cgit v1.2.3