diff options
Diffstat (limited to 'SmartDeviceLink/SDLGlobals.m')
-rw-r--r-- | SmartDeviceLink/SDLGlobals.m | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/SmartDeviceLink/SDLGlobals.m b/SmartDeviceLink/SDLGlobals.m index d5364a119..735139b22 100644 --- a/SmartDeviceLink/SDLGlobals.m +++ b/SmartDeviceLink/SDLGlobals.m @@ -9,12 +9,15 @@ #import "SDLGlobals.h" #import "SDLLogMacros.h" +#import "SDLProtocolHeader.h" +#import "SDLSyncMsgVersion.h" +#import "SDLVersion.h" NS_ASSUME_NONNULL_BEGIN // VERSION DEPENDENT CODE -NSString *const SDLMaxProxyProtocolVersion = @"5.1.0"; -NSString *const SDLMaxProxyRPCVersion = @"5.0.0"; +NSString *const SDLMaxProxyProtocolVersion = @"5.2.0"; +NSString *const SDLMaxProxyRPCVersion = @"5.1.0"; NSUInteger const SDLDefaultMTUSize = UINT32_MAX; NSUInteger const SDLV1MTUSize = 1024; @@ -28,7 +31,7 @@ typedef NSNumber *MTUBox; @interface SDLGlobals () @property (strong, nonatomic) NSMutableDictionary<ServiceTypeBox, MTUBox> *dynamicMTUDict; -@property (copy, nonatomic, readwrite) NSString *protocolVersion; +@property (copy, nonatomic, readwrite) SDLVersion *protocolVersion; @end @@ -51,9 +54,9 @@ typedef NSNumber *MTUBox; return nil; } - _protocolVersion = @"1.0.0"; - _maxHeadUnitVersion = @"0.0.0"; - _rpcVersion = [[SDLSyncMsgVersion alloc] initWithMajorVersion:1 minorVersion:0 patchVersion:0]; + _protocolVersion = [[SDLVersion alloc] initWithString:@"1.0.0"]; + _maxHeadUnitProtocolVersion = [[SDLVersion alloc] initWithString:@"0.0.0"]; + _rpcVersion = [[SDLVersion alloc] initWithString:@"1.0.0"]; _dynamicMTUDict = [NSMutableDictionary dictionary]; return self; @@ -62,14 +65,11 @@ typedef NSNumber *MTUBox; #pragma mark - Custom Getters / Setters -- (void)setMaxHeadUnitVersion:(NSString *)maxHeadUnitVersion { - self.protocolVersion = [self sdl_isVersion:maxHeadUnitVersion greaterThanVersion:SDLMaxProxyProtocolVersion] ? SDLMaxProxyProtocolVersion : maxHeadUnitVersion; +- (void)setMaxHeadUnitProtocolVersion:(SDLVersion *)maxHeadUnitVersion { + SDLVersion *maxProxyProtocolVersion = [SDLVersion versionWithString:SDLMaxProxyProtocolVersion]; + self.protocolVersion = [maxHeadUnitVersion isGreaterThanVersion:maxProxyProtocolVersion] ? maxProxyProtocolVersion : maxHeadUnitVersion; - _maxHeadUnitVersion = maxHeadUnitVersion; -} - -- (NSInteger)majorProtocolVersion { - return [self.protocolVersion substringWithRange:NSMakeRange(0, 1)].integerValue; + _maxHeadUnitProtocolVersion = maxHeadUnitVersion; } - (void)setDynamicMTUSize:(NSUInteger)maxMTUSize forServiceType:(SDLServiceType)serviceType { @@ -90,13 +90,9 @@ typedef NSNumber *MTUBox; #pragma mark - Helpers -- (BOOL)sdl_isVersion:(NSString *)version1 greaterThanVersion:(NSString *)version2 { - return ([version1 compare:version2 options:NSNumericSearch] == NSOrderedDescending); -} - - (NSUInteger)sdl_defaultMaxMTUSize { // VERSION DEPENDENT CODE - switch (self.majorProtocolVersion) { + switch (self.protocolVersion.major) { case 1: // fallthrough case 2: { // HAX: This was set to 1024 at some point, for an unknown reason. We can't change it because of backward compatibility & validation concerns. The actual MTU for v1/2 is 1500 bytes. @@ -106,14 +102,14 @@ typedef NSNumber *MTUBox; case 4: // fallthrough case 5: { // If the head unit isn't running v3/4, but that's the connection scheme we're using, then we have to know that they could be running an MTU that's not 128k, so we default back to the v1/2 MTU for safety. - if ([self sdl_isVersion:self.maxHeadUnitVersion greaterThanVersion:SDLMaxProxyProtocolVersion]) { + if ([self.maxHeadUnitProtocolVersion isGreaterThanVersion:[SDLVersion versionWithString:SDLMaxProxyProtocolVersion]]) { return SDLV1MTUSize; } else { return SDLV3MTUSize; } } break; default: { - NSAssert(NO, @"Unknown version number for MTU Size: %@", @(self.majorProtocolVersion)); + NSAssert(NO, @"Unknown MTU size for protocol version: %@", self.protocolVersion); return 0; } } |