Skip to content

Commit

Permalink
Address review comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Nov 18, 2022
1 parent 5aedb25 commit d3f8221
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MTRDeviceControllerDelegateBridge : public chip::Controller::DevicePairing
void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR error) override;

private:
MTRDeviceController * _Nullable mController;
MTRDeviceController * __weak mController;
_Nullable id<MTRDeviceControllerDelegate> mDelegate;
_Nullable dispatch_queue_t mQueue;

Expand Down
21 changes: 12 additions & 9 deletions src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@
NSLog(@"DeviceControllerDelegate status updated: %d", status);

id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
if ([strongDelegate respondsToSelector:@selector(controller:statusUpdate:)]) {
if (strongDelegate && mQueue) {
MTRDeviceController * strongController = mController;
if (strongDelegate && mQueue && strongController) {
if ([strongDelegate respondsToSelector:@selector(controller:statusUpdate:)]) {
MTRCommissioningStatus commissioningStatus = MapStatus(status);
dispatch_async(mQueue, ^{
[strongDelegate controller:mController statusUpdate:commissioningStatus];
[strongDelegate controller:strongController statusUpdate:commissioningStatus];
});
}
}
Expand All @@ -77,11 +78,12 @@
NSLog(@"DeviceControllerDelegate Pairing complete. Status %s", chip::ErrorStr(error));

id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
if ([strongDelegate respondsToSelector:@selector(controller:commissioningSessionEstablishmentDone:)]) {
if (strongDelegate && mQueue) {
MTRDeviceController * strongController = mController;
if (strongDelegate && mQueue && strongController) {
if ([strongDelegate respondsToSelector:@selector(controller:commissioningSessionEstablishmentDone:)]) {
dispatch_async(mQueue, ^{
NSError * nsError = [MTRError errorForCHIPErrorCode:error];
[strongDelegate controller:mController commissioningSessionEstablishmentDone:nsError];
[strongDelegate controller:strongController commissioningSessionEstablishmentDone:nsError];
});
}
}
Expand All @@ -99,11 +101,12 @@
NSLog(@"DeviceControllerDelegate Commissioning complete. NodeId %llu Status %s", nodeId, chip::ErrorStr(error));

id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
if ([strongDelegate respondsToSelector:@selector(controller:commissioningComplete:)]) {
if (strongDelegate && mQueue) {
MTRDeviceController * strongController = mController;
if (strongDelegate && mQueue && strongController) {
if ([strongDelegate respondsToSelector:@selector(controller:commissioningComplete:)]) {
dispatch_async(mQueue, ^{
NSError * nsError = [MTRError errorForCHIPErrorCode:error];
[strongDelegate controller:mController commissioningComplete:nsError];
[strongDelegate controller:strongController commissioningComplete:nsError];
});
}
}
Expand Down

0 comments on commit d3f8221

Please sign in to comment.