[core] introduce TileDataObserver

avoids passing around bound callback functions
This commit is contained in:
Konstantin Käfer
2016-05-23 13:27:43 +02:00
parent 2b6d0751cf
commit 436d8eb5e0
9 changed files with 87 additions and 79 deletions

View File

@@ -1,5 +1,6 @@
#include <mbgl/tile/raster_tile_data.hpp>
#include <mbgl/style/source.hpp>
#include <mbgl/tile/tile_data_observer.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/storage/file_source.hpp>
@@ -10,12 +11,10 @@ using namespace mbgl;
RasterTileData::RasterTileData(const OverscaledTileID& id_,
gl::TexturePool& texturePool_,
Worker& worker_,
const std::function<void(std::exception_ptr)>& callback_)
Worker& worker_)
: TileData(id_),
texturePool(texturePool_),
worker(worker_),
callback(callback_) {
worker(worker_) {
}
void RasterTileData::setData(std::exception_ptr err,
@@ -23,7 +22,7 @@ void RasterTileData::setData(std::exception_ptr err,
optional<Timestamp> modified_,
optional<Timestamp> expires_) {
if (err) {
callback(err);
observer->onTileError(*this, err);
return;
}
@@ -35,7 +34,7 @@ void RasterTileData::setData(std::exception_ptr err,
workRequest.reset();
availableData = DataAvailability::All;
bucket.reset();
callback(err);
observer->onTileLoaded(*this, true);
return;
}
@@ -43,17 +42,15 @@ void RasterTileData::setData(std::exception_ptr err,
workRequest = worker.parseRasterTile(std::make_unique<RasterBucket>(texturePool), data, [this] (RasterTileParseResult result) {
workRequest.reset();
std::exception_ptr error;
if (result.is<std::unique_ptr<Bucket>>()) {
bucket = std::move(result.get<std::unique_ptr<Bucket>>());
} else {
error = result.get<std::exception_ptr>();
bucket.reset();
}
availableData = DataAvailability::All;
callback(error);
if (result.is<std::unique_ptr<Bucket>>()) {
bucket = std::move(result.get<std::unique_ptr<Bucket>>());
observer->onTileLoaded(*this, true);
} else {
bucket.reset();
observer->onTileError(*this, result.get<std::exception_ptr>());
}
});
}