[darwin] [MGLOfflineStorage mbglFileSource] is now a shared_ptr
This commit is contained in:
@@ -587,7 +587,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
|
||||
|
||||
_cancelled = NO;
|
||||
_options = options;
|
||||
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
|
||||
auto mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
_mbglThreadPool = mbgl::sharedThreadPool();
|
||||
|
||||
std::string styleURL = std::string([options.styleURL.absoluteString UTF8String]);
|
||||
@@ -621,7 +621,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
|
||||
MGLRendererConfiguration* config = [MGLRendererConfiguration currentConfiguration];
|
||||
|
||||
// Create the snapshotter
|
||||
_mbglMapSnapshotter = std::make_unique<mbgl::MapSnapshotter>(mbglFileSource, _mbglThreadPool, style, size, pixelRatio, cameraOptions, coordinateBounds, config.cacheDir, config.localFontFamilyName);
|
||||
_mbglMapSnapshotter = std::make_unique<mbgl::MapSnapshotter>(mbglFileSource.get(), _mbglThreadPool, style, size, pixelRatio, cameraOptions, coordinateBounds, config.cacheDir, config.localFontFamilyName);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
_mbglOfflineRegion = region;
|
||||
_state = MGLOfflinePackStateUnknown;
|
||||
|
||||
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
auto mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
mbglFileSource->setOfflineRegionObserver(*_mbglOfflineRegion, std::make_unique<MBGLOfflineRegionObserver>(self));
|
||||
}
|
||||
return self;
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
|
||||
self.state = MGLOfflinePackStateActive;
|
||||
|
||||
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
auto mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Active);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ private:
|
||||
_isSuspending = YES;
|
||||
}
|
||||
|
||||
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
auto mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Inactive);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ private:
|
||||
MGLAssert(_state != MGLOfflinePackStateInvalid, @"Cannot invalidate an already invalid offline pack.");
|
||||
|
||||
self.state = MGLOfflinePackStateInvalid;
|
||||
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
auto mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
mbglFileSource->setOfflineRegionObserver(*self.mbglOfflineRegion, nullptr);
|
||||
self.mbglOfflineRegion = nil;
|
||||
}
|
||||
@@ -164,8 +164,7 @@ private:
|
||||
MGLLogInfo(@"Requesting pack progress.");
|
||||
MGLAssertOfflinePackIsValid();
|
||||
|
||||
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
|
||||
auto mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
__weak MGLOfflinePack *weakSelf = self;
|
||||
mbglFileSource->getOfflineRegionStatus(*_mbglOfflineRegion, [&, weakSelf](mbgl::expected<mbgl::OfflineRegionStatus, std::exception_ptr> status) {
|
||||
if (status) {
|
||||
|
||||
@@ -43,7 +43,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
@interface MGLOfflineStorage ()
|
||||
|
||||
@property (nonatomic, strong, readwrite) NSMutableArray<MGLOfflinePack *> *packs;
|
||||
@property (nonatomic) mbgl::DefaultFileSource *mbglFileSource;
|
||||
@property (nonatomic) std::shared_ptr<mbgl::DefaultFileSource> mbglFileSource;
|
||||
@property (nonatomic, getter=isPaused) BOOL paused;
|
||||
|
||||
@end
|
||||
@@ -222,7 +222,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
[[NSFileManager defaultManager] moveItemAtPath:subdirectorylessCacheURL.path toPath:cachePath error:NULL];
|
||||
}
|
||||
|
||||
_mbglFileSource = new mbgl::DefaultFileSource(cachePath.UTF8String, [NSBundle mainBundle].resourceURL.path.UTF8String);
|
||||
_mbglFileSource = std::make_shared<mbgl::DefaultFileSource>(cachePath.UTF8String, [NSBundle mainBundle].resourceURL.path.UTF8String);
|
||||
|
||||
// Observe for changes to the API base URL (and find out the current one).
|
||||
[[MGLAccountManager sharedManager] addObserver:self
|
||||
@@ -249,9 +249,6 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
for (MGLOfflinePack *pack in self.packs) {
|
||||
[pack invalidate];
|
||||
}
|
||||
|
||||
delete _mbglFileSource;
|
||||
_mbglFileSource = nullptr;
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context {
|
||||
@@ -259,14 +256,14 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
if ([keyPath isEqualToString:@"accessToken"] && object == [MGLAccountManager sharedManager]) {
|
||||
NSString *accessToken = change[NSKeyValueChangeNewKey];
|
||||
if (![accessToken isKindOfClass:[NSNull class]]) {
|
||||
self.mbglFileSource->setAccessToken(accessToken.UTF8String);
|
||||
_mbglFileSource->setAccessToken(accessToken.UTF8String);
|
||||
}
|
||||
} else if ([keyPath isEqualToString:@"apiBaseURL"] && object == [MGLAccountManager sharedManager]) {
|
||||
NSURL *apiBaseURL = change[NSKeyValueChangeNewKey];
|
||||
if ([apiBaseURL isKindOfClass:[NSNull class]]) {
|
||||
self.mbglFileSource->setAPIBaseURL(mbgl::util::API_BASE_URL);
|
||||
_mbglFileSource->setAPIBaseURL(mbgl::util::API_BASE_URL);
|
||||
} else {
|
||||
self.mbglFileSource->setAPIBaseURL(apiBaseURL.absoluteString.UTF8String);
|
||||
_mbglFileSource->setAPIBaseURL(apiBaseURL.absoluteString.UTF8String);
|
||||
}
|
||||
} else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
@@ -332,7 +329,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
}
|
||||
|
||||
- (void)_addContentsOfFile:(NSString *)filePath withCompletionHandler:(void (^)(NSArray<MGLOfflinePack *> * _Nullable packs, NSError * _Nullable error))completion {
|
||||
self.mbglFileSource->mergeOfflineRegions(std::string(static_cast<const char *>([filePath UTF8String])), [&, completion, filePath](mbgl::expected<mbgl::OfflineRegions, std::exception_ptr> result) {
|
||||
_mbglFileSource->mergeOfflineRegions(std::string(static_cast<const char *>([filePath UTF8String])), [&, completion, filePath](mbgl::expected<mbgl::OfflineRegions, std::exception_ptr> result) {
|
||||
NSError *error;
|
||||
NSMutableArray *packs;
|
||||
if (!result) {
|
||||
@@ -393,7 +390,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
const mbgl::OfflineRegionDefinition regionDefinition = [(id <MGLOfflineRegion_Private>)region offlineRegionDefinition];
|
||||
mbgl::OfflineRegionMetadata metadata(context.length);
|
||||
[context getBytes:&metadata[0] length:metadata.size()];
|
||||
self.mbglFileSource->createOfflineRegion(regionDefinition, metadata, [&, completion](mbgl::expected<mbgl::OfflineRegion, std::exception_ptr> mbglOfflineRegion) {
|
||||
_mbglFileSource->createOfflineRegion(regionDefinition, metadata, [&, completion](mbgl::expected<mbgl::OfflineRegion, std::exception_ptr> mbglOfflineRegion) {
|
||||
NSError *error;
|
||||
if (!mbglOfflineRegion) {
|
||||
NSString *errorDescription = @(mbgl::util::toString(mbglOfflineRegion.error()).c_str());
|
||||
@@ -428,7 +425,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
return;
|
||||
}
|
||||
|
||||
self.mbglFileSource->deleteOfflineRegion(std::move(*mbglOfflineRegion), [&, completion](std::exception_ptr exception) {
|
||||
_mbglFileSource->deleteOfflineRegion(std::move(*mbglOfflineRegion), [&, completion](std::exception_ptr exception) {
|
||||
NSError *error;
|
||||
if (exception) {
|
||||
error = [NSError errorWithDomain:MGLErrorDomain code:-1 userInfo:@{
|
||||
@@ -454,7 +451,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
}
|
||||
|
||||
- (void)getPacksWithCompletionHandler:(void (^)(NSArray<MGLOfflinePack *> *packs, NSError * _Nullable error))completion {
|
||||
self.mbglFileSource->listOfflineRegions([&, completion](mbgl::expected<mbgl::OfflineRegions, std::exception_ptr> result) {
|
||||
_mbglFileSource->listOfflineRegions([&, completion](mbgl::expected<mbgl::OfflineRegions, std::exception_ptr> result) {
|
||||
NSError *error;
|
||||
NSMutableArray *packs;
|
||||
if (!result) {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MGLOfflineStorage (Private)
|
||||
@@ -11,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
/**
|
||||
The shared file source object owned by the shared offline storage object.
|
||||
*/
|
||||
@property (nonatomic) mbgl::DefaultFileSource *mbglFileSource;
|
||||
@property (nonatomic) std::shared_ptr<mbgl::DefaultFileSource> mbglFileSource;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#import "MGLFoundation.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <mbgl/storage/default_file_source.hpp>
|
||||
#import <mbgl/renderer/mode.hpp>
|
||||
|
||||
#include <mbgl/renderer/mode.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -15,9 +16,6 @@ MGL_EXPORT
|
||||
/** Returns an instance of the current renderer configuration. */
|
||||
@property (class, nonatomic, readonly) MGLRendererConfiguration *currentConfiguration;
|
||||
|
||||
/** The file source to use. Defaults to `mbgl::DefaultFileSource` */
|
||||
@property (nonatomic, readonly) mbgl::DefaultFileSource *fileSource;
|
||||
|
||||
/** The GL context mode to use. Defaults to `mbgl::GLContextMode::Unique` */
|
||||
@property (nonatomic, readonly) mbgl::GLContextMode contextMode;
|
||||
|
||||
|
||||
@@ -57,10 +57,6 @@ static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPr
|
||||
return self;
|
||||
}
|
||||
|
||||
- (mbgl::DefaultFileSource *)fileSource {
|
||||
return [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
|
||||
}
|
||||
|
||||
- (mbgl::GLContextMode)contextMode {
|
||||
return mbgl::GLContextMode::Unique;
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ public:
|
||||
.withCrossSourceCollisions(enableCrossSourceCollisions);
|
||||
|
||||
NSAssert(!_mbglMap, @"_mbglMap should be NULL");
|
||||
_mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *[config fileSource], *_mbglThreadPool, mapOptions);
|
||||
_mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *[[MGLOfflineStorage sharedOfflineStorage] mbglFileSource], *_mbglThreadPool, mapOptions);
|
||||
|
||||
// start paused if in IB
|
||||
if (_isTargetingInterfaceBuilder || background) {
|
||||
|
||||
@@ -295,7 +295,7 @@ public:
|
||||
.withConstrainMode(mbgl::ConstrainMode::None)
|
||||
.withViewportMode(mbgl::ViewportMode::Default)
|
||||
.withCrossSourceCollisions(enableCrossSourceCollisions);
|
||||
_mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *config.fileSource, *_mbglThreadPool, mapOptions);
|
||||
_mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *[[MGLOfflineStorage sharedOfflineStorage] mbglFileSource], *_mbglThreadPool, mapOptions);
|
||||
|
||||
// Install the OpenGL layer. Interface Builder’s synchronous drawing means
|
||||
// we can’t display a map, so don’t even bother to have a map layer.
|
||||
|
||||
Reference in New Issue
Block a user