diff options
Diffstat (limited to 'src/Client/InformationManager.cpp')
-rw-r--r-- | src/Client/InformationManager.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index 78a0cf7..03a71c6 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -29,8 +29,8 @@ namespace Client { InformationManager InformationManager::informationManager; -void InformationManager::DaemonStateUpdateRequestHandler::handlePacket(const Common::XmlPacket &packet) { - if(packet.getType() != "UpdateHostState") { +void InformationManager::DaemonStateUpdateRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) { + if(packet->getType() != "UpdateHostState") { Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); Common::XmlPacket ret; @@ -48,9 +48,9 @@ void InformationManager::DaemonStateUpdateRequestHandler::handlePacket(const Com { boost::lock_guard<boost::mutex> lock(informationManager.mutex); - std::map<std::string, Common::HostInfo>::iterator host = informationManager.daemons.find(packet["name"]); + std::map<std::string, Common::HostInfo>::iterator host = informationManager.daemons.find((*packet)["name"]); if(host != informationManager.daemons.end()) - host->second.setState(packet["state"]); + host->second.setState((*packet)["state"]); else Common::Logger::log(Common::Logger::WARNING, "Received a state update for an unknown host."); } @@ -77,19 +77,22 @@ void InformationManager::updateDaemonList(Common::Connection *con) { if(updating) return; - Common::RequestManager::get()->sendRequest0<Requests::DaemonListRequest>(con, - boost::bind(&InformationManager::daemonListRequestFinished, this, _1)); + updateRequest = boost::shared_ptr<Requests::DaemonListRequest>(new Requests::DaemonListRequest); + updateRequest->connectSignalFinished(boost::bind(&InformationManager::daemonListRequestFinished, this, _1, _2)); + + Common::RequestManager::get()->sendRequest(con, updateRequest); updating = true; } -void InformationManager::daemonListRequestFinished(Common::Request &request) { +void InformationManager::daemonListRequestFinished(boost::shared_ptr<const Common::XmlPacket> packet, Net::Exception error) { boost::lock_guard<boost::mutex> lock(mutex); - try { - const Common::XmlPacket &packet = request.getResult(); - - const Common::XmlPacket::Element &hostInfo = packet["hosts"]; + if(!packet || error) { + Common::Logger::logf(Common::Logger::CRITICAL, "Host list request failed: %s", error.strerror().c_str()); + } + else { + const Common::XmlPacket::Element &hostInfo = (*packet)["hosts"]; daemons.clear(); @@ -102,13 +105,8 @@ void InformationManager::daemonListRequestFinished(Common::Request &request) { daemons.insert(std::make_pair(info.getName(), info)); } } - catch(Net::Exception &e) { - Common::Logger::logf(Common::Logger::CRITICAL, "Host list request failed: %s", e.strerror().c_str()); - } updating = false; - - updateCond.notify_all(); } } |