Skip to content

Commit

Permalink
Add an API to get the list of running controllers from a controller f…
Browse files Browse the repository at this point in the history
…actory.
  • Loading branch information
bzbarsky-apple committed Aug 1, 2023
1 parent 1440dd0 commit cdbec84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,7 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo
return nil;
}

os_unfair_lock_lock(&self->_controllersLock);
NSArray<MTRDeviceController *> * controllersCopy = [self->_controllers copy];
os_unfair_lock_unlock(&self->_controllersLock);
auto * controllersCopy = [self getRunningControllers];

for (MTRDeviceController * existing in controllersCopy) {
BOOL isRunning = YES; // assume the worst
Expand Down Expand Up @@ -880,13 +878,19 @@ - (void)controllerShuttingDown:(MTRDeviceController *)controller
[controller deinitFromFactory];
}

- (nullable MTRDeviceController *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
- (NSArray<MTRDeviceController *> *)getRunningControllers
{
assertChipStackLockedByCurrentThread();

os_unfair_lock_lock(&_controllersLock);
NSArray<MTRDeviceController *> * controllersCopy = [_controllers copy];
os_unfair_lock_unlock(&_controllersLock);
return controllersCopy;
}

- (nullable MTRDeviceController *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
{
assertChipStackLockedByCurrentThread();

auto * controllersCopy = [self getRunningControllers];

for (MTRDeviceController * existing in controllersCopy) {
if ([existing fabricIndex] == fabricIndex) {
Expand All @@ -901,9 +905,7 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID
{
assertChipStackLockedByCurrentThread();

os_unfair_lock_lock(&_controllersLock);
NSArray<MTRDeviceController *> * controllersCopy = [_controllers copy];
os_unfair_lock_unlock(&_controllersLock);
auto * controllersCopy = [self getRunningControllers];

for (MTRDeviceController * controller in controllersCopy) {
auto * compressedFabricId = controller.compressedFabricID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ NS_ASSUME_NONNULL_BEGIN

- (void)controllerShuttingDown:(MTRDeviceController *)controller;

/**
* Get the list of running controllers. This will include controllers that are
* in the middle of starting up or shutting down.
*/
- (NSArray<MTRDeviceController *> *)getRunningControllers;

/**
* Find a running controller, if any, for the given fabric index.
*/
Expand Down

0 comments on commit cdbec84

Please sign in to comment.