From 2054512764ca6fb85d7fa332347f3361138b9d51 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 20 Sep 2024 18:02:04 -0400 Subject: [PATCH] Switch MTRDeviceControllerFactory to storing MTRDeviceController_Concrete instances. (#35703) All the controllers it works with are concrete ones. --- .../CHIP/MTRDeviceControllerFactory.mm | 54 +++++++++---------- .../MTRDeviceControllerFactory_Internal.h | 6 +-- .../CHIP/MTRDeviceController_Concrete.mm | 6 +-- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm index 2db245545bc8f9..68f57a6954cc34 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm @@ -150,9 +150,9 @@ @implementation MTRDeviceControllerFactory { // must lock. // D. Locking around reads not from the Matter queue is OK but not required. os_unfair_lock _controllersLock; - NSMutableArray * _controllers; - MTRDeviceController * _controllerBeingStarted; - MTRDeviceController * _controllerBeingShutDown; + NSMutableArray * _controllers; + MTRDeviceController_Concrete * _controllerBeingStarted; + MTRDeviceController_Concrete * _controllerBeingShutDown; // Next available fabric index. Only valid when _controllerBeingStarted is // non-nil, and then it corresponds to the controller being started. This @@ -461,12 +461,12 @@ - (void)stopControllerFactory * The provided controller is expected to have just been allocated and to not be * initialized yet. */ -- (MTRDeviceController * _Nullable)_startDeviceController:(MTRDeviceController_Concrete *)controller - startupParams:(id)startupParams - fabricChecker:(MTRDeviceControllerStartupParamsInternal * (^)(FabricTable * fabricTable, - MTRDeviceController * controller, - CHIP_ERROR & fabricError))fabricChecker - error:(NSError * __autoreleasing *)error +- (MTRDeviceController_Concrete * _Nullable)_startDeviceController:(MTRDeviceController_Concrete *)controller + startupParams:(id)startupParams + fabricChecker:(MTRDeviceControllerStartupParamsInternal * (^)(FabricTable * fabricTable, + MTRDeviceController_Concrete * controller, + CHIP_ERROR & fabricError))fabricChecker + error:(NSError * __autoreleasing *)error { [self _assertCurrentQueueIsNotMatterQueue]; @@ -590,7 +590,7 @@ - (MTRDeviceController * _Nullable)_startDeviceController:(MTRDeviceController_C // Check that we are not trying to start a controller with a uniqueIdentifier that // matches a running controller. auto * controllersCopy = [self getRunningControllers]; - for (MTRDeviceController * existing in controllersCopy) { + for (MTRDeviceController_Concrete * existing in controllersCopy) { if (existing != controller && [existing.uniqueIdentifier isEqual:params.uniqueIdentifier]) { MTR_LOG_ERROR("Already have running controller with uniqueIdentifier %@", existing.uniqueIdentifier); fabricError = CHIP_ERROR_INVALID_ARGUMENT; @@ -661,7 +661,7 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo } // If there is a controller already running with matching parameters that is conceptually shut down from the API consumer's viewpoint, re-use it. - MTRDeviceController * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:startupParams.operationalCertificate andRootCertificate:startupParams.rootCertificate]; + auto * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:startupParams.operationalCertificate andRootCertificate:startupParams.rootCertificate]; if (existingController) { return existingController; } @@ -669,7 +669,7 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo return [self _startDeviceController:[MTRDeviceController_Concrete alloc] startupParams:startupParams fabricChecker:^MTRDeviceControllerStartupParamsInternal *( - FabricTable * fabricTable, MTRDeviceController * controller, CHIP_ERROR & fabricError) { + FabricTable * fabricTable, MTRDeviceController_Concrete * controller, CHIP_ERROR & fabricError) { const FabricInfo * fabric = nullptr; BOOL ok = [self findMatchingFabric:*fabricTable params:startupParams fabric:&fabric]; if (!ok) { @@ -686,7 +686,7 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo auto * controllersCopy = [self getRunningControllers]; - for (MTRDeviceController * existing in controllersCopy) { + for (MTRDeviceController_Concrete * existing in controllersCopy) { BOOL isRunning = YES; // assume the worst if ([existing isRunningOnFabric:fabricTable fabricIndex:fabric->GetFabricIndex() @@ -741,7 +741,7 @@ - (MTRDeviceController * _Nullable)createControllerOnNewFabric:(MTRDeviceControl return [self _startDeviceController:[MTRDeviceController_Concrete alloc] startupParams:startupParams fabricChecker:^MTRDeviceControllerStartupParamsInternal *( - FabricTable * fabricTable, MTRDeviceController * controller, CHIP_ERROR & fabricError) { + FabricTable * fabricTable, MTRDeviceController_Concrete * controller, CHIP_ERROR & fabricError) { const FabricInfo * fabric = nullptr; BOOL ok = [self findMatchingFabric:*fabricTable params:startupParams fabric:&fabric]; if (!ok) { @@ -969,7 +969,7 @@ - (void)controllerShuttingDown:(MTRDeviceController_Concrete *)controller [controller deinitFromFactory]; } -- (NSArray *)getRunningControllers +- (NSArray *)getRunningControllers { std::lock_guard lock(_controllersLock); return [_controllers copy]; @@ -984,11 +984,11 @@ - (nullable MTRDeviceController *)runningControllerForFabricIndex:(FabricIndex)f auto * controllersCopy = [self getRunningControllers]; os_unfair_lock_lock(&_controllersLock); - MTRDeviceController * controllerBeingStarted = _controllerBeingStarted; - MTRDeviceController * controllerBeingShutDown = _controllerBeingShutDown; + auto * controllerBeingStarted = _controllerBeingStarted; + auto * controllerBeingShutDown = _controllerBeingShutDown; os_unfair_lock_unlock(&_controllersLock); - for (MTRDeviceController * existing in controllersCopy) { + for (MTRDeviceController_Concrete * existing in controllersCopy) { if (existing.fabricIndex == fabricIndex) { return existing; } @@ -1088,7 +1088,7 @@ - (nullable NSNumber *)neededReadPrivilegeForClusterID:(NSNumber *)clusterID att } } - for (MTRDeviceController * controller in [self getRunningControllers]) { + for (MTRDeviceController_Concrete * controller in [self getRunningControllers]) { NSNumber * _Nullable neededPrivilege = [controller neededReadPrivilegeForClusterID:clusterID attributeID:attributeID]; if (neededPrivilege != nil) { return neededPrivilege; @@ -1127,7 +1127,7 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID auto * controllersCopy = [self getRunningControllers]; - for (MTRDeviceController * controller in controllersCopy) { + for (MTRDeviceController_Concrete * controller in controllersCopy) { auto * compressedFabricId = controller.compressedFabricID; if (compressedFabricId != nil && compressedFabricId.unsignedLongLongValue == operationalID.GetCompressedFabricId()) { ChipLogProgress(Controller, "Notifying controller at fabric index %u about new operational node 0x" ChipLogFormatX64, @@ -1140,10 +1140,10 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID } } -- (nullable MTRDeviceController *)_findPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate +- (nullable MTRDeviceController_Concrete *)_findPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate { std::lock_guard lock(_controllersLock); - for (MTRDeviceController * controller in _controllers) { + for (MTRDeviceController_Concrete * controller in _controllers) { // TODO: Once we know our controllers are MTRDeviceController_Concrete, move // matchesPendingShutdownControllerWithOperationalCertificate and clearPendingShutdown to that // interface and remove them from base MTRDeviceController_Internal. @@ -1156,14 +1156,14 @@ - (nullable MTRDeviceController *)_findPendingShutdownControllerWithOperationalC return nil; } -- (nullable MTRDeviceController *)initializeController:(MTRDeviceController_Concrete *)controller - withParameters:(MTRDeviceControllerParameters *)parameters - error:(NSError * __autoreleasing *)error +- (nullable MTRDeviceController_Concrete *)initializeController:(MTRDeviceController_Concrete *)controller + withParameters:(MTRDeviceControllerParameters *)parameters + error:(NSError * __autoreleasing *)error { [self _assertCurrentQueueIsNotMatterQueue]; // If there is a controller already running with matching parameters that is conceptually shut down from the API consumer's viewpoint, re-use it. - MTRDeviceController * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:parameters.operationalCertificate andRootCertificate:parameters.rootCertificate]; + MTRDeviceController_Concrete * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:parameters.operationalCertificate andRootCertificate:parameters.rootCertificate]; if (existingController) { return existingController; } @@ -1171,7 +1171,7 @@ - (nullable MTRDeviceController *)initializeController:(MTRDeviceController_Conc return [self _startDeviceController:controller startupParams:parameters fabricChecker:^MTRDeviceControllerStartupParamsInternal *( - FabricTable * fabricTable, MTRDeviceController * controller, CHIP_ERROR & fabricError) { + FabricTable * fabricTable, MTRDeviceController_Concrete * controller, CHIP_ERROR & fabricError) { auto advertiseOperational = self->_advertiseOperational && parameters.shouldAdvertiseOperational; auto * params = [[MTRDeviceControllerStartupParamsInternal alloc] initForNewController:controller diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h index 94c6fe422355ae..46bb7819ad43f1 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h @@ -92,9 +92,9 @@ MTR_DIRECT_MEMBERS /** * Initialize an MTRDeviceController_Concrete with the given parameters. */ -- (nullable MTRDeviceController *)initializeController:(MTRDeviceController_Concrete *)controller - withParameters:(MTRDeviceControllerParameters *)parameters - error:(NSError * __autoreleasing *)error; +- (nullable MTRDeviceController_Concrete *)initializeController:(MTRDeviceController_Concrete *)controller + withParameters:(MTRDeviceControllerParameters *)parameters + error:(NSError * __autoreleasing *)error; /** * Add a server endpoint. This will verify that there is no existing server diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm index 1ddc43f488ab11..7e382825a3a09f 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm @@ -157,9 +157,9 @@ - (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParamete // Start us up normally. MTRDeviceControllerFactory will auto-start in per-controller-storage mode if necessary. MTRDeviceControllerFactory * factory = MTRDeviceControllerFactory.sharedInstance; - id controller = [factory initializeController:self - withParameters:controllerParameters - error:error]; + auto * controller = [factory initializeController:self + withParameters:controllerParameters + error:error]; return controller; }