summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLLifecycleManager.m
diff options
context:
space:
mode:
Diffstat (limited to 'SmartDeviceLink/SDLLifecycleManager.m')
-rw-r--r--SmartDeviceLink/SDLLifecycleManager.m123
1 files changed, 60 insertions, 63 deletions
diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m
index 8c83f9da9..d59b1e4eb 100644
--- a/SmartDeviceLink/SDLLifecycleManager.m
+++ b/SmartDeviceLink/SDLLifecycleManager.m
@@ -127,8 +127,13 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
_rpcOperationQueue = [[NSOperationQueue alloc] init];
_rpcOperationQueue.name = @"com.sdl.lifecycle.rpcOperation.concurrent";
- _rpcOperationQueue.maxConcurrentOperationCount = 3;
- _lifecycleQueue = dispatch_queue_create("com.sdl.lifecycle", DISPATCH_QUEUE_SERIAL);
+ _rpcOperationQueue.underlyingQueue = [SDLGlobals sharedGlobals].sdlConcurrentQueue;
+
+ if (@available(iOS 10.0, *)) {
+ _lifecycleQueue = dispatch_queue_create_with_target("com.sdl.lifecycle", DISPATCH_QUEUE_SERIAL, [SDLGlobals sharedGlobals].sdlProcessingQueue);
+ } else {
+ _lifecycleQueue = [SDLGlobals sharedGlobals].sdlProcessingQueue;
+ }
// Managers
_fileManager = [[SDLFileManager alloc] initWithConnectionManager:self configuration:_configuration.fileManagerConfig];
@@ -273,7 +278,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
// Due to a race condition internally with EAStream, we cannot immediately attempt to restart the proxy, as we will randomly crash.
// Apple Bug ID #30059457
__weak typeof(self) weakSelf = self;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), self.lifecycleQueue, ^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) { return; }
@@ -313,25 +318,23 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
__weak typeof(self) weakSelf = self;
[self sdl_sendRequest:regRequest
withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) {
- dispatch_async(weakSelf.lifecycleQueue, ^{
- // 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]) {
- SDLLogE(@"Failed to register the app. Error: %@, Response: %@", error, response);
- if (weakSelf.readyHandler) {
- weakSelf.readyHandler(NO, error);
- }
-
- if (weakSelf.lifecycleState != SDLLifecycleStateReconnecting) {
- [weakSelf sdl_transitionToState:SDLLifecycleStateStopped];
- }
-
- return;
+ // 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]) {
+ SDLLogE(@"Failed to register the app. Error: %@, Response: %@", error, response);
+ if (weakSelf.readyHandler) {
+ weakSelf.readyHandler(NO, error);
}
- weakSelf.registerResponse = (SDLRegisterAppInterfaceResponse *)response;
- [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithSDLMsgVersion:weakSelf.registerResponse.sdlMsgVersion];
- [weakSelf sdl_transitionToState:SDLLifecycleStateRegistered];
- });
+ if (weakSelf.lifecycleState != SDLLifecycleStateReconnecting) {
+ [weakSelf sdl_transitionToState:SDLLifecycleStateStopped];
+ }
+
+ return;
+ }
+
+ weakSelf.registerResponse = (SDLRegisterAppInterfaceResponse *)response;
+ [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithSDLMsgVersion:weakSelf.registerResponse.sdlMsgVersion];
+ [weakSelf sdl_transitionToState:SDLLifecycleStateRegistered];
}];
}
@@ -483,23 +486,19 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
}
// If we got to this point, we succeeded, send the error if there was a warning.
- dispatch_async(dispatch_get_main_queue(), ^{
- self.readyHandler(YES, startError);
- });
+ 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)
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.delegate hmiLevel:SDLHMILevelNone didChangeToLevel:self.hmiLevel];
+ [self.delegate hmiLevel:SDLHMILevelNone didChangeToLevel:self.hmiLevel];
- // Send the audio streaming state going from NOT_AUDIBLE to whatever we're at now (could still be NOT_AUDIBLE)
- if ([self.delegate respondsToSelector:@selector(audioStreamingState:didChangeToState:)]) {
- [self.delegate audioStreamingState:SDLAudioStreamingStateNotAudible didChangeToState:self.audioStreamingState];
- }
- });
+ // Send the audio streaming state going from NOT_AUDIBLE to whatever we're at now (could still be NOT_AUDIBLE)
+ if ([self.delegate respondsToSelector:@selector(audioStreamingState:didChangeToState:)]) {
+ [self.delegate audioStreamingState:SDLAudioStreamingStateNotAudible didChangeToState:self.audioStreamingState];
+ }
- // Stop the background task now that setup has completed
+ // Stop the background task now that setup has completed
[self.backgroundTaskManager endBackgroundTask];
}
@@ -607,33 +606,25 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
return;
}
- dispatch_async(_lifecycleQueue, ^{
- [self sdl_sendRequest:rpc withResponseHandler:nil];
- });
+ [self sdl_sendRequest:rpc withResponseHandler:nil];
}
- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler {
if (![self.lifecycleStateMachine isCurrentState:SDLLifecycleStateReady]) {
SDLLogW(@"Manager not ready, request not sent (%@)", request);
if (handler) {
- dispatch_async(dispatch_get_main_queue(), ^{
- handler(request, nil, [NSError sdl_lifecycle_notReadyError]);
- });
+ handler(request, nil, [NSError sdl_lifecycle_notReadyError]);
}
return;
}
- dispatch_async(_lifecycleQueue, ^{
- [self sdl_sendRequest:request withResponseHandler:handler];
- });
+ [self sdl_sendRequest:request withResponseHandler:handler];
}
// Managers need to avoid state checking. Part of <SDLConnectionManagerType>.
- (void)sendConnectionManagerRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler {
- dispatch_async(_lifecycleQueue, ^{
- [self sdl_sendRequest:request withResponseHandler:handler];
- });
+ [self sdl_sendRequest:request withResponseHandler:handler];
}
- (void)sdl_sendRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler {
@@ -645,9 +636,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
NSError *error = [NSError sdl_lifecycle_rpcErrorWithDescription:@"Nil Request Sent" andReason:@"A nil RPC request was passed and cannot be sent."];
SDLLogW(@"%@", error);
if (handler) {
- dispatch_async(dispatch_get_main_queue(), ^{
- handler(nil, nil, error);
- });
+ handler(nil, nil, error);
}
return;
}
@@ -686,8 +675,18 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
}
// this is to make sure that the transition happens on the dedicated queue
+- (void)sdl_runOnProcessingQueue:(void (^)(void))block {
+ if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(self.lifecycleQueue)) == 0
+ || strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label([SDLGlobals sharedGlobals].sdlProcessingQueue)) == 0) {
+ block();
+ } else {
+ dispatch_sync(self.lifecycleQueue, block);
+ }
+}
+
- (void)sdl_transitionToState:(SDLState *)state {
- if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(self.lifecycleQueue)) == 0) {
+ if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(self.lifecycleQueue)) == 0
+ || strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label([SDLGlobals sharedGlobals].sdlProcessingQueue)) == 0) {
[self.lifecycleStateMachine transitionToState:state];
} else {
// once this method returns, the transition is completed
@@ -769,24 +768,22 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
return;
}
- dispatch_async(dispatch_get_main_queue(), ^{
- if (![oldHMILevel isEqualToEnum:self.hmiLevel]
- && !(oldHMILevel == nil && self.hmiLevel == nil)) {
- [self.delegate hmiLevel:oldHMILevel didChangeToLevel:self.hmiLevel];
- }
+ if (![oldHMILevel isEqualToEnum:self.hmiLevel]
+ && !(oldHMILevel == nil && self.hmiLevel == nil)) {
+ [self.delegate hmiLevel:oldHMILevel didChangeToLevel:self.hmiLevel];
+ }
- if (![oldStreamingState isEqualToEnum:self.audioStreamingState]
- && !(oldStreamingState == nil && self.audioStreamingState == nil)
- && [self.delegate respondsToSelector:@selector(audioStreamingState:didChangeToState:)]) {
- [self.delegate audioStreamingState:oldStreamingState didChangeToState:self.audioStreamingState];
- }
+ if (![oldStreamingState isEqualToEnum:self.audioStreamingState]
+ && !(oldStreamingState == nil && self.audioStreamingState == nil)
+ && [self.delegate respondsToSelector:@selector(audioStreamingState:didChangeToState:)]) {
+ [self.delegate audioStreamingState:oldStreamingState didChangeToState:self.audioStreamingState];
+ }
- if (![oldSystemContext isEqualToEnum:self.systemContext]
- && !(oldSystemContext == nil && self.systemContext == nil)
- && [self.delegate respondsToSelector:@selector(systemContext:didChangeToContext:)]) {
- [self.delegate systemContext:oldSystemContext didChangeToContext:self.systemContext];
- }
- });
+ if (![oldSystemContext isEqualToEnum:self.systemContext]
+ && !(oldSystemContext == nil && self.systemContext == nil)
+ && [self.delegate respondsToSelector:@selector(systemContext:didChangeToContext:)]) {
+ [self.delegate systemContext:oldSystemContext didChangeToContext:self.systemContext];
+ }
}
- (void)remoteHardwareDidUnregister:(SDLRPCNotificationNotification *)notification {