follow up of #698 and optimized VATSIM cache

(do not set if equal)
This commit is contained in:
Klaus Basan
2016-07-06 00:44:23 +02:00
parent 77c749aba2
commit 8412ab9917
4 changed files with 48 additions and 23 deletions

View File

@@ -23,6 +23,24 @@ namespace BlackCore
m_dataFileUrls(QStringList( { "http://info.vroute.net/vatsim-data.txt" }))
{ }
bool CVatsimSetup::setUrls(const CUrlList &dataFileUrls, const CUrlList &serverFileUrls, const CUrlList &metarFileUrls)
{
const bool changed = (dataFileUrls != getDataFileUrls() || serverFileUrls != getServerFileUrls() || metarFileUrls != getMetarFileUrls());
this->setServerFileUrls(serverFileUrls);
this->setMetarFileUrls(metarFileUrls);
this->setDataFileUrls(dataFileUrls);
return changed;
}
bool CVatsimSetup::setServers(const CServerList &fsdServers, const CServerList &voiceServers)
{
const bool changed = !this->getVoiceServers().equalsByKeys(voiceServers, &CServer::getName, &CServer::getAddress) ||
!this->getFsdServers().equalsByKeys(fsdServers, &CServer::getName, &CServer::getAddress);
this->setFsdServers(fsdServers);
this->setVoiceServers(voiceServers);
return changed;
}
QString CVatsimSetup::convertToQString(bool i18n) const
{
return convertToQString(", ", i18n);

View File

@@ -70,6 +70,9 @@ namespace BlackCore
//! METAR file URLs
void setMetarFileUrls(const BlackMisc::Network::CUrlList &urls) { m_metarFileUrls = urls; }
//! Set all URLs and indicate if something has changed
bool setUrls(const BlackMisc::Network::CUrlList &dataFileUrls, const BlackMisc::Network::CUrlList &serverFileUrls, const BlackMisc::Network::CUrlList &metarFileUrls);
//! FSD test servers
const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; }
@@ -82,6 +85,9 @@ namespace BlackCore
//! Set voice servers
void setVoiceServers(const BlackMisc::Network::CServerList &servers) { m_voiceServers = servers; }
//! Set servers
bool setServers(const BlackMisc::Network::CServerList &fsdServers, const BlackMisc::Network::CServerList &voiceServers);
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;

View File

@@ -391,8 +391,8 @@ namespace BlackCore
// Setup for VATSIM servers and sorting for comparison
fsdServers.setFsdSetup(CFsdSetup::vatsimStandard());
fsdServers.sortBy(&CServer::getName);
voiceServers.sortBy(&CServer::getName);
fsdServers.sortBy(&CServer::getName, &CServer::getDescription);
voiceServers.sortBy(&CServer::getName, &CServer::getDescription);
// this part needs to be synchronized
{
@@ -401,18 +401,20 @@ namespace BlackCore
this->m_aircraft = aircraft;
this->m_atcStations = atcStations;
this->m_voiceCapabilities = voiceCapabilities;
CVatsimSetup vs(this->m_lastGoodSetup.getThreadLocal());
// check if we need to save in cache
if (vs.getVoiceServers() != voiceServers || vs.getFsdServers() != fsdServers)
{
vs.setVoiceServers(voiceServers);
vs.setFsdServers(fsdServers);
vs.setUtcTimestamp(updateTimestampFromFile);
this->m_lastGoodSetup.set(vs);
}
}
// update cache itself is thread safe
CVatsimSetup vs(this->m_lastGoodSetup.get());
const bool changedSetup = vs.setServers(fsdServers, voiceServers);
if (changedSetup)
{
vs.setUtcTimestamp(updateTimestampFromFile);
this->m_lastGoodSetup.set(vs);
}
// warnings, if required
if (!illegalIcaoCodes.isEmpty())
{

View File

@@ -106,9 +106,9 @@ namespace BlackCore
const QStringList lines = dataFileData.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
if (lines.isEmpty()) { return; }
CUrlList dataFiles;
CUrlList serverFiles;
CUrlList metarFiles;
CUrlList dataFileUrls;
CUrlList serverFileUrls;
CUrlList metarFileUrls;
for (const QString &cl : lines)
{
@@ -132,15 +132,15 @@ namespace BlackCore
const CUrl url(value);
if (key.startsWith("url0"))
{
dataFiles.push_back(url);
dataFileUrls.push_back(url);
}
else if (key.startsWith("url1"))
{
serverFiles.push_back(url);
serverFileUrls.push_back(url);
}
else if (key.startsWith("metar"))
{
metarFiles.push_back(url);
metarFileUrls.push_back(url);
}
else if (key.startsWith("atis"))
{
@@ -148,15 +148,14 @@ namespace BlackCore
}
} // for each line
// this part needs to be synchronized
// cache itself is thread safe, avoid writing with unchanged data
CVatsimSetup vs(this->m_lastGoodSetup.get());
bool changed = vs.setUrls(dataFileUrls, serverFileUrls, metarFileUrls);
if (changed)
{
// cache itself is thread safe
CVatsimSetup vs(this->m_lastGoodSetup.get());
vs.setDataFileUrls(dataFiles);
vs.setMetarFileUrls(metarFiles);
vs.setServerFileUrls(serverFiles);
vs.setUtcTimestamp(QDateTime::currentDateTime());
this->m_lastGoodSetup.set(vs);
const CStatusMessage cacheMsg = this->m_lastGoodSetup.set(vs);
if (cacheMsg.isFailure()) { CLogMessage::preformatted(cacheMsg); }
}
// warnings, if required