[core] Use better types for modified / expires / etag
This commit is contained in:
@@ -44,7 +44,7 @@ std::unique_ptr<FileRequest> AnnotationTileMonitor::monitorTile(const GeometryTi
|
||||
}
|
||||
|
||||
void AnnotationTileMonitor::update(std::unique_ptr<GeometryTile> tile) {
|
||||
callback(nullptr, std::move(tile), Seconds::zero(), Seconds::zero());
|
||||
callback(nullptr, std::move(tile), {}, {});
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
|
||||
using Callback = std::function<void (std::exception_ptr,
|
||||
std::unique_ptr<GeometryTile>,
|
||||
Seconds modified,
|
||||
Seconds expires)>;
|
||||
optional<SystemTimePoint> modified,
|
||||
optional<SystemTimePoint> 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.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/map/tile_id.hpp>
|
||||
#include <mbgl/renderer/bucket.hpp>
|
||||
#include <mbgl/text/placement_config.hpp>
|
||||
@@ -91,8 +92,8 @@ public:
|
||||
void dumpDebugLogs() const;
|
||||
|
||||
const TileID id;
|
||||
Seconds modified = Seconds::zero();
|
||||
Seconds expires = Seconds::zero();
|
||||
optional<SystemTimePoint> modified;
|
||||
optional<SystemTimePoint> expires;
|
||||
|
||||
// Contains the tile ID string for painting debug information.
|
||||
std::unique_ptr<DebugBucket> debugBucket;
|
||||
|
||||
@@ -29,8 +29,8 @@ VectorTileData::VectorTileData(const TileID& id_,
|
||||
state = State::loading;
|
||||
tileRequest = monitor->monitorTile([callback, this](std::exception_ptr err,
|
||||
std::unique_ptr<GeometryTile> tile,
|
||||
Seconds modified_,
|
||||
Seconds expires_) {
|
||||
optional<SystemTimePoint> modified_,
|
||||
optional<SystemTimePoint> expires_) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
DebugBucket::DebugBucket(const TileID id, const TileData::State state_, Seconds modified_, Seconds expires_, MapDebugOptions debugMode_)
|
||||
DebugBucket::DebugBucket(const TileID id, const TileData::State state_, optional<SystemTimePoint> modified_, optional<SystemTimePoint> expires_, MapDebugOptions debugMode_)
|
||||
: state(state_),
|
||||
modified(modified_),
|
||||
expires(expires_),
|
||||
@@ -22,11 +22,11 @@ DebugBucket::DebugBucket(const TileID id, const TileData::State state_, Seconds
|
||||
baseline += 200;
|
||||
}
|
||||
|
||||
if (debugMode & MapDebugOptions::Timestamps && modified > Seconds::zero() && expires > Seconds::zero()) {
|
||||
const std::string modifiedText = "modified: " + util::iso8601(modified.count());
|
||||
if (debugMode & MapDebugOptions::Timestamps && modified && expires) {
|
||||
const std::string modifiedText = "modified: " + util::iso8601(SystemClock::to_time_t(*modified));
|
||||
fontBuffer.addText(modifiedText.c_str(), 50, baseline, 5);
|
||||
|
||||
const std::string expiresText = "expires: " + util::iso8601(expires.count());
|
||||
const std::string expiresText = "expires: " + util::iso8601(SystemClock::to_time_t(*expires));
|
||||
fontBuffer.addText(expiresText.c_str(), 50, baseline + 200, 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,17 @@ class PlainShader;
|
||||
|
||||
class DebugBucket : private util::noncopyable {
|
||||
public:
|
||||
DebugBucket(TileID id, TileData::State, Seconds modified, Seconds expires, MapDebugOptions);
|
||||
DebugBucket(TileID id, TileData::State,
|
||||
optional<SystemTimePoint> modified,
|
||||
optional<SystemTimePoint> expires,
|
||||
MapDebugOptions);
|
||||
|
||||
void drawLines(PlainShader& shader);
|
||||
void drawPoints(PlainShader& shader);
|
||||
|
||||
const TileData::State state;
|
||||
const Seconds modified;
|
||||
const Seconds expires;
|
||||
const optional<SystemTimePoint> modified;
|
||||
const optional<SystemTimePoint> expires;
|
||||
const MapDebugOptions debugMode;
|
||||
|
||||
private:
|
||||
|
||||
@@ -25,8 +25,8 @@ void Painter::renderDebugText(TileData& tileData, const mat4 &matrix) {
|
||||
config.depthTest = GL_FALSE;
|
||||
|
||||
if (!tileData.debugBucket || tileData.debugBucket->state != tileData.getState()
|
||||
|| tileData.debugBucket->modified != tileData.modified
|
||||
|| tileData.debugBucket->expires != tileData.expires
|
||||
|| !(tileData.debugBucket->modified == tileData.modified)
|
||||
|| !(tileData.debugBucket->expires == tileData.expires)
|
||||
|| tileData.debugBucket->debugMode != data.getDebug()) {
|
||||
tileData.debugBucket = std::make_unique<DebugBucket>(tileData.id, tileData.getState(), tileData.modified, tileData.expires, data.getDebug());
|
||||
}
|
||||
|
||||
@@ -5,15 +5,19 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
Seconds HTTPRequestBase::parseCacheControl(const char *value) {
|
||||
if (value) {
|
||||
const auto cacheControl = http::CacheControl::parse(value);
|
||||
if (cacheControl.maxAge) {
|
||||
return toSeconds(SystemClock::now()) + Seconds(*cacheControl.maxAge);
|
||||
}
|
||||
optional<SystemTimePoint> HTTPRequestBase::parseCacheControl(const char *value) {
|
||||
if (!value) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return Seconds::zero();
|
||||
const auto cacheControl = http::CacheControl::parse(value);
|
||||
if (!cacheControl.maxAge) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Round trip through time_t to truncate fractional seconds.
|
||||
return SystemClock::from_time_t(SystemClock::to_time_t(
|
||||
SystemClock::now() + std::chrono::seconds(*cacheControl.maxAge)));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
@@ -27,7 +28,7 @@ public:
|
||||
virtual void cancel() { cancelled = true; };
|
||||
|
||||
protected:
|
||||
static Seconds parseCacheControl(const char *value);
|
||||
static optional<SystemTimePoint> parseCacheControl(const char *value);
|
||||
|
||||
std::string url;
|
||||
Callback notify;
|
||||
|
||||
@@ -120,7 +120,7 @@ void GeoJSONTileMonitor::setGeoJSONVT(mapbox::geojsonvt::GeoJSONVT* vt) {
|
||||
void GeoJSONTileMonitor::update() {
|
||||
if (geojsonvt) {
|
||||
auto tile = convertTile(geojsonvt->getTile(tileID.z, tileID.x, tileID.y));
|
||||
callback(nullptr, std::move(tile), Seconds::zero(), Seconds::zero());
|
||||
callback(nullptr, std::move(tile), {}, {});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user