From 62ea1f21858c69f6921c775ba7a3de201f0514d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 26 Jan 2017 18:52:44 +0100 Subject: [core] remove trailing whitespace, add trailing newlines, add space after // --- platform/darwin/src/MGLOfflinePack.mm | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'platform/darwin/src/MGLOfflinePack.mm') diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm index 1f2fd95f2b..218e32940d 100644 --- a/platform/darwin/src/MGLOfflinePack.mm +++ b/platform/darwin/src/MGLOfflinePack.mm @@ -8,7 +8,7 @@ /** Assert that the current offline pack is valid. - + This macro should be used at the beginning of any public-facing instance method of `MGLOfflinePack`. For private methods, an assertion is more appropriate. */ @@ -26,11 +26,11 @@ class MBGLOfflineRegionObserver : public mbgl::OfflineRegionObserver { public: MBGLOfflineRegionObserver(MGLOfflinePack *pack_) : pack(pack_) {} - + void statusChanged(mbgl::OfflineRegionStatus status) override; void responseError(mbgl::Response::Error error) override; void mapboxTileCountLimitExceeded(uint64_t limit) override; - + private: __weak MGLOfflinePack *pack = nullptr; }; @@ -59,7 +59,7 @@ private: if (self = [super init]) { _mbglOfflineRegion = region; _state = MGLOfflinePackStateUnknown; - + mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; mbglFileSource->setOfflineRegionObserver(*_mbglOfflineRegion, std::make_unique(self)); } @@ -72,7 +72,7 @@ private: - (id )region { MGLAssertOfflinePackIsValid(); - + const mbgl::OfflineRegionDefinition ®ionDefinition = _mbglOfflineRegion->getDefinition(); NSAssert([MGLTilePyramidOfflineRegion conformsToProtocol:@protocol(MGLOfflineRegion_Private)], @"MGLTilePyramidOfflineRegion should conform to MGLOfflineRegion_Private."); return [(id )[MGLTilePyramidOfflineRegion alloc] initWithOfflineRegionDefinition:regionDefinition]; @@ -80,35 +80,35 @@ private: - (NSData *)context { MGLAssertOfflinePackIsValid(); - + const mbgl::OfflineRegionMetadata &metadata = _mbglOfflineRegion->getMetadata(); return [NSData dataWithBytes:&metadata[0] length:metadata.size()]; } - (void)resume { MGLAssertOfflinePackIsValid(); - + self.state = MGLOfflinePackStateActive; - + mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Active); } - (void)suspend { MGLAssertOfflinePackIsValid(); - + if (self.state == MGLOfflinePackStateActive) { self.state = MGLOfflinePackStateInactive; _isSuspending = YES; } - + mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Inactive); } - (void)invalidate { NSAssert(_state != MGLOfflinePackStateInvalid, @"Cannot invalidate an already invalid offline pack."); - + self.state = MGLOfflinePackStateInvalid; mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; mbglFileSource->setOfflineRegionObserver(*self.mbglOfflineRegion, nullptr); @@ -123,9 +123,9 @@ private: NSAssert(_state == MGLOfflinePackStateInvalid, @"A valid MGLOfflinePack has no mbgl::OfflineRegion."); return; } - + NSAssert(_state != MGLOfflinePackStateInvalid, @"Cannot change the state of an invalid offline pack."); - + if (!_isSuspending || state != MGLOfflinePackStateActive) { _isSuspending = NO; _state = state; @@ -134,9 +134,9 @@ private: - (void)requestProgress { MGLAssertOfflinePackIsValid(); - + mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; - + __weak MGLOfflinePack *weakSelf = self; mbglFileSource->getOfflineRegionStatus(*_mbglOfflineRegion, [&, weakSelf](__unused std::exception_ptr exception, mbgl::optional status) { if (status) { @@ -151,21 +151,21 @@ private: - (void)offlineRegionStatusDidChange:(mbgl::OfflineRegionStatus)status { NSAssert(_state != MGLOfflinePackStateInvalid, @"Cannot change update progress of an invalid offline pack."); - + switch (status.downloadState) { case mbgl::OfflineRegionDownloadState::Inactive: self.state = status.complete() ? MGLOfflinePackStateComplete : MGLOfflinePackStateInactive; break; - + case mbgl::OfflineRegionDownloadState::Active: self.state = MGLOfflinePackStateActive; break; } - + if (_isSuspending) { return; } - + MGLOfflinePackProgress progress; progress.countOfResourcesCompleted = status.completedResourceCount; progress.countOfBytesCompleted = status.completedResourceSize; @@ -174,7 +174,7 @@ private: progress.countOfResourcesExpected = status.requiredResourceCount; progress.maximumResourcesExpected = status.requiredResourceCountIsPrecise ? status.requiredResourceCount : UINT64_MAX; self.progress = progress; - + [self.delegate offlinePack:self progressDidChange:progress]; } @@ -184,15 +184,15 @@ NSError *MGLErrorFromResponseError(mbgl::Response::Error error) { case mbgl::Response::Error::Reason::NotFound: errorCode = MGLErrorCodeNotFound; break; - + case mbgl::Response::Error::Reason::Server: errorCode = MGLErrorCodeBadServerResponse; break; - + case mbgl::Response::Error::Reason::Connection: errorCode = MGLErrorCodeConnectionFailed; break; - + default: break; } -- cgit v1.2.1 From 7b0881030fdc60130458c2a798de696888c87c7c Mon Sep 17 00:00:00 2001 From: Eimantas Vaiciunas Date: Mon, 6 Feb 2017 15:47:39 +0200 Subject: Make `MGLOfflinePack` instances post notifications This commit also gets rid of private `MGLOfflinePackDelegate` protocol. `userInfo` dictionary in notification objects retain the `state` and `progress` values for backwards compatibility. They can be removed in later major release. --- platform/darwin/src/MGLOfflinePack.mm | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'platform/darwin/src/MGLOfflinePack.mm') diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm index 218e32940d..60a7b55531 100644 --- a/platform/darwin/src/MGLOfflinePack.mm +++ b/platform/darwin/src/MGLOfflinePack.mm @@ -4,6 +4,8 @@ #import "MGLOfflineRegion_Private.h" #import "MGLTilePyramidOfflineRegion.h" +#import "NSValue+MGLAdditions.h" + #include /** @@ -37,7 +39,6 @@ private: @interface MGLOfflinePack () -@property (nonatomic, weak, nullable) id delegate; @property (nonatomic, nullable, readwrite) mbgl::OfflineRegion *mbglOfflineRegion; @property (nonatomic, readwrite) MGLOfflinePackProgress progress; @@ -175,7 +176,29 @@ private: progress.maximumResourcesExpected = status.requiredResourceCountIsPrecise ? status.requiredResourceCount : UINT64_MAX; self.progress = progress; - [self.delegate offlinePack:self progressDidChange:progress]; + NSDictionary *userInfo = @{MGLOfflinePackUserInfoKeyState: @(self.state), + MGLOfflinePackUserInfoKeyProgress: [NSValue valueWithMGLOfflinePackProgress:progress]}; + + NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter]; + [noteCenter postNotificationName:MGLOfflinePackProgressChangedNotification + object:self + userInfo:userInfo]; +} + +- (void)didReceiveError:(NSError *)error { + NSDictionary *userInfo = @{ MGLOfflinePackUserInfoKeyError: error }; + NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter]; + [noteCenter postNotificationName:MGLOfflinePackErrorNotification + object:self + userInfo:userInfo]; +} + +- (void)didReceiveMaximumAllowedMapboxTiles:(uint64_t)limit { + NSDictionary *userInfo = @{ MGLOfflinePackUserInfoKeyMaximumCount: @(limit) }; + NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter]; + [noteCenter postNotificationName:MGLOfflinePackMaximumMapboxTilesReachedNotification + object:self + userInfo:userInfo]; } NSError *MGLErrorFromResponseError(mbgl::Response::Error error) { @@ -211,12 +234,12 @@ void MBGLOfflineRegionObserver::statusChanged(mbgl::OfflineRegionStatus status) void MBGLOfflineRegionObserver::responseError(mbgl::Response::Error error) { dispatch_async(dispatch_get_main_queue(), ^{ - [pack.delegate offlinePack:pack didReceiveError:MGLErrorFromResponseError(error)]; + [pack didReceiveError:MGLErrorFromResponseError(error)]; }); } void MBGLOfflineRegionObserver::mapboxTileCountLimitExceeded(uint64_t limit) { dispatch_async(dispatch_get_main_queue(), ^{ - [pack.delegate offlinePack:pack didReceiveMaximumAllowedMapboxTiles:limit]; + [pack didReceiveMaximumAllowedMapboxTiles:limit]; }); } -- cgit v1.2.1