Skip to content

Commit

Permalink
[Darwin] Rename MTRDevicePairingDelegate to MTRDeviceControllerDelega…
Browse files Browse the repository at this point in the history
…te and MTRPairingStatus to MTRCommissioningStatus (#22633)

* [Darwin] Rename MTRDevicePairingDelegate to MTRDeviceControllerDelegate

* [Darwin] Rename MTRPairingStatus to MTRCommissioningStatus
  • Loading branch information
vivien-apple authored and pull[bot] committed Nov 15, 2023
1 parent acbfac1 commit 2348720
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 108 deletions.
2 changes: 1 addition & 1 deletion examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#import <Matter/Matter.h>

@interface CHIPToolPairingDelegate : NSObject <MTRDevicePairingDelegate>
@interface CHIPToolDeviceControllerDelegate : NSObject <MTRDeviceControllerDelegate>
@property PairingCommandBridge * commandBridge;
@property chip::NodeId deviceID;
@property MTRDeviceController * commissioner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@
*
*/

#include "PairingDelegateBridge.h"
#include "DeviceControllerDelegateBridge.h"
#import <Matter/Matter.h>

@interface CHIPToolPairingDelegate ()
@interface CHIPToolDeviceControllerDelegate ()
@end

@implementation CHIPToolPairingDelegate
- (void)onStatusUpdate:(MTRPairingStatus)status
@implementation CHIPToolDeviceControllerDelegate
- (void)onStatusUpdate:(MTRCommissioningStatus)status
{
NSLog(@"Pairing Status Update: %lu", 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
#import <Matter/Matter.h>

#include "../common/CHIPCommandBridge.h"
#include "DeviceControllerDelegateBridge.h"
#include "PairingCommandBridge.h"
#include "PairingDelegateBridge.h"
#include <lib/support/logging/CHIPLogging.h>

#import "MTRError_Utils.h"

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:
Expand All @@ -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()
Expand All @@ -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];
Expand All @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions examples/darwin-framework-tool/commands/tests/TestCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ const char * getScriptsFolder() { return basePath; }

constexpr const char * kDefaultKey = "default";

@interface TestPairingDelegate : NSObject <MTRDevicePairingDelegate>
@interface TestDeviceControllerDelegate : NSObject <MTRDeviceControllerDelegate>
@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;
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -521,21 +521,21 @@ class TestCommandBridge : public CHIPCommandBridge,
}

private:
TestPairingDelegate * _Nonnull mPairingDelegate;
TestDeviceControllerDelegate * _Nonnull mDeviceControllerDelegate;

// Set of our connected devices, keyed by identity.
std::map<std::string, MTRBaseDevice *> mConnectedDevices;
};

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
#import <UIKit/UIKit.h>

@interface QRCodeViewController
: UIViewController <AVCaptureMetadataOutputObjectsDelegate, MTRDevicePairingDelegate, NFCNDEFReaderSessionDelegate>
: UIViewController <AVCaptureMetadataOutputObjectsDelegate, MTRDeviceControllerDelegate, NFCNDEFReaderSessionDelegate>

@end
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ - (void)setVendorIDOnAccessory
}
}

