summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-07-20 16:21:34 -0400
committerJoel Fischer <joeljfischer@gmail.com>2017-07-20 16:21:34 -0400
commit0b9f03c29df079f93b12d5a87c2c4d9349d94971 (patch)
treeffb868eb18b1b6d0a5d2df2359043b448a5da65e
parentf03bee571896a14a0a59be1ce8e9b1279031d380 (diff)
downloadsdl_ios-0b9f03c29df079f93b12d5a87c2c4d9349d94971.tar.gz
Add RPCStartServiceNak payload object
* Add Int32 and Int64 not found BSON constants * Rename constants * Allow most params to be nullable, put nullability checks in * Create missing initializers
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadConstants.h10
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadConstants.m10
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartService.h3
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartService.m23
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h4
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m43
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.h4
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.m70
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadType.h4
9 files changed, 142 insertions, 29 deletions
diff --git a/SmartDeviceLink/SDLControlFramePayloadConstants.h b/SmartDeviceLink/SDLControlFramePayloadConstants.h
index e2e3b7fde..a207e9d0a 100644
--- a/SmartDeviceLink/SDLControlFramePayloadConstants.h
+++ b/SmartDeviceLink/SDLControlFramePayloadConstants.h
@@ -8,6 +8,10 @@
#import <Foundation/Foundation.h>
-extern char *const protocolVersionKey;
-extern char *const hashIdKey;
-extern char *const mtuKey;
+extern int32_t const SDLControlFrameInt32NotFound;
+extern int64_t const SDLControlFrameInt64NotFound;
+
+extern char *const SDLControlFrameProtocolVersionKey;
+extern char *const SDLControlFrameHashIdKey;
+extern char *const SDLControlFrameMTUKey;
+extern char *const SDLControlFrameRejectedParams;
diff --git a/SmartDeviceLink/SDLControlFramePayloadConstants.m b/SmartDeviceLink/SDLControlFramePayloadConstants.m
index b8c22bf12..6dab9c2ca 100644
--- a/SmartDeviceLink/SDLControlFramePayloadConstants.m
+++ b/SmartDeviceLink/SDLControlFramePayloadConstants.m
@@ -8,6 +8,10 @@
#import "SDLControlFramePayloadConstants.h"
-char *const protocolVersionKey = "protocolVersion";
-char *const hashIdKey = "hashId";
-char *const mtuKey = "mtu";
+int32_t const SDLControlFrameInt32NotFound = -1;
+int64_t const SDLControlFrameInt64NotFound = -1;
+
+char *const SDLControlFrameProtocolVersionKey = "protocolVersion";
+char *const SDLControlFrameHashIdKey = "hashId";
+char *const SDLControlFrameMTUKey = "mtu";
+char *const SDLControlFrameRejectedParams = "rejectedParams";
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartService.h b/SmartDeviceLink/SDLControlFramePayloadRPCStartService.h
index f0be5259e..8dba5d184 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartService.h
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartService.h
@@ -14,10 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLControlFramePayloadRPCStartService : NSObject <SDLControlFramePayloadType>
-@property (copy, nonatomic, readonly) NSString *protocolVersion;
+@property (copy, nonatomic, readonly, nullable) NSString *protocolVersion;
- (instancetype)initWithMajorVersion:(NSUInteger)majorVersion minorVersion:(NSUInteger)minorVersion patchVersion:(NSUInteger)patchVersion;
-- (instancetype)initWithData:(NSData *)data;
@end
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartService.m b/SmartDeviceLink/SDLControlFramePayloadRPCStartService.m
index 66a696492..c60c9f1fd 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartService.m
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartService.m
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLControlFramePayloadRPCStartService ()
-@property (copy, nonatomic, readwrite) NSString *protocolVersion;
+@property (copy, nonatomic, readwrite, nullable) NSString *protocolVersion;
@end
@@ -32,20 +32,28 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithData:(NSData *)data {
+- (instancetype)initWithData:(nullable NSData *)data {
self = [super init];
if (!self) return nil;
- [self sdl_parse:data];
+ if (data) {
+ [self sdl_parse:data];
+ }
return self;
}
-- (NSData *)data {
+- (nullable NSData *)data {
+ if (self.protocolVersion == nil) {
+ return nil;
+ }
+
BsonObject payloadObject;
bson_object_initialize_default(&payloadObject);
- bson_object_put_string(&payloadObject, protocolVersionKey, (char *)self.protocolVersion.UTF8String);
+ if (self.protocolVersion != nil) {
+ bson_object_put_string(&payloadObject, SDLControlFrameProtocolVersionKey, (char *)self.protocolVersion.UTF8String);
+ }
BytePtr bsonData = bson_object_to_bytes(&payloadObject);
NSUInteger length = bson_object_size(&payloadObject);
@@ -58,7 +66,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_parse:(NSData *)data {
BsonObject payloadObject = bson_object_from_bytes((BytePtr)data.bytes);
- self.protocolVersion = [NSString stringWithUTF8String:bson_object_get_string(&payloadObject, protocolVersionKey)];
+ char *utf8String = bson_object_get_string(&payloadObject, SDLControlFrameProtocolVersionKey);
+ if (utf8String != NULL) {
+ self.protocolVersion = [NSString stringWithUTF8String:utf8String];
+ }
bson_object_deinitialize(&payloadObject);
}
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h
index 529acf005..40b59980d 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h
@@ -16,7 +16,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic, readonly) int32_t hashId;
@property (assign, nonatomic, readonly) int64_t mtu;
-@property (copy, nonatomic, readonly) NSString *protocolVersion;
+@property (copy, nonatomic, readonly, nullable) NSString *protocolVersion;
+
+- (instancetype)initWithHashId:(int32_t)hashId mtu:(int64_t)mtu majorVersion:(NSUInteger)major minorVersion:(NSUInteger)minor patchVersion:(NSUInteger)patch;
@end
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m
index 8e44bcb06..05f4c9e20 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m
@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic, readwrite) int32_t hashId;
@property (assign, nonatomic, readwrite) int64_t mtu;
-@property (copy, nonatomic, readwrite) NSString *protocolVersion;
+@property (copy, nonatomic, readwrite, nullable) NSString *protocolVersion;
@end
@@ -36,22 +36,41 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithData:(NSData *)data {
+- (instancetype)initWithData:(nullable NSData *)data {
self = [super init];
if (!self) return nil;
- [self sdl_parse:data];
+ _hashId = SDLControlFrameInt32NotFound;
+ _mtu = SDLControlFrameInt64NotFound;
+
+ if (data) {
+ [self sdl_parse:data];
+ }
return self;
}
-- (NSData *)data {
+- (nullable NSData *)data {
+ if (self.hashId == SDLControlFrameInt32NotFound
+ && self.mtu == SDLControlFrameInt64NotFound
+ && self.protocolVersion == nil) {
+ return nil;
+ }
+
BsonObject payloadObject;
bson_object_initialize_default(&payloadObject);
- bson_object_put_int32(&payloadObject, hashIdKey, self.hashId);
- bson_object_put_int64(&payloadObject, mtuKey, self.mtu);
- bson_object_put_string(&payloadObject, protocolVersionKey, (char *)self.protocolVersion.UTF8String);
+ if (self.hashId != SDLControlFrameInt32NotFound) {
+ bson_object_put_int32(&payloadObject, SDLControlFrameHashIdKey, self.hashId);
+ }
+
+ if (self.mtu != SDLControlFrameInt64NotFound) {
+ bson_object_put_int64(&payloadObject, SDLControlFrameMTUKey, self.mtu);
+ }
+
+ if (self.protocolVersion == nil) {
+ bson_object_put_string(&payloadObject, SDLControlFrameProtocolVersionKey, (char *)self.protocolVersion.UTF8String);
+ }
BytePtr bsonData = bson_object_to_bytes(&payloadObject);
NSUInteger length = bson_object_size(&payloadObject);
@@ -64,9 +83,13 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_parse:(NSData *)data {
BsonObject payloadObject = bson_object_from_bytes((BytePtr)data.bytes);
- self.hashId = bson_object_get_int32(&payloadObject, hashIdKey);
- self.mtu = bson_object_get_int64(&payloadObject, mtuKey);
- self.protocolVersion = [NSString stringWithUTF8String:bson_object_get_string(&payloadObject, protocolVersionKey)];
+ self.hashId = bson_object_get_int32(&payloadObject, SDLControlFrameHashIdKey);
+ self.mtu = bson_object_get_int64(&payloadObject, SDLControlFrameMTUKey);
+
+ char *utf8String = bson_object_get_string(&payloadObject, SDLControlFrameProtocolVersionKey);
+ if (utf8String != NULL) {
+ self.protocolVersion = [NSString stringWithUTF8String:utf8String];
+ }
bson_object_deinitialize(&payloadObject);
}
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.h b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.h
index 0929dfa9e..2b95c1446 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.h
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.h
@@ -15,7 +15,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLControlFramePayloadRPCStartServiceNak : NSObject <SDLControlFramePayloadType>
-@property (copy, nonatomic, readonly) NSArray<NSString *> *rejectedParams;
+@property (copy, nonatomic, readonly, nullable) NSArray<NSString *> *rejectedParams;
+
+- (instancetype)initWithRejectedParams:(nullable NSArray<NSString *> *)rejectedParams;
@end
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.m b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.m
index 238553f4c..08bfacf72 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.m
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceNak.m
@@ -16,12 +16,80 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLControlFramePayloadRPCStartServiceNak ()
-@property (copy, nonatomic, readwrite) NSArray<NSString *> *rejectedParams;
+@property (copy, nonatomic, readwrite, nullable) NSArray<NSString *> *rejectedParams;
@end
@implementation SDLControlFramePayloadRPCStartServiceNak
+- (instancetype)initWithRejectedParams:(nullable NSArray<NSString *> *)rejectedParams {
+ self = [super init];
+ if (!self) return nil;
+
+ _rejectedParams = rejectedParams;
+
+ return self;
+}
+
+- (instancetype)initWithData:(nullable NSData *)data {
+ self = [super init];
+ if (!self) return nil;
+
+ if (data) {
+ [self sdl_parse:data];
+ }
+
+ return self;
+}
+
+- (nullable NSData *)data {
+ if (self.rejectedParams == nil) {
+ return nil;
+ }
+
+ BsonObject payloadObject;
+ bson_object_initialize_default(&payloadObject);
+
+ if (self.rejectedParams != nil) {
+ BsonArray arrayObject;
+ bson_array_initialize(&arrayObject, 512);
+
+ for (NSString *param in self.rejectedParams) {
+ bson_array_add_string(&arrayObject, (char *)param.UTF8String);
+ }
+
+ bson_object_put_array(&payloadObject, SDLControlFrameRejectedParams, &arrayObject);
+
+ bson_array_deinitialize(&arrayObject);
+ }
+
+ BytePtr bsonData = bson_object_to_bytes(&payloadObject);
+ NSUInteger length = bson_object_size(&payloadObject);
+
+ bson_object_deinitialize(&payloadObject);
+
+ return [[NSData alloc] initWithBytes:bsonData length:length];
+}
+
+- (void)sdl_parse:(NSData *)data {
+ BsonObject payloadObject = bson_object_from_bytes((BytePtr)data.bytes);
+ BsonArray *arrayObject = bson_object_get_array(&payloadObject, SDLControlFrameRejectedParams);
+
+ NSMutableArray<NSString *> *rejectedParams = [NSMutableArray array];
+ char *paramString;
+ size_t index = 0;
+ do {
+ paramString = bson_array_get_string(arrayObject, index);
+ [rejectedParams addObject:[NSString stringWithUTF8String:paramString]];
+ index++;
+ } while (paramString != NULL);
+
+ self.rejectedParams = [rejectedParams copy];
+
+ bson_array_deinitialize(arrayObject);
+ bson_object_deinitialize(&payloadObject);
+}
+
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLControlFramePayloadType.h b/SmartDeviceLink/SDLControlFramePayloadType.h
index f7e7d6827..2c9673ccc 100644
--- a/SmartDeviceLink/SDLControlFramePayloadType.h
+++ b/SmartDeviceLink/SDLControlFramePayloadType.h
@@ -12,8 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@protocol SDLControlFramePayloadType <NSObject>
-- (NSData *)data;
-- (instancetype)initWithData:(NSData *)data;;
+- (nullable NSData *)data;
+- (instancetype)initWithData:(nullable NSData *)data;;
@end