summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-01-24 15:48:29 -0500
committerGitHub <noreply@github.com>2017-01-24 15:48:28 -0500
commit21cc10ffeed809384bb6aa8f88f3e7d20b7dcc4e (patch)
tree3213e80dec863354f2c0102f7c3f7c691038fb71
parentfaf1427f72172235a82b7a8d389267653db7f553 (diff)
parent05a99a4e46c8d8201ecf380d6b7e4ab561b72fe2 (diff)
downloadsdl_ios-21cc10ffeed809384bb6aa8f88f3e7d20b7dcc4e.tar.gz
Merge pull request #506 from smartdevicelink/hotfix/issue_505_rai_response_handler
Fixed issue relating to getting unhandled warnings from RAI Response.
-rw-r--r--SmartDeviceLink/SDLLifecycleManager.h10
-rw-r--r--SmartDeviceLink/SDLLifecycleManager.m36
-rw-r--r--SmartDeviceLink/SDLStateMachine.h2
-rw-r--r--SmartDeviceLink/SDLStateMachine.m19
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m47
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m1
6 files changed, 72 insertions, 43 deletions
diff --git a/SmartDeviceLink/SDLLifecycleManager.h b/SmartDeviceLink/SDLLifecycleManager.h
index ae63f92d2..54c584c7b 100644
--- a/SmartDeviceLink/SDLLifecycleManager.h
+++ b/SmartDeviceLink/SDLLifecycleManager.h
@@ -65,13 +65,13 @@ typedef void (^SDLManagerReadyBlock)(BOOL success, NSError *_Nullable error);
// Deprecated internal proxy object
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-@property (strong, nonatomic, readonly, nullable) SDLProxy *proxy;
+@property (strong, nonatomic, nullable) SDLProxy *proxy;
#pragma clang diagnostic pop
-@property (assign, nonatomic, readonly) UInt16 lastCorrelationId;
+@property (assign, nonatomic) UInt16 lastCorrelationId;
@property (copy, nonatomic, readonly) SDLLifecycleState *lifecycleState;
-@property (copy, nonatomic, readonly, nullable) SDLHMILevel *hmiLevel;
-@property (strong, nonatomic, readonly, nullable) SDLRegisterAppInterfaceResponse *registerResponse;
+@property (copy, nonatomic, nullable) SDLHMILevel *hmiLevel;
+@property (strong, nonatomic, nullable) SDLRegisterAppInterfaceResponse *registerResponse;
#pragma mark Lifecycle
@@ -117,4 +117,4 @@ typedef void (^SDLManagerReadyBlock)(BOOL success, NSError *_Nullable error);
@end
-NS_ASSUME_NONNULL_END \ No newline at end of file
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m
index 806265fe9..8f205afd4 100644
--- a/SmartDeviceLink/SDLLifecycleManager.m
+++ b/SmartDeviceLink/SDLLifecycleManager.m
@@ -56,20 +56,11 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready";
@interface SDLLifecycleManager () <SDLConnectionManagerType>
// Readonly public properties
-@property (copy, nonatomic, readwrite, nullable) SDLHMILevel *hmiLevel;
@property (copy, nonatomic, readwrite) SDLConfiguration *configuration;
-@property (assign, nonatomic, readwrite) UInt16 lastCorrelationId;
-@property (strong, nonatomic, readwrite, nullable) SDLRegisterAppInterfaceResponse *registerResponse;
@property (strong, nonatomic, readwrite) SDLNotificationDispatcher *notificationDispatcher;
@property (strong, nonatomic, readwrite) SDLResponseDispatcher *responseDispatcher;
@property (strong, nonatomic, readwrite) SDLStateMachine *lifecycleStateMachine;
-// Deprecated internal proxy object
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-@property (strong, nonatomic, readwrite, nullable) SDLProxy *proxy;
-#pragma clang diagnostic pop
-
// Private properties
@property (copy, nonatomic) SDLManagerReadyBlock readyHandler;
@@ -194,8 +185,10 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready";
__weak typeof(self) weakSelf = self;
[self sdl_sendRequest:regRequest
withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) {
+ // If the success BOOL is NO or we received an error at this point, we failed. Call the ready handler and transition to the DISCONNECTED state.
if (error != nil || ![response.success boolValue]) {
[SDLDebugTool logFormat:@"Failed to register the app. Error: %@, Response: %@", error, response];
+ weakSelf.readyHandler(NO, error);
[weakSelf.lifecycleStateMachine transitionToState:SDLLifecycleStateDisconnected];
return;
}
@@ -255,32 +248,15 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready";
- (void)didEnterStateReady {
SDLResult *registerResult = self.registerResponse.resultCode;
NSString *registerInfo = self.registerResponse.info;
-
- BOOL success = NO;
NSError *startError = nil;
-
- if ([registerResult isEqualToEnum:[SDLResult WARNINGS]] || [registerResult isEqualToEnum:[SDLResult RESUME_FAILED]]) {
- // We succeeded, but with warnings
+ // If the resultCode isn't success, we got a warning. Errors were handled in `didEnterStateConnected`.
+ if (![registerResult isEqualToEnum:[SDLResult SUCCESS]]) {
startError = [NSError sdl_lifecycle_startedWithBadResult:registerResult info:registerInfo];
- success = YES;
- } else if (![registerResult isEqualToEnum:[SDLResult SUCCESS]]) {
- // We did not succeed in registering
- startError = [NSError sdl_lifecycle_failedWithBadResult:registerResult info:registerInfo];
- success = NO;
- } else {
- // We succeeded
- success = YES;
- }
-
- // Notify the block, send the notification if we succeeded.
- self.readyHandler(success, startError);
-
- if (!success) {
- [self.lifecycleStateMachine transitionToState:SDLLifecycleStateReady];
- return;
}
+ // If we got to this point, we succeeded, send the error if there was a warning.
+ self.readyHandler(YES, startError);
[self.notificationDispatcher postNotificationName:SDLDidBecomeReady infoObject:nil];
// Send the hmi level going from NONE to whatever we're at now (could still be NONE)
diff --git a/SmartDeviceLink/SDLStateMachine.h b/SmartDeviceLink/SDLStateMachine.h
index 3690261f9..fa3b3093b 100644
--- a/SmartDeviceLink/SDLStateMachine.h
+++ b/SmartDeviceLink/SDLStateMachine.h
@@ -88,7 +88,7 @@ extern SDLStateMachineTransitionFormat const SDLStateMachineTransitionFormatDidE
*
* @param state The state to set to
*/
-- (void)setToState:(SDLState *)state;
+- (void)setToState:(SDLState *)state fromOldState:(nullable SDLState *)oldState callEnterTransition:(BOOL)shouldCall;
/**
* Return whether or not the current state is the passed state
diff --git a/SmartDeviceLink/SDLStateMachine.m b/SmartDeviceLink/SDLStateMachine.m
index 126f0e55b..ab5c54689 100644
--- a/SmartDeviceLink/SDLStateMachine.m
+++ b/SmartDeviceLink/SDLStateMachine.m
@@ -109,12 +109,25 @@ SDLStateMachineTransitionFormat const SDLStateMachineTransitionFormatDidEnter =
#pragma mark - Helpers
-- (void)setToState:(SDLState *)state {
+- (void)setToState:(SDLState *)state fromOldState:(nullable SDLState *)oldState callEnterTransition:(BOOL)shouldCall {
if (![self.states.allKeys containsObject:state]) {
return;
}
- self.currentState = state;
+ if (oldState != nil && shouldCall) {
+ self.currentState = oldState;
+ [self transitionToState:state];
+ } else if (shouldCall) {
+ SEL didEnter = NSSelectorFromString([NSString stringWithFormat:SDLStateMachineTransitionFormatDidEnter, state]);
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+ if ([self.target respondsToSelector:didEnter]) {
+ [self.target performSelector:didEnter];
+#pragma clang diagnostic pop
+ }
+ } else {
+ self.currentState = state;
+ }
}
/**
@@ -139,4 +152,4 @@ SDLStateMachineTransitionFormat const SDLStateMachineTransitionFormatDidEnter =
@end
-NS_ASSUME_NONNULL_END \ No newline at end of file
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
index 91320c955..ba680de00 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
@@ -21,6 +21,7 @@
#import "SDLProxyFactory.h"
#import "SDLRegisterAppInterface.h"
#import "SDLRegisterAppInterfaceResponse.h"
+#import "SDLResult.h"
#import "SDLShow.h"
#import "SDLStateMachine.h"
#import "SDLTextAlignment.h"
@@ -156,8 +157,17 @@ describe(@"a lifecycle manager", ^{
});
describe(@"when started", ^{
+ __block BOOL readyHandlerSuccess = NO;
+ __block NSError *readyHandlerError = nil;
+
beforeEach(^{
- [testManager startWithReadyHandler:^(BOOL success, NSError * _Nullable error) {}];
+ readyHandlerSuccess = NO;
+ readyHandlerError = nil;
+
+ [testManager startWithReadyHandler:^(BOOL success, NSError * _Nullable error) {
+ readyHandlerSuccess = success;
+ readyHandlerError = error;
+ }];
});
it(@"should initialize the proxy property", ^{
@@ -205,7 +215,7 @@ describe(@"a lifecycle manager", ^{
describe(@"in the connected state", ^{
beforeEach(^{
- [testManager.lifecycleStateMachine setToState:SDLLifecycleStateTransportConnected];
+ [testManager.lifecycleStateMachine setToState:SDLLifecycleStateTransportConnected fromOldState:nil callEnterTransition:NO];
});
describe(@"after receiving a register app interface response", ^{
@@ -252,10 +262,41 @@ describe(@"a lifecycle manager", ^{
});
});
});
+
+ describe(@"transitioning to the ready state", ^{
+ context(@"when the register response is a success", ^{
+ it(@"should call the ready handler with success", ^{
+ SDLRegisterAppInterfaceResponse *response = [[SDLRegisterAppInterfaceResponse alloc] init];
+ response.resultCode = [SDLResult SUCCESS];
+ testManager.registerResponse = response;
+
+ [testManager.lifecycleStateMachine setToState:SDLLifecycleStateReady fromOldState:nil callEnterTransition:YES];
+
+ expect(@(readyHandlerSuccess)).to(equal(@YES));
+ expect(readyHandlerError).to(beNil());
+ });
+ });
+
+ context(@"when the register response is a warning", ^{
+ it(@"should call the ready handler with success but error", ^{
+ SDLRegisterAppInterfaceResponse *response = [[SDLRegisterAppInterfaceResponse alloc] init];
+ response.resultCode = [SDLResult WARNINGS];
+ response.info = @"some info";
+ testManager.registerResponse = response;
+
+ [testManager.lifecycleStateMachine setToState:SDLLifecycleStateReady fromOldState:nil callEnterTransition:YES];
+
+ expect(@(readyHandlerSuccess)).to(equal(@YES));
+ expect(readyHandlerError).toNot(beNil());
+ expect(@(readyHandlerError.code)).to(equal(@(SDLManagerErrorRegistrationFailed)));
+ expect(readyHandlerError.userInfo[NSLocalizedFailureReasonErrorKey]).to(match(response.info));
+ });
+ });
+ });
describe(@"in the ready state", ^{
beforeEach(^{
- [testManager.lifecycleStateMachine setToState:SDLLifecycleStateReady];
+ [testManager.lifecycleStateMachine setToState:SDLLifecycleStateReady fromOldState:nil callEnterTransition:NO];
});
it(@"can send an RPC", ^{
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m
index b5d2bfcf4..15371a53b 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m
@@ -142,7 +142,6 @@ describe(@"Upload File Operation", ^{
it(@"should send correct putfiles", ^{
NSArray<SDLPutFile *> *putFiles = testConnectionManager.receivedRequests;
- SDLPutFile *firstPutFile = putFiles.firstObject;
NSUInteger numberOfPutFiles = (((testFileData.length - 1) / [SDLGlobals globals].maxMTUSize) + 1);
expect(@(putFiles.count)).to(equal(@(numberOfPutFiles)));