From 332276139ac813ca55de32537f8112c0e217386a Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 13 Oct 2022 15:52:16 -0400 Subject: [PATCH] Add error outparam to MTRSetupPayload's qrCodeString. (#23178) --- src/darwin/Framework/CHIP/MTRDeviceController.mm | 2 +- src/darwin/Framework/CHIP/MTRSetupPayload.h | 2 +- src/darwin/Framework/CHIP/MTRSetupPayload.mm | 14 +++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index 81da7ed56c1fc4..bbf793d25a4ff4 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -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]; } diff --git a/src/darwin/Framework/CHIP/MTRSetupPayload.h b/src/darwin/Framework/CHIP/MTRSetupPayload.h index c281f3020009a4..c5734e8dda6705 100644 --- a/src/darwin/Framework/CHIP/MTRSetupPayload.h +++ b/src/darwin/Framework/CHIP/MTRSetupPayload.h @@ -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 diff --git a/src/darwin/Framework/CHIP/MTRSetupPayload.mm b/src/darwin/Framework/CHIP/MTRSetupPayload.mm index 5aa74002eef819..159af529f813e0 100644 --- a/src/darwin/Framework/CHIP/MTRSetupPayload.mm +++ b/src/darwin/Framework/CHIP/MTRSetupPayload.mm @@ -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; } @@ -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; }