Skip to content

Commit

Permalink
Fix removal of all fabrics in CHIPTool (#15982)
Browse files Browse the repository at this point in the history
* Fix removal of all fabrics in CHIPTool

* Restyled by clang-format

* Remove wrorn dispatch_group_remove

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Feb 12, 2024
1 parent 8f11db9 commit f10e8e7
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,27 +325,52 @@ - (IBAction)removeAllFabricsButtonPressed:(id)sender
stringWithFormat:@"Failed to establish a connection with the device %@", error]
isError:YES];
}

CHIPOperationalCredentials * opCredsCluster =
[[CHIPOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];

dispatch_group_t removeGroup = dispatch_group_create();
// Loop over the list of all fabrics and for each, call remove
for (CHIPOperationalCredentialsClusterFabricDescriptor * fabricDescriptor in self.fabricsList) {
CHIPOperationalCredentials * opCredsCluster =
[[CHIPOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];
if ([fabricDescriptor.fabricIndex isEqualToNumber:self.currentFabricIndex]) {
// We'll remove our own fabric later
continue;
}

CHIPOperationalCredentialsClusterRemoveFabricParams * params =
[[CHIPOperationalCredentialsClusterRemoveFabricParams alloc] init];
params.fabricIndex = fabricDescriptor.fabricIndex;
dispatch_group_enter(removeGroup);
[opCredsCluster
removeFabricWithParams:params
completionHandler:^(CHIPOperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable error) {
if (!error) {
CHIPSetDevicePaired(CHIPGetLastPairedDeviceId(), NO);
}
[self updateResult:[NSString stringWithFormat:@"Removed Fabric Index %@ with Error %@",
params.fabricIndex, error]
isError:error];
dispatch_group_leave(removeGroup);
}];
}
dispatch_group_notify(removeGroup, dispatch_get_main_queue(), ^{
// now we can remove ourselves
CHIPOperationalCredentialsClusterRemoveFabricParams * params =
[[CHIPOperationalCredentialsClusterRemoveFabricParams alloc] init];
params.fabricIndex = self.currentFabricIndex;
[opCredsCluster
removeFabricWithParams:params
completionHandler:^(CHIPOperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable error) {
if (!error) {
CHIPSetDevicePaired(CHIPGetLastPairedDeviceId(), NO);
}
[self updateResult:[NSString
stringWithFormat:@"Removed own Fabric Index %@ with Error %@",
params.fabricIndex, error]
isError:error];
}];
});
})) {
[self updateResult:[NSString stringWithFormat:@"Waiting for connection with the device"] isError:NO];
} else {
Expand Down

0 comments on commit f10e8e7

Please sign in to comment.