From 753bafa78fc2fc43930ef96c72bd6f71da88732f Mon Sep 17 00:00:00 2001 From: Andreas Bircher Date: Fri, 24 Nov 2017 11:17:53 -0500 Subject: [PATCH] error handling --- src/QtLocationPlugin/QGeoMapReplyQGC.cpp | 7 +++-- src/Terrain.cc | 39 ++++++++++++++++++------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/QtLocationPlugin/QGeoMapReplyQGC.cpp b/src/QtLocationPlugin/QGeoMapReplyQGC.cpp index ff47fc082..d95f1db57 100644 --- a/src/QtLocationPlugin/QGeoMapReplyQGC.cpp +++ b/src/QtLocationPlugin/QGeoMapReplyQGC.cpp @@ -104,6 +104,7 @@ QGeoTiledMapReplyQGC::abort() _timer.stop(); if (_reply) _reply->abort(); + emit aborted(); } //----------------------------------------------------------------------------- @@ -112,11 +113,11 @@ QGeoTiledMapReplyQGC::networkReplyFinished() { _timer.stop(); if (!_reply) { - abort(); + emit aborted(); return; } if (_reply->error() != QNetworkReply::NoError) { - abort(); + emit aborted(); return; } QByteArray a = _reply->readAll(); @@ -197,5 +198,5 @@ QGeoTiledMapReplyQGC::timeout() if(_reply) { _reply->abort(); } - abort(); + emit aborted(); } diff --git a/src/Terrain.cc b/src/Terrain.cc index 64d878e4e..c0fb92cef 100644 --- a/src/Terrain.cc +++ b/src/Terrain.cc @@ -10,7 +10,6 @@ #include "Terrain.h" #include "QGCMapEngine.h" #include "QGeoMapReplyQGC.h" -#include #include #include @@ -20,6 +19,7 @@ #include #include #include +#include QGC_LOGGING_CATEGORY(TerrainLog, "TerrainLog") @@ -165,16 +165,37 @@ void ElevationProvider::_fetchedTile() { QGeoTiledMapReplyQGC* reply = qobject_cast(QObject::sender()); - if (!reply || !reply->isFinished()) { - if (reply) { - qCDebug(TerrainLog) << "Error in fetching elevation tile: " << reply->errorString(); - reply->deleteLater(); + if (!reply) { + qCDebug(TerrainLog) << "Elevation tile fetched but invalid reply data type."; + return; + } + + // remove from download queue + QGeoTileSpec spec = reply->tileSpec(); + QString hash = QGCMapEngine::getTileHash(UrlFactory::AirmapElevation, spec.x(), spec.y(), spec.zoom()); + _tilesMutex.lock(); + if (_downloadQueue.contains(hash)) { + _downloadQueue.removeOne(hash); + } + _tilesMutex.unlock(); + + // handle potential errors + if (reply->error() != QGeoTiledMapReply::NoError) { + if (reply->error() == QGeoTiledMapReply::CommunicationError) { + qCDebug(TerrainLog) << "Elevation tile fetching returned communication error. " << reply->errorString(); } else { - qCDebug(TerrainLog) << "Elevation tile fetched but invalid reply data type."; + qCDebug(TerrainLog) << "Elevation tile fetching returned error. " << reply->errorString(); } + reply->deleteLater(); + return; + } + if (!reply->isFinished()) { + qCDebug(TerrainLog) << "Error in fetching elevation tile. Not finished. " << reply->errorString(); + reply->deleteLater(); return; } + // parse received data and insert into hash table QByteArray responseBytes = reply->mapImageData(); QJsonParseError parseError; @@ -194,12 +215,12 @@ void ElevationProvider::_fetchedTile() } else { delete terrainTile; } - if (_downloadQueue.contains(_getTileHash(terrainTile->centerCoordinate()))) { - _downloadQueue.removeOne(_getTileHash(terrainTile->centerCoordinate())); - } _tilesMutex.unlock(); } reply->deleteLater(); + + // now try to query the data again + queryTerrainData(_coordinates); } QString ElevationProvider::_getTileHash(const QGeoCoordinate& coordinate) -- 2.22.0