summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-09-15 17:26:44 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-09-24 16:14:09 +0200
commitd9fc7708a2dfb6e2506a5d10d896a813557c056d (patch)
tree50b2dba9e0a8766c88f7c276a8f71742a06a1d67 /src/platform
parent062e911c6d570a794431023f9f0cb0b02cd85667 (diff)
downloadqtlocation-mapboxgl-d9fc7708a2dfb6e2506a5d10d896a813557c056d.tar.gz
do 304 requests and cache them in sqlite
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/request.cpp54
-rw-r--r--src/platform/response.cpp31
2 files changed, 0 insertions, 85 deletions
diff --git a/src/platform/request.cpp b/src/platform/request.cpp
deleted file mode 100644
index efd17895db..0000000000
--- a/src/platform/request.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#include <mbgl/platform/request.hpp>
-#include <mbgl/platform/platform.hpp>
-#include <mbgl/util/std.hpp>
-#include <mbgl/util/uv_detail.hpp>
-
-using namespace mbgl::platform;
-
-Request::Request(const std::string &url,
- std::function<void(Response *)> callback,
- std::shared_ptr<uv::loop> loop)
- : url(url),
- res(std::make_unique<Response>(callback)),
- cancelled(false),
- loop(loop) {
- if (loop) {
- // Add a check handle without a callback to keep the default loop running.
- // We don't have a real handler attached to the default loop right from the
- // beginning, because we're using asynchronous messaging to perform the actual
- // request in the request thread. Only after the request is complete, we
- // create an actual work request that is attached to the default loop.
- async = new uv_async_t();
- async->data = new std::unique_ptr<Response>();
- uv_async_init(**loop, async, complete);
- }
-}
-
-Request::~Request() {
-}
-
-void Request::complete() {
- if (loop) {
- // We're scheduling the response callback to be invoked in the event loop.
- // Since the Request object will be deleted before the callback is invoked,
- // we move over the Response object to be owned by the async handle.
- ((std::unique_ptr<Response> *)async->data)->swap(res);
- uv_async_send(async);
- } else {
- // We're calling the response callback immediately. We're currently on an
- // arbitrary thread, but that's okay.
- res->callback(res.get());
- }
-}
-
-void Request::complete(uv_async_t *async) {
- Response *res = static_cast<std::unique_ptr<Response> *>(async->data)->get();
-
- res->callback(res);
-
- // We need to remove our async handle again to allow the main event loop to exit.
- uv_close((uv_handle_t *)async, [](uv_handle_t *handle) {
- delete static_cast<std::unique_ptr<Response> *>(handle->data);
- delete (uv_async_t *)handle;
- });
-}
diff --git a/src/platform/response.cpp b/src/platform/response.cpp
deleted file mode 100644
index ce376380fa..0000000000
--- a/src/platform/response.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <mbgl/platform/response.hpp>
-#include <curl/curl.h>
-
-#include <cstdio>
-
-namespace mbgl {
-namespace platform {
-
-
-void Response::setCacheControl(const char *value) {
- if (!value) {
- expires = -1;
- return;
- }
-
- int seconds = 0;
- // TODO: cache-control may contain other information as well:
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
- if (std::sscanf(value, "max-age=%u", &seconds) == 1) {
- if (std::time(&expires) != -1) {
- expires += seconds;
- }
- }
-}
-
-void Response::setLastModified(const char *value) {
- modified = curl_getdate(value, nullptr);
-}
-
-}
-}