Skip to content

Commit

Permalink
Additional completion handler fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joeljfischer committed Sep 24, 2021
1 parent 1844b32 commit 7769ece
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
3 changes: 3 additions & 0 deletions SmartDeviceLink/private/SDLError.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSError *)sdl_softButtonManager_pendingUpdateSuperseded;
+ (NSError *)sdl_subscribeButtonManager_notSubscribed;
+ (NSError *)sdl_textAndGraphicManager_pendingUpdateSuperseded;
+ (NSError *)sdl_textAndGraphicManager_batchingUpdate;
+ (NSError *)sdl_textAndGraphicManager_nothingToUpdate;

#pragma mark Menu Manager

Expand Down Expand Up @@ -91,6 +93,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSError *)sdl_systemCapabilityManager_moduleDoesNotSupportSystemCapabilities;
+ (NSError *)sdl_systemCapabilityManager_cannotUpdateInHMINONE;
+ (NSError *)sdl_systemCapabilityManager_cannotUpdateTypeDISPLAYS;
+ (NSError *)sdl_systemCapabilityManager_unknownSystemCapabilityType;

#pragma mark Transport

Expand Down
24 changes: 24 additions & 0 deletions SmartDeviceLink/private/SDLError.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ + (NSError *)sdl_subscribeButtonManager_notSubscribed {
return [NSError errorWithDomain:SDLErrorDomainSubscribeButtonManager code:SDLSubscribeButtonManagerErrorNotSubscribed userInfo:userInfo];
}

+ (NSError *)sdl_textAndGraphicManager_batchingUpdate {
return [NSError errorWithDomain:SDLErrorDomainTextAndGraphicManager code:SDLTextAndGraphicManagerErrorCurrentlyBatching userInfo:@{
NSLocalizedDescriptionKey: @"Update will not run because batching is enabled",
NSLocalizedFailureReasonErrorKey: @"Text and Graphic manager will not run this update and call this handler because its currently batching updates. The update will occur when batching ends.",
NSLocalizedRecoverySuggestionErrorKey: @"This callback shouldn't occur. Please open an issue on https://www.github.com/smartdevicelink/sdl_ios/ if it does"
}];
}

+ (NSError *)sdl_textAndGraphicManager_nothingToUpdate {
return [NSError errorWithDomain:SDLErrorDomainTextAndGraphicManager code:SDLTextAndGraphicManagerErrorNothingToUpdate userInfo:@{
NSLocalizedDescriptionKey: @"Update will not run because there's nothing to update",
NSLocalizedFailureReasonErrorKey: @"This callback shouldn't occur, so there's no known reason for this failure.",
NSLocalizedRecoverySuggestionErrorKey: @"This callback shouldn't occur. Please open an issue on https://www.github.com/smartdevicelink/sdl_ios/ if it does"
}];
}

#pragma mark Menu Manager

