summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-09-29 12:27:34 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-09-29 12:27:34 +0200
commit46e06bf378e5edc38b5ce1c3ab1e4567eb756d24 (patch)
tree452414d3ed8fdf82a12af25f3a1bfb116e073330 /src
parentb9628c86543ffe819b030c3d84f65fa09e084850 (diff)
downloadqtlocation-mapboxgl-46e06bf378e5edc38b5ce1c3ab1e4567eb756d24.tar.gz
don't pass the loop through all function calls
Diffstat (limited to 'src')
-rw-r--r--src/storage/http_request.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/storage/http_request.cpp b/src/storage/http_request.cpp
index 9dc289e141..fb079d2588 100644
--- a/src/storage/http_request.cpp
+++ b/src/storage/http_request.cpp
@@ -18,27 +18,31 @@ struct CacheRequestBaton {
HTTPRequest *request = nullptr;
std::string path;
util::ptr<SQLiteStore> store;
- uv_loop_t *loop;
};
-HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path, uv_loop_t *loop, util::ptr<SQLiteStore> store_)
- : BaseRequest(path), thread_id(uv_thread_self()), store(store_), type(type_) {
+HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path, uv_loop_t *loop_, util::ptr<SQLiteStore> store_)
+ : BaseRequest(path), thread_id(uv_thread_self()), loop(loop_), store(store_), type(type_) {
+ startCacheRequest();
+}
+
+void HTTPRequest::startCacheRequest() {
+ assert(uv_thread_self() == thread_id);
+
cache_baton = new CacheRequestBaton;
cache_baton->request = this;
cache_baton->path = path;
cache_baton->store = store;
- cache_baton->loop = loop;
store->get(path, [](std::unique_ptr<Response> &&response, void *ptr) {
// Wrap in a unique_ptr, so it'll always get auto-destructed.
std::unique_ptr<CacheRequestBaton> baton((CacheRequestBaton *)ptr);
if (baton->request) {
baton->request->cache_baton = nullptr;
- baton->request->handleCacheResponse(std::move(response), baton->loop);
+ baton->request->handleCacheResponse(std::move(response));
}
}, cache_baton);
}
-void HTTPRequest::handleCacheResponse(std::unique_ptr<Response> &&res, uv_loop_t *loop) {
+void HTTPRequest::handleCacheResponse(std::unique_ptr<Response> &&res) {
assert(uv_thread_self() == thread_id);
if (res) {
@@ -56,10 +60,10 @@ void HTTPRequest::handleCacheResponse(std::unique_ptr<Response> &&res, uv_loop_t
}
}
- startRequest(std::move(res), loop);
+ startHTTPRequest(std::move(res));
}
-void HTTPRequest::startRequest(std::unique_ptr<Response> &&res, uv_loop_t *loop) {
+void HTTPRequest::startHTTPRequest(std::unique_ptr<Response> &&res) {
assert(uv_thread_self() == thread_id);
assert(!http_baton);
@@ -76,7 +80,7 @@ void HTTPRequest::startRequest(std::unique_ptr<Response> &&res, uv_loop_t *loop)
HTTPRequest *request = http_baton->request;
request->http_baton.reset();
http_baton->request = nullptr;
- request->handleHTTPResponse(http_baton->type, std::move(http_baton->response), async->loop);
+ request->handleHTTPResponse(http_baton->type, std::move(http_baton->response));
}
delete (util::ptr<HTTPRequestBaton> *)async->data;
@@ -85,10 +89,11 @@ void HTTPRequest::startRequest(std::unique_ptr<Response> &&res, uv_loop_t *loop)
delete async;
});
});
+ attempts++;
HTTPRequestBaton::start(http_baton);
}
-void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr<Response> &&res, uv_loop_t *loop) {
+void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr<Response> &&res) {
assert(uv_thread_self() == thread_id);
assert(!http_baton);
assert(!response);