From b9b8ce3d8e69180a38b5617ba61495a726e8047d Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Thu, 7 Sep 2017 11:06:40 -0400 Subject: Make constants styled correctly --- SmartDeviceLink/SDLIAPSession.m | 4 ++-- SmartDeviceLink/SDLIAPTransport.m | 24 +++++++++++------------- SmartDeviceLink/SDLPolicyDataParser.m | 6 +++--- SmartDeviceLink/SDLProxy.m | 14 +++++++------- SmartDeviceLink/SDLV1ProtocolHeader.m | 8 ++++---- SmartDeviceLink/SDLV2ProtocolHeader.m | 8 ++++---- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/SmartDeviceLink/SDLIAPSession.m b/SmartDeviceLink/SDLIAPSession.m index fe4b629fe..8e0df7f50 100644 --- a/SmartDeviceLink/SDLIAPSession.m +++ b/SmartDeviceLink/SDLIAPSession.m @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *const IOStreamThreadName = @"com.smartdevicelink.iostream"; -NSTimeInterval const streamThreadWaitSecs = 1.0; +NSTimeInterval const StreamThreadWaitSecs = 1.0; @interface SDLIAPSession () @@ -86,7 +86,7 @@ NSTimeInterval const streamThreadWaitSecs = 1.0; if (self.isDataSession) { [self.ioStreamThread cancel]; - long lWait = dispatch_semaphore_wait(self.canceledSemaphore, dispatch_time(DISPATCH_TIME_NOW, streamThreadWaitSecs * NSEC_PER_SEC)); + long lWait = dispatch_semaphore_wait(self.canceledSemaphore, dispatch_time(DISPATCH_TIME_NOW, StreamThreadWaitSecs * NSEC_PER_SEC)); if (lWait == 0) { SDLLogW(@"Stream thread cancelled"); } else { diff --git a/SmartDeviceLink/SDLIAPTransport.m b/SmartDeviceLink/SDLIAPTransport.m index bc5b06fc0..c077d05fa 100644 --- a/SmartDeviceLink/SDLIAPTransport.m +++ b/SmartDeviceLink/SDLIAPTransport.m @@ -24,10 +24,8 @@ NSString *const IndexedProtocolStringPrefix = @"com.smartdevicelink.prot"; NSString *const MultiSessionProtocolString = @"com.smartdevicelink.multisession"; NSString *const BackgroundTaskName = @"com.sdl.transport.iap.backgroundTask"; -int const createSessionRetries = 1; -int const protocolIndexTimeoutSeconds = 20; -int const streamOpenTimeoutSeconds = 2; - +int const CreateSessionRetries = 1; +int const ProtocolIndexTimeoutSeconds = 20; @interface SDLIAPTransport () { BOOL _alreadyDestructed; @@ -223,7 +221,7 @@ int const streamOpenTimeoutSeconds = 2; */ - (void)sdl_establishSessionWithAccessory:(nullable EAAccessory *)accessory { SDLLogD(@"Attempting to connect"); - if (self.retryCounter < createSessionRetries) { + if (self.retryCounter < CreateSessionRetries) { // We should be attempting to connect self.retryCounter++; EAAccessory *sdlAccessory = accessory; @@ -261,7 +259,7 @@ int const streamOpenTimeoutSeconds = 2; self.controlSession.delegate = self; if (self.protocolIndexTimer == nil) { - self.protocolIndexTimer = [[SDLTimer alloc] initWithDuration:protocolIndexTimeoutSeconds repeat:NO]; + self.protocolIndexTimer = [[SDLTimer alloc] initWithDuration:ProtocolIndexTimeoutSeconds repeat:NO]; } else { [self.protocolIndexTimer cancel]; } @@ -505,14 +503,14 @@ int const streamOpenTimeoutSeconds = 2; } - (double)retryDelay { - const double min_value = 1.5; - const double max_value = 9.5; - double range_length = max_value - min_value; + const double MinRetrySeconds = 1.5; + const double MaxRetrySeconds = 9.5; + double RetryRangeSeconds = MaxRetrySeconds - MinRetrySeconds; - static double delay = 0; + static double appDelaySeconds = 0; // HAX: This pull the app name and hashes it in an attempt to provide a more even distribution of retry delays. The evidence that this does so is anecdotal. A more ideal solution would be to use a list of known, installed SDL apps on the phone to try and deterministically generate an even delay. - if (delay == 0) { + if (appDelaySeconds == 0) { NSString *appName = [[NSProcessInfo processInfo] processName]; if (appName == nil) { appName = @"noname"; @@ -536,10 +534,10 @@ int const streamOpenTimeoutSeconds = 2; double hashBasedValueInRange0to1 = ((double)firstHalf) / 0xffffffffffffffff; // Transform the number into a number between min and max - delay = ((range_length * hashBasedValueInRange0to1) + min_value); + appDelaySeconds = ((RetryRangeSeconds * hashBasedValueInRange0to1) + MinRetrySeconds); } - return delay; + return appDelaySeconds; } diff --git a/SmartDeviceLink/SDLPolicyDataParser.m b/SmartDeviceLink/SDLPolicyDataParser.m index 20b7573fd..9e23aeedc 100644 --- a/SmartDeviceLink/SDLPolicyDataParser.m +++ b/SmartDeviceLink/SDLPolicyDataParser.m @@ -54,11 +54,11 @@ NS_ASSUME_NONNULL_BEGIN self.CPUDestination = (thirdByte & 0b00001000) != 0; self.encryptionKeyIndex = (thirdByte & 0b00000111); - const int payloadSizeOffset = 3; + const int PayloadSizeOffset = 3; if (self.isHighBandwidth) { - self.payloadSize = ntohl(*(UInt32 *)(bytes + payloadSizeOffset)); + self.payloadSize = ntohl(*(UInt32 *)(bytes + PayloadSizeOffset)); } else { - self.payloadSize = ntohs(*(UInt16 *)(bytes + payloadSizeOffset)); + self.payloadSize = ntohs(*(UInt16 *)(bytes + PayloadSizeOffset)); } if (self.hasESN) { diff --git a/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink/SDLProxy.m index 9b65076ca..34b06e366 100644 --- a/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink/SDLProxy.m @@ -42,9 +42,9 @@ typedef void (^URLSessionTaskCompletionHandler)(NSData *data, NSURLResponse *res typedef void (^URLSessionDownloadTaskCompletionHandler)(NSURL *location, NSURLResponse *response, NSError *error); NSString *const SDLProxyVersion = @"4.6.1"; -const float startSessionTime = 10.0; -const float notifyProxyClosedDelay = 0.1; -const int POLICIES_CORRELATION_ID = 65535; +const float StartSessionTime = 10.0; +const float NotifyProxyClosedDelay = 0.1; +const int PoliciesCorrelationId = 65535; static float DefaultConnectionTimeout = 45.0; @interface SDLProxy () { @@ -197,11 +197,11 @@ static float DefaultConnectionTimeout = 45.0; [self.protocol startServiceWithType:SDLServiceTypeRPC]; if (self.startSessionTimer == nil) { - self.startSessionTimer = [[SDLTimer alloc] initWithDuration:startSessionTime repeat:NO]; + self.startSessionTimer = [[SDLTimer alloc] initWithDuration:StartSessionTime repeat:NO]; __weak typeof(self) weakSelf = self; self.startSessionTimer.elapsedBlock = ^{ SDLLogW(@"Start session timed out"); - [weakSelf performSelector:@selector(notifyProxyClosed) withObject:nil afterDelay:notifyProxyClosedDelay]; + [weakSelf performSelector:@selector(notifyProxyClosed) withObject:nil afterDelay:NotifyProxyClosedDelay]; }; } [self.startSessionTimer start]; @@ -450,7 +450,7 @@ static float DefaultConnectionTimeout = 45.0; // Create the SystemRequest RPC to send to module. SDLLogV(@"OnSystemRequest HTTP response"); SDLSystemRequest *request = [[SDLSystemRequest alloc] init]; - request.correlationID = [NSNumber numberWithInt:POLICIES_CORRELATION_ID]; + request.correlationID = [NSNumber numberWithInt:PoliciesCorrelationId]; request.requestType = SDLRequestTypeProprietary; request.bulkData = data; @@ -509,7 +509,7 @@ static float DefaultConnectionTimeout = 45.0; // Create the SystemRequest RPC to send to module. SDLPutFile *putFile = [[SDLPutFile alloc] init]; putFile.fileType = SDLFileTypeJSON; - putFile.correlationID = @(POLICIES_CORRELATION_ID); + putFile.correlationID = @(PoliciesCorrelationId); putFile.syncFileName = @"response_data"; putFile.bulkData = data; diff --git a/SmartDeviceLink/SDLV1ProtocolHeader.m b/SmartDeviceLink/SDLV1ProtocolHeader.m index 1de39fb29..288774248 100644 --- a/SmartDeviceLink/SDLV1ProtocolHeader.m +++ b/SmartDeviceLink/SDLV1ProtocolHeader.m @@ -4,7 +4,7 @@ #import "SDLV1ProtocolHeader.h" -const int V1PROTOCOL_HEADERSIZE = 8; +const int ProtocolV1HeaderByteSize = 8; NS_ASSUME_NONNULL_BEGIN @@ -13,14 +13,14 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init { if (self = [super init]) { _version = 1; - _size = V1PROTOCOL_HEADERSIZE; + _size = ProtocolV1HeaderByteSize; } return self; } - (NSData *)data { // Assembles the properties in the binary header format - Byte headerBytes[V1PROTOCOL_HEADERSIZE] = {0}; + Byte headerBytes[ProtocolV1HeaderByteSize] = {0}; Byte version = (self.version & 0xF) << 4; // first 4 bits Byte compressed = (self.encrypted ? 1 : 0) << 3; // next 1 bit @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN *p = CFSwapInt32HostToBig(self.bytesInPayload); // swap the byte order // Now put it all in an NSData object. - NSData *dataOut = [NSData dataWithBytes:headerBytes length:V1PROTOCOL_HEADERSIZE]; + NSData *dataOut = [NSData dataWithBytes:headerBytes length:ProtocolV1HeaderByteSize]; return dataOut; } diff --git a/SmartDeviceLink/SDLV2ProtocolHeader.m b/SmartDeviceLink/SDLV2ProtocolHeader.m index edb6a060e..646c1bee0 100644 --- a/SmartDeviceLink/SDLV2ProtocolHeader.m +++ b/SmartDeviceLink/SDLV2ProtocolHeader.m @@ -4,7 +4,7 @@ #import "SDLV2ProtocolHeader.h" -const int V2PROTOCOL_HEADERSIZE = 12; +const int ProtocolV2HeaderByteSize = 12; @interface SDLV2ProtocolHeader () @@ -22,14 +22,14 @@ const int V2PROTOCOL_HEADERSIZE = 12; - (instancetype)initWithVersion:(UInt8)version { if (self = [super init]) { _version = version; - _size = V2PROTOCOL_HEADERSIZE; + _size = ProtocolV2HeaderByteSize; } return self; } - (NSData *)data { // Assembles the properties in the binary header format - Byte headerBytes[V2PROTOCOL_HEADERSIZE] = {0}; + Byte headerBytes[ProtocolV2HeaderByteSize] = {0}; Byte version = (self.version & 0xF) << 4; // first 4 bits Byte encrypted = (self.encrypted ? 1 : 0) << 3; // next 1 bit @@ -48,7 +48,7 @@ const int V2PROTOCOL_HEADERSIZE = 12; *p = CFSwapInt32HostToBig(self.messageID); // Now put it all in an NSData object. - NSData *dataOut = [NSData dataWithBytes:headerBytes length:V2PROTOCOL_HEADERSIZE]; + NSData *dataOut = [NSData dataWithBytes:headerBytes length:ProtocolV2HeaderByteSize]; return dataOut; } -- cgit v1.2.1