diff options
Diffstat (limited to 'src/Client/InformationManager.cpp')
-rw-r--r-- | src/Client/InformationManager.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index 8a3227c..1d54498 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -28,7 +28,7 @@ namespace Mad { namespace Client { -std::auto_ptr<InformationManager> InformationManager::informationManager; +InformationManager InformationManager::informationManager; void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { @@ -44,8 +44,8 @@ void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection Net::Packets::HostStatePacket hostStatePacket(packet); - std::map<std::string, Common::HostInfo>::iterator host = informationManager->daemons.find(hostStatePacket.getName()); - if(host != informationManager->daemons.end()) + 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."); @@ -56,20 +56,29 @@ void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection } -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)) - ) - ); +void InformationManager::doInit() { + Common::RequestManager::getRequestManager()->init(); Common::RequestManager::getRequestManager()->registerPacketType<DaemonStateUpdateRequest>(Net::Packet::DAEMON_STATE_UPDATE); } -InformationManager::~InformationManager() { +void InformationManager::doUninit() { Common::RequestManager::getRequestManager()->unregisterPacketType(Net::Packet::DAEMON_STATE_UPDATE); } +void InformationManager::updateDaemonList(Net::Connection *con) { + if(updating) + return; + + Common::RequestManager::getRequestManager()->sendRequest(con, + std::auto_ptr<Common::RequestBase>( + new Requests::DaemonListRequest(sigc::mem_fun(this, &InformationManager::daemonListRequestFinished)) + ) + ); + + updating = true; +} + void InformationManager::daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request) { try { const std::vector<Common::HostInfo> &hostInfo = request.getResult().getHostInfo(); @@ -78,12 +87,12 @@ void InformationManager::daemonListRequestFinished(const Common::Request<Net::Pa daemons.clear(); daemons.insert(std::make_pair(daemon->getName(), *daemon)); } - - initFinished = true; } catch(Common::Exception &e) { Common::Logger::logf(Common::Logger::CRITICAL, "Host list request failed: %s", e.strerror().c_str()); } + + updating = false; } } |