Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Belouosv <aleksey@maps.me>2018-12-12 14:31:39 +0300
committerAleksey Belousov <beloal@users.noreply.github.com>2019-02-12 17:11:57 +0300
commit823d823f520c33de5d9896c7b219d14b49872138 (patch)
tree5847407c72eeb34bb7bc72e95ed8598a5706c508 /platform
parente8062de68eac2f2ae137955467800c39816e1d1a (diff)
[iOS] fix apple http downloader objc-cpp bridging
Diffstat (limited to 'platform')
-rw-r--r--platform/http_thread_apple.h2
-rw-r--r--platform/http_thread_apple.mm56
2 files changed, 34 insertions, 24 deletions
diff --git a/platform/http_thread_apple.h b/platform/http_thread_apple.h
index e511d35165..97f3bf4d72 100644
--- a/platform/http_thread_apple.h
+++ b/platform/http_thread_apple.h
@@ -11,7 +11,7 @@ namespace downloader { class IHttpThreadCallback; }
#import "../iphone/Maps/Classes/DownloadIndicatorProtocol.h"
#endif
-@interface HttpThread : NSObject
+@interface HttpThreadImpl : NSObject
- (instancetype)initWithURL:(string const &)url callback:(downloader::IHttpThreadCallback &)cb
begRange:(int64_t)beg endRange:(int64_t)end expectedSize:(int64_t)size postBody:(string const &)pb;
diff --git a/platform/http_thread_apple.mm b/platform/http_thread_apple.mm
index f37b9b241a..d4840707d0 100644
--- a/platform/http_thread_apple.mm
+++ b/platform/http_thread_apple.mm
@@ -10,7 +10,7 @@
#define TIMEOUT_IN_SECONDS 60.0
-@interface HttpThread ()<NSURLSessionDataDelegate>
+@interface HttpThreadImpl ()<NSURLSessionDataDelegate>
{
downloader::IHttpThreadCallback * m_callback;
NSURLSessionDataTask * m_dataTask;
@@ -23,7 +23,7 @@
@end
-@implementation HttpThread
+@implementation HttpThreadImpl
#ifdef OMIM_OS_IPHONE
static id<DownloadIndicatorProtocol> downloadIndicator = nil;
@@ -66,8 +66,9 @@ static id<DownloadIndicatorProtocol> downloadIndicator = nil;
m_expectedSize = size;
NSMutableURLRequest * request =
- [NSMutableURLRequest requestWithURL:static_cast<NSURL *>([NSURL URLWithString:@(url.c_str())])
- cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:TIMEOUT_IN_SECONDS];
+ [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@(url.c_str())]
+ cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
+ timeoutInterval:TIMEOUT_IN_SECONDS];
// use Range header only if we don't download whole file from start
if (!(beg == 0 && end < 0))
@@ -178,7 +179,7 @@ didReceiveResponse:(NSURLResponse *)response
else if (m_expectedSize > 0)
{
// get full file expected size from Content-Range header
- int64_t sizeOnServer = [HttpThread getContentRange:[(NSHTTPURLResponse *)response allHeaderFields]];
+ int64_t sizeOnServer = [HttpThreadImpl getContentRange:[(NSHTTPURLResponse *)response allHeaderFields]];
// if it's absent, use Content-Length instead
if (sizeOnServer < 0)
sizeOnServer = [response expectedContentLength];
@@ -232,25 +233,34 @@ didCompleteWithError:(NSError *)error
@end
+class HttpThread
+{
+public:
+ HttpThread(HttpThreadImpl * request)
+ : m_request(request)
+ {}
+
+ HttpThreadImpl * m_request;
+};
+
///////////////////////////////////////////////////////////////////////////////////////
namespace downloader
{
- HttpThread * CreateNativeHttpThread(string const & url,
- downloader::IHttpThreadCallback & cb,
- int64_t beg,
- int64_t end,
- int64_t size,
- string const & pb)
- {
- HttpThread * request = [[HttpThread alloc] initWithURL:url callback:cb begRange:beg endRange:end expectedSize:size postBody:pb];
- CFRetain(reinterpret_cast<void *>(request));
- return request;
- }
-
- void DeleteNativeHttpThread(HttpThread * request)
- {
- [request cancel];
- CFRelease(reinterpret_cast<void *>(request));
- }
-
+HttpThread * CreateNativeHttpThread(string const & url,
+ downloader::IHttpThreadCallback & cb,
+ int64_t beg,
+ int64_t end,
+ int64_t size,
+ string const & pb)
+{
+ HttpThreadImpl * request = [[HttpThreadImpl alloc] initWithURL:url callback:cb begRange:beg endRange:end expectedSize:size postBody:pb];
+ return new HttpThread(request);
+}
+
+void DeleteNativeHttpThread(HttpThread * request)
+{
+ [request->m_request cancel];
+ delete request;
+}
+
} // namespace downloader