summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2015-09-16 17:52:49 -0700
committerJustin R. Miller <incanus@codesorcery.net>2015-09-23 15:46:32 -0700
commit15cffcd3a2137ce97a093e114aa4d3e71fd9990b (patch)
treea3e2c94c278b77c31d24f6335c0c129c38108755 /platform
parent888444cc41aeb2a19c25a4202aa4adc14e5dc026 (diff)
downloadqtlocation-mapboxgl-15cffcd3a2137ce97a093e114aa4d3e71fd9990b.tar.gz
fixes #2350: remove iOS-specific SQLite cache wrapper
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLFileCache.h14
-rw-r--r--platform/ios/MGLFileCache.mm83
-rw-r--r--platform/ios/MGLMapView.mm28
3 files changed, 19 insertions, 106 deletions
diff --git a/platform/ios/MGLFileCache.h b/platform/ios/MGLFileCache.h
deleted file mode 100644
index 082cec69a3..0000000000
--- a/platform/ios/MGLFileCache.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#import "MGLTypes.h"
-
-#include <mbgl/storage/sqlite_cache.hpp>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface MGLFileCache : NSObject
-
-+ (mbgl::SQLiteCache *)obtainSharedCacheWithObject:(NSObject *)object;
-+ (void)releaseSharedCacheForObject:(NSObject *)object;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/platform/ios/MGLFileCache.mm b/platform/ios/MGLFileCache.mm
deleted file mode 100644
index 3303b395f9..0000000000
--- a/platform/ios/MGLFileCache.mm
+++ /dev/null
@@ -1,83 +0,0 @@
-#import "MGLFileCache.h"
-
-@interface MGLFileCache ()
-
-@property (nonatomic) MGLFileCache *sharedInstance;
-@property (nonatomic) mbgl::SQLiteCache *sharedCache;
-@property (nonatomic) NSHashTable *retainers;
-
-@end
-
-@implementation MGLFileCache
-
-const std::string &defaultCacheDatabasePath() {
- static const std::string path = []() -> std::string {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- if ([paths count] == 0) {
- // Disable the cache if we don't have a location to write.
- return "";
- }
-
- NSString *libraryDirectory = [paths objectAtIndex:0];
- return [[libraryDirectory stringByAppendingPathComponent:@"cache.db"] UTF8String];
- }();
- return path;
-}
-
-- (instancetype)init {
- self = [super init];
- if (self) {
- _retainers = [NSHashTable weakObjectsHashTable];
- }
- return self;
-}
-
-+ (instancetype)sharedInstance {
- static dispatch_once_t onceToken;
- static MGLFileCache *_sharedInstance;
- dispatch_once(&onceToken, ^{
- _sharedInstance = [[self alloc] init];
- });
- return _sharedInstance;
-}
-
-- (void)teardown {
- if (self.sharedCache) {
- delete self.sharedCache;
- self.sharedCache = nullptr;
- }
-}
-
-- (void)dealloc {
- [self.retainers removeAllObjects];
- [self teardown];
-}
-
-+ (mbgl::SQLiteCache *)obtainSharedCacheWithObject:(NSObject *)object {
- return [[MGLFileCache sharedInstance] obtainSharedCacheWithObject:object];
-}
-
-- (mbgl::SQLiteCache *)obtainSharedCacheWithObject:(NSObject *)object {
- assert([[NSThread currentThread] isMainThread]);
- if (!self.sharedCache) {
- self.sharedCache = new mbgl::SQLiteCache(defaultCacheDatabasePath());
- }
- [self.retainers addObject:object];
- return self.sharedCache;
-}
-
-+ (void)releaseSharedCacheForObject:(NSObject *)object {
- return [[MGLFileCache sharedInstance] releaseSharedCacheForObject:object];
-}
-
-- (void)releaseSharedCacheForObject:(NSObject *)object {
- assert([[NSThread currentThread] isMainThread]);
- if ([self.retainers containsObject:object]) {
- [self.retainers removeObject:object];
- }
- if ([self.retainers count] == 0) {
- [self teardown];
- }
-}
-
-@end
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 7056276637..3cee7db4e9 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -13,6 +13,7 @@
#include <mbgl/annotation/sprite_image.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/darwin/reachability.h>
+#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/geo.hpp>
@@ -28,7 +29,6 @@
#import "NSException+MGLAdditions.h"
#import "MGLUserLocationAnnotationView.h"
#import "MGLUserLocation_Private.h"
-#import "MGLFileCache.h"
#import "MGLAccountManager_Private.h"
#import "MGLMapboxEvents.h"
@@ -112,12 +112,14 @@ mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction
{
mbgl::Map *_mbglMap;
MBGLView *_mbglView;
+ std::shared_ptr<mbgl::SQLiteCache> _mbglFileCache;
mbgl::DefaultFileSource *_mbglFileSource;
- BOOL _isWaitingForRedundantReachableNotification;
-
+
NS_MUTABLE_ARRAY_OF(NSURL *) *_bundledStyleURLs;
+ BOOL _isWaitingForRedundantReachableNotification;
BOOL _isTargetingInterfaceBuilder;
+
CLLocationDegrees _pendingLatitude;
CLLocationDegrees _pendingLongitude;
}
@@ -225,14 +227,24 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = YES;
- // setup mbgl map
- //
+ // setup mbgl view
const float scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale];
_mbglView = new MBGLView(self, scaleFactor);
- _mbglFileSource = new mbgl::DefaultFileSource([MGLFileCache obtainSharedCacheWithObject:self]);
- // Start paused
+ // setup mbgl cache & file source
+ NSString *fileCachePath = @"";
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+ if ([paths count] != 0) {
+ NSString *libraryDirectory = [paths objectAtIndex:0];
+ fileCachePath = [libraryDirectory stringByAppendingPathComponent:@"cache.db"];
+ }
+ _mbglFileCache = mbgl::SharedSQLiteCache::get([fileCachePath UTF8String]);
+ _mbglFileSource = new mbgl::DefaultFileSource(_mbglFileCache.get());
+
+ // setup mbgl map
_mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous);
+
+ // start paused if in IB
if (_isTargetingInterfaceBuilder || background) {
self.dormant = YES;
_mbglMap->pause();
@@ -465,8 +477,6 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
_mbglFileSource = nullptr;
}
- [MGLFileCache releaseSharedCacheForObject:self];
-
if (_mbglView)
{
delete _mbglView;