Skip to content

Commit

Permalink
Remove all mention of "pairing" from non-deprecated Darwin public API…
Browse files Browse the repository at this point in the history
…s. (#23647)

This is a re-landing of PR #22676, but with backwards-compat shims in place.

The change to MTRDeviceControllerDelegate is OK because this is a
newly-introduced protocol.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jun 5, 2023
1 parent 5fe027f commit 8384013
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (void)onStatusUpdate:(MTRCommissioningStatus)status
}
}

- (void)onPairingComplete:(NSError *)error
- (void)onCommissioningSessionEstablishmentDone:(NSError *)error
{
if (error != nil) {
ChipLogProgress(chipTool, "PASE establishment failed");
Expand All @@ -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");
Expand Down
12 changes: 2 additions & 10 deletions examples/darwin-framework-tool/commands/tests/TestCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -543,7 +542,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}

- (void)onPairingComplete:(NSError * _Nullable)error
- (void)onCommissioningSessionEstablishmentDone:(NSError * _Nullable)error
{
if (_active) {
if (error != nil) {
Expand All @@ -557,13 +556,6 @@ NS_ASSUME_NONNULL_BEGIN
}
}

- (void)onPairingDeleted:(NSError * _Nullable)error
{
if (_active) {
_commandBridge->PairingDeleted();
}
}

- (void)onCommissioningComplete:(NSError * _Nullable)error
{
if (_active) {
Expand Down
8 changes: 4 additions & 4 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
* 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.
Expand Down Expand Up @@ -109,9 +109,9 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
+ (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
*/
Expand Down
8 changes: 2 additions & 6 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -850,18 +850,14 @@ - (BOOL)respondsToSelector:(SEL)selector
return [self.delegate respondsToSelector:@selector(onStatusUpdate:)];
}

if (selector == @selector(onPairingComplete:)) {
if (selector == @selector(onCommissioningSessionEstablishmentDone:)) {
return [self.delegate respondsToSelector:@selector(onPairingComplete:)];
}

if (selector == @selector(onCommissioningComplete:)) {
return [self.delegate respondsToSelector:@selector(onCommissioningComplete:)];
}

if (selector == @selector(onPairingDeleted:)) {
return [self.delegate respondsToSelector:@selector(onPairingDeleted:)];
}

return [super respondsToSelector:selector];
}

Expand All @@ -870,7 +866,7 @@ - (void)onStatusUpdate:(MTRCommissioningStatus)status
[self.delegate onStatusUpdate:static_cast<MTRPairingStatus>(status)];
}

- (void)onPairingComplete:(NSError * _Nullable)error
- (void)onCommissioningSessionEstablishmentDone:(NSError * _Nullable)error
{
[self.delegate onPairingComplete:error];
}
Expand Down
20 changes: 6 additions & 14 deletions src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,29 @@ typedef NS_ENUM(NSInteger, MTRCommissioningStatus) {
} MTR_NEWLY_AVAILABLE;

/**
* The protocol definition for the MTRDeviceControllerDelegate
* The protocol definition for the MTRDeviceControllerDelegate.
*
* All delegate methods will be called on the supplied Delegate Queue.
*/
MTR_NEWLY_AVAILABLE
@protocol MTRDeviceControllerDelegate <NSObject>
@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

typedef NS_ENUM(NSUInteger, MTRPairingStatus) {
Expand Down
14 changes: 3 additions & 11 deletions src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@
NSLog(@"DeviceControllerDelegate Pairing complete. Status %s", chip::ErrorStr(error));

id<MTRDeviceControllerDelegate> 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];
});
}
}
Expand All @@ -87,15 +87,7 @@
{
NSLog(@"DeviceControllerDelegate Pairing deleted. Status %s", chip::ErrorStr(error));

id<MTRDeviceControllerDelegate> 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)
Expand Down
12 changes: 7 additions & 5 deletions src/darwin/Framework/CHIP/MTRSetupPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
NS_ASSUME_NONNULL_BEGIN

typedef NS_OPTIONS(NSUInteger, MTRDiscoveryCapabilities) {
MTRDiscoveryCapabilitiesUnknown = 0, // Device capabilities are not known (e.g. all we have is a manual pairing code).
MTRDiscoveryCapabilitiesUnknown = 0, // Device capabilities are not known (e.g. all we have is a numeric code).
MTRDiscoveryCapabilitiesNone MTR_NEWLY_DEPRECATED("Please use MTRDiscoveryCapabilitiesUnknown") = 0,
MTRDiscoveryCapabilitiesSoftAP = 1 << 0, // Device supports WiFi softAP
MTRDiscoveryCapabilitiesBLE = 1 << 1, // Device supports BLE
Expand All @@ -31,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,
};
Expand All @@ -58,8 +58,10 @@ typedef NS_ENUM(NSUInteger, MTROptionalQRCodeInfoType) {
@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 <NSSecureCoding>

Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ - (id)initWithExpectation:(XCTestExpectation *)expectation
return self;
}

- (void)onPairingComplete:(NSError *)error
- (void)onCommissioningSessionEstablishmentDone:(NSError *)error
{
XCTAssertEqual(error.code, 0);

Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ - (id)initWithExpectation:(XCTestExpectation *)expectation
return self;
}

- (void)onPairingComplete:(NSError *)error
- (void)onCommissioningSessionEstablishmentDone:(NSError *)error
{
XCTAssertEqual(error.code, 0);
NSError * commissionError = nil;
Expand Down

0 comments on commit 8384013

Please sign in to comment.