From 3debebd060ace6ffb57d1480c3367235be2eff8b Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Tue, 3 Dec 2019 13:22:49 -0500 Subject: [PATCH 1/3] Add APIs to SDLTemplateConfiguration for Objective-CPP compatibility --- SmartDeviceLink/SDLTemplateConfiguration.m | 111 +++++++++++++-------- 1 file changed, 68 insertions(+), 43 deletions(-) diff --git a/SmartDeviceLink/SDLTemplateConfiguration.m b/SmartDeviceLink/SDLTemplateConfiguration.m index 1f2d2cca1..2f84ddef1 100644 --- a/SmartDeviceLink/SDLTemplateConfiguration.m +++ b/SmartDeviceLink/SDLTemplateConfiguration.m @@ -1,60 +1,85 @@ // -// SDLTemplateConfiguration.m +// SDLTemplateConfiguration.h // SmartDeviceLink -#import "SDLTemplateConfiguration.h" +#import "SDLTemplateColorScheme.h" +#import "SDLPredefinedLayout.h" -#import "NSMutableDictionary+Store.h" -#import "SDLRPCParameterNames.h" +NS_ASSUME_NONNULL_BEGIN -@implementation SDLTemplateConfiguration +/** + Used to set an alternate template layout to a window. + @since SDL 6.0 + */ +@interface SDLTemplateConfiguration : SDLRPCStruct -- (instancetype)initWithPredefinedLayout:(SDLPredefinedLayout)predefinedLayout { - return [self initWithTemplate:predefinedLayout]; -} -- (instancetype)initWithTemplate:(NSString *)template { - self = [super init]; - if (!self) { - return nil; - } - self.template = template; - return self; -} +/** + Constructor with the required values. -- (instancetype)initWithTemplate:(NSString *)template dayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme nightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme { - self = [self initWithTemplate:template]; - if (!self) { - return nil; - } - self.dayColorScheme = dayColorScheme; - self.nightColorScheme = nightColorScheme; - return self; -} + @param predefinedLayout A template layout an app uses to display information. The broad details of the layout are defined, but the details depend on the IVI system. Used in SetDisplayLayout. + */ +- (instancetype)initWithPredefinedLayout:(SDLPredefinedLayout)predefinedLayout; -- (void)setTemplate:(NSString *)template { - [self.store sdl_setObject:template forName:SDLRPCParameterNameTemplate]; -} +#ifndef __cplusplus +/** + Init with the required values. -- (NSString *)template { - return [self.store sdl_objectForName:SDLRPCParameterNameTemplate ofClass:NSString.class error:nil]; -} + @param template Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + */ +- (instancetype)initWithTemplate:(NSString *)template; -- (void)setDayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme { - [self.store sdl_setObject:dayColorScheme forName:SDLRPCParameterNameDayColorScheme]; -} -- (nullable SDLTemplateColorScheme *)dayColorScheme { - return [self.store sdl_objectForName:SDLRPCParameterNameDayColorScheme ofClass:SDLTemplateColorScheme.class error:nil]; -} +/** + Convinience constructor with all the parameters. -- (void)setNightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme { - [self.store sdl_setObject:nightColorScheme forName:SDLRPCParameterNameNightColorScheme]; -} + @param template Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + @param dayColorScheme The color scheme to use when the head unit is in a light / day situation. If nil, the existing color scheme will be used. + @param nightColorScheme The color scheme to use when the head unit is in a dark / night situation. + */ +- (instancetype)initWithTemplate:(NSString *)template dayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme nightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme; -- (nullable SDLTemplateColorScheme *)nightColorScheme { - return [self.store sdl_objectForName:SDLRPCParameterNameNightColorScheme ofClass:SDLTemplateColorScheme.class error:nil]; -} +/** + Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + */ +@property (strong, nonatomic) NSString *template; +#endif + +#ifdef __cplusplus +/** + Init with the required values. + + @param templateName Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + */ +- (instancetype)initWithTemplate:(NSString *)templateName; + + +/** + Convinience constructor with all the parameters. + + @param templateName Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + @param dayColorScheme The color scheme to use when the head unit is in a light / day situation. If nil, the existing color scheme will be used. + @param nightColorScheme The color scheme to use when the head unit is in a dark / night situation. + */ +- (instancetype)initWithTemplate:(NSString *)templateName dayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme nightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme; + +/** + Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + */ +@property (strong, nonatomic) NSString *templateName; +#endif + +/** + The color scheme to use when the head unit is in a light / day situation. + */ +@property (strong, nonatomic, nullable) SDLTemplateColorScheme *dayColorScheme; + +/** + The color scheme to use when the head unit is in a dark / night situation. + */ +@property (strong, nonatomic, nullable) SDLTemplateColorScheme *nightColorScheme; @end + +NS_ASSUME_NONNULL_END From 03a33bd53065f24ab7c12ddb209f2846292995d8 Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Tue, 3 Dec 2019 13:51:10 -0500 Subject: [PATCH 2/3] Add SDLTemplateConfiguration stuff for .m --- SmartDeviceLink/SDLTemplateConfiguration.h | 32 ++++- SmartDeviceLink/SDLTemplateConfiguration.m | 142 +++++++++++---------- 2 files changed, 103 insertions(+), 71 deletions(-) diff --git a/SmartDeviceLink/SDLTemplateConfiguration.h b/SmartDeviceLink/SDLTemplateConfiguration.h index 6a2b3a66e..2f84ddef1 100644 --- a/SmartDeviceLink/SDLTemplateConfiguration.h +++ b/SmartDeviceLink/SDLTemplateConfiguration.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN /** Used to set an alternate template layout to a window. - + @since SDL 6.0 */ @interface SDLTemplateConfiguration : SDLRPCStruct @@ -22,9 +22,10 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initWithPredefinedLayout:(SDLPredefinedLayout)predefinedLayout; +#ifndef __cplusplus /** Init with the required values. - + @param template Predefined or dynamically created window template. Currently only predefined window template layouts are defined. */ - (instancetype)initWithTemplate:(NSString *)template; @@ -32,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN /** Convinience constructor with all the parameters. - + @param template Predefined or dynamically created window template. Currently only predefined window template layouts are defined. @param dayColorScheme The color scheme to use when the head unit is in a light / day situation. If nil, the existing color scheme will be used. @param nightColorScheme The color scheme to use when the head unit is in a dark / night situation. @@ -43,6 +44,31 @@ NS_ASSUME_NONNULL_BEGIN Predefined or dynamically created window template. Currently only predefined window template layouts are defined. */ @property (strong, nonatomic) NSString *template; +#endif + +#ifdef __cplusplus +/** + Init with the required values. + + @param templateName Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + */ +- (instancetype)initWithTemplate:(NSString *)templateName; + + +/** + Convinience constructor with all the parameters. + + @param templateName Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + @param dayColorScheme The color scheme to use when the head unit is in a light / day situation. If nil, the existing color scheme will be used. + @param nightColorScheme The color scheme to use when the head unit is in a dark / night situation. + */ +- (instancetype)initWithTemplate:(NSString *)templateName dayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme nightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme; + +/** + Predefined or dynamically created window template. Currently only predefined window template layouts are defined. + */ +@property (strong, nonatomic) NSString *templateName; +#endif /** The color scheme to use when the head unit is in a light / day situation. diff --git a/SmartDeviceLink/SDLTemplateConfiguration.m b/SmartDeviceLink/SDLTemplateConfiguration.m index 2f84ddef1..9407a0d33 100644 --- a/SmartDeviceLink/SDLTemplateConfiguration.m +++ b/SmartDeviceLink/SDLTemplateConfiguration.m @@ -1,85 +1,91 @@ // -// SDLTemplateConfiguration.h +// SDLTemplateConfiguration.m // SmartDeviceLink -#import "SDLTemplateColorScheme.h" -#import "SDLPredefinedLayout.h" +#import "SDLTemplateConfiguration.h" -NS_ASSUME_NONNULL_BEGIN +#import "NSMutableDictionary+Store.h" +#import "SDLRPCParameterNames.h" -/** - Used to set an alternate template layout to a window. +@implementation SDLTemplateConfiguration - @since SDL 6.0 - */ -@interface SDLTemplateConfiguration : SDLRPCStruct - -/** - Constructor with the required values. - - @param predefinedLayout A template layout an app uses to display information. The broad details of the layout are defined, but the details depend on the IVI system. Used in SetDisplayLayout. - */ -- (instancetype)initWithPredefinedLayout:(SDLPredefinedLayout)predefinedLayout; +- (instancetype)initWithPredefinedLayout:(SDLPredefinedLayout)predefinedLayout { + return [self initWithTemplate:predefinedLayout]; +} #ifndef __cplusplus -/** - Init with the required values. - - @param template Predefined or dynamically created window template. Currently only predefined window template layouts are defined. - */ -- (instancetype)initWithTemplate:(NSString *)template; - - -/** - Convinience constructor with all the parameters. - - @param template Predefined or dynamically created window template. Currently only predefined window template layouts are defined. - @param dayColorScheme The color scheme to use when the head unit is in a light / day situation. If nil, the existing color scheme will be used. - @param nightColorScheme The color scheme to use when the head unit is in a dark / night situation. - */ -- (instancetype)initWithTemplate:(NSString *)template dayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme nightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme; - -/** - Predefined or dynamically created window template. Currently only predefined window template layouts are defined. - */ -@property (strong, nonatomic) NSString *template; +- (instancetype)initWithTemplate:(NSString *)template { + self = [super init]; + if (!self) { + return nil; + } + self.template = template; + return self; +} + +- (instancetype)initWithTemplate:(NSString *)template dayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme nightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme { + self = [self initWithTemplate:template]; + if (!self) { + return nil; + } + self.dayColorScheme = dayColorScheme; + self.nightColorScheme = nightColorScheme; + return self; +} + +- (void)setTemplate:(NSString *)template { + [self.store sdl_setObject:template forName:SDLRPCParameterNameTemplate]; +} + +- (NSString *)template { + return [self.store sdl_objectForName:SDLRPCParameterNameTemplate ofClass:NSString.class error:nil]; +} #endif -#ifdef __cplusplus -/** - Init with the required values. - - @param templateName Predefined or dynamically created window template. Currently only predefined window template layouts are defined. - */ -- (instancetype)initWithTemplate:(NSString *)templateName; - - -/** - Convinience constructor with all the parameters. +#ifdef _cplusplus +- (instancetype)initWithTemplate:(NSString *)templateName { + self = [super init]; + if (!self) { + return nil; + } + self.templateName = templateName; + return self; +} + +- (instancetype)initWithTemplate:(NSString *)templateName dayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme nightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme; { + self = [self initWithTemplate:templateName]; + if (!self) { + return nil; + } + self.dayColorScheme = dayColorScheme; + self.nightColorScheme = nightColorScheme; + return self; +} + +- (void)setTemplateName:(NSString *)templateName { + [self.store sdl_setObject:template forName:SDLRPCParameterNameTemplate]; +} + +- (NSString *)templateName { + return [self.store sdl_objectForName:SDLRPCParameterNameTemplate ofClass:NSString.class error:nil]; +} +#endif - @param templateName Predefined or dynamically created window template. Currently only predefined window template layouts are defined. - @param dayColorScheme The color scheme to use when the head unit is in a light / day situation. If nil, the existing color scheme will be used. - @param nightColorScheme The color scheme to use when the head unit is in a dark / night situation. - */ -- (instancetype)initWithTemplate:(NSString *)templateName dayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme nightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme; +- (void)setDayColorScheme:(nullable SDLTemplateColorScheme *)dayColorScheme { + [self.store sdl_setObject:dayColorScheme forName:SDLRPCParameterNameDayColorScheme]; +} -/** - Predefined or dynamically created window template. Currently only predefined window template layouts are defined. - */ -@property (strong, nonatomic) NSString *templateName; -#endif +- (nullable SDLTemplateColorScheme *)dayColorScheme { + return [self.store sdl_objectForName:SDLRPCParameterNameDayColorScheme ofClass:SDLTemplateColorScheme.class error:nil]; +} -/** - The color scheme to use when the head unit is in a light / day situation. - */ -@property (strong, nonatomic, nullable) SDLTemplateColorScheme *dayColorScheme; +- (void)setNightColorScheme:(nullable SDLTemplateColorScheme *)nightColorScheme { + [self.store sdl_setObject:nightColorScheme forName:SDLRPCParameterNameNightColorScheme]; +} -/** - The color scheme to use when the head unit is in a dark / night situation. - */ -@property (strong, nonatomic, nullable) SDLTemplateColorScheme *nightColorScheme; +- (nullable SDLTemplateColorScheme *)nightColorScheme { + return [self.store sdl_objectForName:SDLRPCParameterNameNightColorScheme ofClass:SDLTemplateColorScheme.class error:nil]; +} @end - -NS_ASSUME_NONNULL_END From 1dee918047870f640c26e0e12a02f27159b6a740 Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Wed, 4 Dec 2019 13:04:03 -0500 Subject: [PATCH 3/3] Add a comment explaining the C++ template configuration hack --- SmartDeviceLink/SDLTemplateConfiguration.h | 1 + 1 file changed, 1 insertion(+) diff --git a/SmartDeviceLink/SDLTemplateConfiguration.h b/SmartDeviceLink/SDLTemplateConfiguration.h index 2f84ddef1..39d0b0df7 100644 --- a/SmartDeviceLink/SDLTemplateConfiguration.h +++ b/SmartDeviceLink/SDLTemplateConfiguration.h @@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initWithPredefinedLayout:(SDLPredefinedLayout)predefinedLayout; +// HAX: We are doing this because `template` is a C++ keyword and won't compile. #ifndef __cplusplus /** Init with the required values.