summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-19 15:57:17 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-01-21 11:22:11 -0800
commit1c21d0fd4cd30cbf6c5b863fd0179b227c28bc0b (patch)
treedfb6b788285d2b28f7060138ae28734ece13942e /src
parentc33ed50c98c57ce2f2cf3b971bcf72c4208bf120 (diff)
downloadqtlocation-mapboxgl-1c21d0fd4cd30cbf6c5b863fd0179b227c28bc0b.tar.gz
[core] Use better types for modified / expires / etag
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_tile.cpp2
-rw-r--r--src/mbgl/map/geometry_tile.hpp4
-rw-r--r--src/mbgl/map/tile_data.hpp5
-rw-r--r--src/mbgl/map/vector_tile_data.cpp4
-rw-r--r--src/mbgl/renderer/debug_bucket.cpp8
-rw-r--r--src/mbgl/renderer/debug_bucket.hpp9
-rw-r--r--src/mbgl/renderer/painter_debug.cpp4
-rw-r--r--src/mbgl/storage/http_request_base.cpp18
-rw-r--r--src/mbgl/storage/http_request_base.hpp3
-rw-r--r--src/mbgl/tile/geojson_tile.cpp2
10 files changed, 34 insertions, 25 deletions
diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp
index 39dbee408a..a4590ffe30 100644
--- a/src/mbgl/annotation/annotation_tile.cpp
+++ b/src/mbgl/annotation/annotation_tile.cpp
@@ -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
diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp
index dd9a21bc62..e906fed8f3 100644
--- a/src/mbgl/map/geometry_tile.hpp
+++ b/src/mbgl/map/geometry_tile.hpp
@@ -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.
diff --git a/src/mbgl/map/tile_data.hpp b/src/mbgl/map/tile_data.hpp
index 1067c86d3d..fec8ba4901 100644
--- a/src/mbgl/map/tile_data.hpp
+++ b/src/mbgl/map/tile_data.hpp
@@ -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;
diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp
index 9e1390decd..fa08432b20 100644
--- a/src/mbgl/map/vector_tile_data.cpp
+++ b/src/mbgl/map/vector_tile_data.cpp
@@ -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;
diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp
index a1a24eab73..a6663b35c3 100644
--- a/src/mbgl/renderer/debug_bucket.cpp
+++ b/src/mbgl/renderer/debug_bucket.cpp
@@ -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);
}
}
diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp
index 73af338c2c..5c7511ce87 100644
--- a/src/mbgl/renderer/debug_bucket.hpp
+++ b/src/mbgl/renderer/debug_bucket.hpp
@@ -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:
diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp
index 0a0900526a..d6b1aec73c 100644
--- a/src/mbgl/renderer/painter_debug.cpp
+++ b/src/mbgl/renderer/painter_debug.cpp
@@ -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());
}
diff --git a/src/mbgl/storage/http_request_base.cpp b/src/mbgl/storage/http_request_base.cpp
index 8a4a81b291..81be716ff2 100644
--- a/src/mbgl/storage/http_request_base.cpp
+++ b/src/mbgl/storage/http_request_base.cpp
@@ -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
diff --git a/src/mbgl/storage/http_request_base.hpp b/src/mbgl/storage/http_request_base.hpp
index 8f1caf7bdc..1a8cf73da6 100644
--- a/src/mbgl/storage/http_request_base.hpp
+++ b/src/mbgl/storage/http_request_base.hpp
@@ -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;
diff --git a/src/mbgl/tile/geojson_tile.cpp b/src/mbgl/tile/geojson_tile.cpp
index e7ce5385fe..d8eabf00a2 100644
--- a/src/mbgl/tile/geojson_tile.cpp
+++ b/src/mbgl/tile/geojson_tile.cpp
@@ -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), {}, {});
}
}