From 14ab60cb73e6a7c9589f0e9c9bc1fc53fcf72680 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 15 Feb 2020 20:36:50 +0100 Subject: [PATCH] Guarding by "hasWebDataServices" --- src/blackcore/afv/clients/afvclient.cpp | 4 +- src/blackcore/aircraftmatcher.cpp | 5 +- src/blackcore/airspacemonitor.cpp | 95 ++++++++++--------- .../components/autopublishcomponent.cpp | 4 +- .../dbaircrafticaoselectorcomponent.cpp | 7 +- 5 files changed, 65 insertions(+), 50 deletions(-) diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index e3cc9ac14..c0baa2fb9 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -1113,10 +1113,10 @@ namespace BlackCore if (it != m_aliasedStations.end()) { - if (sApp->getIContextNetwork()) + if (sApp && sApp->getIContextNetwork()) { // Get the callsign for this frequency and fuzzy compare with our alias station - // !\todo KB 2019-10 replace by com unit channel spacing + // !\todo KB 2019-10 replace by COM unit channel spacing const CComSystem::ChannelSpacing spacing = CComSystem::ChannelSpacing25KHz; const CFrequency f(static_cast(roundedFrequencyHz), CFrequencyUnit::Hz()); const CAtcStationList matchingAtcStations = sApp->getIContextNetwork()->getOnlineStationsForFrequency(f, spacing); diff --git a/src/blackcore/aircraftmatcher.cpp b/src/blackcore/aircraftmatcher.cpp index 554bf5b02..44f71cd50 100644 --- a/src/blackcore/aircraftmatcher.cpp +++ b/src/blackcore/aircraftmatcher.cpp @@ -47,7 +47,7 @@ namespace BlackCore CAircraftMatcher::CAircraftMatcher(const CAircraftMatcherSetup &setup, QObject *parent) : QObject(parent), m_setup(setup) { - if (sApp && !sApp->isShuttingDown()) + if (sApp && sApp->hasWebDataServices()) { sApp->getWebDataServices()->synchronizeDbCaches(CEntityFlags::AircraftCategoryEntity); const CAircraftCategoryList categories = sApp->getWebDataServices()->getAircraftCategories(); @@ -513,7 +513,8 @@ namespace BlackCore const CCallsign callsign = inModel.getCallsign(); if (js.isEmpty() && log) { CLogUtilities::addLogDetailsToList(log, callsign, QStringLiteral("Matching script is empty")); } - while (!js.isEmpty() && sApp && !sApp->isShuttingDown()) + + while (!js.isEmpty() && sApp && sApp->hasWebDataServices()) { rv.runScript = true; diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index 403e6ce54..8db2821e8 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -94,7 +94,7 @@ namespace BlackCore connect(m_fsdClient, &CFSDClient::connectionStatusChanged, this, &CAirspaceMonitor::onConnectionStatusChanged); // AutoConnection: this should also avoid race conditions by updating the bookings - Q_ASSERT_X(sApp && sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader"); + Q_ASSERT_X(sApp && sApp->hasWebDataServices(), Q_FUNC_INFO, "Missing data reader"); // optional readers if (sApp && sApp->getWebDataServices()->getBookingReader()) @@ -340,7 +340,7 @@ namespace BlackCore void CAirspaceMonitor::requestAtcBookingsUpdate() { - if (!sApp || sApp->isShuttingDown()) { return; } + if (!sApp || sApp->isShuttingDown() || !sApp->hasWebDataServices()) { return; } sApp->getWebDataServices()->readInBackground(BlackMisc::Network::CEntityFlags::BookingEntity); m_bookingsRequested = true; } @@ -1360,55 +1360,64 @@ namespace BlackCore CAircraftSituation correctedSituation(allowTestOffset ? this->addTestAltitudeOffsetToSituation(situation) : situation); bool haveRequestedElevation = false; const bool canLikelySkipNearGround = correctedSituation.canLikelySkipNearGroundInterpolation(); - if (!correctedSituation.hasGroundElevation() && !canLikelySkipNearGround) + if (!correctedSituation.hasGroundElevation()) { - // fetch from cache or request - const CAircraftSituationList situations = this->remoteAircraftSituations(callsign); - const CAircraftSituation situationWithElv = situations.findCLosestElevationWithinRange(correctedSituation, correctedSituation.getDistancePerTime(100, CElevationPlane::singlePointRadius())); - if (!situationWithElv.getGroundElevation().isNull()) - { - // from nearby situations of own aircraft - correctedSituation.transferGroundElevation(situationWithElv); - } - else - { - // from cache - const CLength distance(correctedSituation.getDistancePerTime250ms(CElevationPlane::singlePointRadius())); // distance per ms - const CElevationPlane ep = this->findClosestElevationWithinRangeOrRequest(correctedSituation, distance, callsign); - haveRequestedElevation = ep.isNull(); // NULL means we requested - Q_ASSERT_X(haveRequestedElevation || !ep.getRadius().isNull(), Q_FUNC_INFO, "null radius"); + // set a defined state + correctedSituation.resetGroundElevation(); - // also can handle NULL elevations - correctedSituation.setGroundElevation(ep, CAircraftSituation::FromCache); - } - - // we have a new situation, so we try to get the elevation - // so far we have requested it, but we set it upfront either by - // a) average value from other planes in the vicinity or - // b) by extrapolating - // - // if we would NOT preset it, we could end up with oscillation - // - if (!correctedSituation.hasGroundElevation()) + if (!canLikelySkipNearGround) { - const CElevationPlane averagePlane = this->averageElevationOfNonMovingAircraft(situation, CElevationPlane::majorAirportRadius(), 2); - if (!averagePlane.isNull()) + // fetch from cache or request + const CAircraftSituationList situations = this->remoteAircraftSituations(callsign); + const CAircraftSituation situationWithElv = situations.findCLosestElevationWithinRange(correctedSituation, correctedSituation.getDistancePerTime(100, CElevationPlane::singlePointRadius())); + if (!situationWithElv.getGroundElevation().isNull()) { - correctedSituation.setGroundElevation(averagePlane, CAircraftSituation::Average); + // from nearby situations of own aircraft + correctedSituation.transferGroundElevation(situationWithElv); } else { - // values before updating (i.e. "storing") so the new situation is not yet considered - const CAircraftSituationList oldSituations = this->remoteAircraftSituations(callsign); - const CAircraftSituationChangeList oldChanges = this->remoteAircraftSituationChanges(callsign); - if (oldSituations.size() > 1) - { - const bool extrapolated = correctedSituation.extrapolateElevation(oldSituations[0], oldSituations[1], oldChanges.frontOrDefault()); - BLACK_AUDIT_X(extrapolated, Q_FUNC_INFO, "Cannot extrapolate"); - } + // from cache + const CLength distance(correctedSituation.getDistancePerTime250ms(CElevationPlane::singlePointRadius())); // distance per ms + const CElevationPlane ep = this->findClosestElevationWithinRangeOrRequest(correctedSituation, distance, callsign); + haveRequestedElevation = ep.isNull(); // NULL means we requested + Q_ASSERT_X(haveRequestedElevation || !ep.getRadius().isNull(), Q_FUNC_INFO, "null radius"); + + // also can handle NULL elevations + correctedSituation.setGroundElevation(ep, CAircraftSituation::FromCache); } - } // gnd. elevation - } + + // we have a new situation, so we try to get the elevation + // so far we have requested it, but we set it upfront either by + // a) average value from other planes in the vicinity or + // b) by extrapolating + // + // if we would NOT preset it, we could end up with oscillation + // + if (!correctedSituation.hasGroundElevation()) + { + const CElevationPlane averagePlane = this->averageElevationOfNonMovingAircraft(situation, CElevationPlane::majorAirportRadius(), 2); + if (!averagePlane.isNull()) + { + correctedSituation.setGroundElevation(averagePlane, CAircraftSituation::Average); + } + else + { + // values before updating (i.e. "storing") so the new situation is not yet considered + const CAircraftSituationList oldSituations = this->remoteAircraftSituations(callsign); + const CAircraftSituationChangeList oldChanges = this->remoteAircraftSituationChanges(callsign); + if (oldSituations.size() > 1) + { + const bool extrapolated = correctedSituation.extrapolateElevation(oldSituations[0], oldSituations[1], oldChanges.frontOrDefault()); + Q_UNUSED(extrapolated) + + // extrapolation only works if there is a provider and already data + // BLACK_AUDIT_X(extrapolated, Q_FUNC_INFO, "Cannot extrapolate"); + } + } + } // gnd. elevation + } // can skip? + } // have already elevation? // do we already have ground details? if (situation.getOnGroundDetails() == CAircraftSituation::NotSetGroundDetails) diff --git a/src/blackgui/components/autopublishcomponent.cpp b/src/blackgui/components/autopublishcomponent.cpp index 9cc27a3c4..edcb04abd 100644 --- a/src/blackgui/components/autopublishcomponent.cpp +++ b/src/blackgui/components/autopublishcomponent.cpp @@ -38,7 +38,7 @@ namespace BlackGui connect(ui->pb_SendToDB, &QPushButton::released, this, &CAutoPublishComponent::sendToDb, Qt::QueuedConnection); connect(ui->pb_DeleteFiles, &QPushButton::released, this, &CAutoPublishComponent::deleteAllFiles, Qt::QueuedConnection); - if (sGui && sGui->getWebDataServices() && sGui->getWebDataServices()->getDatabaseWriter()) + if (sGui && sGui->hasWebDataServices() && sGui->getWebDataServices()->getDatabaseWriter()) { CDatabaseWriter *w = sGui->getWebDataServices()->getDatabaseWriter(); connect(w, &CDatabaseWriter::autoPublished, this, &CAutoPublishComponent::onAutoPublished, Qt::QueuedConnection); @@ -77,7 +77,7 @@ namespace BlackGui return; } - if (!sGui->getWebDataServices()) + if (!sGui->hasWebDataServices()) { this->showOverlayHTMLMessage("No publishing web service!", 5000); return; diff --git a/src/blackgui/components/dbaircrafticaoselectorcomponent.cpp b/src/blackgui/components/dbaircrafticaoselectorcomponent.cpp index 02c398506..7bc3d8be7 100644 --- a/src/blackgui/components/dbaircrafticaoselectorcomponent.cpp +++ b/src/blackgui/components/dbaircrafticaoselectorcomponent.cpp @@ -49,8 +49,13 @@ namespace BlackGui this->setAcceptDrops(true); this->setAcceptedMetaTypeIds({qMetaTypeId(), qMetaTypeId()}); ui->le_Aircraft->setValidator(new CUpperCaseValidator(this)); + connect(ui->le_Aircraft, &QLineEdit::editingFinished, this, &CDbAircraftIcaoSelectorComponent::onDataChanged); - connect(sApp->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbAircraftIcaoSelectorComponent::onCodesRead, Qt::QueuedConnection); + if (sApp && sApp->hasWebDataServices()) + { + connect(sApp->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbAircraftIcaoSelectorComponent::onCodesRead, Qt::QueuedConnection); + } + this->onCodesRead(CEntityFlags::AircraftIcaoEntity, CEntityFlags::ReadFinished, sApp->getWebDataServices()->getAircraftIcaoCodesCount()); }