summaryrefslogtreecommitdiff
path: root/macosx/main.mm
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-01-30 16:57:38 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-01-30 16:57:38 +0100
commit04c855bd649ce8589c81d653455e8b1e3e5900b2 (patch)
tree5c5e46c9e07ef33c1afbbba4bf4a17f5c0b8f6ea /macosx/main.mm
parentbc07cb4b2615ba0f622189fdc30092a021750598 (diff)
downloadqtlocation-mapboxgl-04c855bd649ce8589c81d653455e8b1e3e5900b2.tar.gz
add request_http() function
refs #23
Diffstat (limited to 'macosx/main.mm')
-rw-r--r--macosx/main.mm42
1 files changed, 40 insertions, 2 deletions
diff --git a/macosx/main.mm b/macosx/main.mm
index cbbbd96ef0..1bcadad725 100644
--- a/macosx/main.mm
+++ b/macosx/main.mm
@@ -15,7 +15,7 @@ public:
last_click(-1),
settings(),
map(settings) {
- }
+ }
void init() {
if (!glfwInit()) {
@@ -238,7 +238,7 @@ void request(void *, Tile::Ptr tile) {
NSData * data,
NSError * error) {
if (error == nil) {
- NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
int code = [httpResponse statusCode];
if (code == 200) {
@@ -261,6 +261,44 @@ void request(void *, Tile::Ptr tile) {
}];
}
+
+void request_http(std::string url, std::function<void(const Response&)> func) {
+ NSMutableURLRequest *urlRequest = [NSMutableURLRequest
+ requestWithURL:[NSURL
+ URLWithString:[NSString
+ stringWithUTF8String:url.c_str()]]];
+
+ if (!queue) {
+ queue = [[NSOperationQueue alloc] init];
+ }
+
+ [NSURLConnection
+ sendAsynchronousRequest:urlRequest
+ queue:queue
+ completionHandler: ^ (NSURLResponse* response, NSData* data, NSError* error) {
+ if (error == nil) {
+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
+ dispatch_async(dispatch_get_main_queue(), ^ {
+ func({
+ [httpResponse statusCode],
+ (const char *)[data bytes],
+ [data length]
+ });
+ });
+ } else {
+ dispatch_async(dispatch_get_main_queue(), ^ {
+ func({
+ -1,
+ 0,
+ 0
+ });
+ });
+ }
+ }];
+}
+
+
+
double time() {
return glfwGetTime();
}