Guarding by "hasWebDataServices"

This commit is contained in:
Klaus Basan
2020-02-15 20:36:50 +01:00
committed by Mat Sutcliffe
parent 70e08fdf8b
commit 14ab60cb73
5 changed files with 65 additions and 50 deletions

View File

@@ -1113,10 +1113,10 @@ namespace BlackCore
if (it != m_aliasedStations.end()) 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 // 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 CComSystem::ChannelSpacing spacing = CComSystem::ChannelSpacing25KHz;
const CFrequency f(static_cast<int>(roundedFrequencyHz), CFrequencyUnit::Hz()); const CFrequency f(static_cast<int>(roundedFrequencyHz), CFrequencyUnit::Hz());
const CAtcStationList matchingAtcStations = sApp->getIContextNetwork()->getOnlineStationsForFrequency(f, spacing); const CAtcStationList matchingAtcStations = sApp->getIContextNetwork()->getOnlineStationsForFrequency(f, spacing);

View File

@@ -47,7 +47,7 @@ namespace BlackCore
CAircraftMatcher::CAircraftMatcher(const CAircraftMatcherSetup &setup, QObject *parent) : QObject(parent), m_setup(setup) 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); sApp->getWebDataServices()->synchronizeDbCaches(CEntityFlags::AircraftCategoryEntity);
const CAircraftCategoryList categories = sApp->getWebDataServices()->getAircraftCategories(); const CAircraftCategoryList categories = sApp->getWebDataServices()->getAircraftCategories();
@@ -513,7 +513,8 @@ namespace BlackCore
const CCallsign callsign = inModel.getCallsign(); const CCallsign callsign = inModel.getCallsign();
if (js.isEmpty() && log) { CLogUtilities::addLogDetailsToList(log, callsign, QStringLiteral("Matching script is empty")); } 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; rv.runScript = true;

View File

@@ -94,7 +94,7 @@ namespace BlackCore
connect(m_fsdClient, &CFSDClient::connectionStatusChanged, this, &CAirspaceMonitor::onConnectionStatusChanged); connect(m_fsdClient, &CFSDClient::connectionStatusChanged, this, &CAirspaceMonitor::onConnectionStatusChanged);
// AutoConnection: this should also avoid race conditions by updating the bookings // 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 // optional readers
if (sApp && sApp->getWebDataServices()->getBookingReader()) if (sApp && sApp->getWebDataServices()->getBookingReader())
@@ -340,7 +340,7 @@ namespace BlackCore
void CAirspaceMonitor::requestAtcBookingsUpdate() void CAirspaceMonitor::requestAtcBookingsUpdate()
{ {
if (!sApp || sApp->isShuttingDown()) { return; } if (!sApp || sApp->isShuttingDown() || !sApp->hasWebDataServices()) { return; }
sApp->getWebDataServices()->readInBackground(BlackMisc::Network::CEntityFlags::BookingEntity); sApp->getWebDataServices()->readInBackground(BlackMisc::Network::CEntityFlags::BookingEntity);
m_bookingsRequested = true; m_bookingsRequested = true;
} }
@@ -1360,55 +1360,64 @@ namespace BlackCore
CAircraftSituation correctedSituation(allowTestOffset ? this->addTestAltitudeOffsetToSituation(situation) : situation); CAircraftSituation correctedSituation(allowTestOffset ? this->addTestAltitudeOffsetToSituation(situation) : situation);
bool haveRequestedElevation = false; bool haveRequestedElevation = false;
const bool canLikelySkipNearGround = correctedSituation.canLikelySkipNearGroundInterpolation(); const bool canLikelySkipNearGround = correctedSituation.canLikelySkipNearGroundInterpolation();
if (!correctedSituation.hasGroundElevation() && !canLikelySkipNearGround) if (!correctedSituation.hasGroundElevation())
{ {
// fetch from cache or request // set a defined state
const CAircraftSituationList situations = this->remoteAircraftSituations(callsign); correctedSituation.resetGroundElevation();
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");
// also can handle NULL elevations if (!canLikelySkipNearGround)
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())
{ {
const CElevationPlane averagePlane = this->averageElevationOfNonMovingAircraft(situation, CElevationPlane::majorAirportRadius(), 2); // fetch from cache or request
if (!averagePlane.isNull()) 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 else
{ {
// values before updating (i.e. "storing") so the new situation is not yet considered // from cache
const CAircraftSituationList oldSituations = this->remoteAircraftSituations(callsign); const CLength distance(correctedSituation.getDistancePerTime250ms(CElevationPlane::singlePointRadius())); // distance per ms
const CAircraftSituationChangeList oldChanges = this->remoteAircraftSituationChanges(callsign); const CElevationPlane ep = this->findClosestElevationWithinRangeOrRequest(correctedSituation, distance, callsign);
if (oldSituations.size() > 1) haveRequestedElevation = ep.isNull(); // NULL means we requested
{ Q_ASSERT_X(haveRequestedElevation || !ep.getRadius().isNull(), Q_FUNC_INFO, "null radius");
const bool extrapolated = correctedSituation.extrapolateElevation(oldSituations[0], oldSituations[1], oldChanges.frontOrDefault());
BLACK_AUDIT_X(extrapolated, Q_FUNC_INFO, "Cannot extrapolate"); // 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? // do we already have ground details?
if (situation.getOnGroundDetails() == CAircraftSituation::NotSetGroundDetails) if (situation.getOnGroundDetails() == CAircraftSituation::NotSetGroundDetails)

View File

@@ -38,7 +38,7 @@ namespace BlackGui
connect(ui->pb_SendToDB, &QPushButton::released, this, &CAutoPublishComponent::sendToDb, Qt::QueuedConnection); connect(ui->pb_SendToDB, &QPushButton::released, this, &CAutoPublishComponent::sendToDb, Qt::QueuedConnection);
connect(ui->pb_DeleteFiles, &QPushButton::released, this, &CAutoPublishComponent::deleteAllFiles, 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(); CDatabaseWriter *w = sGui->getWebDataServices()->getDatabaseWriter();
connect(w, &CDatabaseWriter::autoPublished, this, &CAutoPublishComponent::onAutoPublished, Qt::QueuedConnection); connect(w, &CDatabaseWriter::autoPublished, this, &CAutoPublishComponent::onAutoPublished, Qt::QueuedConnection);
@@ -77,7 +77,7 @@ namespace BlackGui
return; return;
} }
if (!sGui->getWebDataServices()) if (!sGui->hasWebDataServices())
{ {
this->showOverlayHTMLMessage("No publishing web service!", 5000); this->showOverlayHTMLMessage("No publishing web service!", 5000);
return; return;

View File

@@ -49,8 +49,13 @@ namespace BlackGui
this->setAcceptDrops(true); this->setAcceptDrops(true);
this->setAcceptedMetaTypeIds({qMetaTypeId<CAircraftIcaoCode>(), qMetaTypeId<CAircraftIcaoCodeList>()}); this->setAcceptedMetaTypeIds({qMetaTypeId<CAircraftIcaoCode>(), qMetaTypeId<CAircraftIcaoCodeList>()});
ui->le_Aircraft->setValidator(new CUpperCaseValidator(this)); ui->le_Aircraft->setValidator(new CUpperCaseValidator(this));
connect(ui->le_Aircraft, &QLineEdit::editingFinished, this, &CDbAircraftIcaoSelectorComponent::onDataChanged); 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()); this->onCodesRead(CEntityFlags::AircraftIcaoEntity, CEntityFlags::ReadFinished, sApp->getWebDataServices()->getAircraftIcaoCodesCount());
} }