Switch MTRDeviceControllerFactory to storing MTRDeviceController_Concrete instances. (#35703)
All the controllers it works with are concrete ones.
diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
index 2db2455..68f57a6 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
@@ -150,9 +150,9 @@
// must lock.
// D. Locking around reads not from the Matter queue is OK but not required.
os_unfair_lock _controllersLock;
- NSMutableArray<MTRDeviceController *> * _controllers;
- MTRDeviceController * _controllerBeingStarted;
- MTRDeviceController * _controllerBeingShutDown;
+ NSMutableArray<MTRDeviceController_Concrete *> * _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 @@
* 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 @@
// 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 @@
}
// 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 @@
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 @@
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 @@
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 @@
[controller deinitFromFactory];
}
-- (NSArray<MTRDeviceController *> *)getRunningControllers
+- (NSArray<MTRDeviceController_Concrete *> *)getRunningControllers
{
std::lock_guard lock(_controllersLock);
return [_controllers copy];
@@ -984,11 +984,11 @@
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 @@
}
}
- 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 @@
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 @@
}
}
-- (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 @@
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 @@
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 94c6fe4..46bb781 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h
+++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h
@@ -92,9 +92,9 @@
/**
* 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 1ddc43f..7e38282 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
@@ -157,9 +157,9 @@
// 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;
}