summaryrefslogtreecommitdiff
path: root/macosx
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2014-02-19 23:13:20 -0800
committerJustin R. Miller <incanus@codesorcery.net>2014-02-19 23:13:20 -0800
commiteac69ae30c4777f2593fe3d46c10e9fc1449211c (patch)
tree7e2df97d18c51c08d3fd8a725215da3c9ad3b911 /macosx
parent536e0343c955180da850628cbe6282bfaf162321 (diff)
downloadqtlocation-mapboxgl-eac69ae30c4777f2593fe3d46c10e9fc1449211c.tar.gz
move to cancellable tile-specific fetches on OS X
Diffstat (limited to 'macosx')
-rw-r--r--macosx/llmr-app.gyp2
-rw-r--r--macosx/main.mm69
2 files changed, 53 insertions, 18 deletions
diff --git a/macosx/llmr-app.gyp b/macosx/llmr-app.gyp
index 9b589c7230..b206e8d76a 100644
--- a/macosx/llmr-app.gyp
+++ b/macosx/llmr-app.gyp
@@ -41,7 +41,7 @@
'INFOPLIST_FILE': 'Info.plist',
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD':'c++11',
- 'MACOSX_DEPLOYMENT_TARGET':'10.8',
+ 'MACOSX_DEPLOYMENT_TARGET':'10.9',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'CLANG_ENABLE_OBJC_ARC': 'YES'
},
diff --git a/macosx/main.mm b/macosx/main.mm
index 7c2f0cc1ec..49fa13ea43 100644
--- a/macosx/main.mm
+++ b/macosx/main.mm
@@ -3,6 +3,7 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#include <llmr/platform/platform.hpp>
+#include <llmr/map/tile.hpp>
#include "settings.hpp"
#include <thread>
@@ -229,34 +230,68 @@ void restart(void *) {
mapView->dirty = true;
}
-void request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback) {
- if (!queue) {
- queue = [NSOperationQueue new];
- }
+void request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback)
+{
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@(url.c_str())] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
+ {
+ Response res;
+
+ if ( ! error)
+ {
+ res.code = [(NSHTTPURLResponse *)response statusCode];
+ res.body = { (const char *)[data bytes], [data length] };
+ }
+
+ background_function(res);
+
+ dispatch_async(dispatch_get_main_queue(), ^(void)
+ {
+ foreground_callback();
+ });
+ }];
- NSMutableURLRequest *urlRequest = [NSMutableURLRequest
- requestWithURL:[NSURL
- URLWithString:@(url.c_str())]];
+ [task resume];
+}
+
+void request_http_tile(std::string url, tile_ptr tile_object, std::function<void(Response&)> background_function, std::function<void()> foreground_callback)
+{
+ NSString *latestZoom = [@(tile_object->id.z) stringValue];
+
+ [[NSURLSession sharedSession] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks)
+ {
+ for (NSURLSessionDownloadTask *task in downloadTasks)
+ if (task.taskDescription && ! [task.taskDescription isEqualToString:latestZoom])
+ [task cancel];
+ }];
+
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@(url.c_str())] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
+ {
+ if (error && [[error domain] isEqualToString:NSURLErrorDomain] && [error code] == NSURLErrorCancelled)
+ return;
- [NSURLConnection
- sendAsynchronousRequest:urlRequest
- queue:[NSOperationQueue mainQueue]
- completionHandler: ^(NSURLResponse * response, NSData * data, NSError * error) {
Response res;
- if (error == nil) {
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
- res.code = [httpResponse statusCode];
+
+ if ( ! error)
+ {
+ res.code = [(NSHTTPURLResponse *)response statusCode];
res.body = { (const char *)[data bytes], [data length] };
}
background_function(res);
- dispatch_async(dispatch_get_main_queue(), ^(void) {
+
+ dispatch_async(dispatch_get_main_queue(), ^(void)
+ {
foreground_callback();
});
- [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil];
+
+ if ( ! error)
+ [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil];
}];
-}
+ task.taskDescription = [@(tile_object->id.z) stringValue];
+
+ [task resume];
+}
double time() {
return glfwGetTime();