Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Darwin] add commissioning callback (read Commissioning Info, commissioningComplete add deviceId) #25832

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
65fe2d4
Implement commissioning event callback api
joonhaengHeo Mar 17, 2023
55c2b73
restyle
joonhaengHeo Mar 17, 2023
5593f59
Merge branch 'master' of github.com:joonhaengHeo/connectedhomeip into…
joonhaengHeo Mar 25, 2023
f441c85
Merge branch 'darwin_add_commissioning_callback' of github.com:joonha…
joonhaengHeo Mar 25, 2023
e13d843
Add comment, fix typo
joonhaengHeo Mar 25, 2023
0015b4e
Modify from comment
joonhaengHeo Mar 26, 2023
5963cfa
Update after review
joonhaengHeo Apr 7, 2023
245ae34
restyle
joonhaengHeo Apr 7, 2023
c389dc8
Merge branch 'master' into darwin_add_commissioning_callback
joonhaengHeo Apr 7, 2023
219fd19
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 8, 2023
fa33adb
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 8, 2023
30466b0
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 8, 2023
53aa9d2
Change Variable name(nodeID) remove ununsed code
joonhaengHeo Apr 9, 2023
dea007b
Modify readCommissioningInfo to interface
joonhaengHeo Apr 9, 2023
aa4c866
restyle
joonhaengHeo Apr 9, 2023
de187fa
Merge branch 'master' into darwin_add_commissioning_callback
joonhaengHeo Apr 9, 2023
1f65c3b
restyle-2
joonhaengHeo Apr 9, 2023
79c16d8
Merge branch 'darwin_add_commissioning_callback' of github.com:joonha…
joonhaengHeo Apr 9, 2023
fb2f173
Merge branch 'master' into darwin_add_commissioning_callback
joonhaengHeo Apr 11, 2023
8f1b610
Modify nodeID error check
joonhaengHeo Apr 25, 2023
8dc46fb
restyle
joonhaengHeo Apr 25, 2023
3748b1a
Merge branch 'master' into darwin_add_commissioning_callback
joonhaengHeo Apr 25, 2023
7966406
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 25, 2023
fe0347f
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 25, 2023
483429a
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm
joonhaengHeo Apr 25, 2023
ebf5811
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 25, 2023
a728d54
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm
joonhaengHeo Apr 25, 2023
462ea5f
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm
joonhaengHeo Apr 25, 2023
a802c30
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 25, 2023
7059d24
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 25, 2023
6cfa412
Update src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
joonhaengHeo Apr 25, 2023
e82a92d
modify for changing variable name
joonhaengHeo Apr 25, 2023
8f750bf
Merge branch 'darwin_add_commissioning_callback' of github.com:joonha…
joonhaengHeo Apr 25, 2023
430cb9f
restyle
joonhaengHeo Apr 25, 2023
e5d49b9
restyle-2
joonhaengHeo Apr 25, 2023
8a1b216
Merge branch 'master' into darwin_add_commissioning_callback
joonhaengHeo Apr 25, 2023
7666555
Apply suggestions from code review
bzbarsky-apple Apr 26, 2023
2cbc460
Fix deprecation message.
bzbarsky-apple Apr 26, 2023
346f7d6
Remove redundant availability annotations.
bzbarsky-apple Apr 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -408,7 +408,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];
Expand Down Expand Up @@ -478,8 +478,8 @@ - (void)setVendorIDOnAccessory
}
}

// MARK: MTRDevicePairingDelegate
- (void)onPairingComplete:(NSError * _Nullable)error
// MARK: MTRDeviceControllerDelegate
- (void)controller:(MTRDeviceController *)controller commissioningSessionEstablishmentDone:(NSError * _Nullable)error
{
if (error != nil) {
NSLog(@"Got pairing error back %@", error);
Expand Down Expand Up @@ -672,18 +672,26 @@ - (void)commissionWithSSID:(NSString *)ssid password:(NSString *)password
}
}

- (void)onCommissioningComplete:(NSError * _Nullable)error
// MARK: MTRDeviceControllerDelegate
- (void)controller:(MTRDeviceController *)controller
commissioningComplete:(NSError * _Nullable)error
nodeID:(NSNumber * _Nullable)nodeID
{
if (error != nil) {
NSLog(@"Error retrieving device informations over Mdns: %@", error);
return;
}
// track this device
uint64_t deviceId = MTRGetNextAvailableDeviceID() - 1;
MTRSetDevicePaired(deviceId, YES);
MTRSetDevicePaired([nodeID unsignedLongLongValue], YES);
[self setVendorIDOnAccessory];
}

// MARK: MTRDeviceControllerDelegate
- (void)controller:(MTRDeviceController *)controller readCommissioningInfo:(MTRProductIdentity *)info
{
NSLog(@"readCommissioningInfo, vendorID:%@, productID:%@", info.vendorID, info.productID);
}

