summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2020-11-06 15:40:00 -0500
committerJoel Fischer <joeljfischer@gmail.com>2020-11-06 15:40:00 -0500
commit9650ef51fc12b451cbd5fdb63e750dcf8d349640 (patch)
treeeab1c6428e6c4d03045f98e0e434c8d44289beb2
parent76f9a87109830c0295a680cc5d820a87daa96de7 (diff)
downloadsdl_ios-9650ef51fc12b451cbd5fdb63e750dcf8d349640.tar.gz
Make the operation finish up and not keep going if deletion fails
-rw-r--r--SmartDeviceLink/SDLVoiceCommandUpdateOperation.m60
-rw-r--r--SmartDeviceLink/private/SDLError.h1
2 files changed, 40 insertions, 21 deletions
diff --git a/SmartDeviceLink/SDLVoiceCommandUpdateOperation.m b/SmartDeviceLink/SDLVoiceCommandUpdateOperation.m
index 708b95abe..6ccd5abea 100644
--- a/SmartDeviceLink/SDLVoiceCommandUpdateOperation.m
+++ b/SmartDeviceLink/SDLVoiceCommandUpdateOperation.m
@@ -51,44 +51,63 @@ NS_ASSUME_NONNULL_BEGIN
[super start];
if (self.isCancelled) { return; }
- __weak typeof(self) weakself = self;
+ __weak typeof(self) weakSelf = self;
[self sdl_sendDeleteCurrentVoiceCommands:^(NSError * _Nullable error) {
- [weakself sdl_sendCurrentVoiceCommands:^(NSError * _Nullable error) {
- if (weakself.completionHandler != nil) {
- weakself.completionHandler(error);
+ // If any of the deletions failed, don't send the new commands
+ if (error != nil) {
+ SDLLogD(@"Some voice commands failed to delete; aborting operation");
+ weakSelf.internalError = error;
+ [weakSelf finishOperation];
+
+ return;
+ }
+
+ // If the operation has been canceled, then don't send the new commands
+ if (self.isCancelled) {
+ [weakSelf finishOperation];
+ }
+
+ // If no error, send the new commands
+ [weakSelf sdl_sendCurrentVoiceCommands:^(NSError * _Nullable error) {
+ if (weakSelf.completionHandler != nil) {
+ weakSelf.completionHandler(error);
+ [weakSelf finishOperation];
}
}];
}];
}
-#pragma mark Delete Old Menu Items
+#pragma mark - Sending RPCs
- (void)sdl_sendDeleteCurrentVoiceCommands:(void(^)(NSError * _Nullable))completionHandler {
if (self.oldVoiceCommands.count == 0) {
- self.completionHandler(nil);
-
- return;
+ SDLLogD(@"No voice commands to delete");
+ return completionHandler(nil);
}
NSArray<SDLRPCRequest *> *deleteVoiceCommands = [self sdl_deleteCommandsForVoiceCommands:self.oldVoiceCommands];
- self.oldVoiceCommands = @[];
- [self.connectionManager sendRequests:deleteVoiceCommands progressHandler:nil completionHandler:^(BOOL success) {
+
+ __block NSMutableDictionary<SDLRPCRequest *, NSError *> *errors = [NSMutableDictionary dictionary];
+ __weak typeof(self) weakSelf = self;
+ [self.connectionManager sendRequests:deleteVoiceCommands progressHandler:^(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
+ if (error != nil) {
+ errors[request] = error;
+ }
+ } completionHandler:^(BOOL success) {
if (!success) {
- SDLLogE(@"Error deleting old voice commands");
- } else {
- SDLLogD(@"Finished deleting old voice commands");
+ SDLLogE(@"Error deleting old voice commands: %@", errors);
+ return completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]);
}
- completionHandler(nil);
+ self.oldVoiceCommands = @[];
+ SDLLogD(@"Finished deleting old voice commands");
+ return completionHandler(nil);
}];
}
-#pragma mark Send New Menu Items
-
- (void)sdl_sendCurrentVoiceCommands:(void(^)(NSError * _Nullable))completionHandler {
if (self.updatedVoiceCommands.count == 0) {
SDLLogD(@"No voice commands to send");
-
return completionHandler(nil);
}
@@ -103,13 +122,12 @@ NS_ASSUME_NONNULL_BEGIN
} completionHandler:^(BOOL success) {
if (!success) {
SDLLogE(@"Failed to send main menu commands: %@", errors);
- completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]);
- return;
+ return completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]);
}
- SDLLogD(@"Finished updating voice commands");
weakSelf.oldVoiceCommands = weakSelf.updatedVoiceCommands;
- completionHandler(nil);
+ SDLLogD(@"Finished updating voice commands");
+ return completionHandler(nil);
}];
}
diff --git a/SmartDeviceLink/private/SDLError.h b/SmartDeviceLink/private/SDLError.h
index fae799fe9..3a20e2248 100644
--- a/SmartDeviceLink/private/SDLError.h
+++ b/SmartDeviceLink/private/SDLError.h
@@ -56,6 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSError *)sdl_menuManager_failedToUpdateWithDictionary:(NSDictionary *)userInfo;
+ (NSError *)sdl_voiceCommandManager_pendingUpdateSuperseded;
++ (NSError *)sdl_voiceCommandManager_deleteFailed;
#pragma mark Choice Set Manager