summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-05-19 00:28:55 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-05-22 10:44:18 +0300
commitac64bef87f5c0b3d23be59de984fd93eb7f2378f (patch)
treefadbdf96d5b0f9e6c64f1fefbc2a7f3e7e4d4a12
parent7274d2e195b419babbc8c10e99af4f6d7803195f (diff)
downloadqtlocation-mapboxgl-ac64bef87f5c0b3d23be59de984fd93eb7f2378f.tar.gz
Notify failures when loading tiles
-rw-r--r--include/mbgl/util/exception.hpp5
-rw-r--r--src/mbgl/map/resource_loader.cpp4
-rw-r--r--src/mbgl/map/resource_loader.hpp1
-rw-r--r--src/mbgl/map/source.cpp21
-rw-r--r--src/mbgl/map/source.hpp2
-rw-r--r--src/mbgl/map/tile_data.cpp21
-rw-r--r--src/mbgl/map/tile_data.hpp5
7 files changed, 47 insertions, 12 deletions
diff --git a/include/mbgl/util/exception.hpp b/include/mbgl/util/exception.hpp
index dd0199d4e3..7ef8ea9762 100644
--- a/include/mbgl/util/exception.hpp
+++ b/include/mbgl/util/exception.hpp
@@ -31,6 +31,11 @@ struct SpriteLoadingException : Exception {
inline SpriteLoadingException(const std::string &msg) : Exception(msg) {}
};
+struct TileLoadingException : Exception {
+ inline TileLoadingException(const char *msg) : Exception(msg) {}
+ inline TileLoadingException(const std::string &msg) : Exception(msg) {}
+};
+
}
}
diff --git a/src/mbgl/map/resource_loader.cpp b/src/mbgl/map/resource_loader.cpp
index 90c87c1426..ddef11293a 100644
--- a/src/mbgl/map/resource_loader.cpp
+++ b/src/mbgl/map/resource_loader.cpp
@@ -120,6 +120,10 @@ void ResourceLoader::onTileLoaded(bool isNewTile) {
emitTileDataChanged();
}
+void ResourceLoader::onTileLoadingFailed(std::exception_ptr error) {
+ emitResourceLoadingFailed(error);
+}
+
void ResourceLoader::onSpriteLoaded() {
shouldReparsePartialTiles_ = true;
diff --git a/src/mbgl/map/resource_loader.hpp b/src/mbgl/map/resource_loader.hpp
index 5b7863a6d3..9d94cb6495 100644
--- a/src/mbgl/map/resource_loader.hpp
+++ b/src/mbgl/map/resource_loader.hpp
@@ -68,6 +68,7 @@ public:
void onSourceLoaded() override;
void onSourceLoadingFailed(std::exception_ptr error) override;
void onTileLoaded(bool isNewTile) override;
+ void onTileLoadingFailed(std::exception_ptr error) override;
// Sprite::Observer implementation.
void onSpriteLoaded() override;
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 37bc40830b..b0c4e22f55 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -287,22 +287,26 @@ TileData::State Source::addTile(MapData& data,
new_tile.data = cache.get(normalized_id.to_uint64());
}
- auto callback = std::bind(&Source::emitTileLoaded, this, true);
+ auto successCallback = std::bind(&Source::emitTileLoaded, this, true);
+ auto failureCallback = std::bind(&Source::emitTileLoadingFailed, this, std::placeholders::_1);
+
if (!new_tile.data) {
// If we don't find working tile data, we're just going to load it.
if (info.type == SourceType::Vector) {
new_tile.data =
std::make_shared<VectorTileData>(normalized_id, data.transform.getMaxZoom(), style, glyphAtlas,
glyphStore, spriteAtlas, sprite, info);
- new_tile.data->request(style.workers, transformState.getPixelRatio(), callback);
+ new_tile.data->request(
+ style.workers, transformState.getPixelRatio(), successCallback, failureCallback);
} else if (info.type == SourceType::Raster) {
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info);
- new_tile.data->request(style.workers, transformState.getPixelRatio(), callback);
+ new_tile.data->request(
+ style.workers, transformState.getPixelRatio(), successCallback, failureCallback);
} else if (info.type == SourceType::Annotations) {
new_tile.data = std::make_shared<LiveTileData>(normalized_id, data.annotationManager,
data.transform.getMaxZoom(), style, glyphAtlas,
glyphStore, spriteAtlas, sprite, info);
- new_tile.data->reparse(style.workers, callback);
+ new_tile.data->reparse(style.workers, successCallback);
} else {
throw std::runtime_error("source type not implemented");
}
@@ -556,4 +560,13 @@ void Source::emitTileLoaded(bool isNewTile) {
}
}
+void Source::emitTileLoadingFailed(const std::string& message) {
+ if (!observer_) {
+ return;
+ }
+
+ auto error = std::make_exception_ptr(util::TileLoadingException(message));
+ observer_->onTileLoadingFailed(error);
+}
+
}
diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp
index 781e8621a7..303d4d0245 100644
--- a/src/mbgl/map/source.hpp
+++ b/src/mbgl/map/source.hpp
@@ -61,6 +61,7 @@ public:
virtual void onSourceLoadingFailed(std::exception_ptr error) = 0;
virtual void onTileLoaded(bool isNewTile) = 0;
+ virtual void onTileLoadingFailed(std::exception_ptr error) = 0;
};
Source();
@@ -106,6 +107,7 @@ private:
void emitSourceLoaded();
void emitSourceLoadingFailed(const std::string& message);
void emitTileLoaded(bool isNewTile);
+ void emitTileLoadingFailed(const std::string& message);
bool handlePartialTile(const TileID &id, Worker &worker);
bool findLoadedChildren(const TileID& id, int32_t maxCoveringZoom, std::forward_list<TileID>& retain);
diff --git a/src/mbgl/map/tile_data.cpp b/src/mbgl/map/tile_data.cpp
index e9084bdff2..be0d7d32fe 100644
--- a/src/mbgl/map/tile_data.cpp
+++ b/src/mbgl/map/tile_data.cpp
@@ -1,11 +1,13 @@
#include <mbgl/map/tile_data.hpp>
+
#include <mbgl/map/environment.hpp>
#include <mbgl/map/source.hpp>
-
+#include <mbgl/platform/log.hpp>
#include <mbgl/storage/file_source.hpp>
-#include <mbgl/util/worker.hpp>
#include <mbgl/util/work_request.hpp>
-#include <mbgl/platform/log.hpp>
+#include <mbgl/util/worker.hpp>
+
+#include <sstream>
using namespace mbgl;
@@ -34,15 +36,20 @@ void TileData::setState(const State& state_) {
state = state_;
}
-void TileData::request(Worker& worker, float pixelRatio, std::function<void()> callback) {
+void TileData::request(Worker& worker,
+ float pixelRatio,
+ const std::function<void()>& successCallback,
+ const std::function<void(const std::string& message)>& failureCallback) {
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
- req = env.request({ Resource::Kind::Tile, url }, [url, callback, &worker, this](const Response &res) {
+ req = env.request({ Resource::Kind::Tile, url }, [url, successCallback, failureCallback, &worker, this](const Response &res) {
req = nullptr;
if (res.status != Response::Successful) {
- Log::Error(Event::HttpRequest, "[%s] tile loading failed: %s", url.c_str(), res.message.c_str());
+ std::stringstream message;
+ message << "Failed to load [" << url << "]: " << res.message;
+ failureCallback(message.str());
return;
}
@@ -50,7 +57,7 @@ void TileData::request(Worker& worker, float pixelRatio, std::function<void()> c
data = res.data;
// Schedule tile parsing in another thread
- reparse(worker, callback);
+ reparse(worker, successCallback);
});
}
diff --git a/src/mbgl/map/tile_data.hpp b/src/mbgl/map/tile_data.hpp
index 3945a32147..0d34b2df74 100644
--- a/src/mbgl/map/tile_data.hpp
+++ b/src/mbgl/map/tile_data.hpp
@@ -44,7 +44,10 @@ public:
TileData(const TileID&, const SourceInfo&);
~TileData();
- void request(Worker&, float pixelRatio, std::function<void ()> callback);
+ void request(Worker&,
+ float pixelRatio,
+ const std::function<void()>& successCallback,
+ const std::function<void(const std::string& message)>& failureCallback);
// Schedule a tile reparse on a worker thread and call the callback on
// completion. It will return true if the work was schedule or false it was