diff options
Diffstat (limited to 'SmartDeviceLink/SDLLifecycleManager.m')
-rw-r--r-- | SmartDeviceLink/SDLLifecycleManager.m | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m index 5436d8945..1a5070154 100644 --- a/SmartDeviceLink/SDLLifecycleManager.m +++ b/SmartDeviceLink/SDLLifecycleManager.m @@ -43,6 +43,7 @@ #import "SDLRegisterAppInterface.h" #import "SDLRegisterAppInterfaceResponse.h" #import "SDLResponseDispatcher.h" +#import "SDLRPCResponseOperation.h" #import "SDLResult.h" #import "SDLScreenManager.h" #import "SDLSecondaryTransportManager.h" @@ -522,11 +523,23 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; #pragma mark Sending Requests -- (void)sendRequest:(SDLRPCRequest *)request { - [self sendRequest:request withResponseHandler:nil]; +- (void)sendRequest:(__kindof SDLRPCMessage *)request { + if ([request isKindOfClass:SDLRPCRequest.class]) { + SDLRPCRequest *requestRPC = (SDLRPCRequest *)request; + [self sendRequest:requestRPC withResponseHandler:nil]; + } else if ([request isKindOfClass:SDLRPCResponse.class] || [request isKindOfClass:SDLRPCNotification.class]) { + [self sdl_sendRPC:request]; + } else { + NSAssert(false, @"The request should be of type `Request`, `Response` or `Notification"); + } +} + +- (void)sdl_sendRPC:(__kindof SDLRPCMessage *)rpc { + SDLRPCResponseOperation *op = [[SDLRPCResponseOperation alloc] initWithConnectionManager:self rpc:rpc]; + [self.rpcOperationQueue addOperation:op]; } -- (void)sendRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { +- (void)sendRequest:(SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { SDLAsynchronousRPCRequestOperation *op = [[SDLAsynchronousRPCRequestOperation alloc] initWithConnectionManager:self request:request responseHandler:handler]; [self.rpcOperationQueue addOperation:op]; } @@ -551,10 +564,10 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; [self.rpcOperationQueue addOperation:op]; } -- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { +- (void)sendConnectionRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler { if (![self.lifecycleStateMachine isCurrentState:SDLLifecycleStateReady]) { SDLLogW(@"Manager not ready, message not sent (%@)", request); - if (handler) { + if (handler && [request isKindOfClass:SDLRPCRequest.class]) { dispatch_async(dispatch_get_main_queue(), ^{ handler(request, nil, [NSError sdl_lifecycle_notReadyError]); }); @@ -569,13 +582,13 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; } // Managers need to avoid state checking. Part of <SDLConnectionManagerType>. -- (void)sendConnectionManagerRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { +- (void)sendConnectionManagerRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler { dispatch_async(_lifecycleQueue, ^{ [self sdl_sendRequest:request withResponseHandler:handler]; }); } -- (void)sdl_sendRequest:(SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { +- (void)sdl_sendRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler { // We will allow things to be sent in a "SDLLifecycleStateConnected" state in the private method, but block it in the public method sendRequest:withCompletionHandler: so that the lifecycle manager can complete its setup without being bothered by developer error NSParameterAssert(request != nil); @@ -591,12 +604,18 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; return; } - // Add a correlation ID to the request - NSNumber *corrID = [self sdl_getNextCorrelationId]; - request.correlationID = corrID; - - [self.responseDispatcher storeRequest:request handler:handler]; - [self.proxy sendRPC:request]; + if ([request isKindOfClass:SDLRPCRequest.class]) { + // Generate and add a correlation ID to the request. When a response for the request is returned from Core, it will have the same correlation ID + SDLRPCRequest *requestRPC = (SDLRPCRequest *)request; + NSNumber *corrID = [self sdl_getNextCorrelationId]; + requestRPC.correlationID = corrID; + [self.responseDispatcher storeRequest:requestRPC handler:handler]; + [self.proxy sendRPC:requestRPC]; + } else if ([request isKindOfClass:SDLRPCResponse.class] || [request isKindOfClass:SDLRPCNotification.class]) { + [self.proxy sendRPC:request]; + } else { + SDLLogE(@"Attempting to send an RPC with unknown type, %@. The request should be of type request, response or notification. Returning...", request.class); + } } |