Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make constants styled correctly #724

Merged
merged 2 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SmartDeviceLink/SDLIAPSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()

Expand Down Expand Up @@ -86,7 +86,7 @@ - (void)stop {
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 {
Expand Down
24 changes: 11 additions & 13 deletions SmartDeviceLink/SDLIAPTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
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;
Expand Down Expand Up @@ -223,7 +221,7 @@ - (BOOL)sdl_connectAccessory:(EAAccessory *)accessory {
*/
- (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;
Expand Down Expand Up @@ -261,7 +259,7 @@ - (void)sdl_createIAPControlSessionWithAccessory:(EAAccessory *)accessory {
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];
}
Expand Down Expand Up @@ -505,14 +503,14 @@ - (SDLStreamErrorHandler)sdl_dataStreamErroredHandler {
}

- (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";
Expand All @@ -536,10 +534,10 @@ - (double)retryDelay {
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;
}


Expand Down
6 changes: 3 additions & 3 deletions SmartDeviceLink/SDLPolicyDataParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ - (void)parsePolicyData:(NSData *)data {
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) {
Expand Down
14 changes: 7 additions & 7 deletions SmartDeviceLink/SDLProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POLICIES_CORRELATION_ID on line no. 702 has not been updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

const float StartSessionTime = 10.0;
const float NotifyProxyClosedDelay = 0.1;
const int PoliciesCorrelationId = 65535;
static float DefaultConnectionTimeout = 45.0;

@interface SDLProxy () {
Expand Down Expand Up @@ -197,11 +197,11 @@ - (void)onProtocolOpened {
[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];
Expand Down Expand Up @@ -450,7 +450,7 @@ - (void)handleSystemRequestProprietary:(SDLOnSystemRequest *)request {
// 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;

Expand Down Expand Up @@ -509,7 +509,7 @@ - (void)sdl_handleSystemRequestHTTP:(SDLOnSystemRequest *)request {
// 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;

Expand Down
8 changes: 4 additions & 4 deletions SmartDeviceLink/SDLV1ProtocolHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#import "SDLV1ProtocolHeader.h"

const int V1PROTOCOL_HEADERSIZE = 8;
const int ProtocolV1HeaderByteSize = 8;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -13,14 +13,14 @@ @implementation SDLV1ProtocolHeader
- (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
Expand All @@ -36,7 +36,7 @@ - (NSData *)data {
*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;
}
Expand Down
8 changes: 4 additions & 4 deletions SmartDeviceLink/SDLV2ProtocolHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#import "SDLV2ProtocolHeader.h"

const int V2PROTOCOL_HEADERSIZE = 12;
const int ProtocolV2HeaderByteSize = 12;


@interface SDLV2ProtocolHeader ()
Expand All @@ -22,14 +22,14 @@ - (instancetype)init {
- (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
Expand All @@ -48,7 +48,7 @@ - (NSData *)data {
*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;
}
Expand Down