Skip to content

Commit

Permalink
Add error outparam to MTRSetupPayload's qrCodeString. (#23178)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored Oct 13, 2022
1 parent 638a3f9 commit 6eccf8c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ - (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload

// Try to get a QR code if possible (because it has a better
// discriminator, etc), then fall back to manual code if that fails.
NSString * pairingCode = [payload qrCodeString];
NSString * pairingCode = [payload qrCodeString:nil];
if (pairingCode == nil) {
pairingCode = [payload manualEntryCode];
}
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRSetupPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ typedef NS_ENUM(NSUInteger, MTROptionalQRCodeInfoType) {
* Returns nil on failure (e.g. if the setup payload does not have all the
* information a QR code needs).
*/
- (NSString * _Nullable)qrCodeString;
- (NSString * _Nullable)qrCodeString:(NSError * __autoreleasing *)error;

@end

Expand Down
14 changes: 13 additions & 1 deletion src/darwin/Framework/CHIP/MTRSetupPayload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,29 @@ - (nullable NSString *)manualEntryCode
return [NSString stringWithUTF8String:outDecimalString.c_str()];
}

- (NSString * _Nullable)qrCodeString
- (NSString * _Nullable)qrCodeString:(NSError * __autoreleasing *)error
{
if (self.commissioningFlow == MTRCommissioningFlowInvalid) {
// No idea how to map this to the standard codes.
if (error != nil) {
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE];
}
return nil;
}

if (self.hasShortDiscriminator) {
// Can't create a QR code with a short discriminator.
if (error != nil) {
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE];
}
return nil;
}

if (self.rendezvousInformation == nil) {
// Can't create a QR code if we don't know the discovery capabilities.
if (error != nil) {
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE];
}
return nil;
}

Expand All @@ -320,6 +329,9 @@ - (NSString * _Nullable)qrCodeString
CHIP_ERROR err = chip::QRCodeSetupPayloadGenerator(payload).payloadBase38Representation(outDecimalString);

if (err != CHIP_NO_ERROR) {
if (error != nil) {
*error = [MTRError errorForCHIPErrorCode:err];
}
return nil;
}

Expand Down

0 comments on commit 6eccf8c

Please sign in to comment.