// MARK: MTRDevicePairingDelegate
// MARK: MTRDeviceControllerDelegate
- (void)onPairingComplete:(NSError * _Nullable)error
{
if (error != nil) {
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
NS_ASSUME_NONNULL_BEGIN

@class MTRCommissioningParameters;
@protocol MTRDevicePairingDelegate;
@protocol MTRDeviceControllerDelegate;
@class MTRSetupPayload;

@interface MTRDeviceController : NSObject
Expand Down Expand Up @@ -109,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @param[in] queue The queue on which the callbacks will be delivered
*/
- (void)setPairingDelegate:(id<MTRDevicePairingDelegate>)delegate queue:(dispatch_queue_t)queue;
- (void)setDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate queue:(dispatch_queue_t)queue;

/**
* Sets this MTRDeviceController to use the given issuer for issuing operational certs. By default, the MTRDeviceController uses an
Expand Down
20 changes: 10 additions & 10 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -83,7 +83,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;
Expand All @@ -103,8 +103,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;
}

Expand Down Expand Up @@ -183,9 +183,9 @@ - (void)cleanup
_partialDACVerifier = nullptr;
}

if (_pairingDelegateBridge) {
delete _pairingDelegateBridge;
_pairingDelegateBridge = nullptr;
if (_deviceControllerDelegateBridge) {
delete _deviceControllerDelegateBridge;
_deviceControllerDelegateBridge = nullptr;
}
}

Expand Down Expand Up @@ -255,7 +255,7 @@ - (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams

chip::Controller::SetupParams commissionerParams;

commissionerParams.pairingDelegate = _pairingDelegateBridge;
commissionerParams.pairingDelegate = _deviceControllerDelegateBridge;

_operationalCredentialsDelegate->SetDeviceCommissioner(_cppCommissioner);

Expand Down Expand Up @@ -533,10 +533,10 @@ - (void)removeDevice:(MTRDevice *)device
os_unfair_lock_unlock(&_deviceMapLock);
}

- (void)setPairingDelegate:(id<MTRDevicePairingDelegate>)delegate queue:(dispatch_queue_t)queue
- (void)setDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate queue:(dispatch_queue_t)queue
{
dispatch_async(_chipWorkQueue, ^{
self->_pairingDelegateBridge->setDelegate(delegate, queue);
self->_deviceControllerDelegateBridge->setDelegate(delegate, queue);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, MTRPairingStatus) {
MTRPairingStatusUnknown = 0,
MTRPairingStatusSuccess = 1,
MTRPairingStatusFailed = 2,
MTRPairingStatusDiscoveringMoreDevices = 3
typedef NS_ENUM(NSUInteger, MTRCommissioningStatus) {
MTRCommissioningStatusUnknown = 0,
MTRCommissioningStatusSuccess = 1,
MTRCommissioningStatusFailed = 2,
MTRCommissioningStatusDiscoveringMoreDevices = 3
};

/**
* 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 <NSObject>
@protocol MTRDeviceControllerDelegate <NSObject>
@optional
/**
* Notify the delegate when pairing status gets updated
*
*/
- (void)onStatusUpdate:(MTRPairingStatus)status;
- (void)onStatusUpdate:(MTRCommissioningStatus)status;

/**
* Notify the delegate when pairing is completed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
* limitations under the License.
*/

#import "MTRDevicePairingDelegate.h"
#import "MTRDeviceControllerDelegate.h"

#include <controller/CHIPDeviceController.h>
#include <platform/CHIPDeviceBuildConfig.h>

NS_ASSUME_NONNULL_BEGIN

class MTRDevicePairingDelegateBridge : public chip::Controller::DevicePairingDelegate
class MTRDeviceControllerDelegateBridge : public chip::Controller::DevicePairingDelegate
{
public:
MTRDevicePairingDelegateBridge();
~MTRDevicePairingDelegateBridge();
MTRDeviceControllerDelegateBridge();
~MTRDeviceControllerDelegateBridge();

void setDelegate(id<MTRDevicePairingDelegate> delegate, dispatch_queue_t queue);
void setDelegate(id<MTRDeviceControllerDelegate> delegate, dispatch_queue_t queue);

void OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) override;

Expand All @@ -39,10 +39,10 @@ class MTRDevicePairingDelegateBridge : public chip::Controller::DevicePairingDel
void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR error) override;

private:
_Nullable id<MTRDevicePairingDelegate> mDelegate;
_Nullable id<MTRDeviceControllerDelegate> mDelegate;
_Nullable dispatch_queue_t mQueue;

MTRPairingStatus MapStatus(chip::Controller::DevicePairingDelegate::Status status);
MTRCommissioningStatus MapStatus(chip::Controller::DevicePairingDelegate::Status status);
};

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 2348720

Please sign in to comment.