26
26
#import " MTRCommissionableBrowserResult_Internal.h"
27
27
#import " MTRCommissioningParameters.h"
28
28
#import " MTRConversion.h"
29
+ #import " MTRDefines_Internal.h"
29
30
#import " MTRDeviceControllerDelegateBridge.h"
30
31
#import " MTRDeviceControllerFactory_Internal.h"
31
32
#import " MTRDeviceControllerLocalTestStorage.h"
@@ -160,11 +161,6 @@ @implementation MTRDeviceController {
160
161
// specific queue, so can't race against each other.
161
162
std::atomic<bool > _suspended;
162
163
163
- // Counters to track assertion status and access controlled by the _assertionLock
164
- NSUInteger _keepRunningAssertionCounter;
165
- BOOL _shutdownPending;
166
- os_unfair_lock _assertionLock;
167
-
168
164
NSMutableArray <MTRDeviceControllerDelegateInfo *> * _delegates;
169
165
id <MTRDeviceControllerDelegate> _strongDelegateForSetDelegateAPI;
170
166
}
@@ -183,11 +179,6 @@ - (instancetype)initForSubclasses:(BOOL)startSuspended
183
179
}
184
180
_underlyingDeviceMapLock = OS_UNFAIR_LOCK_INIT;
185
181
186
- // Setup assertion variables
187
- _keepRunningAssertionCounter = 0 ;
188
- _shutdownPending = NO ;
189
- _assertionLock = OS_UNFAIR_LOCK_INIT;
190
-
191
182
_suspended = startSuspended;
192
183
193
184
_nodeIDToDeviceMap = [NSMapTable strongToWeakObjectsMapTable ];
@@ -231,11 +222,6 @@ - (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
231
222
// before we start doing anything else with the controller.
232
223
_uniqueIdentifier = uniqueIdentifier;
233
224
234
- // Setup assertion variables
235
- _keepRunningAssertionCounter = 0 ;
236
- _shutdownPending = NO ;
237
- _assertionLock = OS_UNFAIR_LOCK_INIT;
238
-
239
225
_suspended = startSuspended;
240
226
241
227
if (storageDelegate != nil ) {
@@ -478,75 +464,21 @@ - (void)_controllerResumed
478
464
479
465
- (BOOL )matchesPendingShutdownControllerWithOperationalCertificate : (nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate : (nullable MTRCertificateDERBytes)rootCertificate
480
466
{
481
- if (!operationalCertificate || !rootCertificate) {
482
- return FALSE ;
483
- }
484
- NSNumber * nodeID = [MTRDeviceControllerParameters nodeIDFromNOC: operationalCertificate];
485
- NSNumber * fabricID = [MTRDeviceControllerParameters fabricIDFromNOC: operationalCertificate];
486
- NSData * publicKey = [MTRDeviceControllerParameters publicKeyFromCertificate: rootCertificate];
487
-
488
- std::lock_guard lock (_assertionLock);
489
-
490
- // If any of the local above are nil, the return will be false since MTREqualObjects handles them correctly
491
- return _keepRunningAssertionCounter > 0 && _shutdownPending && MTREqualObjects (nodeID, self.nodeID ) && MTREqualObjects (fabricID, self.fabricID ) && MTREqualObjects (publicKey, self.rootPublicKey );
492
- }
493
-
494
- - (void )addRunAssertion
495
- {
496
- std::lock_guard lock (_assertionLock);
497
-
498
- // Only take an assertion if running
499
- if ([self isRunning ]) {
500
- ++_keepRunningAssertionCounter;
501
- MTR_LOG (" %@ Adding keep running assertion, total %lu" , self, static_cast <unsigned long >(_keepRunningAssertionCounter));
502
- }
503
- }
504
-
505
- - (void )removeRunAssertion ;
506
- {
507
- std::lock_guard lock (_assertionLock);
508
-
509
- if (_keepRunningAssertionCounter > 0 ) {
510
- --_keepRunningAssertionCounter;
511
- MTR_LOG (" %@ Removing keep running assertion, total %lu" , self, static_cast <unsigned long >(_keepRunningAssertionCounter));
512
-
513
- if ([self isRunning ] && _keepRunningAssertionCounter == 0 && _shutdownPending) {
514
- MTR_LOG (" %@ All assertions removed and shutdown is pending, shutting down" , self);
515
- [self finalShutdown ];
516
- }
517
- }
467
+ // TODO: Once the factory knows it's dealing with MTRDeviceController_Concrete, this can be removed, and its
468
+ // declaration moved to MTRDeviceController_Concrete.
469
+ return NO ;
518
470
}
519
471
520
472
- (void )clearPendingShutdown
521
473
{
522
- std::lock_guard lock (_assertionLock);
523
- _shutdownPending = NO ;
474
+ // TODO: Once the factory knows it's dealing with MTRDeviceController_Concrete, this can be removed, and its
475
+ // declaration moved to MTRDeviceController_Concrete.
476
+ MTR_ABSTRACT_METHOD ();
524
477
}
525
478
526
479
- (void )shutdown
527
480
{
528
- std::lock_guard lock (_assertionLock);
529
-
530
- if (_keepRunningAssertionCounter > 0 ) {
531
- MTR_LOG (" %@ Pending shutdown since %lu assertions are present" , self, static_cast <unsigned long >(_keepRunningAssertionCounter));
532
- _shutdownPending = YES ;
533
- return ;
534
- }
535
- [self finalShutdown ];
536
- }
537
-
538
- - (void )finalShutdown
539
- {
540
- os_unfair_lock_assert_owner (&_assertionLock);
541
-
542
- MTR_LOG (" %@ shutdown called" , self);
543
- if (_cppCommissioner == nullptr ) {
544
- // Already shut down.
545
- return ;
546
- }
547
-
548
- MTR_LOG (" Shutting down %@: %@" , NSStringFromClass (self.class ), self);
549
- [self cleanupAfterStartup ];
481
+ MTR_ABSTRACT_METHOD ();
550
482
}
551
483
552
484
// Clean up from a state where startup was called.
@@ -604,7 +536,6 @@ - (void)shutDownCppController
604
536
_operationalCredentialsDelegate->SetDeviceCommissioner (nullptr );
605
537
}
606
538
}
607
- _shutdownPending = NO ;
608
539
}
609
540
610
541
- (void )deinitFromFactory
0 commit comments