From 305e688a3a1d255fe34269cc327284275a0a3044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 14 Apr 2014 11:47:57 -0400 Subject: clean up os x + ios request code fixes #129 --- linux/main.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'linux/main.cpp') 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 requests; +std::forward_list> 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 &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 background_function, std::function foreground_callback) { - Request *req = new Request(url, background_function, foreground_callback); +std::shared_ptr +platform::request_http(const std::string &url, std::function background_function, + std::function foreground_callback) { + std::shared_ptr req = + std::make_shared(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 &req) { + if (req) { + req->cancel(); } } -} + } -- cgit v1.2.1