summaryrefslogtreecommitdiff
path: root/linux/main.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-04-14 11:47:57 -0400
committerKonstantin Käfer <mail@kkaefer.com>2014-04-14 11:47:57 -0400
commit305e688a3a1d255fe34269cc327284275a0a3044 (patch)
tree0ebd115503ade3217f7f4571381b09f17a9780aa /linux/main.cpp
parentb4ad5157924bb7af289ce68e4e9f008fd6baa90e (diff)
downloadqtlocation-mapboxgl-305e688a3a1d255fe34269cc327284275a0a3044.tar.gz
clean up os x + ios request code
fixes #129
Diffstat (limited to 'linux/main.cpp')
-rw-r--r--linux/main.cpp28
1 files changed, 14 insertions, 14 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();
}
}
-}
+
}