From 78d6f9a0d8910a285bc55d56376202936d739636 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 15 Sep 2022 12:53:44 -0400 Subject: [PATCH] Remove all mention of "pairing" from Darwin public APIs. Fixes https://github.com/project-chip/connectedhomeip/issues/22674 Addresses part of https://github.com/project-chip/connectedhomeip/issues/22420 --- .../pairing/DeviceControllerDelegateBridge.h | 3 +-- .../pairing/DeviceControllerDelegateBridge.mm | 7 +------ .../commands/tests/TestCommandBridge.h | 12 ++--------- .../QRCode/QRCodeViewController.m | 6 +++--- .../Framework/CHIP/MTRDeviceController.h | 8 ++++---- .../CHIP/MTRDeviceControllerDelegate.h | 20 ++++++------------- .../CHIP/MTRDeviceControllerDelegateBridge.mm | 14 +++---------- src/darwin/Framework/CHIP/MTRSetupPayload.h | 13 +++++++----- .../Framework/CHIPTests/MTRDeviceTests.m | 2 +- .../CHIPTests/MTRXPCListenerSampleTests.m | 2 +- 10 files changed, 30 insertions(+), 57 deletions(-) diff --git a/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.h b/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.h index 1c48daba882f0a..7d62b1ba960fb4 100644 --- a/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.h +++ b/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.h @@ -26,8 +26,7 @@ @property MTRDeviceController * commissioner; @property MTRCommissioningParameters * params; -- (void)onPairingComplete:(NSError *)error; -- (void)onPairingDeleted:(NSError *)error; +- (void)onCommissioningSessionEstablishmentDone:(NSError *)error; - (void)onCommissioningComplete:(NSError *)error; @end diff --git a/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.mm b/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.mm index 2245c01f1aa2dc..0c42416e432683 100644 --- a/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.mm +++ b/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.mm @@ -44,7 +44,7 @@ - (void)onStatusUpdate:(MTRCommissioningStatus)status } } -- (void)onPairingComplete:(NSError *)error +- (void)onCommissioningSessionEstablishmentDone:(NSError *)error { if (error != nil) { ChipLogProgress(chipTool, "PASE establishment failed"); @@ -61,11 +61,6 @@ - (void)onPairingComplete:(NSError *)error } } -- (void)onPairingDeleted:(NSError *)error -{ - _commandBridge->SetCommandExitStatus(error, "Pairing Delete"); -} - - (void)onCommissioningComplete:(NSError *)error { _commandBridge->SetCommandExitStatus(error, "Pairing Commissioning Complete"); diff --git a/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h b/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h index 8c4fe33d0ea87f..8f031981bd82b3 100644 --- a/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h +++ b/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h @@ -49,8 +49,7 @@ constexpr const char * kDefaultKey = "default"; @property BOOL active; // Whether to pass on notifications to the commandBridge - (void)onStatusUpdate:(MTRCommissioningStatus)status; -- (void)onPairingComplete:(NSError * _Nullable)error; -- (void)onPairingDeleted:(NSError * _Nullable)error; +- (void)onCommissioningSessionEstablishmentDone:(NSError * _Nullable)error; - (void)onCommissioningComplete:(NSError * _Nullable)error; - (instancetype)init NS_UNAVAILABLE; @@ -543,7 +542,7 @@ NS_ASSUME_NONNULL_BEGIN } } -- (void)onPairingComplete:(NSError * _Nullable)error +- (void)onCommissioningSessionEstablishmentDone:(NSError * _Nullable)error { if (_active) { if (error != nil) { @@ -557,13 +556,6 @@ NS_ASSUME_NONNULL_BEGIN } } -- (void)onPairingDeleted:(NSError * _Nullable)error -{ - if (_active) { - _commandBridge->PairingDeleted(); - } -} - - (void)onCommissioningComplete:(NSError * _Nullable)error { if (_active) { diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m index 829b8e0bae6d43..16b97f1169e371 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m @@ -419,7 +419,7 @@ - (void)viewDidLoad dispatch_queue_t callbackQueue = dispatch_queue_create("com.csa.matter.qrcodevc.callback", DISPATCH_QUEUE_SERIAL); self.chipController = InitializeMTR(); - [self.chipController setPairingDelegate:self queue:callbackQueue]; + [self.chipController setDeviceControllerDelegate:self queue:callbackQueue]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]; [self.view addGestureRecognizer:tap]; @@ -490,7 +490,7 @@ - (void)setVendorIDOnAccessory } // MARK: MTRDeviceControllerDelegate -- (void)onPairingComplete:(NSError * _Nullable)error +- (void)onCommissioningSessionEstablishmentDone:(NSError * _Nullable)error { if (error != nil) { NSLog(@"Got pairing error back %@", error); @@ -803,7 +803,7 @@ - (void)_restartMatterStack { self.chipController = MTRRestartController(self.chipController); dispatch_queue_t callbackQueue = dispatch_queue_create("com.csa.matter.qrcodevc.callback", DISPATCH_QUEUE_SERIAL); - [self.chipController setPairingDelegate:self queue:callbackQueue]; + [self.chipController setDeviceControllerDelegate:self queue:callbackQueue]; } - (void)handleRendezVousDefault:(NSString *)payload diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.h b/src/darwin/Framework/CHIP/MTRDeviceController.h index c3b49508a1cb87..8bf5e0dcc1b76e 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.h +++ b/src/darwin/Framework/CHIP/MTRDeviceController.h @@ -54,9 +54,9 @@ NS_ASSUME_NONNULL_BEGIN * provided discriminator. * * Then a PASE session will be established with the device, unless an error - * occurs. MTRDevicePairingDelegate will be notified as follows: + * occurs. MTRDeviceControllerDelegate will be notified as follows: * - * * Discovery fails: onStatusUpdate with MTRPairingStatusFailed. + * * Discovery fails: onStatusUpdate with MTRCommissioningStatusFailed. * * * Discovery succeeds but commissioning session setup fails: onPairingComplete * with an error. @@ -103,9 +103,9 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)new NS_UNAVAILABLE; /** - * Set the Delegate for the Device Pairing as well as the Queue on which the Delegate callbacks will be triggered + * Set the Delegate for the device controller as well as the Queue on which the Delegate callbacks will be triggered * - * @param[in] delegate The delegate the pairing process should use + * @param[in] delegate The delegate the commissioning process should use * * @param[in] queue The queue on which the callbacks will be delivered */ diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h index 9fcacd903e216e..b6f7cdf4a72eac 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h @@ -27,36 +27,28 @@ typedef NS_ENUM(NSUInteger, MTRCommissioningStatus) { }; /** - * The protocol definition for the MTRDeviceControllerDelegate + * The protocol definition for the MTRDeviceControllerDelegate. * * All delegate methods will be called on the supplied Delegate Queue. */ @protocol MTRDeviceControllerDelegate @optional /** - * Notify the delegate when pairing status gets updated - * + * Notify the delegate when commissioning status gets updated. */ - (void)onStatusUpdate:(MTRCommissioningStatus)status; /** - * Notify the delegate when pairing is completed - * + * Notify the delegate when a commissioning session is established or the + * establishment has errored out. */ -- (void)onPairingComplete:(NSError * _Nullable)error; +- (void)onCommissioningSessionEstablishmentDone:(NSError * _Nullable)error; /** - * Notify the delegate when commissioning is completed - * + * Notify the delegate when commissioning is completed. */ - (void)onCommissioningComplete:(NSError * _Nullable)error; -/** - * Notify the delegate when pairing is deleted - * - */ -- (void)onPairingDeleted:(NSError * _Nullable)error; - @end NS_ASSUME_NONNULL_END diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm index 7ef07f87ce860c..f84a99e4d2664b 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm @@ -73,11 +73,11 @@ NSLog(@"DeviceControllerDelegate Pairing complete. Status %s", chip::ErrorStr(error)); id strongDelegate = mDelegate; - if ([strongDelegate respondsToSelector:@selector(onPairingComplete:)]) { + if ([strongDelegate respondsToSelector:@selector(onCommissioningSessionEstablishmentDone:)]) { if (strongDelegate && mQueue) { dispatch_async(mQueue, ^{ NSError * nsError = [MTRError errorForCHIPErrorCode:error]; - [strongDelegate onPairingComplete:nsError]; + [strongDelegate onCommissioningSessionEstablishmentDone:nsError]; }); } } @@ -87,15 +87,7 @@ { NSLog(@"DeviceControllerDelegate Pairing deleted. Status %s", chip::ErrorStr(error)); - id strongDelegate = mDelegate; - if ([strongDelegate respondsToSelector:@selector(onPairingDeleted:)]) { - if (strongDelegate && mQueue) { - dispatch_async(mQueue, ^{ - NSError * nsError = [MTRError errorForCHIPErrorCode:error]; - [strongDelegate onPairingDeleted:nsError]; - }); - } - } + // This is never actually called; just do nothing. } void MTRDeviceControllerDelegateBridge::OnCommissioningComplete(chip::NodeId nodeId, CHIP_ERROR error) diff --git a/src/darwin/Framework/CHIP/MTRSetupPayload.h b/src/darwin/Framework/CHIP/MTRSetupPayload.h index 721ccdd67a5781..e8c363961a2c77 100644 --- a/src/darwin/Framework/CHIP/MTRSetupPayload.h +++ b/src/darwin/Framework/CHIP/MTRSetupPayload.h @@ -20,7 +20,8 @@ NS_ASSUME_NONNULL_BEGIN typedef NS_OPTIONS(NSUInteger, MTRDiscoveryCapabilities) { - MTRDiscoveryCapabilitiesUnknown = 0, // Device capabilties are not known (e.g. all we have is a manual pairing code). + MTRDiscoveryCapabilitiesUnknown = 0, // Device capabilties are not known + // (e.g. all we have is a numeric code). MTRDiscoveryCapabilitiesSoftAP = 1 << 0, // Device supports WiFi softAP MTRDiscoveryCapabilitiesBLE = 1 << 1, // Device supports BLE MTRDiscoveryCapabilitiesOnNetwork = 1 << 2, // Device supports On Network setup @@ -30,8 +31,8 @@ typedef NS_OPTIONS(NSUInteger, MTRDiscoveryCapabilities) { }; typedef NS_ENUM(NSUInteger, MTRCommissioningFlow) { - MTRCommissioningFlowStandard = 0, // Device automatically enters pairing mode upon power-up - MTRCommissioningFlowUserActionRequired = 1, // Device requires a user interaction to enter pairing mode + MTRCommissioningFlowStandard = 0, // Device automatically enters commissioning mode upon power-up + MTRCommissioningFlowUserActionRequired = 1, // Device requires a user interaction to enter commissioning mode MTRCommissioningFlowCustom = 2, // Commissioning steps should be retrieved from the distributed compliance ledger MTRCommissioningFlowInvalid = 3, }; @@ -53,8 +54,10 @@ typedef NS_ENUM(NSUInteger, MTROptionalQRCodeInfoType) { MTROptionalQRCodeInfoTy @end /** - * A setup payload that can be created from a pairing code and serialized to a - * pairing code. + * A setup payload that can be created from a numeric code or QR code and + * serialized to a numeric code or QR code, though serializing to QR code after + * creating from numeric code will not work, because some required information + * will be missing. */ @interface MTRSetupPayload : NSObject diff --git a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m index cd14933a3caee7..02d33fd8bba8e7 100644 --- a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m +++ b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m @@ -91,7 +91,7 @@ - (id)initWithExpectation:(XCTestExpectation *)expectation return self; } -- (void)onPairingComplete:(NSError *)error +- (void)onCommissioningSessionEstablishmentDone:(NSError *)error { XCTAssertEqual(error.code, 0); diff --git a/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m b/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m index 0c285aba126fb7..90e7f8323511b0 100644 --- a/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m +++ b/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m @@ -398,7 +398,7 @@ - (id)initWithExpectation:(XCTestExpectation *)expectation return self; } -- (void)onPairingComplete:(NSError *)error +- (void)onCommissioningSessionEstablishmentDone:(NSError *)error { XCTAssertEqual(error.code, 0); NSError * commissionError = nil;