diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-05-13 15:41:22 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-05-13 17:24:22 +0200 |
commit | cd65a43855f33555eca5f3e3ad5d37661253209f (patch) | |
tree | d83b63f4baeb3672c4909a08b14783c717b74681 /platform | |
parent | c1dde52c73061a49d576454a9ab4739e72561ca6 (diff) | |
download | qtlocation-mapboxgl-cd65a43855f33555eca5f3e3ad5d37661253209f.tar.gz |
[core] move from microsecond precision timestamp to integer second precision
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/src/http_file_source.cpp | 4 | ||||
-rw-r--r-- | platform/darwin/src/http_file_source.mm | 4 | ||||
-rw-r--r-- | platform/default/http_file_source.cpp | 4 | ||||
-rw-r--r-- | platform/default/mbgl/storage/offline_database.cpp | 24 | ||||
-rw-r--r-- | platform/default/online_file_source.cpp | 22 | ||||
-rw-r--r-- | platform/default/sqlite3.cpp | 25 | ||||
-rw-r--r-- | platform/node/src/node_request.cpp | 6 | ||||
-rw-r--r-- | platform/qt/src/http_request.cpp | 4 |
8 files changed, 53 insertions, 40 deletions
diff --git a/platform/android/src/http_file_source.cpp b/platform/android/src/http_file_source.cpp index ceb241af4e..97ccdb14b4 100644 --- a/platform/android/src/http_file_source.cpp +++ b/platform/android/src/http_file_source.cpp @@ -110,7 +110,7 @@ void HTTPRequest::onResponse(jni::JNIEnv& env, int code, } if (modified) { - response.modified = util::parseTimePoint(jni::Make<std::string>(env, modified).c_str()); + response.modified = util::parseTimestamp(jni::Make<std::string>(env, modified).c_str()); } if (cacheControl) { @@ -118,7 +118,7 @@ void HTTPRequest::onResponse(jni::JNIEnv& env, int code, } if (expires) { - response.expires = util::parseTimePoint(jni::Make<std::string>(env, expires).c_str()); + response.expires = util::parseTimestamp(jni::Make<std::string>(env, expires).c_str()); } if (code == 200) { diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index 82d3e04378..eb751258c8 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -271,12 +271,12 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, NSString *expires = [headers objectForKey:@"Expires"]; if (expires) { - response.expires = util::parseTimePoint([expires UTF8String]); + response.expires = util::parseTimestamp([expires UTF8String]); } NSString *last_modified = [headers objectForKey:@"Last-Modified"]; if (last_modified) { - response.modified = util::parseTimePoint([last_modified UTF8String]); + response.modified = util::parseTimestamp([last_modified UTF8String]); } NSString *etag = [headers objectForKey:@"ETag"]; diff --git a/platform/default/http_file_source.cpp b/platform/default/http_file_source.cpp index 3250a77c80..e83ecfbfc9 100644 --- a/platform/default/http_file_source.cpp +++ b/platform/default/http_file_source.cpp @@ -316,7 +316,7 @@ size_t HTTPRequest::headerCallback(char *const buffer, const size_t size, const // Always overwrite the modification date; We might already have a value here from the // Date header, but this one is more accurate. const std::string value { buffer + begin, length - begin - 2 }; // remove \r\n - baton->response->modified = SystemClock::from_time_t(curl_getdate(value.c_str(), nullptr)); + baton->response->modified = Timestamp{ Seconds(curl_getdate(value.c_str(), nullptr)) }; } else if ((begin = headerMatches("etag: ", buffer, length)) != std::string::npos) { baton->response->etag = std::string(buffer + begin, length - begin - 2); // remove \r\n } else if ((begin = headerMatches("cache-control: ", buffer, length)) != std::string::npos) { @@ -324,7 +324,7 @@ size_t HTTPRequest::headerCallback(char *const buffer, const size_t size, const baton->response->expires = http::CacheControl::parse(value.c_str()).toTimePoint(); } else if ((begin = headerMatches("expires: ", buffer, length)) != std::string::npos) { const std::string value { buffer + begin, length - begin - 2 }; // remove \r\n - baton->response->expires = SystemClock::from_time_t(curl_getdate(value.c_str(), nullptr)); + baton->response->expires = Timestamp{ Seconds(curl_getdate(value.c_str(), nullptr)) }; } return length; diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index 52ab6504fa..3193909294 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -181,7 +181,7 @@ optional<std::pair<Response, uint64_t>> OfflineDatabase::getResource(const Resou Statement accessedStmt = getStatement( "UPDATE resources SET accessed = ?1 WHERE url = ?2"); - accessedStmt->bind(1, SystemClock::now()); + accessedStmt->bind(1, util::now()); accessedStmt->bind(2, resource.url); accessedStmt->run(); @@ -201,8 +201,8 @@ optional<std::pair<Response, uint64_t>> OfflineDatabase::getResource(const Resou uint64_t size = 0; response.etag = stmt->get<optional<std::string>>(0); - response.expires = stmt->get<optional<SystemTimePoint>>(1); - response.modified = stmt->get<optional<SystemTimePoint>>(2); + response.expires = stmt->get<optional<Timestamp>>(1); + response.modified = stmt->get<optional<Timestamp>>(2); optional<std::string> data = stmt->get<optional<std::string>>(3); if (!data) { @@ -229,7 +229,7 @@ bool OfflineDatabase::putResource(const Resource& resource, " expires = ?2 " "WHERE url = ?3 "); - update->bind(1, SystemClock::now()); + update->bind(1, util::now()); update->bind(2, response.expires); update->bind(3, resource.url); update->run(); @@ -257,7 +257,7 @@ bool OfflineDatabase::putResource(const Resource& resource, update->bind(2, response.etag); update->bind(3, response.expires); update->bind(4, response.modified); - update->bind(5, SystemClock::now()); + update->bind(5, util::now()); update->bind(8, resource.url); if (response.noContent) { @@ -283,7 +283,7 @@ bool OfflineDatabase::putResource(const Resource& resource, insert->bind(3, response.etag); insert->bind(4, response.expires); insert->bind(5, response.modified); - insert->bind(6, SystemClock::now()); + insert->bind(6, util::now()); if (response.noContent) { insert->bind(7, nullptr); @@ -309,7 +309,7 @@ optional<std::pair<Response, uint64_t>> OfflineDatabase::getTile(const Resource: " AND y = ?5 " " AND z = ?6 "); - accessedStmt->bind(1, SystemClock::now()); + accessedStmt->bind(1, util::now()); accessedStmt->bind(2, tile.urlTemplate); accessedStmt->bind(3, tile.pixelRatio); accessedStmt->bind(4, tile.x); @@ -341,8 +341,8 @@ optional<std::pair<Response, uint64_t>> OfflineDatabase::getTile(const Resource: uint64_t size = 0; response.etag = stmt->get<optional<std::string>>(0); - response.expires = stmt->get<optional<SystemTimePoint>>(1); - response.modified = stmt->get<optional<SystemTimePoint>>(2); + response.expires = stmt->get<optional<Timestamp>>(1); + response.modified = stmt->get<optional<Timestamp>>(2); optional<std::string> data = stmt->get<optional<std::string>>(3); if (!data) { @@ -373,7 +373,7 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile, " AND y = ?6 " " AND z = ?7 "); - update->bind(1, SystemClock::now()); + update->bind(1, util::now()); update->bind(2, response.expires); update->bind(3, tile.urlTemplate); update->bind(4, tile.pixelRatio); @@ -407,7 +407,7 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile, update->bind(1, response.modified); update->bind(2, response.etag); update->bind(3, response.expires); - update->bind(4, SystemClock::now()); + update->bind(4, util::now()); update->bind(7, tile.urlTemplate); update->bind(8, tile.pixelRatio); update->bind(9, tile.x); @@ -440,7 +440,7 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile, insert->bind(6, response.modified); insert->bind(7, response.etag); insert->bind(8, response.expires); - insert->bind(9, SystemClock::now()); + insert->bind(9, util::now()); if (response.noContent) { insert->bind(10, nullptr); diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index 6753b34f25..a4ac2c2b2b 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -30,7 +30,7 @@ public: ~OnlineFileRequest(); void networkIsReachableAgain(); - void schedule(optional<SystemTimePoint> expires); + void schedule(optional<Timestamp> expires); void completed(Response); OnlineFileSource::Impl& impl; @@ -192,7 +192,7 @@ OnlineFileRequest::OnlineFileRequest(const Resource& resource_, Callback callbac if (resource.priorExpires) { schedule(resource.priorExpires); } else { - schedule(SystemClock::now()); + schedule(util::now()); } } @@ -214,20 +214,20 @@ static Duration errorRetryTimeout(Response::Error::Reason failedRequestReason, u } } -static Duration expirationTimeout(optional<SystemTimePoint> expires, uint32_t expiredRequests) { +static Duration expirationTimeout(optional<Timestamp> expires, uint32_t expiredRequests) { if (expiredRequests) { return Seconds(1 << std::min(expiredRequests - 1, 31u)); } else if (expires) { - return std::max(SystemDuration::zero(), *expires - SystemClock::now()); + return std::max(Seconds::zero(), *expires - util::now()); } else { return Duration::max(); } } -SystemTimePoint interpolateExpiration(const SystemTimePoint& current, - optional<SystemTimePoint> prior, - bool& expired) { - auto now = SystemClock::now(); +Timestamp interpolateExpiration(const Timestamp& current, + optional<Timestamp> prior, + bool& expired) { + auto now = util::now(); if (current > now) { return current; } @@ -256,10 +256,10 @@ SystemTimePoint interpolateExpiration(const SystemTimePoint& current, // Assume that either the client or server clock is wrong and // try to interpolate a valid expiration date (from the client POV) // observing a minimum timeout. - return now + std::max<SystemDuration>(delta, util::CLOCK_SKEW_RETRY_TIMEOUT); + return now + std::max<Seconds>(delta, util::CLOCK_SKEW_RETRY_TIMEOUT); } -void OnlineFileRequest::schedule(optional<SystemTimePoint> expires) { +void OnlineFileRequest::schedule(optional<Timestamp> expires) { if (request) { // There's already a request in progress; don't start another one. return; @@ -339,7 +339,7 @@ void OnlineFileRequest::networkIsReachableAgain() { // We need all requests to fail at least once before we are going to start retrying // them, and we only immediately restart request that failed due to connection issues. if (failedRequestReason == Response::Error::Reason::Connection) { - schedule(SystemClock::now()); + schedule(util::now()); } } diff --git a/platform/default/sqlite3.cpp b/platform/default/sqlite3.cpp index 505423d1fd..b6db71a752 100644 --- a/platform/default/sqlite3.cpp +++ b/platform/default/sqlite3.cpp @@ -218,7 +218,9 @@ void Statement::bindBlob(int offset, const std::vector<uint8_t>& value, bool ret bindBlob(offset, value.data(), value.size(), retain); } -template <> void Statement::bind(int offset, std::chrono::system_clock::time_point value) { +template <> +void Statement::bind( + int offset, std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> value) { assert(stmt); check(sqlite3_bind_int64(stmt, offset, std::chrono::system_clock::to_time_t(value))); } @@ -231,7 +233,10 @@ template <> void Statement::bind(int offset, optional<std::string> value) { } } -template <> void Statement::bind(int offset, optional<std::chrono::system_clock::time_point> value) { +template <> +void Statement::bind( + int offset, + optional<std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>> value) { if (!value) { bind(offset, nullptr); } else { @@ -283,9 +288,12 @@ template <> std::vector<uint8_t> Statement::get(int offset) { return { begin, end }; } -template <> std::chrono::system_clock::time_point Statement::get(int offset) { +template <> +std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> +Statement::get(int offset) { assert(stmt); - return std::chrono::system_clock::from_time_t(sqlite3_column_int64(stmt, offset)); + return std::chrono::time_point_cast<std::chrono::seconds>( + std::chrono::system_clock::from_time_t(sqlite3_column_int64(stmt, offset))); } template <> optional<int64_t> Statement::get(int offset) { @@ -315,12 +323,15 @@ template <> optional<std::string> Statement::get(int offset) { } } -template <> optional<std::chrono::system_clock::time_point> Statement::get(int offset) { +template <> +optional<std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>> +Statement::get(int offset) { assert(stmt); if (sqlite3_column_type(stmt, offset) == SQLITE_NULL) { - return optional<std::chrono::system_clock::time_point>(); + return {}; } else { - return get<std::chrono::system_clock::time_point>(offset); + return get<std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>>( + offset); } } diff --git a/platform/node/src/node_request.cpp b/platform/node/src/node_request.cpp index 50d7628a2b..d1a40a9080 100644 --- a/platform/node/src/node_request.cpp +++ b/platform/node/src/node_request.cpp @@ -79,14 +79,16 @@ NAN_METHOD(NodeRequest::Respond) { if (Nan::Has(res, Nan::New("modified").ToLocalChecked()).FromJust()) { const double modified = Nan::Get(res, Nan::New("modified").ToLocalChecked()).ToLocalChecked()->ToNumber()->Value(); if (!std::isnan(modified)) { - response.modified = mbgl::SystemClock::from_time_t(modified / 1000); + response.modified = mbgl::Timestamp{ mbgl::Seconds( + static_cast<mbgl::Seconds::rep>(modified / 1000)) }; } } if (Nan::Has(res, Nan::New("expires").ToLocalChecked()).FromJust()) { const double expires = Nan::Get(res, Nan::New("expires").ToLocalChecked()).ToLocalChecked()->ToNumber()->Value(); if (!std::isnan(expires)) { - response.expires = mbgl::SystemClock::from_time_t(expires / 1000); + response.expires = mbgl::Timestamp{ mbgl::Seconds( + static_cast<mbgl::Seconds::rep>(expires / 1000)) }; } } diff --git a/platform/qt/src/http_request.cpp b/platform/qt/src/http_request.cpp index a8ef43c9e2..7290f5a974 100644 --- a/platform/qt/src/http_request.cpp +++ b/platform/qt/src/http_request.cpp @@ -71,13 +71,13 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply) QString header = QString(line.first).toLower(); if (header == "last-modified") { - response.modified = util::parseTimePoint(line.second.constData()); + response.modified = util::parseTimestamp(line.second.constData()); } else if (header == "etag") { response.etag = std::string(line.second.constData(), line.second.size()); } else if (header == "cache-control") { response.expires = http::CacheControl::parse(line.second.constData()).toTimePoint(); } else if (header == "expires") { - response.expires = util::parseTimePoint(line.second.constData()); + response.expires = util::parseTimestamp(line.second.constData()); } } |