From f67c1b7a715939e15018f83ae3ebcd75625e929a Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 16 Nov 2022 11:03:02 -0500 Subject: [PATCH] [Darwin] Rename MTRDevicePairingDelegate to MTRDeviceControllerDelegate and MTRPairingStatus to MTRCommissioningStatus (#23587) * [Darwin] Rename MTRDevicePairingDelegate to MTRDeviceControllerDelegate and MTRPairingStatus to MTRCommissioningStatus This is a re-landing of PR #22633 but with changes made for backwards compat. * [Darwin] Rename MTRDevicePairingDelegate to MTRDeviceControllerDelegate * [Darwin] Rename MTRPairingStatus to MTRCommissioningStatus * Add backwards compat shims for the old APIs. * Address review comments. Co-authored-by: Vivien Nicolas --- examples/darwin-framework-tool/BUILD.gn | 2 +- ...dge.h => DeviceControllerDelegateBridge.h} | 2 +- ...e.mm => DeviceControllerDelegateBridge.mm} | 16 ++-- .../commands/pairing/PairingCommandBridge.h | 2 +- .../commands/pairing/PairingCommandBridge.mm | 20 ++--- .../commands/tests/TestCommandBridge.h | 22 ++--- .../Framework/CHIP/MTRDeviceController.h | 6 +- .../Framework/CHIP/MTRDeviceController.mm | 90 ++++++++++++++++--- ...legate.h => MTRDeviceControllerDelegate.h} | 36 ++++++-- ....h => MTRDeviceControllerDelegateBridge.h} | 14 +-- ...m => MTRDeviceControllerDelegateBridge.mm} | 46 +++++----- src/darwin/Framework/CHIP/Matter.h | 2 +- .../Framework/CHIPTests/MTRDeviceTests.m | 11 +-- .../CHIPTests/MTRXPCListenerSampleTests.m | 12 +-- .../Matter.xcodeproj/project.pbxproj | 24 ++--- 15 files changed, 199 insertions(+), 106 deletions(-) rename examples/darwin-framework-tool/commands/pairing/{PairingDelegateBridge.h => DeviceControllerDelegateBridge.h} (92%) rename examples/darwin-framework-tool/commands/pairing/{PairingDelegateBridge.mm => DeviceControllerDelegateBridge.mm} (84%) rename src/darwin/Framework/CHIP/{MTRDevicePairingDelegate.h => MTRDeviceControllerDelegate.h} (54%) rename src/darwin/Framework/CHIP/{MTRDevicePairingDelegateBridge.h => MTRDeviceControllerDelegateBridge.h} (71%) rename src/darwin/Framework/CHIP/{MTRDevicePairingDelegateBridge.mm => MTRDeviceControllerDelegateBridge.mm} (57%) diff --git a/examples/darwin-framework-tool/BUILD.gn b/examples/darwin-framework-tool/BUILD.gn index d71e0501e1cf32..5a9fbabfbbe5b2 100644 --- a/examples/darwin-framework-tool/BUILD.gn +++ b/examples/darwin-framework-tool/BUILD.gn @@ -128,10 +128,10 @@ executable("darwin-framework-tool") { "commands/common/MTRError_Utils.h", "commands/common/MTRLogging.h", "commands/pairing/Commands.h", + "commands/pairing/DeviceControllerDelegateBridge.mm", "commands/pairing/OpenCommissioningWindowCommand.h", "commands/pairing/OpenCommissioningWindowCommand.mm", "commands/pairing/PairingCommandBridge.mm", - "commands/pairing/PairingDelegateBridge.mm", "commands/payload/SetupPayloadParseCommand.mm", "commands/provider/Commands.h", "commands/provider/OTAProviderDelegate.mm", diff --git a/examples/darwin-framework-tool/commands/pairing/PairingDelegateBridge.h b/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.h similarity index 92% rename from examples/darwin-framework-tool/commands/pairing/PairingDelegateBridge.h rename to examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.h index e295e084725701..1c48daba882f0a 100644 --- a/examples/darwin-framework-tool/commands/pairing/PairingDelegateBridge.h +++ b/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.h @@ -20,7 +20,7 @@ #import -@interface CHIPToolPairingDelegate : NSObject +@interface CHIPToolDeviceControllerDelegate : NSObject @property PairingCommandBridge * commandBridge; @property chip::NodeId deviceID; @property MTRDeviceController * commissioner; diff --git a/examples/darwin-framework-tool/commands/pairing/PairingDelegateBridge.mm b/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.mm similarity index 84% rename from examples/darwin-framework-tool/commands/pairing/PairingDelegateBridge.mm rename to examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.mm index 5ea335271bce9a..e83f81089b45b8 100644 --- a/examples/darwin-framework-tool/commands/pairing/PairingDelegateBridge.mm +++ b/examples/darwin-framework-tool/commands/pairing/DeviceControllerDelegateBridge.mm @@ -16,29 +16,29 @@ * */ -#include "PairingDelegateBridge.h" +#include "DeviceControllerDelegateBridge.h" #import -@interface CHIPToolPairingDelegate () +@interface CHIPToolDeviceControllerDelegate () @end -@implementation CHIPToolPairingDelegate -- (void)onStatusUpdate:(MTRPairingStatus)status +@implementation CHIPToolDeviceControllerDelegate +- (void)onStatusUpdate:(MTRCommissioningStatus)status { NSLog(@"Pairing Status Update: %tu", status); switch (status) { - case MTRPairingStatusSuccess: + case MTRCommissioningStatusSuccess: ChipLogProgress(chipTool, "Secure Pairing Success"); ChipLogProgress(chipTool, "CASE establishment successful"); break; - case MTRPairingStatusFailed: + case MTRCommissioningStatusFailed: ChipLogError(chipTool, "Secure Pairing Failed"); _commandBridge->SetCommandExitStatus(CHIP_ERROR_INCORRECT_STATE); break; - case MTRPairingStatusDiscoveringMoreDevices: + case MTRCommissioningStatusDiscoveringMoreDevices: ChipLogProgress(chipTool, "Secure Pairing Discovering More Devices"); break; - case MTRPairingStatusUnknown: + case MTRCommissioningStatusUnknown: ChipLogError(chipTool, "Uknown Pairing Status"); break; } diff --git a/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.h b/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.h index 4885b328c8ad9a..1b098adba25937 100644 --- a/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.h +++ b/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.h @@ -78,7 +78,7 @@ class PairingCommandBridge : public CHIPCommandBridge void PairWithCode(NSError * __autoreleasing * error); void PairWithPayload(NSError * __autoreleasing * error); void Unpair(); - void SetUpPairingDelegate(); + void SetUpDeviceControllerDelegate(); const PairingMode mPairingMode; const PairingNetworkType mNetworkType; diff --git a/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm b/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm index a05e9ab2eddf7e..beb8cfcec08327 100644 --- a/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm +++ b/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm @@ -19,8 +19,8 @@ #import #include "../common/CHIPCommandBridge.h" +#include "DeviceControllerDelegateBridge.h" #include "PairingCommandBridge.h" -#include "PairingDelegateBridge.h" #include #import "MTRError_Utils.h" @@ -28,14 +28,14 @@ using namespace ::chip; using namespace ::chip::Controller; -void PairingCommandBridge::SetUpPairingDelegate() +void PairingCommandBridge::SetUpDeviceControllerDelegate() { dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.pairing", DISPATCH_QUEUE_SERIAL); - CHIPToolPairingDelegate * pairing = [[CHIPToolPairingDelegate alloc] init]; + CHIPToolDeviceControllerDelegate * deviceControllerDelegate = [[CHIPToolDeviceControllerDelegate alloc] init]; MTRCommissioningParameters * params = [[MTRCommissioningParameters alloc] init]; MTRDeviceController * commissioner = CurrentCommissioner(); - [pairing setDeviceID:mNodeId]; + [deviceControllerDelegate setDeviceID:mNodeId]; switch (mNetworkType) { case PairingNetworkType::None: case PairingNetworkType::Ethernet: @@ -49,11 +49,11 @@ break; } - [pairing setCommandBridge:this]; - [pairing setParams:params]; - [pairing setCommissioner:commissioner]; + [deviceControllerDelegate setCommandBridge:this]; + [deviceControllerDelegate setParams:params]; + [deviceControllerDelegate setCommissioner:commissioner]; - [commissioner setPairingDelegate:pairing queue:callbackQueue]; + [commissioner setDeviceControllerDelegate:deviceControllerDelegate queue:callbackQueue]; } CHIP_ERROR PairingCommandBridge::RunCommand() @@ -79,7 +79,7 @@ void PairingCommandBridge::PairWithCode(NSError * __autoreleasing * error) { - SetUpPairingDelegate(); + SetUpDeviceControllerDelegate(); auto * payload = [[MTRSetupPayload alloc] initWithSetupPasscode:@(mSetupPINCode) discriminator:@(mDiscriminator)]; MTRDeviceController * commissioner = CurrentCommissioner(); [commissioner setupCommissioningSessionWithPayload:payload newNodeID:@(mNodeId) error:error]; @@ -88,7 +88,7 @@ void PairingCommandBridge::PairWithPayload(NSError * __autoreleasing * error) { NSString * onboardingPayload = [NSString stringWithUTF8String:mOnboardingPayload]; - SetUpPairingDelegate(); + SetUpDeviceControllerDelegate(); auto * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:onboardingPayload error:error]; if (payload == nil) { return; diff --git a/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h b/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h index 03f6b70aae719b..8c4fe33d0ea87f 100644 --- a/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h +++ b/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h @@ -43,12 +43,12 @@ const char * getScriptsFolder() { return basePath; } constexpr const char * kDefaultKey = "default"; -@interface TestPairingDelegate : NSObject +@interface TestDeviceControllerDelegate : NSObject @property TestCommandBridge * commandBridge; @property chip::NodeId deviceId; @property BOOL active; // Whether to pass on notifications to the commandBridge -- (void)onStatusUpdate:(MTRPairingStatus)status; +- (void)onStatusUpdate:(MTRCommissioningStatus)status; - (void)onPairingComplete:(NSError * _Nullable)error; - (void)onPairingDeleted:(NSError * _Nullable)error; - (void)onCommissioningComplete:(NSError * _Nullable)error; @@ -70,7 +70,7 @@ class TestCommandBridge : public CHIPCommandBridge, public: TestCommandBridge(const char * _Nonnull commandName) : CHIPCommandBridge(commandName) - , mPairingDelegate([[TestPairingDelegate alloc] initWithTestCommandBridge:this]) + , mDeviceControllerDelegate([[TestDeviceControllerDelegate alloc] initWithTestCommandBridge:this]) { AddArgument("delayInMs", 0, UINT64_MAX, &mDelayInMs); AddArgument("PICS", &mPICSFilePath); @@ -183,9 +183,9 @@ class TestCommandBridge : public CHIPCommandBridge, SetIdentity(identity); - [controller setPairingDelegate:mPairingDelegate queue:mCallbackQueue]; - [mPairingDelegate setDeviceId:value.nodeId]; - [mPairingDelegate setActive:YES]; + [controller setDeviceControllerDelegate:mDeviceControllerDelegate queue:mCallbackQueue]; + [mDeviceControllerDelegate setDeviceId:value.nodeId]; + [mDeviceControllerDelegate setActive:YES]; NSString * payloadStr = [[NSString alloc] initWithBytes:value.payload.data() length:value.payload.size() @@ -521,7 +521,7 @@ class TestCommandBridge : public CHIPCommandBridge, } private: - TestPairingDelegate * _Nonnull mPairingDelegate; + TestDeviceControllerDelegate * _Nonnull mDeviceControllerDelegate; // Set of our connected devices, keyed by identity. std::map mConnectedDevices; @@ -529,13 +529,13 @@ class TestCommandBridge : public CHIPCommandBridge, NS_ASSUME_NONNULL_BEGIN -@implementation TestPairingDelegate -- (void)onStatusUpdate:(MTRPairingStatus)status +@implementation TestDeviceControllerDelegate +- (void)onStatusUpdate:(MTRCommissioningStatus)status { if (_active) { - if (status == MTRPairingStatusSuccess) { + if (status == MTRCommissioningStatusSuccess) { NSLog(@"Secure pairing success"); - } else if (status == MTRPairingStatusFailed) { + } else if (status == MTRCommissioningStatusFailed) { _active = NO; NSLog(@"Secure pairing failed"); _commandBridge->OnStatusUpdate(chip::app::StatusIB(chip::Protocols::InteractionModel::Status::Failure)); diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.h b/src/darwin/Framework/CHIP/MTRDeviceController.h index 3ba788bbbfc5f6..4f46861da7de3c 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.h +++ b/src/darwin/Framework/CHIP/MTRDeviceController.h @@ -29,6 +29,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS @class MTRCommissioningParameters; @class MTRSetupPayload; @protocol MTRDevicePairingDelegate; +@protocol MTRDeviceControllerDelegate; @interface MTRDeviceController : NSObject @@ -114,7 +115,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS * * @param[in] queue The queue on which the callbacks will be delivered */ -- (void)setPairingDelegate:(id)delegate queue:(dispatch_queue_t)queue; +- (void)setDeviceControllerDelegate:(id)delegate queue:(dispatch_queue_t)queue MTR_NEWLY_AVAILABLE; /** * Sets this MTRDeviceController to use the given issuer for issuing operational certs. By default, the MTRDeviceController uses an @@ -217,6 +218,9 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS salt:(NSData *)salt MTR_NEWLY_DEPRECATED("Please use computePASEVerifierForSetupPasscode:iterations:salt:error:"); +- (void)setPairingDelegate:(id)delegate + queue:(dispatch_queue_t)queue MTR_NEWLY_DEPRECATED("Please use setDeviceControllerDelegate:"); + @end NS_ASSUME_NONNULL_END diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index 33de705b8fc660..9dadeb117ce406 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -20,10 +20,10 @@ #import "MTRBaseDevice_Internal.h" #import "MTRCommissioningParameters.h" +#import "MTRDeviceControllerDelegateBridge.h" #import "MTRDeviceControllerFactory_Internal.h" #import "MTRDeviceControllerStartupParams.h" #import "MTRDeviceControllerStartupParams_Internal.h" -#import "MTRDevicePairingDelegateBridge.h" #import "MTRDevice_Internal.h" #import "MTRError_Internal.h" #import "MTRKeypair.h" @@ -84,7 +84,7 @@ @interface MTRDeviceController () @property (readonly) chip::Controller::DeviceCommissioner * cppCommissioner; @property (readonly) chip::Credentials::PartialDACVerifier * partialDACVerifier; -@property (readonly) MTRDevicePairingDelegateBridge * pairingDelegateBridge; +@property (readonly) MTRDeviceControllerDelegateBridge * deviceControllerDelegateBridge; @property (readonly) MTROperationalCredentialsDelegate * operationalCredentialsDelegate; @property (readonly) MTRP256KeypairBridge signingKeypairBridge; @property (readonly) MTRP256KeypairBridge operationalKeypairBridge; @@ -104,8 +104,8 @@ - (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory queue:(dis _deviceMapLock = OS_UNFAIR_LOCK_INIT; _nodeIDToDeviceMap = [NSMutableDictionary dictionary]; - _pairingDelegateBridge = new MTRDevicePairingDelegateBridge(); - if ([self checkForInitError:(_pairingDelegateBridge != nullptr) logMsg:kErrorPairingInit]) { + _deviceControllerDelegateBridge = new MTRDeviceControllerDelegateBridge(); + if ([self checkForInitError:(_deviceControllerDelegateBridge != nullptr) logMsg:kErrorPairingInit]) { return nil; } @@ -184,9 +184,9 @@ - (void)cleanup _partialDACVerifier = nullptr; } - if (_pairingDelegateBridge) { - delete _pairingDelegateBridge; - _pairingDelegateBridge = nullptr; + if (_deviceControllerDelegateBridge) { + delete _deviceControllerDelegateBridge; + _deviceControllerDelegateBridge = nullptr; } } @@ -256,7 +256,7 @@ - (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams chip::Controller::SetupParams commissionerParams; - commissionerParams.pairingDelegate = _pairingDelegateBridge; + commissionerParams.pairingDelegate = _deviceControllerDelegateBridge; _operationalCredentialsDelegate->SetDeviceCommissioner(_cppCommissioner); @@ -535,14 +535,14 @@ - (void)removeDevice:(MTRDevice *)device os_unfair_lock_unlock(&_deviceMapLock); } -- (void)setPairingDelegate:(id)delegate queue:(dispatch_queue_t)queue +- (void)setDeviceControllerDelegate:(id)delegate queue:(dispatch_queue_t)queue { VerifyOrReturn([self checkIsRunning]); dispatch_async(_chipWorkQueue, ^{ VerifyOrReturn([self checkIsRunning]); - self->_pairingDelegateBridge->setDelegate(delegate, queue); + self->_deviceControllerDelegateBridge->setDelegate(delegate, queue); }); } @@ -823,6 +823,70 @@ - (void)invalidateCASESessionForNode:(chip::NodeId)nodeID; } @end +/** + * Shim to allow us to treat an MTRDevicePairingDelegate as an + * MTRDeviceControllerDelegate. + */ +@interface MTRDevicePairingDelegateShim : NSObject +@property (nonatomic, readonly) id delegate; +- (instancetype)initWithDelegate:(id)delegate; +@end + +@implementation MTRDevicePairingDelegateShim +- (instancetype)initWithDelegate:(id)delegate +{ + if (self = [super init]) { + _delegate = delegate; + } + return self; +} + +- (BOOL)respondsToSelector:(SEL)selector +{ + // This logic will need to change a bit when the MTRDeviceControllerDelegate + // signatures change. It's shaped the way it is to make those changes + // easier. + if (selector == @selector(onStatusUpdate:)) { + return [self.delegate respondsToSelector:@selector(onStatusUpdate:)]; + } + + if (selector == @selector(onPairingComplete:)) { + 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]; +} + +- (void)onStatusUpdate:(MTRCommissioningStatus)status +{ + [self.delegate onStatusUpdate:static_cast(status)]; +} + +- (void)onPairingComplete:(NSError * _Nullable)error +{ + [self.delegate onPairingComplete:error]; +} + +- (void)onCommissioningComplete:(NSError * _Nullable)error +{ + [self.delegate onCommissioningComplete:error]; +} + +- (void)onPairingDeleted:(NSError * _Nullable)error +{ + [self.delegate onPairingDeleted:error]; +} + +@end + @implementation MTRDeviceController (Deprecated) - (NSNumber *)controllerNodeId @@ -1040,4 +1104,10 @@ - (nullable NSData *)computePaseVerifier:(uint32_t)setupPincode iterations:(uint return [MTRDeviceController computePASEVerifierForSetupPasscode:@(setupPincode) iterations:@(iterations) salt:salt error:nil]; } +- (void)setPairingDelegate:(id)delegate queue:(dispatch_queue_t)queue +{ + auto * delegateShim = [[MTRDevicePairingDelegateShim alloc] initWithDelegate:delegate]; + [self setDeviceControllerDelegate:delegateShim queue:queue]; +} + @end diff --git a/src/darwin/Framework/CHIP/MTRDevicePairingDelegate.h b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h similarity index 54% rename from src/darwin/Framework/CHIP/MTRDevicePairingDelegate.h rename to src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h index 0ecce764b66908..fc0c0d9ec2d008 100644 --- a/src/darwin/Framework/CHIP/MTRDevicePairingDelegate.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h @@ -19,25 +19,26 @@ NS_ASSUME_NONNULL_BEGIN -typedef NS_ENUM(NSUInteger, MTRPairingStatus) { - MTRPairingStatusUnknown = 0, - MTRPairingStatusSuccess = 1, - MTRPairingStatusFailed = 2, - MTRPairingStatusDiscoveringMoreDevices = 3 -}; +typedef NS_ENUM(NSInteger, MTRCommissioningStatus) { + MTRCommissioningStatusUnknown = 0, + MTRCommissioningStatusSuccess = 1, + MTRCommissioningStatusFailed = 2, + MTRCommissioningStatusDiscoveringMoreDevices = 3 +} MTR_NEWLY_AVAILABLE; /** - * The protocol definition for the MTRDevicePairingDelegate + * The protocol definition for the MTRDeviceControllerDelegate * * All delegate methods will be called on the supplied Delegate Queue. */ -@protocol MTRDevicePairingDelegate +MTR_NEWLY_AVAILABLE +@protocol MTRDeviceControllerDelegate @optional /** * Notify the delegate when pairing status gets updated * */ -- (void)onStatusUpdate:(MTRPairingStatus)status; +- (void)onStatusUpdate:(MTRCommissioningStatus)status; /** * Notify the delegate when pairing is completed @@ -59,4 +60,21 @@ typedef NS_ENUM(NSUInteger, MTRPairingStatus) { @end +typedef NS_ENUM(NSUInteger, MTRPairingStatus) { + MTRPairingStatusUnknown MTR_NEWLY_DEPRECATED("Please use MTRCommissioningStatusUnknown") = 0, + MTRPairingStatusSuccess MTR_NEWLY_DEPRECATED("Please use MTRCommissioningStatusSuccess") = 1, + MTRPairingStatusFailed MTR_NEWLY_DEPRECATED("Please use MTRCommissioningStatusFailed") = 2, + MTRPairingStatusDiscoveringMoreDevices MTR_NEWLY_DEPRECATED("Please use MTRCommissioningStatusDiscoveringMoreDevices") = 3 +} MTR_NEWLY_DEPRECATED("Please use MTRCommissioningStatus"); + +MTR_NEWLY_DEPRECATED("Please use MTRDeviceControllerDelegate") +@protocol MTRDevicePairingDelegate +@optional +- (void)onStatusUpdate:(MTRPairingStatus)status; +- (void)onPairingComplete:(NSError * _Nullable)error; +- (void)onCommissioningComplete:(NSError * _Nullable)error; +- (void)onPairingDeleted:(NSError * _Nullable)error; + +@end + NS_ASSUME_NONNULL_END diff --git a/src/darwin/Framework/CHIP/MTRDevicePairingDelegateBridge.h b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.h similarity index 71% rename from src/darwin/Framework/CHIP/MTRDevicePairingDelegateBridge.h rename to src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.h index a932319aaf4352..299e85b6a3b5ae 100644 --- a/src/darwin/Framework/CHIP/MTRDevicePairingDelegateBridge.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.h @@ -15,20 +15,20 @@ * limitations under the License. */ -#import "MTRDevicePairingDelegate.h" +#import "MTRDeviceControllerDelegate.h" #include #include NS_ASSUME_NONNULL_BEGIN -class MTRDevicePairingDelegateBridge : public chip::Controller::DevicePairingDelegate +class MTRDeviceControllerDelegateBridge : public chip::Controller::DevicePairingDelegate { public: - MTRDevicePairingDelegateBridge(); - ~MTRDevicePairingDelegateBridge(); + MTRDeviceControllerDelegateBridge(); + ~MTRDeviceControllerDelegateBridge(); - void setDelegate(id delegate, dispatch_queue_t queue); + void setDelegate(id delegate, dispatch_queue_t queue); void OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) override; @@ -39,10 +39,10 @@ class MTRDevicePairingDelegateBridge : public chip::Controller::DevicePairingDel void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR error) override; private: - _Nullable id mDelegate; + _Nullable id mDelegate; _Nullable dispatch_queue_t mQueue; - MTRPairingStatus MapStatus(chip::Controller::DevicePairingDelegate::Status status); + MTRCommissioningStatus MapStatus(chip::Controller::DevicePairingDelegate::Status status); }; NS_ASSUME_NONNULL_END diff --git a/src/darwin/Framework/CHIP/MTRDevicePairingDelegateBridge.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm similarity index 57% rename from src/darwin/Framework/CHIP/MTRDevicePairingDelegateBridge.mm rename to src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm index f0393f562d8262..7ef07f87ce860c 100644 --- a/src/darwin/Framework/CHIP/MTRDevicePairingDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm @@ -15,17 +15,17 @@ * limitations under the License. */ -#import "MTRDevicePairingDelegateBridge.h" +#import "MTRDeviceControllerDelegateBridge.h" #import "MTRError_Internal.h" -MTRDevicePairingDelegateBridge::MTRDevicePairingDelegateBridge(void) +MTRDeviceControllerDelegateBridge::MTRDeviceControllerDelegateBridge(void) : mDelegate(nil) { } -MTRDevicePairingDelegateBridge::~MTRDevicePairingDelegateBridge(void) {} +MTRDeviceControllerDelegateBridge::~MTRDeviceControllerDelegateBridge(void) {} -void MTRDevicePairingDelegateBridge::setDelegate(id delegate, dispatch_queue_t queue) +void MTRDeviceControllerDelegateBridge::setDelegate(id delegate, dispatch_queue_t queue) { if (delegate && queue) { mDelegate = delegate; @@ -36,43 +36,43 @@ } } -MTRPairingStatus MTRDevicePairingDelegateBridge::MapStatus(chip::Controller::DevicePairingDelegate::Status status) +MTRCommissioningStatus MTRDeviceControllerDelegateBridge::MapStatus(chip::Controller::DevicePairingDelegate::Status status) { - MTRPairingStatus rv = MTRPairingStatusUnknown; + MTRCommissioningStatus rv = MTRCommissioningStatusUnknown; switch (status) { case chip::Controller::DevicePairingDelegate::Status::SecurePairingSuccess: - rv = MTRPairingStatusSuccess; + rv = MTRCommissioningStatusSuccess; break; case chip::Controller::DevicePairingDelegate::Status::SecurePairingFailed: - rv = MTRPairingStatusFailed; + rv = MTRCommissioningStatusFailed; break; case chip::Controller::DevicePairingDelegate::Status::SecurePairingDiscoveringMoreDevices: - rv = MTRPairingStatusDiscoveringMoreDevices; + rv = MTRCommissioningStatusDiscoveringMoreDevices; break; } return rv; } -void MTRDevicePairingDelegateBridge::OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) +void MTRDeviceControllerDelegateBridge::OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) { - NSLog(@"DevicePairingDelegate status updated: %d", status); + NSLog(@"DeviceControllerDelegate status updated: %d", status); - id strongDelegate = mDelegate; + id strongDelegate = mDelegate; if ([strongDelegate respondsToSelector:@selector(onStatusUpdate:)]) { if (strongDelegate && mQueue) { - MTRPairingStatus pairingStatus = MapStatus(status); + MTRCommissioningStatus commissioningStatus = MapStatus(status); dispatch_async(mQueue, ^{ - [strongDelegate onStatusUpdate:pairingStatus]; + [strongDelegate onStatusUpdate:commissioningStatus]; }); } } } -void MTRDevicePairingDelegateBridge::OnPairingComplete(CHIP_ERROR error) +void MTRDeviceControllerDelegateBridge::OnPairingComplete(CHIP_ERROR error) { - NSLog(@"DevicePairingDelegate Pairing complete. Status %s", chip::ErrorStr(error)); + NSLog(@"DeviceControllerDelegate Pairing complete. Status %s", chip::ErrorStr(error)); - id strongDelegate = mDelegate; + id strongDelegate = mDelegate; if ([strongDelegate respondsToSelector:@selector(onPairingComplete:)]) { if (strongDelegate && mQueue) { dispatch_async(mQueue, ^{ @@ -83,11 +83,11 @@ } } -void MTRDevicePairingDelegateBridge::OnPairingDeleted(CHIP_ERROR error) +void MTRDeviceControllerDelegateBridge::OnPairingDeleted(CHIP_ERROR error) { - NSLog(@"DevicePairingDelegate Pairing deleted. Status %s", chip::ErrorStr(error)); + NSLog(@"DeviceControllerDelegate Pairing deleted. Status %s", chip::ErrorStr(error)); - id strongDelegate = mDelegate; + id strongDelegate = mDelegate; if ([strongDelegate respondsToSelector:@selector(onPairingDeleted:)]) { if (strongDelegate && mQueue) { dispatch_async(mQueue, ^{ @@ -98,11 +98,11 @@ } } -void MTRDevicePairingDelegateBridge::OnCommissioningComplete(chip::NodeId nodeId, CHIP_ERROR error) +void MTRDeviceControllerDelegateBridge::OnCommissioningComplete(chip::NodeId nodeId, CHIP_ERROR error) { - NSLog(@"DevicePairingDelegate Commissioning complete. NodeId %llu Status %s", nodeId, chip::ErrorStr(error)); + NSLog(@"DeviceControllerDelegate Commissioning complete. NodeId %llu Status %s", nodeId, chip::ErrorStr(error)); - id strongDelegate = mDelegate; + id strongDelegate = mDelegate; if ([strongDelegate respondsToSelector:@selector(onCommissioningComplete:)]) { if (strongDelegate && mQueue) { dispatch_async(mQueue, ^{ diff --git a/src/darwin/Framework/CHIP/Matter.h b/src/darwin/Framework/CHIP/Matter.h index dc71d1cb998dd5..0961053495f706 100644 --- a/src/darwin/Framework/CHIP/Matter.h +++ b/src/darwin/Framework/CHIP/Matter.h @@ -41,9 +41,9 @@ #import #import #import +#import #import #import -#import #import #import #import diff --git a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m index 0c23ae5a017b28..9ad67477413651 100644 --- a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m +++ b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m @@ -80,11 +80,11 @@ - (void)failSubscribers:(dispatch_queue_t)queue completion:(void (^)(void))compl @end #endif -@interface MTRDeviceTestPairingDelegate : NSObject +@interface MTRDeviceTestDeviceControllerDelegate : NSObject @property (nonatomic, strong) XCTestExpectation * expectation; @end -@implementation MTRDeviceTestPairingDelegate +@implementation MTRDeviceTestDeviceControllerDelegate - (id)initWithExpectation:(XCTestExpectation *)expectation { self = [super init]; @@ -186,10 +186,11 @@ - (void)initStack sController = controller; - MTRDeviceTestPairingDelegate * pairing = [[MTRDeviceTestPairingDelegate alloc] initWithExpectation:expectation]; - dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.pairing", DISPATCH_QUEUE_SERIAL); + MTRDeviceTestDeviceControllerDelegate * deviceControllerDelegate = + [[MTRDeviceTestDeviceControllerDelegate alloc] initWithExpectation:expectation]; + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.device_controller_delegate", DISPATCH_QUEUE_SERIAL); - [controller setPairingDelegate:pairing queue:callbackQueue]; + [controller setDeviceControllerDelegate:deviceControllerDelegate queue:callbackQueue]; NSError * error; __auto_type * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:kOnboardingPayload error:&error]; diff --git a/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m b/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m index ad82cd9ab742ae..1cb29d3c274cdd 100644 --- a/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m +++ b/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m @@ -402,11 +402,11 @@ - (void)readAttributeCacheWithController:(id _Nullable)controller return mConnectedDevice; } -@interface MTRRemoteDeviceSampleTestPairingDelegate : NSObject +@interface MTRRemoteDeviceSampleTestDeviceControllerDelegate : NSObject @property (nonatomic, strong) XCTestExpectation * expectation; @end -@implementation MTRRemoteDeviceSampleTestPairingDelegate +@implementation MTRRemoteDeviceSampleTestDeviceControllerDelegate - (id)initWithExpectation:(XCTestExpectation *)expectation { self = [super init]; @@ -485,11 +485,11 @@ - (void)initStack sController = controller; - MTRRemoteDeviceSampleTestPairingDelegate * pairing = - [[MTRRemoteDeviceSampleTestPairingDelegate alloc] initWithExpectation:expectation]; - dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.pairing", DISPATCH_QUEUE_SERIAL); + MTRRemoteDeviceSampleTestDeviceControllerDelegate * deviceControllerDelegate = + [[MTRRemoteDeviceSampleTestDeviceControllerDelegate alloc] initWithExpectation:expectation]; + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.device_controller_delegate", DISPATCH_QUEUE_SERIAL); - [controller setPairingDelegate:pairing queue:callbackQueue]; + [controller setDeviceControllerDelegate:deviceControllerDelegate queue:callbackQueue]; __auto_type * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:kOnboardingPayload error:&error]; XCTAssertNotNil(payload); diff --git a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj index 0cf5642bf40f9b..9ed05837ea22a9 100644 --- a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj +++ b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj @@ -29,9 +29,9 @@ 2C8C8FC0253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C8C8FBD253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.h */; }; 2C8C8FC1253E0C2100797F05 /* MTRStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C8C8FBE253E0C2100797F05 /* MTRStorage.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2C8C8FC2253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2C8C8FBF253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.mm */; }; - 2CB7163B252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CB71638252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.h */; }; - 2CB7163C252E8A7C0026E2BB /* MTRDevicePairingDelegateBridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2CB71639252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.mm */; }; - 2CB7163F252F731E0026E2BB /* MTRDevicePairingDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CB7163E252F731E0026E2BB /* MTRDevicePairingDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 2CB7163B252E8A7B0026E2BB /* MTRDeviceControllerDelegateBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CB71638252E8A7B0026E2BB /* MTRDeviceControllerDelegateBridge.h */; }; + 2CB7163C252E8A7C0026E2BB /* MTRDeviceControllerDelegateBridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2CB71639252E8A7B0026E2BB /* MTRDeviceControllerDelegateBridge.mm */; }; + 2CB7163F252F731E0026E2BB /* MTRDeviceControllerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CB7163E252F731E0026E2BB /* MTRDeviceControllerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2FD775552695557E00FF4B12 /* error-mapping.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2FD775542695557E00FF4B12 /* error-mapping.cpp */; }; 3CF134A7289D8ADA0017A19E /* MTRCSRInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CF134A6289D8AD90017A19E /* MTRCSRInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3CF134A9289D8D800017A19E /* MTRCSRInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CF134A8289D8D800017A19E /* MTRCSRInfo.m */; }; @@ -170,9 +170,9 @@ 2C8C8FBD253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRPersistentStorageDelegateBridge.h; sourceTree = ""; }; 2C8C8FBE253E0C2100797F05 /* MTRStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRStorage.h; sourceTree = ""; }; 2C8C8FBF253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MTRPersistentStorageDelegateBridge.mm; sourceTree = ""; }; - 2CB71638252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRDevicePairingDelegateBridge.h; sourceTree = ""; }; - 2CB71639252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MTRDevicePairingDelegateBridge.mm; sourceTree = ""; }; - 2CB7163E252F731E0026E2BB /* MTRDevicePairingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRDevicePairingDelegate.h; sourceTree = ""; }; + 2CB71638252E8A7B0026E2BB /* MTRDeviceControllerDelegateBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRDeviceControllerDelegateBridge.h; sourceTree = ""; }; + 2CB71639252E8A7B0026E2BB /* MTRDeviceControllerDelegateBridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MTRDeviceControllerDelegateBridge.mm; sourceTree = ""; }; + 2CB7163E252F731E0026E2BB /* MTRDeviceControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRDeviceControllerDelegate.h; sourceTree = ""; }; 2FD775542695557E00FF4B12 /* error-mapping.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "error-mapping.cpp"; path = "../../../app/util/error-mapping.cpp"; sourceTree = ""; }; 3CF134A6289D8AD90017A19E /* MTRCSRInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTRCSRInfo.h; sourceTree = ""; }; 3CF134A8289D8D800017A19E /* MTRCSRInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MTRCSRInfo.m; sourceTree = ""; }; @@ -403,9 +403,9 @@ 2C8C8FBF253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.mm */, 99D466E02798936D0089A18F /* MTRCommissioningParameters.h */, 99AECC7F2798A57E00B6355B /* MTRCommissioningParameters.m */, - 2CB7163E252F731E0026E2BB /* MTRDevicePairingDelegate.h */, - 2CB71638252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.h */, - 2CB71639252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.mm */, + 2CB7163E252F731E0026E2BB /* MTRDeviceControllerDelegate.h */, + 2CB71638252E8A7B0026E2BB /* MTRDeviceControllerDelegateBridge.h */, + 2CB71639252E8A7B0026E2BB /* MTRDeviceControllerDelegateBridge.mm */, AF1CB86D2874B03B00865A96 /* MTROTAProviderDelegate.h */, AF1CB86F2874B04C00865A96 /* MTROTAProviderDelegateBridge.h */, AF5F90FE2878D351005503FA /* MTROTAProviderDelegateBridge.mm */, @@ -507,7 +507,7 @@ 5A6FEC9927B5C88900F25F42 /* MTRDeviceOverXPC.h in Headers */, 51B22C222740CB1D008D5055 /* MTRCommandPayloadsObjc.h in Headers */, 51B22C1E2740CB0A008D5055 /* MTRStructsObjc.h in Headers */, - 2CB7163B252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.h in Headers */, + 2CB7163B252E8A7B0026E2BB /* MTRDeviceControllerDelegateBridge.h in Headers */, 5ACDDD7A27CD129700EFD68A /* MTRAttributeCacheContainer.h in Headers */, 5A6FEC9227B5669C00F25F42 /* MTRDeviceControllerOverXPC.h in Headers */, 2C1B027B2641DB4E00780EF1 /* MTROperationalCredentialsDelegate.h in Headers */, @@ -519,7 +519,7 @@ D4772A46285AE98400383630 /* MTRClusterConstants.h in Headers */, B289D4212639C0D300D4E314 /* MTROnboardingPayloadParser.h in Headers */, 513DDB862761F69300DAA01A /* MTRAttributeTLVValueDecoder_Internal.h in Headers */, - 2CB7163F252F731E0026E2BB /* MTRDevicePairingDelegate.h in Headers */, + 2CB7163F252F731E0026E2BB /* MTRDeviceControllerDelegate.h in Headers */, 88EBF8CE27FABDD500686BC1 /* MTRDeviceAttestationDelegate.h in Headers */, 2C222AD0255C620600E446B9 /* MTRBaseDevice.h in Headers */, 7596A84F2877E6A9004DAE0E /* MTRCluster_internal.h in Headers */, @@ -689,7 +689,7 @@ files = ( 2C8C8FC2253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.mm in Sources */, 99AECC802798A57F00B6355B /* MTRCommissioningParameters.m in Sources */, - 2CB7163C252E8A7C0026E2BB /* MTRDevicePairingDelegateBridge.mm in Sources */, + 2CB7163C252E8A7C0026E2BB /* MTRDeviceControllerDelegateBridge.mm in Sources */, 997DED162695343400975E97 /* MTRThreadOperationalDataset.mm in Sources */, 515C1C6F284F9FFB00A48F0C /* MTRMemory.mm in Sources */, 27A53C1827FBC6920053F131 /* MTRAttestationTrustStoreBridge.mm in Sources */,