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 /macosx | |
parent | b4ad5157924bb7af289ce68e4e9f008fd6baa90e (diff) | |
download | qtlocation-mapboxgl-305e688a3a1d255fe34269cc327284275a0a3044.tar.gz |
clean up os x + ios request code
fixes #129
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/llmr-app.gyp | 3 | ||||
-rw-r--r-- | macosx/main.mm | 59 |
2 files changed, 4 insertions, 58 deletions
diff --git a/macosx/llmr-app.gyp b/macosx/llmr-app.gyp index dd6f29c5bf..3c1bfedf77 100644 --- a/macosx/llmr-app.gyp +++ b/macosx/llmr-app.gyp @@ -11,7 +11,8 @@ 'sources': [ './main.mm', './settings.mm', - './settings.hpp' + './settings.hpp', + '../common/foundation_request.mm' ], 'product_extension': 'app', 'mac_bundle': 1, diff --git a/macosx/main.mm b/macosx/main.mm index 269d2bc6ed..6a40f22e11 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -23,13 +23,12 @@ int main() { namespace llmr { -namespace platform { -void cleanup() { +void platform::cleanup() { // noop } -void restart() { +void platform::restart() { if (mapView) { mapView->dirty = true; CGEventRef event = CGEventCreate(NULL); @@ -38,58 +37,4 @@ void restart() { } } -class Request { -public: - int16_t identifier; - std::string original_url; -}; - -Request *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) - { - if ([error code] == NSURLErrorCancelled) { - // We intentionally cancelled this request. Do nothing. - return; - } - - Response res; - - if ( ! error && [response isKindOfClass:[NSHTTPURLResponse class]]) - { - res.code = [(NSHTTPURLResponse *)response statusCode]; - res.body = { (const char *)[data bytes], [data length] }; - } else { - NSLog(@"http error (%s): %@", url.c_str(), [error localizedDescription]); - } - - background_function(res); - - dispatch_async(dispatch_get_main_queue(), ^(void) - { - foreground_callback(); - }); - }]; - - [task resume]; - - Request *req = new Request(); - - req->identifier = task.taskIdentifier; - req->original_url = url; - - return req; -} - -void cancel_request_http(Request *request) -{ - [[NSURLSession sharedSession] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) - { - for (NSURLSessionDownloadTask *task in downloadTasks) - if (task.taskIdentifier == request->identifier) - return [task cancel]; - }]; -} - -} } |