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

Add an API to get the list of running controllers from a controller factory. #28461

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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