Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ksperling-apple committed May 6, 2024
1 parent adbde6c commit a3466cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
22 changes: 15 additions & 7 deletions src/darwin/Framework/CHIP/MTRSetupPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef NS_ENUM(NSUInteger, MTROptionalQRCodeInfoType) {
* setters has no effect.
*/
MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
@interface MTROptionalQRCodeInfo : NSObject <NSCopying>
@interface MTROptionalQRCodeInfo : NSObject /* <NSCopying> (see below) */

- (instancetype)initWithTag:(uint8_t)tag stringValue:(NSString *)value MTR_NEWLY_AVAILABLE;
- (instancetype)initWithTag:(uint8_t)tag int32Value:(int32_t)value MTR_NEWLY_AVAILABLE;
Expand All @@ -72,7 +72,7 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
* Tags in the range 0x00 - 0x7F are reserved for Matter-defined elements.
* Vendor-specific elements must have tags in the range 0x80 - 0xFF.
*/
@property (nonatomic, readonly, assign) uint8_t tagNumber;
@property (nonatomic, readonly, assign) uint8_t tagNumber MTR_NEWLY_AVAILABLE;

/**
* The value held in this extension element,
Expand All @@ -88,6 +88,10 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))

@end

MTR_NEWLY_AVAILABLE
@interface MTROptionalQRCodeInfo () <NSCopying>
@end

/**
* A Matter Onboarding Payload.
*
Expand All @@ -100,7 +104,7 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
* from the underlying values
*/
MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
@interface MTRSetupPayload : NSObject <NSCopying, NSSecureCoding>
@interface MTRSetupPayload : NSObject <NSSecureCoding> /* also <NSCopying> (see below) */

/**
* Initializes the payload object from the provide QR Code or Manual Pairing Code string.
Expand Down Expand Up @@ -153,23 +157,23 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
/**
* The list of Manufacturer-specific extension elements contained in the setup code. May be empty.
*/
@property (nonatomic, readonly, copy) NSArray<MTROptionalQRCodeInfo *> * vendorElements;
@property (nonatomic, readonly, copy) NSArray<MTROptionalQRCodeInfo *> * vendorElements MTR_NEWLY_AVAILABLE;

/**
Returns the Manufacturer-specific extension element with the specified tag, if any.
*/
- (nullable MTROptionalQRCodeInfo *)vendorElementWithTag:(uint8_t)tag;
- (nullable MTROptionalQRCodeInfo *)vendorElementWithTag:(uint8_t)tag MTR_NEWLY_AVAILABLE;

/**
* Removes the extension element with the specified tag, if any.
*/
- (void)removeVendorElementWithTag:(uint8_t)tag;
- (void)removeVendorElementWithTag:(uint8_t)tag MTR_NEWLY_AVAILABLE;

/**
* Adds or replaces a Manufacturer-specific extension element.
* The element must have a tag in the vendor-specific range (0x80 - 0xFF).
*/
- (void)addOrReplaceVendorElement:(MTROptionalQRCodeInfo *)element;
- (void)addOrReplaceVendorElement:(MTROptionalQRCodeInfo *)element MTR_NEWLY_AVAILABLE;

/**
* Generate a random Matter-valid setup PIN.
Expand Down Expand Up @@ -215,6 +219,10 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))

@end

MTR_NEWLY_AVAILABLE
@interface MTRSetupPayload () <NSCopying>
@end

@interface MTROptionalQRCodeInfo (Deprecated)

- (instancetype)init MTR_NEWLY_DEPRECATED("Please use -initWithTag:...value:");
Expand Down
12 changes: 9 additions & 3 deletions src/darwin/Framework/CHIP/MTRSetupPayload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ - (MTROptionalQRCodeInfoType)type
case chip::optionalQRCodeInfoTypeInt32:
return MTROptionalQRCodeInfoTypeInt32;
// No 'default:' so we get a warning if new types are added.
// Note: isEqual: also switches over these types.
// OptionalQRCodeInfo does not support these types
case chip::optionalQRCodeInfoTypeInt64:
case chip::optionalQRCodeInfoTypeUInt32:
Expand Down Expand Up @@ -129,9 +130,14 @@ - (BOOL)isEqual:(id)object
MTROptionalQRCodeInfo * other = object;
VerifyOrReturnValue(_info.tag == other->_info.tag, NO);
VerifyOrReturnValue(_info.type == other->_info.type, NO);
VerifyOrReturnValue(_info.int32 == other->_info.int32, NO);
VerifyOrReturnValue(_info.data == other->_info.data, NO);
return YES;
switch (_info.type) {
case chip::optionalQRCodeInfoTypeString:
return _info.data == other->_info.data;
case chip::optionalQRCodeInfoTypeInt32:
return _info.int32 == other->_info.int32;
default:
return NO; // unreachable, type is checked in init
}
}

- (NSString *)description
Expand Down

0 comments on commit a3466cc

Please sign in to comment.