diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-04-14 11:47:57 -0400 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-04-14 11:47:57 -0400 |
commit | 305e688a3a1d255fe34269cc327284275a0a3044 (patch) | |
tree | 0ebd115503ade3217f7f4571381b09f17a9780aa /linux | |
parent | b4ad5157924bb7af289ce68e4e9f008fd6baa90e (diff) | |
download | qtlocation-mapboxgl-305e688a3a1d255fe34269cc327284275a0a3044.tar.gz |
clean up os x + ios request code
fixes #129
Diffstat (limited to 'linux')
-rw-r--r-- | linux/main.cpp | 28 | ||||
-rw-r--r-- | linux/request.cpp | 4 | ||||
-rw-r--r-- | linux/request.hpp | 4 |
3 files changed, 18 insertions, 18 deletions
diff --git a/linux/main.cpp b/linux/main.cpp index 51d31bd0b1..bb32029bb8 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -11,7 +11,7 @@ MapView *mapView = nullptr; -std::forward_list<llmr::platform::Request *> requests; +std::forward_list<std::shared_ptr<llmr::platform::Request>> requests; @@ -74,14 +74,12 @@ int main(int argc, char *argv[]) { } namespace llmr { -namespace platform { -void cleanup() { +void platform::cleanup() { bool& dirty = mapView->dirty; - requests.remove_if([&dirty](llmr::platform::Request * req) { + requests.remove_if([&dirty](std::shared_ptr<llmr::platform::Request> &req) { if (req->done) { req->foreground_callback(); - delete req; dirty = true; return true; } else { @@ -90,25 +88,27 @@ void cleanup() { }); } -void restart() { +void platform::restart() { if (mapView) { mapView->dirty = true; } } -Request *request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback) { - Request *req = new Request(url, background_function, foreground_callback); +std::shared_ptr<platform::Request> +platform::request_http(const std::string &url, std::function<void(Response *)> background_function, + std::function<void()> foreground_callback) { + std::shared_ptr<Request> req = + std::make_shared<Request>(url, background_function, foreground_callback); requests.push_front(req); return req; } -void cancel_request_http(Request *request) { - for (Request *req : requests) { - if (req == request) { - req->cancel(); - } +// Cancels an HTTP request. +void platform::cancel_request_http(const std::shared_ptr<Request> &req) { + if (req) { + req->cancel(); } } -} + } diff --git a/linux/request.cpp b/linux/request.cpp index 651dcd2d15..5581957604 100644 --- a/linux/request.cpp +++ b/linux/request.cpp @@ -44,7 +44,7 @@ void Request::finish() { curl_share_cleanup(curl_share); } -Request::Request(std::string url, std::function<void(platform::Response&)> bg, std::function<void()> fg) +Request::Request(std::string url, std::function<void(platform::Response *)> bg, std::function<void()> fg) : done(false), cancelled(false), url(url), @@ -102,7 +102,7 @@ void Request::request(void *ptr) { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &res.code); if (code != CURLE_ABORTED_BY_CALLBACK) { - req->background_function(res); + req->background_function(&res); } req->done = true; diff --git a/linux/request.hpp b/linux/request.hpp index 78348d4bfd..8350d9d459 100644 --- a/linux/request.hpp +++ b/linux/request.hpp @@ -14,7 +14,7 @@ struct Response; class Request { public: - Request(std::string url, std::function<void(platform::Response&)> bg, std::function<void()> fg); + Request(std::string url, std::function<void(platform::Response *)> bg, std::function<void()> fg); static void initialize(); static void finish(); @@ -36,7 +36,7 @@ public: std::atomic<bool> done; std::atomic<bool> cancelled; const std::string url; - const std::function<void(platform::Response&)> background_function; + const std::function<void(platform::Response *)> background_function; const std::function<void()> foreground_callback; private: |