summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-05-13 15:41:22 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-05-13 17:24:22 +0200
commitcd65a43855f33555eca5f3e3ad5d37661253209f (patch)
treed83b63f4baeb3672c4909a08b14783c717b74681 /include
parentc1dde52c73061a49d576454a9ab4739e72561ca6 (diff)
downloadqtlocation-mapboxgl-cd65a43855f33555eca5f3e3ad5d37661253209f.tar.gz
[core] move from microsecond precision timestamp to integer second precision
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/storage/resource.hpp16
-rw-r--r--include/mbgl/storage/response.hpp4
-rw-r--r--include/mbgl/util/chrono.hpp15
-rw-r--r--include/mbgl/util/constants.hpp2
4 files changed, 24 insertions, 13 deletions
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp
index 296dff7f3d..01c2ee4e39 100644
--- a/include/mbgl/storage/resource.hpp
+++ b/include/mbgl/storage/resource.hpp
@@ -29,8 +29,14 @@ public:
int8_t z;
};
- Resource(Kind kind_, const std::string& url_, optional<TileData> tileData_ = {})
+ enum Necessity : bool {
+ Optional = false,
+ Required = true,
+ };
+
+ Resource(Kind kind_, const std::string& url_, optional<TileData> tileData_ = {}, Necessity necessity_ = Required)
: kind(kind_),
+ necessity(necessity_),
url(url_),
tileData(std::move(tileData_)) {
}
@@ -41,7 +47,8 @@ public:
float pixelRatio,
int32_t x,
int32_t y,
- int8_t z);
+ int8_t z,
+ Necessity = Required);
static Resource glyphs(const std::string& urlTemplate,
const FontStack& fontStack,
const std::pair<uint16_t, uint16_t>& glyphRange);
@@ -49,13 +56,14 @@ public:
static Resource spriteJSON(const std::string& base, float pixelRatio);
Kind kind;
+ Necessity necessity;
std::string url;
// Includes auxiliary data if this is a tile request.
optional<TileData> tileData;
- optional<SystemTimePoint> priorModified = {};
- optional<SystemTimePoint> priorExpires = {};
+ optional<Timestamp> priorModified = {};
+ optional<Timestamp> priorExpires = {};
optional<std::string> priorEtag = {};
};
diff --git a/include/mbgl/storage/response.hpp b/include/mbgl/storage/response.hpp
index bec1efe6b1..f140e42b02 100644
--- a/include/mbgl/storage/response.hpp
+++ b/include/mbgl/storage/response.hpp
@@ -30,8 +30,8 @@ public:
// The actual data of the response. Present only for non-error, non-notModified responses.
std::shared_ptr<const std::string> data;
- optional<SystemTimePoint> modified;
- optional<SystemTimePoint> expires;
+ optional<Timestamp> modified;
+ optional<Timestamp> expires;
optional<std::string> etag;
};
diff --git a/include/mbgl/util/chrono.hpp b/include/mbgl/util/chrono.hpp
index 8e0da1419a..81f05d610d 100644
--- a/include/mbgl/util/chrono.hpp
+++ b/include/mbgl/util/chrono.hpp
@@ -7,7 +7,6 @@
namespace mbgl {
using Clock = std::chrono::steady_clock;
-using SystemClock = std::chrono::system_clock;
using Seconds = std::chrono::seconds;
using Milliseconds = std::chrono::milliseconds;
@@ -15,18 +14,22 @@ using Milliseconds = std::chrono::milliseconds;
using TimePoint = Clock::time_point;
using Duration = Clock::duration;
-using SystemTimePoint = SystemClock::time_point;
-using SystemDuration = SystemClock::duration;
+// Used to measure second-precision times, such as times gathered from HTTP responses.
+using Timestamp = std::chrono::time_point<std::chrono::system_clock, Seconds>;
namespace util {
+inline Timestamp now() {
+ return std::chrono::time_point_cast<Seconds>(std::chrono::system_clock::now());
+}
+
// Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT"
-std::string rfc1123(SystemTimePoint);
+std::string rfc1123(Timestamp);
// YYYY-mm-dd HH:MM:SS e.g. "2015-11-26 16:11:23"
-std::string iso8601(SystemTimePoint);
+std::string iso8601(Timestamp);
-SystemTimePoint parseTimePoint(const char *);
+Timestamp parseTimestamp(const char *);
// C++17 polyfill
template <class Rep, class Period, class = std::enable_if_t<
diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp
index 58f4143766..3517299df2 100644
--- a/include/mbgl/util/constants.hpp
+++ b/include/mbgl/util/constants.hpp
@@ -39,7 +39,7 @@ constexpr double MAX_ZOOM = 25.5;
constexpr uint64_t DEFAULT_MAX_CACHE_SIZE = 50 * 1024 * 1024;;
constexpr Duration DEFAULT_FADE_DURATION = Milliseconds(300);
-constexpr SystemDuration CLOCK_SKEW_RETRY_TIMEOUT = Seconds(30);
+constexpr Seconds CLOCK_SKEW_RETRY_TIMEOUT { 30 };
} // namespace util