From 4dfb45a61531b35c1ec0d2d9b0b6b146b0e1a131 Mon Sep 17 00:00:00 2001 From: Conner Wu <244295790@qq.com> Date: Mon, 19 Jun 2017 09:29:41 +0800 Subject: [PATCH] Ad transport protocol type. --- SmartDeviceLink/SDLLifecycleConfiguration.h | 13 ++++++++++++- SmartDeviceLink/SDLLifecycleConfiguration.m | 11 ++++++----- SmartDeviceLink/SDLLifecycleManager.m | 10 +++++----- SmartDeviceLink/SDLManager.m | 2 +- SmartDeviceLink/SDLProxyFactory.h | 8 ++++---- SmartDeviceLink/SDLProxyFactory.m | 18 +++++++++--------- SmartDeviceLink_Example/Classes/ProxyManager.m | 2 +- 7 files changed, 38 insertions(+), 26 deletions(-) diff --git a/SmartDeviceLink/SDLLifecycleConfiguration.h b/SmartDeviceLink/SDLLifecycleConfiguration.h index 638c1703a4..d5178882fd 100644 --- a/SmartDeviceLink/SDLLifecycleConfiguration.h +++ b/SmartDeviceLink/SDLLifecycleConfiguration.h @@ -25,6 +25,11 @@ typedef NS_OPTIONS(NSUInteger, SDLLogOutput) { SDLLogOutputSiphon = 1 << 2 }; +typedef NS_ENUM(NSInteger, SDLTransportType) { + SDLTransportTypeTCP = 0, + SDLTransportTypeIAP = 1 << 0 +}; + NS_ASSUME_NONNULL_BEGIN @@ -40,10 +45,11 @@ NS_ASSUME_NONNULL_BEGIN * * @param appName The name of the app. * @param appId The appId to be used. This should be registered with the radio's manufacturer. + * @param transportType The transport type. * * @return The lifecycle configuration */ -+ (SDLLifecycleConfiguration *)defaultConfigurationWithAppName:(NSString *)appName appId:(NSString *)appId; ++ (SDLLifecycleConfiguration *)defaultConfigurationWithAppName:(NSString *)appName appId:(NSString *)appId transportType:(SDLTransportType)transportType; /** * A debug configuration that runs using TCP. Additional functionality should be customized on the properties. @@ -137,6 +143,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (assign, nonatomic) SDLLogOutput logFlags; +/** + * The transport type. + */ +@property (assign, nonatomic) SDLTransportType transportType; + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLLifecycleConfiguration.m b/SmartDeviceLink/SDLLifecycleConfiguration.m index f1b8acf7eb..0ae295e4c3 100644 --- a/SmartDeviceLink/SDLLifecycleConfiguration.m +++ b/SmartDeviceLink/SDLLifecycleConfiguration.m @@ -31,7 +31,7 @@ @implementation SDLLifecycleConfiguration #pragma mark Lifecycle -- (instancetype)initDefaultConfigurationWithAppName:(NSString *)appName appId:(NSString *)appId { +- (instancetype)initDefaultConfigurationWithAppName:(NSString *)appName appId:(NSString *)appId transportType:(SDLTransportType)transportType { self = [super init]; if (!self) { return nil; @@ -52,16 +52,17 @@ - (instancetype)initDefaultConfigurationWithAppName:(NSString *)appName appId:(N _ttsName = nil; _voiceRecognitionCommandNames = nil; _logFlags = SDLLogOutputNone; + _transportType = transportType; return self; } -+ (SDLLifecycleConfiguration *)defaultConfigurationWithAppName:(NSString *)appName appId:(NSString *)appId { - return [[self alloc] initDefaultConfigurationWithAppName:appName appId:appId]; ++ (SDLLifecycleConfiguration *)defaultConfigurationWithAppName:(NSString *)appName appId:(NSString *)appId transportType:(SDLTransportType)transportType { + return [[self alloc] initDefaultConfigurationWithAppName:appName appId:appId transportType:SDLTransportTypeTCP]; } + (SDLLifecycleConfiguration *)debugConfigurationWithAppName:(NSString *)appName appId:(NSString *)appId ipAddress:(NSString *)ipAddress port:(UInt16)port { - SDLLifecycleConfiguration *config = [[self alloc] initDefaultConfigurationWithAppName:appName appId:appId]; + SDLLifecycleConfiguration *config = [[self alloc] initDefaultConfigurationWithAppName:appName appId:appId transportType:SDLTransportTypeTCP]; config.tcpDebugMode = YES; config.tcpDebugIPAddress = ipAddress; config.tcpDebugPort = port; @@ -101,7 +102,7 @@ - (void)setAppType:(nullable SDLAppHMIType *)appType { #pragma mark NSCopying - (id)copyWithZone:(nullable NSZone *)zone { - SDLLifecycleConfiguration *newConfig = [[self.class allocWithZone:zone] initDefaultConfigurationWithAppName:_appName appId:_appId]; + SDLLifecycleConfiguration *newConfig = [[self.class allocWithZone:zone] initDefaultConfigurationWithAppName:_appName appId:_appId transportType:_transportType]; newConfig->_tcpDebugMode = _tcpDebugMode; newConfig->_tcpDebugIPAddress = _tcpDebugIPAddress; newConfig->_tcpDebugPort = _tcpDebugPort; diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m index b08abc3431..0ec9e3bb20 100644 --- a/SmartDeviceLink/SDLLifecycleManager.m +++ b/SmartDeviceLink/SDLLifecycleManager.m @@ -74,7 +74,7 @@ @implementation SDLLifecycleManager #pragma mark Lifecycle - (instancetype)init { - return [self initWithConfiguration:[SDLConfiguration configurationWithLifecycle:[SDLLifecycleConfiguration defaultConfigurationWithAppName:@"SDL APP" appId:@"001"] lockScreen:[SDLLockScreenConfiguration disabledConfiguration]] delegate:nil]; + return [self initWithConfiguration:[SDLConfiguration configurationWithLifecycle:[SDLLifecycleConfiguration defaultConfigurationWithAppName:@"SDL APP" appId:@"001" transportType:SDLTransportTypeTCP] lockScreen:[SDLLockScreenConfiguration disabledConfiguration]] delegate:nil]; } - (instancetype)initWithConfiguration:(SDLConfiguration *)configuration delegate:(nullable id)delegate { @@ -157,10 +157,10 @@ - (void)didEnterStateStarted { // Start up the internal proxy object #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - if (self.configuration.lifecycleConfig.tcpDebugMode) { - self.proxy = [SDLProxyFactory buildSDLProxyWithListener:self.notificationDispatcher tcpIPAddress:self.configuration.lifecycleConfig.tcpDebugIPAddress tcpPort:[@(self.configuration.lifecycleConfig.tcpDebugPort) stringValue]]; - } else { - self.proxy = [SDLProxyFactory buildSDLProxyWithListener:self.notificationDispatcher]; + if (self.configuration.lifecycleConfig.transportType == SDLTransportTypeTCP) { + self.proxy = [SDLProxyFactory buildSDLProxyWithTCPListener:self.notificationDispatcher tcpIPAddress:self.configuration.lifecycleConfig.tcpDebugIPAddress tcpPort:[@(self.configuration.lifecycleConfig.tcpDebugPort) stringValue]]; + } else if (self.configuration.lifecycleConfig.transportType == SDLTransportTypeIAP) { + self.proxy = [SDLProxyFactory buildSDLProxyWithiAPListener:self.notificationDispatcher]; } #pragma clang diagnostic pop } diff --git a/SmartDeviceLink/SDLManager.m b/SmartDeviceLink/SDLManager.m index c83511db61..c6a957e2d8 100644 --- a/SmartDeviceLink/SDLManager.m +++ b/SmartDeviceLink/SDLManager.m @@ -35,7 +35,7 @@ @implementation SDLManager #pragma mark Lifecycle - (instancetype)init { - return [self initWithConfiguration:[SDLConfiguration configurationWithLifecycle:[SDLLifecycleConfiguration defaultConfigurationWithAppName:@"SDL APP" appId:@"001"] lockScreen:[SDLLockScreenConfiguration enabledConfiguration]] delegate:nil]; + return [self initWithConfiguration:[SDLConfiguration configurationWithLifecycle:[SDLLifecycleConfiguration defaultConfigurationWithAppName:@"SDL APP" appId:@"001"transportType:SDLTransportTypeTCP] lockScreen:[SDLLockScreenConfiguration enabledConfiguration]] delegate:nil]; } - (instancetype)initWithConfiguration:(SDLConfiguration *)configuration delegate:(nullable id)delegate { diff --git a/SmartDeviceLink/SDLProxyFactory.h b/SmartDeviceLink/SDLProxyFactory.h index f4aee30896..bbac8c3794 100644 --- a/SmartDeviceLink/SDLProxyFactory.h +++ b/SmartDeviceLink/SDLProxyFactory.h @@ -11,9 +11,9 @@ __deprecated_msg("Use SDLManager instead") @interface SDLProxyFactory : NSObject { } -+ (SDLProxy *)buildSDLProxyWithListener:(NSObject *)listener; ++ (SDLProxy *)buildSDLProxyWithiAPListener:(NSObject *)listener; -+ (SDLProxy *)buildSDLProxyWithListener:(NSObject *)listener - tcpIPAddress:(NSString *)ipaddress - tcpPort:(NSString *)port; ++ (SDLProxy *)buildSDLProxyWithTCPListener:(NSObject *)listener + tcpIPAddress:(NSString *)ipaddress + tcpPort:(NSString *)port; @end diff --git a/SmartDeviceLink/SDLProxyFactory.m b/SmartDeviceLink/SDLProxyFactory.m index b2320c6412..0f0dd78bd7 100644 --- a/SmartDeviceLink/SDLProxyFactory.m +++ b/SmartDeviceLink/SDLProxyFactory.m @@ -12,26 +12,26 @@ @implementation SDLProxyFactory -+ (SDLProxy *)buildSDLProxyWithListener:(NSObject *)delegate { ++ (SDLProxy *)buildSDLProxyWithiAPListener:(NSObject *)delegate { SDLIAPTransport *transport = [[SDLIAPTransport alloc] init]; SDLProtocol *protocol = [[SDLProtocol alloc] init]; SDLProxy *ret = [[SDLProxy alloc] initWithTransport:transport protocol:protocol delegate:delegate]; - + return ret; } -+ (SDLProxy *)buildSDLProxyWithListener:(NSObject *)delegate - tcpIPAddress:(NSString *)ipaddress - tcpPort:(NSString *)port { ++ (SDLProxy *)buildSDLProxyWithTCPListener:(NSObject *)delegate + tcpIPAddress:(NSString *)ipaddress + tcpPort:(NSString *)port { SDLTCPTransport *transport = [[SDLTCPTransport alloc] init]; transport.hostName = ipaddress; transport.portNumber = port; - + SDLProtocol *protocol = [[SDLProtocol alloc] init]; - + SDLProxy *ret = [[SDLProxy alloc] initWithTransport:transport protocol:protocol delegate:delegate]; - + return ret; } -@end \ No newline at end of file +@end diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.m b/SmartDeviceLink_Example/Classes/ProxyManager.m index 7096f4bd91..5e46d89506 100644 --- a/SmartDeviceLink_Example/Classes/ProxyManager.m +++ b/SmartDeviceLink_Example/Classes/ProxyManager.m @@ -70,7 +70,7 @@ - (instancetype)init { - (void)startIAP { [self sdlex_updateProxyState:ProxyStateSearchingForConnection]; - SDLLifecycleConfiguration *lifecycleConfig = [self.class setLifecycleConfigurationPropertiesOnConfiguration:[SDLLifecycleConfiguration defaultConfigurationWithAppName:SDLAppName appId:SDLAppId]]; + SDLLifecycleConfiguration *lifecycleConfig = [self.class setLifecycleConfigurationPropertiesOnConfiguration:[SDLLifecycleConfiguration defaultConfigurationWithAppName:SDLAppName appId:SDLAppId transportType:SDLTransportTypeIAP]]; // Assume this is production and disable logging lifecycleConfig.logFlags = SDLLogOutputNone;