Skip to content

Commit e14ecf7

Browse files
Switch MTRDeviceControllerFactory to storing MTRDeviceController_Concrete instances.
All the controllers it works with are concrete ones.
1 parent d63051a commit e14ecf7

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm

+27-27
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ @implementation MTRDeviceControllerFactory {
150150
// must lock.
151151
// D. Locking around reads not from the Matter queue is OK but not required.
152152
os_unfair_lock _controllersLock;
153-
NSMutableArray<MTRDeviceController *> * _controllers;
154-
MTRDeviceController * _controllerBeingStarted;
155-
MTRDeviceController * _controllerBeingShutDown;
153+
NSMutableArray<MTRDeviceController_Concrete *> * _controllers;
154+
MTRDeviceController_Concrete * _controllerBeingStarted;
155+
MTRDeviceController_Concrete * _controllerBeingShutDown;
156156

157157
// Next available fabric index. Only valid when _controllerBeingStarted is
158158
// non-nil, and then it corresponds to the controller being started. This
@@ -461,12 +461,12 @@ - (void)stopControllerFactory
461461
* The provided controller is expected to have just been allocated and to not be
462462
* initialized yet.
463463
*/
464-
- (MTRDeviceController * _Nullable)_startDeviceController:(MTRDeviceController_Concrete *)controller
465-
startupParams:(id)startupParams
466-
fabricChecker:(MTRDeviceControllerStartupParamsInternal * (^)(FabricTable * fabricTable,
467-
MTRDeviceController * controller,
468-
CHIP_ERROR & fabricError))fabricChecker
469-
error:(NSError * __autoreleasing *)error
464+
- (MTRDeviceController_Concrete * _Nullable)_startDeviceController:(MTRDeviceController_Concrete *)controller
465+
startupParams:(id)startupParams
466+
fabricChecker:(MTRDeviceControllerStartupParamsInternal * (^)(FabricTable * fabricTable,
467+
MTRDeviceController_Concrete * controller,
468+
CHIP_ERROR & fabricError))fabricChecker
469+
error:(NSError * __autoreleasing *)error
470470
{
471471
[self _assertCurrentQueueIsNotMatterQueue];
472472

@@ -590,7 +590,7 @@ - (MTRDeviceController * _Nullable)_startDeviceController:(MTRDeviceController_C
590590
// Check that we are not trying to start a controller with a uniqueIdentifier that
591591
// matches a running controller.
592592
auto * controllersCopy = [self getRunningControllers];
593-
for (MTRDeviceController * existing in controllersCopy) {
593+
for (MTRDeviceController_Concrete * existing in controllersCopy) {
594594
if (existing != controller && [existing.uniqueIdentifier isEqual:params.uniqueIdentifier]) {
595595
MTR_LOG_ERROR("Already have running controller with uniqueIdentifier %@", existing.uniqueIdentifier);
596596
fabricError = CHIP_ERROR_INVALID_ARGUMENT;
@@ -661,15 +661,15 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo
661661
}
662662

663663
// If there is a controller already running with matching parameters that is conceptually shut down from the API consumer's viewpoint, re-use it.
664-
MTRDeviceController * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:startupParams.operationalCertificate andRootCertificate:startupParams.rootCertificate];
664+
auto * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:startupParams.operationalCertificate andRootCertificate:startupParams.rootCertificate];
665665
if (existingController) {
666666
return existingController;
667667
}
668668

669669
return [self _startDeviceController:[MTRDeviceController_Concrete alloc]
670670
startupParams:startupParams
671671
fabricChecker:^MTRDeviceControllerStartupParamsInternal *(
672-
FabricTable * fabricTable, MTRDeviceController * controller, CHIP_ERROR & fabricError) {
672+
FabricTable * fabricTable, MTRDeviceController_Concrete * controller, CHIP_ERROR & fabricError) {
673673
const FabricInfo * fabric = nullptr;
674674
BOOL ok = [self findMatchingFabric:*fabricTable params:startupParams fabric:&fabric];
675675
if (!ok) {
@@ -686,7 +686,7 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo
686686

687687
auto * controllersCopy = [self getRunningControllers];
688688

689-
for (MTRDeviceController * existing in controllersCopy) {
689+
for (MTRDeviceController_Concrete * existing in controllersCopy) {
690690
BOOL isRunning = YES; // assume the worst
691691
if ([existing isRunningOnFabric:fabricTable
692692
fabricIndex:fabric->GetFabricIndex()
@@ -741,7 +741,7 @@ - (MTRDeviceController * _Nullable)createControllerOnNewFabric:(MTRDeviceControl
741741
return [self _startDeviceController:[MTRDeviceController_Concrete alloc]
742742
startupParams:startupParams
743743
fabricChecker:^MTRDeviceControllerStartupParamsInternal *(
744-
FabricTable * fabricTable, MTRDeviceController * controller, CHIP_ERROR & fabricError) {
744+
FabricTable * fabricTable, MTRDeviceController_Concrete * controller, CHIP_ERROR & fabricError) {
745745
const FabricInfo * fabric = nullptr;
746746
BOOL ok = [self findMatchingFabric:*fabricTable params:startupParams fabric:&fabric];
747747
if (!ok) {
@@ -969,7 +969,7 @@ - (void)controllerShuttingDown:(MTRDeviceController_Concrete *)controller
969969
[controller deinitFromFactory];
970970
}
971971

972-
- (NSArray<MTRDeviceController *> *)getRunningControllers
972+
- (NSArray<MTRDeviceController_Concrete *> *)getRunningControllers
973973
{
974974
std::lock_guard lock(_controllersLock);
975975
return [_controllers copy];
@@ -984,11 +984,11 @@ - (nullable MTRDeviceController *)runningControllerForFabricIndex:(FabricIndex)f
984984
auto * controllersCopy = [self getRunningControllers];
985985

986986
os_unfair_lock_lock(&_controllersLock);
987-
MTRDeviceController * controllerBeingStarted = _controllerBeingStarted;
988-
MTRDeviceController * controllerBeingShutDown = _controllerBeingShutDown;
987+
auto * controllerBeingStarted = _controllerBeingStarted;
988+
auto * controllerBeingShutDown = _controllerBeingShutDown;
989989
os_unfair_lock_unlock(&_controllersLock);
990990

991-
for (MTRDeviceController * existing in controllersCopy) {
991+
for (MTRDeviceController_Concrete * existing in controllersCopy) {
992992
if (existing.fabricIndex == fabricIndex) {
993993
return existing;
994994
}
@@ -1088,7 +1088,7 @@ - (nullable NSNumber *)neededReadPrivilegeForClusterID:(NSNumber *)clusterID att
10881088
}
10891089
}
10901090

1091-
for (MTRDeviceController * controller in [self getRunningControllers]) {
1091+
for (MTRDeviceController_Concrete * controller in [self getRunningControllers]) {
10921092
NSNumber * _Nullable neededPrivilege = [controller neededReadPrivilegeForClusterID:clusterID attributeID:attributeID];
10931093
if (neededPrivilege != nil) {
10941094
return neededPrivilege;
@@ -1127,7 +1127,7 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID
11271127

11281128
auto * controllersCopy = [self getRunningControllers];
11291129

1130-
for (MTRDeviceController * controller in controllersCopy) {
1130+
for (MTRDeviceController_Concrete * controller in controllersCopy) {
11311131
auto * compressedFabricId = controller.compressedFabricID;
11321132
if (compressedFabricId != nil && compressedFabricId.unsignedLongLongValue == operationalID.GetCompressedFabricId()) {
11331133
ChipLogProgress(Controller, "Notifying controller at fabric index %u about new operational node 0x" ChipLogFormatX64,
@@ -1140,10 +1140,10 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID
11401140
}
11411141
}
11421142

1143-
- (nullable MTRDeviceController *)_findPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate
1143+
- (nullable MTRDeviceController_Concrete *)_findPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate
11441144
{
11451145
std::lock_guard lock(_controllersLock);
1146-
for (MTRDeviceController * controller in _controllers) {
1146+
for (MTRDeviceController_Concrete * controller in _controllers) {
11471147
// TODO: Once we know our controllers are MTRDeviceController_Concrete, move
11481148
// matchesPendingShutdownControllerWithOperationalCertificate and clearPendingShutdown to that
11491149
// interface and remove them from base MTRDeviceController_Internal.
@@ -1156,22 +1156,22 @@ - (nullable MTRDeviceController *)_findPendingShutdownControllerWithOperationalC
11561156
return nil;
11571157
}
11581158

1159-
- (nullable MTRDeviceController *)initializeController:(MTRDeviceController_Concrete *)controller
1160-
withParameters:(MTRDeviceControllerParameters *)parameters
1161-
error:(NSError * __autoreleasing *)error
1159+
- (nullable MTRDeviceController_Concrete *)initializeController:(MTRDeviceController_Concrete *)controller
1160+
withParameters:(MTRDeviceControllerParameters *)parameters
1161+
error:(NSError * __autoreleasing *)error
11621162
{
11631163
[self _assertCurrentQueueIsNotMatterQueue];
11641164

11651165
// If there is a controller already running with matching parameters that is conceptually shut down from the API consumer's viewpoint, re-use it.
1166-
MTRDeviceController * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:parameters.operationalCertificate andRootCertificate:parameters.rootCertificate];
1166+
MTRDeviceController_Concrete * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:parameters.operationalCertificate andRootCertificate:parameters.rootCertificate];
11671167
if (existingController) {
11681168
return existingController;
11691169
}
11701170

11711171
return [self _startDeviceController:controller
11721172
startupParams:parameters
11731173
fabricChecker:^MTRDeviceControllerStartupParamsInternal *(
1174-
FabricTable * fabricTable, MTRDeviceController * controller, CHIP_ERROR & fabricError) {
1174+
FabricTable * fabricTable, MTRDeviceController_Concrete * controller, CHIP_ERROR & fabricError) {
11751175
auto advertiseOperational = self->_advertiseOperational && parameters.shouldAdvertiseOperational;
11761176
auto * params =
11771177
[[MTRDeviceControllerStartupParamsInternal alloc] initForNewController:controller

src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ MTR_DIRECT_MEMBERS
9292
/**
9393
* Initialize an MTRDeviceController_Concrete with the given parameters.
9494
*/
95-
- (nullable MTRDeviceController *)initializeController:(MTRDeviceController_Concrete *)controller
96-
withParameters:(MTRDeviceControllerParameters *)parameters
97-
error:(NSError * __autoreleasing *)error;
95+
- (nullable MTRDeviceController_Concrete *)initializeController:(MTRDeviceController_Concrete *)controller
96+
withParameters:(MTRDeviceControllerParameters *)parameters
97+
error:(NSError * __autoreleasing *)error;
9898

9999
/**
100100
* Add a server endpoint. This will verify that there is no existing server

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ - (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParamete
157157

158158
// Start us up normally. MTRDeviceControllerFactory will auto-start in per-controller-storage mode if necessary.
159159
MTRDeviceControllerFactory * factory = MTRDeviceControllerFactory.sharedInstance;
160-
id controller = [factory initializeController:self
161-
withParameters:controllerParameters
162-
error:error];
160+
auto * controller = [factory initializeController:self
161+
withParameters:controllerParameters
162+
error:error];
163163
return controller;
164164
}
165165

0 commit comments

Comments
 (0)