summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/public/SDLLifecycleConfiguration.m
blob: 18fb195353435d58963ffd861732aa9755f85760 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
//  SDLManagerConfiguration.m
//  SmartDeviceLink-iOS
//
//  Created by Joel Fischer on 10/7/15.
//  Copyright © 2015 smartdevicelink. All rights reserved.
//

#import "SDLLifecycleConfiguration.h"

#import "SDLFile.h"
#import "SDLVersion.h"

static NSString *const DefaultTCPIPAddress = @"192.168.0.1";
static UInt16 const DefaultTCPIPPort = 12345;


NS_ASSUME_NONNULL_BEGIN

@interface SDLLifecycleConfiguration ()

@property (assign, nonatomic, readwrite) BOOL tcpDebugMode;
@property (copy, nonatomic, readwrite, null_resettable) NSString *tcpDebugIPAddress;
@property (assign, nonatomic, readwrite) UInt16 tcpDebugPort;

@end

static NSUInteger const AppIdCharacterCount = 10;

@implementation SDLLifecycleConfiguration

#pragma mark Lifecycle

+ (SDLLifecycleConfiguration *)defaultConfigurationWithAppName:(NSString *)appName fullAppId:(NSString *)fullAppId {
    return [[self alloc] initDefaultConfigurationWithAppName:appName fullAppId:fullAppId];
}

+ (SDLLifecycleConfiguration *)debugConfigurationWithAppName:(NSString *)appName fullAppId:(NSString *)fullAppId ipAddress:(NSString *)ipAddress port:(UInt16)port {
    SDLLifecycleConfiguration *config = [[self alloc] initDefaultConfigurationWithAppName:appName fullAppId:fullAppId];

    config.tcpDebugMode = YES;
    config.tcpDebugIPAddress = ipAddress;
    config.tcpDebugPort = port;

    return config;
}

#pragma mark Initalization Helpers

- (instancetype)initDefaultConfigurationWithAppName:(NSString *)appName fullAppId:(NSString *)fullAppId  {
    self = [super init];
    if (!self) {
        return nil;
    }

    _tcpDebugMode = NO;
    _tcpDebugIPAddress = DefaultTCPIPAddress;
    _tcpDebugPort = DefaultTCPIPPort;

    _appName = appName;
    _appType = SDLAppHMITypeDefault;
    _language = SDLLanguageEnUs;
    _languagesSupported = @[_language];
    _appIcon = nil;
    _shortAppName = nil;
    _ttsName = nil;
    _voiceRecognitionCommandNames = nil;
    _minimumProtocolVersion = [SDLVersion versionWithString:@"1.0.0"];
    _minimumRPCVersion = [SDLVersion versionWithString:@"1.0.0"];
    _allowedSecondaryTransports = SDLSecondaryTransportsTCP;

    _fullAppId = fullAppId;
    _appId = [self.class sdl_shortAppIdFromFullAppId:fullAppId];

    return self;
}

#pragma mark - Computed Properties

- (BOOL)isMedia {
    if ([self.appType isEqualToEnum:SDLAppHMITypeMedia] || [self.additionalAppTypes containsObject:SDLAppHMITypeMedia]) {
        return YES;
    }

    return NO;
}

- (void)setTcpDebugIPAddress:(nullable NSString *)tcpDebugIPAddress {
    if (tcpDebugIPAddress == nil) {
        _tcpDebugIPAddress = DefaultTCPIPAddress;
    } else {
        _tcpDebugIPAddress = tcpDebugIPAddress;
    }
}

- (void)setAppType:(nullable SDLAppHMIType)appType {
    if (appType == nil) {
        _appType = SDLAppHMITypeDefault;
        return;
    }

    _appType = appType;
}

#pragma mark - Full App ID Helpers

/**
 *  Generates the `appId` from the `fullAppId`
 *
 *  @discussion When an app is registered with an OEM, it is assigned an `appID` and a `fullAppID`. The `fullAppID` is the full UUID appID. The `appID` is the first 10 non-dash (i.e. "-") characters of the  `fullAppID`.
 *
 *  @param fullAppId   A `fullAppId`
 *  @return            An `appID` made of the first 10 non-dash characters of the "fullAppID"
 */
+ (NSString *)sdl_shortAppIdFromFullAppId:(NSString *)fullAppId {
    // Do not generate a short app id unless the fullAppID is greater than 10 characters
    if (fullAppId.length <= AppIdCharacterCount) {
        return @"";
    }
    NSString *filteredString = [self sdl_filterDashesFromText:fullAppId];
    return [filteredString substringToIndex:MIN(AppIdCharacterCount, filteredString.length)];
}

/**
 *  Filters the dash characters from a string
 *
 *  @param text    The string
 *  @return        The string with all dash characters removed
 */
+ (NSString *)sdl_filterDashesFromText:(NSString *)text {
    NSCharacterSet *supportedCharacters = [NSCharacterSet characterSetWithCharactersInString:@"-"];
    return [[text componentsSeparatedByCharactersInSet:supportedCharacters] componentsJoinedByString:@""];
}

#pragma mark - NSCopying

- (id)copyWithZone:(nullable NSZone *)zone {
    SDLLifecycleConfiguration *newConfig = [[self.class allocWithZone:zone] initDefaultConfigurationWithAppName:_appName fullAppId:_fullAppId];
    newConfig->_tcpDebugMode = _tcpDebugMode;
    newConfig->_tcpDebugIPAddress = _tcpDebugIPAddress;
    newConfig->_tcpDebugPort = _tcpDebugPort;
    newConfig->_appType = _appType;
    newConfig->_additionalAppTypes = _additionalAppTypes;
    newConfig->_language = _language;
    newConfig->_languagesSupported = _languagesSupported;
    newConfig->_appIcon = _appIcon;
    newConfig->_shortAppName = _shortAppName;
    newConfig->_ttsName = _ttsName;
    newConfig->_voiceRecognitionCommandNames = _voiceRecognitionCommandNames;
    newConfig->_dayColorScheme = _dayColorScheme;
    newConfig->_nightColorScheme = _nightColorScheme;
    newConfig->_allowedSecondaryTransports = _allowedSecondaryTransports;

    return newConfig;
}

@end

NS_ASSUME_NONNULL_END