refs #325, using new applyIf method in airspace monitor

This commit is contained in:
Klaus Basan
2014-09-21 18:38:10 +02:00
parent 6795158c7e
commit be0d1e8153

View File

@@ -222,6 +222,7 @@ namespace BlackCore
void CAirspaceMonitor::testCreateDummyOnlineAtcStations(int number) void CAirspaceMonitor::testCreateDummyOnlineAtcStations(int number)
{ {
if (number < 1) return;
this->m_atcStationsOnline.push_back( this->m_atcStationsOnline.push_back(
BlackMisc::Aviation::CTesting::createAtcStations(number) BlackMisc::Aviation::CTesting::createAtcStations(number)
); );
@@ -394,12 +395,12 @@ namespace BlackCore
else else
{ {
// update // update
CPropertyIndexVariantMap values; CPropertyIndexVariantMap vm;
values.addValue(CAtcStation::IndexFrequency, frequency); vm.addValue(CAtcStation::IndexFrequency, frequency);
values.addValue(CAtcStation::IndexPosition, position); vm.addValue(CAtcStation::IndexPosition, position);
values.addValue(CAtcStation::IndexRange, range); vm.addValue(CAtcStation::IndexRange, range);
this->m_atcStationsOnline.applyIf(BlackMisc::Predicates::MemberEqual(&CAtcStation::getCallsign, callsign), values); int changed = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm, true);
emit this->changedAtcStationsOnline(); if (changed > 0) { emit this->changedAtcStationsOnline(); }
} }
} }
@@ -427,9 +428,9 @@ namespace BlackCore
// receiving an ATIS means station is online, update in bookings // receiving an ATIS means station is online, update in bookings
vm.addValue(CAtcStation::IndexIsOnline, true); vm.addValue(CAtcStation::IndexIsOnline, true);
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm); int changedBooked = this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
if (this->m_atcStationsOnline.contains(&CAtcStation::getCallsign, callsign)) { emit this->changedAtcStationsOnline(); } if (changedOnline > 0) { emit this->changedAtcStationsOnline(); }
if (this->m_atcStationsBooked.contains(&CAtcStation::getCallsign, callsign)) { emit this->changedAtcStationsBooked(); } if (changedBooked > 0) { emit this->changedAtcStationsBooked(); }
} }
void CAirspaceMonitor::ps_atisVoiceRoomReceived(const CCallsign &callsign, const QString &url) void CAirspaceMonitor::ps_atisVoiceRoomReceived(const CCallsign &callsign, const QString &url)
@@ -437,28 +438,25 @@ namespace BlackCore
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this)); Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
QString trimmedUrl = url.trimmed(); QString trimmedUrl = url.trimmed();
CPropertyIndexVariantMap vm({ CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl }, trimmedUrl); CPropertyIndexVariantMap vm({ CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl }, trimmedUrl);
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm); int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm, true);
if (changedOnline > 0) if (changedOnline < 1) { return; }
{
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm); Q_ASSERT(changedOnline == 1);
CAtcStation station = this->m_atcStationsOnline.findFirstByCallsign(callsign); CAtcStation station = this->m_atcStationsOnline.findFirstByCallsign(callsign);
emit this->changedAtcStationsOnline(); // single ATIS received emit this->changedAtcStationsOnline();
emit this->changedAtcStationOnlineConnectionStatus(station, true); emit this->changedAtcStationOnlineConnectionStatus(station, true);
}
if (this->m_atcStationsBooked.contains(&CAtcStation::getCallsign, callsign)) vm.addValue(CAtcStation::IndexIsOnline, true); // with voice room ATC is online
int changedBooked = this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm, true);
if (changedBooked > 0)
{ {
// receiving a voice room means station is online, update in bookings // receiving a voice room means station is online, update in bookings
vm.addValue(CAtcStation::IndexIsOnline, true); emit this->changedAtcStationsBooked();
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
emit this->changedAtcStationsBooked(); // single ATIS received
} }
// receiving voice room means ATC has voice // receiving voice room means ATC has voice
if (changedOnline > 0) vm = CPropertyIndexVariantMap(CClient::IndexVoiceCapabilities, CVoiceCapabilities::fromVoiceCapabilities(CVoiceCapabilities::Voice).toQVariant());
{ this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm, false);
vm = CPropertyIndexVariantMap(CClient::IndexVoiceCapabilities, CVoiceCapabilities::fromVoiceCapabilities(CVoiceCapabilities::Voice).toQVariant());
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
} }
void CAirspaceMonitor::ps_atisLogoffTimeReceived(const CCallsign &callsign, const QString &zuluTime) void CAirspaceMonitor::ps_atisLogoffTimeReceived(const CCallsign &callsign, const QString &zuluTime)
@@ -476,8 +474,8 @@ namespace BlackCore
logoffDateTime.setTime(QTime(h, m)); logoffDateTime.setTime(QTime(h, m));
CPropertyIndexVariantMap vm(CAtcStation::IndexBookedUntil, logoffDateTime); CPropertyIndexVariantMap vm(CAtcStation::IndexBookedUntil, logoffDateTime);
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm); int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm, true);
int changedBooked = this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm); int changedBooked = this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm, true);
if (changedOnline > 0) { emit changedAtcStationsOnline(); } if (changedOnline > 0) { emit changedAtcStationsOnline(); }
if (changedBooked > 0) { emit changedAtcStationsBooked(); } if (changedBooked > 0) { emit changedAtcStationsBooked(); }
@@ -498,8 +496,8 @@ namespace BlackCore
if (!icaoDataDataFile.hasAircraftDesignator()) return; // give up! if (!icaoDataDataFile.hasAircraftDesignator()) return; // give up!
vm = CPropertyIndexVariantMap(CAircraft::IndexIcao, icaoData.toQVariant()); vm = CPropertyIndexVariantMap(CAircraft::IndexIcao, icaoData.toQVariant());
} }
this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual(&CAircraft::getCallsign, callsign), vm); int changed = this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm, true);
emit this->changedAircraftsInRange(); if (changed > 0) {emit this->changedAircraftsInRange();}
} }
void CAirspaceMonitor::ps_aircraftUpdateReceived(const CCallsign &callsign, const CAircraftSituation &situation, const CTransponder &transponder) void CAirspaceMonitor::ps_aircraftUpdateReceived(const CCallsign &callsign, const CAircraftSituation &situation, const CTransponder &transponder)
@@ -548,8 +546,9 @@ namespace BlackCore
vm.addValue(CAircraft::IndexTransponder, transponder); vm.addValue(CAircraft::IndexTransponder, transponder);
vm.addValue(CAircraft::IndexSituation, situation); vm.addValue(CAircraft::IndexSituation, situation);
vm.addValue(CAircraft::IndexDistance, distance); vm.addValue(CAircraft::IndexDistance, distance);
this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual(&CAircraft::getCallsign, callsign), vm);
// here I expect always a changed value
this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm, false);
emit this->changedAircraftSituation(callsign, situation); emit this->changedAircraftSituation(callsign, situation);
} }
@@ -559,14 +558,11 @@ namespace BlackCore
void CAirspaceMonitor::ps_pilotDisconnected(const CCallsign &callsign) void CAirspaceMonitor::ps_pilotDisconnected(const CCallsign &callsign)
{ {
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this)); Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
bool contains = this->m_aircraftsInRange.contains(&CAircraft::getCallsign, callsign); bool contains = this->m_aircraftsInRange.contains(&CAircraft::getCallsign, callsign);
this->m_aircraftsInRange.removeIf(&CAircraft::getCallsign, callsign);
this->m_otherClients.removeIf(&CClient::getCallsign, callsign);
if (contains) if (contains)
{ {
this->m_aircraftsInRange.removeIf(&CAircraft::getCallsign, callsign);
this->m_otherClients.removeIf(&CClient::getCallsign, callsign);
emit this->removedAircraft(callsign); emit this->removedAircraft(callsign);
} }
} }
@@ -577,8 +573,8 @@ namespace BlackCore
// update // update
CPropertyIndexVariantMap vm({CAircraft::IndexCom1System, CComSystem::IndexActiveFrequency}, frequency.toQVariant()); CPropertyIndexVariantMap vm({CAircraft::IndexCom1System, CComSystem::IndexActiveFrequency}, frequency.toQVariant());
this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual(&CAircraft::getCallsign, callsign), vm); int changed = this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm, true);
emit this->changedAircraftsInRange(); if (changed > 0) { emit this->changedAircraftsInRange(); }
} }
} // namespace } // namespace