- (void)updateUIFields:(MTRSetupPayload *)payload rawPayload:(nullable NSString *)rawPayload isManualCode:(BOOL)isManualCode
{
if (isManualCode) {
Expand Down Expand Up @@ -789,7 +797,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
Expand Down
35 changes: 34 additions & 1 deletion src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ typedef NS_ENUM(NSInteger, MTRCommissioningStatus) {
= 3,
} API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4));

/**
* A representation of a (vendor, product) pair that identifies a specific product.
*/
MTR_NEWLY_AVAILABLE
@interface MTRProductIdentity : NSObject

@property (nonatomic, copy, readonly) NSNumber * vendorID;

@property (nonatomic, copy, readonly) NSNumber * productID;

- (instancetype)initWithVendorID:(NSNumber *)vendorID productID:(NSNumber *)productID;
@end

@class MTRDeviceController;

/**
Expand All @@ -52,8 +65,28 @@ API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4))
/**
* Notify the delegate when commissioning is completed.
*/
- (void)controller:(MTRDeviceController *)controller commissioningComplete:(NSError * _Nullable)error;
- (void)controller:(MTRDeviceController *)controller
commissioningComplete:(NSError * _Nullable)error MTR_NEWLY_DEPRECATED("Please use controller:commissioningComplete:nodeID:");

/**
joonhaengHeo marked this conversation as resolved.
Show resolved Hide resolved
* Notify the delegate when commissioning is completed.
*
* Exactly one of error and nodeID will be nil.
*
* If nodeID is not nil, then it represents the node id the node was assigned, as encoded in its operational certificate.
*/
- (void)controller:(MTRDeviceController *)controller
commissioningComplete:(NSError * _Nullable)error
nodeID:(NSNumber * _Nullable)nodeID MTR_NEWLY_AVAILABLE;

/**
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
* Notify the delegate when commissioning infomation has been read from the Basic
* Information cluster of the commissionee.
*
* At the point when this notification happens, device attestation has not been performed yet,
* so the information delivered by this notification should not be trusted.
*/
- (void)controller:(MTRDeviceController *)controller readCommissioningInfo:(MTRProductIdentity *)info MTR_NEWLY_AVAILABLE;
@end

typedef NS_ENUM(NSUInteger, MTRPairingStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "MTRDeviceControllerDelegate.h"

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

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -37,6 +38,8 @@ class MTRDeviceControllerDelegateBridge : public chip::Controller::DevicePairing

void OnPairingDeleted(CHIP_ERROR error) override;

void OnReadCommissioningInfo(const chip::Controller::ReadCommissioningInfo & info) override;

void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR error) override;

private:
Expand Down
44 changes: 44 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,44 @@
// This is never actually called; just do nothing.
}

void MTRDeviceControllerDelegateBridge::OnReadCommissioningInfo(const chip::Controller::ReadCommissioningInfo & info)
{
chip::VendorId vendorId = info.basic.vendorId;
uint16_t productId = info.basic.productId;

MTR_LOG_DEFAULT("DeviceControllerDelegate Read Commissioning Info. VendorId %u ProductId %u", vendorId, productId);
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved

id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
MTRDeviceController * strongController = mController;
if (strongDelegate && mQueue && strongController) {
if ([strongDelegate respondsToSelector:@selector(controller:readCommissioningInfo:)]) {
dispatch_async(mQueue, ^{
auto * info = [[MTRProductIdentity alloc] initWithVendorID:@(vendorId) productID:@(productId)];
[strongDelegate controller:strongController readCommissioningInfo:info];
});
}
}
}

void MTRDeviceControllerDelegateBridge::OnCommissioningComplete(chip::NodeId nodeId, CHIP_ERROR error)
{
MTR_LOG_DEFAULT("DeviceControllerDelegate Commissioning complete. NodeId %llu Status %s", nodeId, chip::ErrorStr(error));

id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
MTRDeviceController * strongController = mController;
if (strongDelegate && mQueue && strongController) {
if ([strongDelegate respondsToSelector:@selector(controller:commissioningComplete:nodeID:)]) {
dispatch_async(mQueue, ^{
NSError * nsError = [MTRError errorForCHIPErrorCode:error];
NSNumber * nodeID = nil;
if (error == CHIP_NO_ERROR) {
nodeID = @(nodeId);
}
[strongDelegate controller:strongController commissioningComplete:nsError nodeID:nodeID];
});
return;
}
// If only the DEPRECATED function is defined
if ([strongDelegate respondsToSelector:@selector(controller:commissioningComplete:)]) {
dispatch_async(mQueue, ^{
NSError * nsError = [MTRError errorForCHIPErrorCode:error];
Expand All @@ -109,3 +140,16 @@
}
}
}

@implementation MTRProductIdentity

- (instancetype)initWithVendorID:(NSNumber *)vendorID productID:(NSNumber *)productID
{
if (self = [super init]) {
_vendorID = vendorID;
_productID = productID;
}
return self;
}

@end