diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2020-07-30 11:13:00 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2020-07-30 11:13:00 -0400 |
commit | 6940d4fe418e48e9edfd18975038d9de8f37fe36 (patch) | |
tree | 04ab1111b172c6fab192b6aa6b66b2fedbcc51a4 | |
parent | 300846fb33ed76682fb293a51d26273f7654e4c8 (diff) | |
download | sdl_ios-6940d4fe418e48e9edfd18975038d9de8f37fe36.tar.gz |
Add support for protocol nak reason parameter
6 files changed, 31 insertions, 17 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index 435b4e720..aade199e8 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -7401,7 +7401,7 @@ }; 5D61FA1B1A84237100846EE7 = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 1150; + LastSwiftMigration = 1160; }; 5D61FA251A84237100846EE7 = { CreatedOnToolsVersion = 6.1.1; diff --git a/SmartDeviceLink/SDLControlFramePayloadNak.h b/SmartDeviceLink/SDLControlFramePayloadNak.h index 41781cb2e..eb917de58 100644 --- a/SmartDeviceLink/SDLControlFramePayloadNak.h +++ b/SmartDeviceLink/SDLControlFramePayloadNak.h @@ -18,7 +18,10 @@ NS_ASSUME_NONNULL_BEGIN /// An array of rejected parameters such as: [`hashId`] @property (copy, nonatomic, readonly, nullable) NSArray<NSString *> *rejectedParams; -- (instancetype)initWithRejectedParams:(nullable NSArray<NSString *> *)rejectedParams; +/// A string describing the failure +@property (copy, nonatomic, readonly, nullable) NSString *reason; + +- (instancetype)initWithRejectedParams:(nullable NSArray<NSString *> *)rejectedParams reason:(nullable NSString *)reason; @end diff --git a/SmartDeviceLink/SDLControlFramePayloadNak.m b/SmartDeviceLink/SDLControlFramePayloadNak.m index 55b9a6dad..a6344bbc9 100644 --- a/SmartDeviceLink/SDLControlFramePayloadNak.m +++ b/SmartDeviceLink/SDLControlFramePayloadNak.m @@ -17,16 +17,18 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLControlFramePayloadNak () @property (copy, nonatomic, readwrite, nullable) NSArray<NSString *> *rejectedParams; +@property (copy, nonatomic, readwrite, nullable) NSString *reason; @end @implementation SDLControlFramePayloadNak -- (instancetype)initWithRejectedParams:(nullable NSArray<NSString *> *)rejectedParams { +- (instancetype)initWithRejectedParams:(nullable NSArray<NSString *> *)rejectedParams reason:(nullable NSString *)reason { self = [super init]; if (!self) return nil; _rejectedParams = rejectedParams; + _reason = reason; return self; } @@ -43,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN } - (nullable NSData *)data { - if (self.rejectedParams == nil) { + if (self.rejectedParams == nil && self.reason == nil) { return nil; } @@ -61,6 +63,10 @@ NS_ASSUME_NONNULL_BEGIN bson_object_put_array(&payloadObject, SDLControlFrameRejectedParams, &arrayObject); } + if (self.reason != nil) { + bson_object_put_string(&payloadObject, SDLControlFrameReasonKey, (char *)self.reason.UTF8String); + } + BytePtr bsonData = bson_object_to_bytes(&payloadObject); NSUInteger length = bson_object_size(&payloadObject); @@ -75,7 +81,14 @@ NS_ASSUME_NONNULL_BEGIN if (retval <= 0) { return; } - + + // Pull out the reason + char *reasonChars = bson_object_get_string(&payloadObject, SDLControlFrameReasonKey); + if (reasonChars != NULL) { + self.reason = [NSString stringWithUTF8String:reasonChars]; + } + + // Pull out the rejected params BsonArray *arrayObject = bson_object_get_array(&payloadObject, SDLControlFrameRejectedParams); if (arrayObject == NULL) { return; @@ -97,7 +110,7 @@ NS_ASSUME_NONNULL_BEGIN } - (NSString *)description { - return [NSString stringWithFormat:@"<%@>: Rejected params: %@", NSStringFromClass(self.class), self.rejectedParams]; + return [NSString stringWithFormat:@"<%@>: Rejected params: %@, reason: %@", NSStringFromClass(self.class), self.rejectedParams, self.reason]; } @end diff --git a/SmartDeviceLink/SDLProtocol.m b/SmartDeviceLink/SDLProtocol.m index d9d3c03d7..ad660eb79 100644 --- a/SmartDeviceLink/SDLProtocol.m +++ b/SmartDeviceLink/SDLProtocol.m @@ -674,8 +674,7 @@ NS_ASSUME_NONNULL_BEGIN case SDLFrameInfoEndServiceNACK: { if (nakMessage.header.version >= 5) { SDLControlFramePayloadNak *endServiceNakPayload = [[SDLControlFramePayloadNak alloc] initWithData:nakMessage.payload]; - NSArray<NSString *> *rejectedParams = endServiceNakPayload.rejectedParams; - SDLLogE(@"%@ service NAK'd, service type: %@, rejectedParams: %@", (nakMessage.header.frameData == SDLFrameInfoStartServiceNACK) ? @"Start" : @"End", @(nakMessage.header.serviceType), rejectedParams); + SDLLogE(@"%@ service NAK'd, service type: %@, payload: %@", (nakMessage.header.frameData == SDLFrameInfoStartServiceNACK) ? @"Start" : @"End", @(nakMessage.header.serviceType), endServiceNakPayload); } else { SDLLogE(@"NAK received message: %@", nakMessage); } diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m index f138e873d..d2c2889db 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m @@ -646,7 +646,7 @@ describe(@"the streaming video manager", ^{ testPreferredResolutions = @[testImageResolution, testImageResolution2]; streamingLifecycleManager.preferredResolutions = testPreferredResolutions; - testVideoStartNakPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:@[[NSString stringWithUTF8String:SDLControlFrameHeightKey], [NSString stringWithUTF8String:SDLControlFrameVideoCodecKey]]]; + testVideoStartNakPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:@[[NSString stringWithUTF8String:SDLControlFrameHeightKey], [NSString stringWithUTF8String:SDLControlFrameVideoCodecKey]] reason:@"failed"]; testVideoMessage = [[SDLV2ProtocolMessage alloc] initWithHeader:testVideoHeader andPayload:testVideoStartNakPayload.data]; [streamingLifecycleManager protocol:protocolMock didReceiveStartServiceNAK:testVideoMessage]; }); @@ -668,7 +668,7 @@ describe(@"the streaming video manager", ^{ testPreferredResolutions = @[testImageResolution]; streamingLifecycleManager.preferredResolutions = testPreferredResolutions; - testVideoStartNakPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:@[[NSString stringWithUTF8String:SDLControlFrameVideoCodecKey]]]; + testVideoStartNakPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:@[[NSString stringWithUTF8String:SDLControlFrameVideoCodecKey]] reason:@"failed"]; testVideoMessage = [[SDLV2ProtocolMessage alloc] initWithHeader:testVideoHeader andPayload:testVideoStartNakPayload.data]; [streamingLifecycleManager protocol:protocolMock didReceiveStartServiceNAK:testVideoMessage]; }); @@ -689,7 +689,7 @@ describe(@"the streaming video manager", ^{ testPreferredResolutions = @[testImageResolution]; streamingLifecycleManager.preferredResolutions = testPreferredResolutions; - testVideoStartNakPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:@[[NSString stringWithUTF8String:SDLControlFrameVideoCodecKey]]]; + testVideoStartNakPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:@[[NSString stringWithUTF8String:SDLControlFrameVideoCodecKey]] reason:@"failed"]; testVideoMessage = [[SDLV2ProtocolMessage alloc] initWithHeader:testVideoHeader andPayload:testVideoStartNakPayload.data]; [streamingLifecycleManager protocol:protocolMock didReceiveStartServiceNAK:testVideoMessage]; }); @@ -704,7 +704,7 @@ describe(@"the streaming video manager", ^{ streamingLifecycleManager.preferredFormats = testPreferredFormats; streamingLifecycleManager.preferredResolutions = testPreferredResolutions; - testVideoStartNakPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:nil]; + testVideoStartNakPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:nil reason:nil]; testVideoMessage = [[SDLV2ProtocolMessage alloc] initWithHeader:testVideoHeader andPayload:testVideoStartNakPayload.data]; [streamingLifecycleManager protocol:protocolMock didReceiveStartServiceNAK:testVideoMessage]; }); diff --git a/SmartDeviceLinkTests/ProtocolSpecs/ControlFramePayloadSpecs/SDLControlFramePayloadNakSpec.m b/SmartDeviceLinkTests/ProtocolSpecs/ControlFramePayloadSpecs/SDLControlFramePayloadNakSpec.m index 282ce9bc7..78a2e8137 100644 --- a/SmartDeviceLinkTests/ProtocolSpecs/ControlFramePayloadSpecs/SDLControlFramePayloadNakSpec.m +++ b/SmartDeviceLinkTests/ProtocolSpecs/ControlFramePayloadSpecs/SDLControlFramePayloadNakSpec.m @@ -15,19 +15,18 @@ describe(@"Test encoding data", ^{ context(@"with paramaters", ^{ beforeEach(^{ testParams = @[@"testParam1", @"testParam2"]; - testPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:testParams]; + testPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:testParams reason:@"failed"]; }); it(@"should create the correct data", ^{ NSString *base64Encoded = [testPayload.data base64EncodedStringWithOptions:0]; - expect(base64Encoded).to(equal(@"PgAAAARyZWplY3RlZFBhcmFtcwApAAAAAjAACwAAAHRlc3RQYXJhbTEAAjEACwAAAHRlc3RQYXJhbTIAAAA=")); + expect(base64Encoded).to(equal(@"UQAAAARyZWplY3RlZFBhcmFtcwApAAAAAjAACwAAAHRlc3RQYXJhbTEAAjEACwAAAHRlc3RQYXJhbTIAAAJyZWFzb24ABwAAAGZhaWxlZAAA")); }); }); context(@"without parameters", ^{ beforeEach(^{ - testParams = nil; - testPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:testParams]; + testPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:nil reason:nil]; }); it(@"should create no data", ^{ @@ -44,7 +43,7 @@ describe(@"Test decoding data", ^{ beforeEach(^{ testParams = @[@"testParam1", @"testParam2"]; - SDLControlFramePayloadNak *firstPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:testParams]; + SDLControlFramePayloadNak *firstPayload = [[SDLControlFramePayloadNak alloc] initWithRejectedParams:testParams reason:@"failed"]; testData = firstPayload.data; testPayload = [[SDLControlFramePayloadNak alloc] initWithData:testData]; |