summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Beharry <justin.beharry@livio.io>2022-08-26 11:06:05 -0400
committerJustin Beharry <justin.beharry@livio.io>2022-08-26 11:06:05 -0400
commit4342db0eef9775b919b73fc6ad84fd9d4fa9c952 (patch)
treebd94c34b7ac6798f979ffd40d75ab4e72ead1e92
parentaba5ba83d902a1c5e7e68915180eaae319855430 (diff)
downloadsdl_ios-4342db0eef9775b919b73fc6ad84fd9d4fa9c952.tar.gz
Add error handling new state update
-rw-r--r--SmartDeviceLink/private/SDLTextAndGraphicManager.m9
-rw-r--r--SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.h6
-rw-r--r--SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m25
3 files changed, 31 insertions, 9 deletions
diff --git a/SmartDeviceLink/private/SDLTextAndGraphicManager.m b/SmartDeviceLink/private/SDLTextAndGraphicManager.m
index 34c4dcf54..d4c665b38 100644
--- a/SmartDeviceLink/private/SDLTextAndGraphicManager.m
+++ b/SmartDeviceLink/private/SDLTextAndGraphicManager.m
@@ -173,16 +173,16 @@ NS_ASSUME_NONNULL_BEGIN
}
__weak typeof(self) weakSelf = self;
- SDLTextAndGraphicUpdateOperation *updateOperation = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:self.connectionManager fileManager:self.fileManager currentCapabilities:self.windowCapability currentScreenData:self.currentScreenData newState:[self currentState] currentScreenDataUpdatedHandler:^(SDLTextAndGraphicState *_Nullable newScreenData, NSError *_Nullable error) {
+ SDLTextAndGraphicUpdateOperation *updateOperation = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:self.connectionManager fileManager:self.fileManager currentCapabilities:self.windowCapability currentScreenData:self.currentScreenData newState:[self currentState] currentScreenDataUpdatedHandler:^(SDLTextAndGraphicState *_Nullable newScreenData, NSError *_Nullable error, SDLTextAndGraphicState *_Nullable errorScreenData) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (newScreenData != nil) {
// Update our current screen data
strongSelf.currentScreenData = newScreenData;
- [strongSelf sdl_updatePendingOperationsWithNewScreenData:newScreenData];
+ [strongSelf sdl_updatePendingOperationsWithNewScreenData:newScreenData errorState:nil];
} else if (error != nil) {
// Invalidate data that's different from our current screen data if a Show or SetDisplayLayout fails. This will prevent subsequent `Show`s from failing if the request failed due to the developer setting invalid data or subsequent `SetDisplayLayout`s from failing if the template is not supported on the module.
[strongSelf sdl_resetFieldsToCurrentScreenData];
- [strongSelf sdl_updatePendingOperationsWithNewScreenData:strongSelf.currentScreenData];
+ [strongSelf sdl_updatePendingOperationsWithNewScreenData:strongSelf.currentScreenData errorState:errorScreenData];
}
} updateCompletionHandler:handler];
@@ -195,12 +195,13 @@ NS_ASSUME_NONNULL_BEGIN
[self.transactionQueue addOperation:updateOperation];
}
-- (void)sdl_updatePendingOperationsWithNewScreenData:(SDLTextAndGraphicState *)newScreenData {
+- (void)sdl_updatePendingOperationsWithNewScreenData:(SDLTextAndGraphicState *)newScreenData errorState:(SDLTextAndGraphicState *_Nullable)errorData {
for (NSOperation *operation in self.transactionQueue.operations) {
if (operation.isExecuting) { continue; }
SDLTextAndGraphicUpdateOperation *updateOp = (SDLTextAndGraphicUpdateOperation *)operation;
updateOp.currentScreenData = newScreenData;
+ [updateOp updateStateDataWithErrorData:errorData];
}
}
diff --git a/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.h b/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.h
index d3f88b667..00227db65 100644
--- a/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.h
+++ b/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.h
@@ -22,7 +22,7 @@
NS_ASSUME_NONNULL_BEGIN
typedef void(^SDLTextAndGraphicUpdateCompletionHandler)(NSError *__nullable error);
-typedef void(^CurrentDataUpdatedHandler)(SDLTextAndGraphicState *__nullable newScreenData, NSError *__nullable error);
+typedef void(^CurrentDataUpdatedHandler)(SDLTextAndGraphicState *__nullable newScreenData, NSError *__nullable error, SDLTextAndGraphicState *__nullable errorScreenData);
@interface SDLTextAndGraphicUpdateOperation : SDLAsynchronousOperation
@@ -38,6 +38,10 @@ typedef void(^CurrentDataUpdatedHandler)(SDLTextAndGraphicState *__nullable newS
/// @param updateCompletionHandler The handler potentially passed by the developer to be called when the update finishes
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager fileManager:(SDLFileManager *)fileManager currentCapabilities:(SDLWindowCapability *)currentCapabilities currentScreenData:(SDLTextAndGraphicState *)currentData newState:(SDLTextAndGraphicState *)newState currentScreenDataUpdatedHandler:(CurrentDataUpdatedHandler)currentDataUpdatedHandler updateCompletionHandler:(nullable SDLTextAndGraphicUpdateCompletionHandler)updateCompletionHandler;
+/// Changes updated state to remove potential errors from previous update operations
+/// @param errorData A updated state that failed in a previous operation that will be used to filter out erroneous data
+- (void)updateStateDataWithErrorData:(SDLTextAndGraphicState *)errorData;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m b/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
index cd47531e2..a623ad8ad 100644
--- a/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
+++ b/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
@@ -97,6 +97,23 @@ NS_ASSUME_NONNULL_BEGIN
}
}
+- (void)updateStateDataWithErrorData:(SDLTextAndGraphicState *)errorData {
+ self.updatedState.textField1 = errorData.textField1 == self.updatedState.textField1 ? self.currentScreenData.textField1 : self.updatedState.textField1;
+ self.updatedState.textField2 = errorData.textField2 == self.updatedState.textField2 ? self.currentScreenData.textField2 : self.updatedState.textField2;
+ self.updatedState.textField3 = errorData.textField3 == self.updatedState.textField3 ? self.currentScreenData.textField3 : self.updatedState.textField3;
+ self.updatedState.textField4 = errorData.textField4 == self.updatedState.textField4 ? self.currentScreenData.textField4 : self.updatedState.textField4;
+ self.updatedState.mediaTrackTextField = errorData.mediaTrackTextField == self.updatedState.mediaTrackTextField ? self.currentScreenData.mediaTrackTextField : self.updatedState.mediaTrackTextField;
+ self.updatedState.title = errorData.title == self.updatedState.title ? self.currentScreenData.title : self.updatedState.title;
+ self.updatedState.primaryGraphic = errorData.primaryGraphic == self.updatedState.primaryGraphic ? self.currentScreenData.primaryGraphic : self.updatedState.primaryGraphic;
+ self.updatedState.secondaryGraphic = errorData.secondaryGraphic == self.updatedState.secondaryGraphic ? self.currentScreenData.secondaryGraphic : self.updatedState.secondaryGraphic;
+ self.updatedState.alignment = errorData.alignment == self.updatedState.alignment ? self.currentScreenData.alignment : self.updatedState.alignment;
+ self.updatedState.textField1Type = errorData.textField1Type == self.updatedState.textField1Type ? self.currentScreenData.textField1Type : self.updatedState.textField1Type;
+ self.updatedState.textField2Type = errorData.textField2Type == self.updatedState.textField2Type ? self.currentScreenData.textField2Type : self.updatedState.textField2Type;
+ self.updatedState.textField3Type = errorData.textField3Type == self.updatedState.textField3Type ? self.currentScreenData.textField3Type : self.updatedState.textField3Type;
+ self.updatedState.textField4Type = errorData.textField4Type == self.updatedState.textField4Type ? self.currentScreenData.textField4Type : self.updatedState.textField4Type;
+ self.updatedState.templateConfig = errorData.templateConfig == self.updatedState.templateConfig ? self.currentScreenData.templateConfig : self.updatedState.templateConfig;
+}
+
#pragma mark - Send Show / Set Display Layout
- (void)sdl_updateGraphicsAndShow:(SDLShow *)show {
@@ -159,7 +176,7 @@ NS_ASSUME_NONNULL_BEGIN
[strongSelf sdl_updateCurrentScreenDataFromShow:request];
} else {
SDLLogD(@"Text and Graphic Show failed");
- self.currentDataUpdatedHandler(nil, error);
+ self.currentDataUpdatedHandler(nil, error, self.updatedState);
}
handler(error);
@@ -182,7 +199,7 @@ NS_ASSUME_NONNULL_BEGIN
[strongSelf sdl_updateCurrentScreenDataFromSetDisplayLayout:request];
} else {
SDLLogD(@"Text and Graphic SetDisplayLayout failed to change to new layout: %@", setLayout.displayLayout);
- self.currentDataUpdatedHandler(nil, error);
+ self.currentDataUpdatedHandler(nil, error, nil);
}
handler(error);
@@ -498,7 +515,7 @@ NS_ASSUME_NONNULL_BEGIN
self.currentScreenData.templateConfig = show.templateConfiguration ? self.updatedState.templateConfig : self.currentScreenData.templateConfig;
if (self.currentDataUpdatedHandler != nil) {
- self.currentDataUpdatedHandler(self.currentScreenData, nil);
+ self.currentDataUpdatedHandler(self.currentScreenData, nil, nil);
}
}
@@ -509,7 +526,7 @@ NS_ASSUME_NONNULL_BEGIN
self.currentScreenData.templateConfig = [[SDLTemplateConfiguration alloc] initWithTemplate:setDisplayLayout.displayLayout dayColorScheme:setDisplayLayout.dayColorScheme nightColorScheme:setDisplayLayout.nightColorScheme];
if (self.currentDataUpdatedHandler != nil) {
- self.currentDataUpdatedHandler(self.currentScreenData, nil);
+ self.currentDataUpdatedHandler(self.currentScreenData, nil, nil);
}
}