From a9f0cebe13db045e08326ea96b0979e9b6e77537 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 17 Sep 2018 18:24:42 +0200 Subject: [PATCH] Ref T345, fixed bug: only one station must be updated with the new message --- src/blackcore/airspacemonitor.cpp | 7 ++----- src/blackmisc/aviation/atcstationlist.cpp | 22 +++++++++++++--------- src/blackmisc/aviation/atcstationlist.h | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index 9d1138766..01ed11b9e 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -604,16 +604,13 @@ namespace BlackCore { Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this)); if (!this->isConnectedAndNotShuttingDown() || callsign.isEmpty()) return; - const int changedAtis = m_atcStationsOnline.updateIfMessageChanged(atisMessage, true); + bool changedAtis = m_atcStationsOnline.updateIfMessageChanged(atisMessage, callsign, true); // receiving an ATIS means station is online, update in bookings m_atcStationsBooked.setOnline(callsign, true); // signal - if (changedAtis > 0) - { - emit this->changedAtisReceived(callsign); - } + if (changedAtis) { emit this->changedAtisReceived(callsign); } } void CAirspaceMonitor::onAtisVoiceRoomReceived(const CCallsign &callsign, const QString &url) diff --git a/src/blackmisc/aviation/atcstationlist.cpp b/src/blackmisc/aviation/atcstationlist.cpp index 18253e229..d98fc6ae9 100644 --- a/src/blackmisc/aviation/atcstationlist.cpp +++ b/src/blackmisc/aviation/atcstationlist.cpp @@ -40,28 +40,32 @@ namespace BlackMisc }); } - int CAtcStationList::updateIfMessageChanged(const CInformationMessage &im, bool overrideWithNewer) + bool CAtcStationList::updateIfMessageChanged(const CInformationMessage &im, const CCallsign &callsign, bool overrideWithNewer) { - int c = 0; const CInformationMessage::InformationType t = im.getType(); + + // for loop just to get reference + bool unequal = false; for (CAtcStation &station : *this) { - bool unequal = false; + if (station.getCallsign() != callsign) { continue; } + const CInformationMessage m = station.getInformationMessage(t); - if (m.getType() == CInformationMessage::Unspecified) { continue; } + if (m.getType() == CInformationMessage::Unspecified) { break; } + if (m.getMessage() == im.getMessage()) { - if (!overrideWithNewer) { continue; } - if (!im.isNewerThan(m)) { continue; } + if (!overrideWithNewer) { break; } + if (!im.isNewerThan(m)) { break; } } else { unequal = true; } - station.setMessage(m); - if (unequal) c++; // only count unequals + station.setMessage(im); + break; // only count unequals } - return c; + return unequal; } int CAtcStationList::setOnline(const CCallsign &callsign, bool online) diff --git a/src/blackmisc/aviation/atcstationlist.h b/src/blackmisc/aviation/atcstationlist.h index e51080b08..12ce1aabf 100644 --- a/src/blackmisc/aviation/atcstationlist.h +++ b/src/blackmisc/aviation/atcstationlist.h @@ -49,7 +49,7 @@ namespace BlackMisc CAtcStationList findIfComUnitTunedIn25KHz(const CComSystem &comUnit) const; //! Update if message changed - int updateIfMessageChanged(const CInformationMessage &im, bool overrideWithNewer); + bool updateIfMessageChanged(const CInformationMessage &im, const CCallsign &callsign, bool overrideWithNewer); //! Set online status int setOnline(const CCallsign &callsign, bool online);