[core] Added modified, expires information to TileData

This commit is contained in:
Bruno de Oliveira Abinader
2015-11-25 15:06:33 +02:00
parent 31fd2822f5
commit 591e0dde2f
10 changed files with 37 additions and 14 deletions

View File

@@ -36,14 +36,14 @@ AnnotationTileMonitor::~AnnotationTileMonitor() {
data.getAnnotationManager()->removeTileMonitor(*this);
}
std::unique_ptr<FileRequest> AnnotationTileMonitor::monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback_) {
std::unique_ptr<FileRequest> AnnotationTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback_) {
callback = callback_;
data.getAnnotationManager()->addTileMonitor(*this);
return nullptr;
}
void AnnotationTileMonitor::update(std::unique_ptr<GeometryTile> tile) {
callback(nullptr, std::move(tile));
callback(nullptr, std::move(tile), Seconds::zero(), Seconds::zero());
}
}

View File

@@ -46,13 +46,13 @@ public:
~AnnotationTileMonitor();
void update(std::unique_ptr<GeometryTile>);
std::unique_ptr<FileRequest> monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)>) override;
std::unique_ptr<FileRequest> monitorTile(const GeometryTileMonitor::Callback&) override;
TileID tileID;
private:
MapData& data;
std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback;
GeometryTileMonitor::Callback callback;
};
}

View File

@@ -5,6 +5,7 @@
#include <mapbox/optional.hpp>
#include <mbgl/style/value.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/util/noncopyable.hpp>
@@ -52,6 +53,10 @@ class GeometryTileMonitor : private util::noncopyable {
public:
virtual ~GeometryTileMonitor() = default;
using Callback = std::function<void (std::exception_ptr,
std::unique_ptr<GeometryTile>,
Seconds modified,
Seconds expires)>;
/*
* Monitor the tile held by this object for changes. When the tile is loaded for the first time,
* or updates, the callback is executed. If an error occurs, the first parameter will be set.
@@ -60,7 +65,7 @@ public:
*
* To cease monitoring, release the returned Request.
*/
virtual std::unique_ptr<FileRequest> monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)>) = 0;
virtual std::unique_ptr<FileRequest> monitorTile(const Callback&) = 0;
};
class GeometryTileFeatureExtractor {

View File

@@ -25,7 +25,7 @@ RasterTileData::~RasterTileData() {
}
void RasterTileData::request(float pixelRatio,
const std::function<void()>& callback) {
const RasterTileData::Callback& callback) {
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
@@ -55,6 +55,9 @@ void RasterTileData::request(float pixelRatio,
state = State::loaded;
}
modified = res.modified;
expires = res.expires;
workRequest = worker.parseRasterTile(std::make_unique<RasterBucket>(texturePool), res.data, [this, callback] (RasterTileParseResult result) {
workRequest.reset();
if (state != State::loaded) {

View File

@@ -17,8 +17,10 @@ public:
RasterTileData(const TileID&, TexturePool&, const SourceInfo&, Worker&);
~RasterTileData();
using Callback = std::function<void()>;
void request(float pixelRatio,
const std::function<void()>& callback);
const Callback& callback);
void cancel() override;

View File

@@ -285,7 +285,11 @@ TileData::State Source::addTile(MapData& data,
// If we don't find working tile data, we're just going to load it.
if (info.type == SourceType::Raster) {
auto tileData = std::make_shared<RasterTileData>(normalized_id, texturePool, info, style.workers);
auto tileData = std::make_shared<RasterTileData>(normalized_id,
texturePool,
info,
style.workers);
tileData->request(data.pixelRatio, callback);
new_tile.data = tileData;
} else {

View File

@@ -2,6 +2,7 @@
#define MBGL_MAP_TILE_DATA
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/text/placement_config.hpp>
@@ -94,6 +95,8 @@ public:
void dumpDebugLogs() const;
const TileID id;
Seconds modified = Seconds::zero();
Seconds expires = Seconds::zero();
// Contains the tile ID string for painting debug information.
std::unique_ptr<DebugBucket> debugBucket;

View File

@@ -181,7 +181,7 @@ VectorTileMonitor::VectorTileMonitor(const SourceInfo& source, const TileID& id,
: url(source.tileURL(id, pixelRatio)) {
}
std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback) {
std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback) {
return util::ThreadContext::getFileSource()->request({ Resource::Kind::Tile, url }, [callback, this](Response res) {
if (res.data && data == res.data) {
// We got the same data again. Abort early.
@@ -190,18 +190,18 @@ std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(std::function<void (
if (res.error) {
if (res.error->reason == Response::Error::Reason::NotFound) {
callback(nullptr, nullptr);
callback(nullptr, nullptr, res.modified, res.expires);
return;
} else {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.error->message;
callback(std::make_exception_ptr(std::runtime_error(message.str())), nullptr);
callback(std::make_exception_ptr(std::runtime_error(message.str())), nullptr, res.modified, res.expires);
return;
}
}
data = res.data;
callback(nullptr, std::make_unique<VectorTile>(data));
callback(nullptr, std::make_unique<VectorTile>(data), res.modified, res.expires);
});
}

View File

@@ -63,7 +63,7 @@ class VectorTileMonitor : public GeometryTileMonitor {
public:
VectorTileMonitor(const SourceInfo&, const TileID&, float pixelRatio);
std::unique_ptr<FileRequest> monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)>) override;
std::unique_ptr<FileRequest> monitorTile(const GeometryTileMonitor::Callback&) override;
private:
std::string url;

View File

@@ -25,7 +25,10 @@ VectorTileData::VectorTileData(const TileID& id_,
monitor(std::move(monitor_))
{
state = State::loading;
tileRequest = monitor->monitorTile([callback, this](std::exception_ptr err, std::unique_ptr<GeometryTile> tile) {
tileRequest = monitor->monitorTile([callback, this](std::exception_ptr err,
std::unique_ptr<GeometryTile> tile,
Seconds modified_,
Seconds expires_) {
if (err) {
try {
std::rethrow_exception(err);
@@ -50,6 +53,9 @@ VectorTileData::VectorTileData(const TileID& id_,
state = State::partial;
}
modified = modified_;
expires = expires_;
// Kick off a fresh parse of this tile. This happens when the tile is new, or
// when tile data changed. Replacing the workdRequest will cancel a pending work
// request in case there is one.