+ (NSError *)sdl_menuManager_configurationOperationLayoutsNotSupported {
Expand Down Expand Up @@ -454,6 +470,14 @@ + (NSError *)sdl_systemCapabilityManager_cannotUpdateTypeDISPLAYS {
return [NSError errorWithDomain:SDLErrorDomainSystemCapabilityManager code:SDLSystemCapabilityManagerErrorCannotUpdateTypeDisplays userInfo:userInfo];
}

+ (NSError *)sdl_systemCapabilityManager_unknownSystemCapabilityType {
return [NSError errorWithDomain:SDLErrorDomainSystemCapabilityManager code:SDLSystemCapabilityManagerErrorUnknownType userInfo:@{
NSLocalizedDescriptionKey: @"An unknown system capability type was received.",
NSLocalizedFailureReasonErrorKey: @"Failure reason unknown. If you see this, please open an issue on https://www.github.com/smartdevicelink/sdl_ios/",
NSLocalizedRecoverySuggestionErrorKey: @"Ensure you are only attempting to manually subscribe to known system capability types for the version of this library. You may also want to update this library to its latest version."
}];
}

#pragma mark Transport

+ (NSError *)sdl_transport_unknownError {
Expand Down
13 changes: 10 additions & 3 deletions SmartDeviceLink/private/SDLTextAndGraphicManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,18 @@ - (void)sdl_updateTransactionQueueSuspended {
#pragma mark - Upload / Send

- (void)updateWithCompletionHandler:(nullable SDLTextAndGraphicUpdateCompletionHandler)handler {
if (self.isBatchingUpdates) { return; }

if (self.isDirty) {
if (self.isBatchingUpdates) {
if (handler != nil) {
// This shouldn't be possible, but just in case
handler([NSError sdl_textAndGraphicManager_batchingUpdate]);
}
} else if (self.isDirty) {
self.isDirty = NO;
[self sdl_updateAndCancelPreviousOperations:YES completionHandler:handler];
} else {
if (handler != nil) {
handler([NSError sdl_textAndGraphicManager_nothingToUpdate]);
}
}
}

Expand Down
13 changes: 11 additions & 2 deletions SmartDeviceLink/public/SDLErrorConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ typedef NS_ENUM(NSInteger, SDLFileManagerError) {
*/
typedef NS_ENUM(NSInteger, SDLTextAndGraphicManagerError) {
/// A pending update was superseded by a newer requested update. The old update will not be sent
SDLTextAndGraphicManagerErrorPendingUpdateSuperseded = -1
SDLTextAndGraphicManagerErrorPendingUpdateSuperseded = -1,

/// The manager is currently batching updates so the update will not yet be sent and the handler will not be called
SDLTextAndGraphicManagerErrorCurrentlyBatching = -2,

/// The manager could find nothing to update
SDLTextAndGraphicManagerErrorNothingToUpdate = -3,
};

/**
Expand Down Expand Up @@ -251,7 +257,10 @@ typedef NS_ENUM(NSInteger, SDLSystemCapabilityManagerError) {
SDLSystemCapabilityManagerErrorHMINone = -2,

/// You may not update the system capability type DISPLAYS because it is always subscribed
SDLSystemCapabilityManagerErrorCannotUpdateTypeDisplays = -3
SDLSystemCapabilityManagerErrorCannotUpdateTypeDisplays = -3,

/// The module sent an unknown system capability type
SDLSystemCapabilityManagerErrorUnknownType = -4,
};

/**
Expand Down
5 changes: 2 additions & 3 deletions SmartDeviceLink/public/SDLFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ - (void)uploadFile:(SDLFile *)file completionHandler:(nullable SDLFileManagerUpl

- (void)sdl_uploadFile:(SDLFile *)file completionHandler:(nullable SDLFileManagerUploadCompletionHandler)handler {
__block NSString *fileName = file.name;
__block SDLFileManagerUploadCompletionHandler uploadCompletion = [handler copy];

__weak typeof(self) weakSelf = self;
SDLFileWrapper *fileWrapper = [SDLFileWrapper wrapperWithFile:file completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError *_Nullable error) {
Expand All @@ -425,8 +424,8 @@ - (void)sdl_uploadFile:(SDLFile *)file completionHandler:(nullable SDLFileManage
}
}

if (uploadCompletion != nil) {
uploadCompletion(success, bytesAvailable, error);
if (handler != nil) {
handler(success, bytesAvailable, error);
}
}];

Expand Down
4 changes: 3 additions & 1 deletion SmartDeviceLink/public/SDLSystemCapabilityManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,13 @@ - (BOOL)sdl_saveSystemCapability:(nullable SDLSystemCapability *)systemCapabilit
[self sdl_saveDisplayCapabilityListUpdate:systemCapability.displayCapabilities];
} else {
SDLLogW(@"Received response for unknown System Capability Type: %@", systemCapabilityType);
if (handler != nil) {
handler(systemCapability, NO, [NSError sdl_systemCapabilityManager_unknownSystemCapabilityType]);
}
return NO;
}

SDLLogD(@"Updated system capability manager with new data: %@", systemCapability);

[self sdl_callObserversForUpdate:systemCapability error:error handler:handler];
return YES;
}
Expand Down

0 comments on commit 7769ece

Please sign in to comment.