@@ -131,6 +131,8 @@ @implementation MTRDeviceController {
131
131
MTRP256KeypairBridge _signingKeypairBridge;
132
132
MTRP256KeypairBridge _operationalKeypairBridge;
133
133
134
+ BOOL _suspended;
135
+
134
136
// Counters to track assertion status and access controlled by the _assertionLock
135
137
NSUInteger _keepRunningAssertionCounter;
136
138
BOOL _shutdownPending;
@@ -142,7 +144,7 @@ - (os_unfair_lock_t)deviceMapLock
142
144
return &_underlyingDeviceMapLock;
143
145
}
144
146
145
- - (instancetype )initForSubclasses
147
+ - (instancetype )initForSubclasses : ( BOOL ) startSuspended
146
148
{
147
149
if (self = [super init ]) {
148
150
// nothing, as superclass of MTRDeviceController is NSObject
@@ -153,15 +155,17 @@ - (instancetype)initForSubclasses
153
155
_keepRunningAssertionCounter = 0 ;
154
156
_shutdownPending = NO ;
155
157
_assertionLock = OS_UNFAIR_LOCK_INIT;
158
+
159
+ _suspended = startSuspended;
160
+
156
161
return self;
157
162
}
158
163
159
164
- (nullable MTRDeviceController *)initWithParameters : (MTRDeviceControllerAbstractParameters *)parameters error : (NSError * __autoreleasing *)error
160
165
{
161
166
if ([parameters isKindOfClass: MTRXPCDeviceControllerParameters.class ]) {
162
- MTRXPCDeviceControllerParameters * resolvedParameters = (MTRXPCDeviceControllerParameters *) parameters;
163
167
MTR_LOG (" Starting up with XPC Device Controller Parameters: %@" , parameters);
164
- return [[MTRDeviceController_XPC alloc ] initWithUniqueIdentifier: resolvedParameters.uniqueIdentifier xpConnectionBlock: resolvedParameters.xpcConnectionBlock ];
168
+ return [[MTRDeviceController_XPC alloc ] initWithParameters: parameters error: error ];
165
169
} else if (![parameters isKindOfClass: MTRDeviceControllerParameters.class ]) {
166
170
MTR_LOG_ERROR (" Unsupported type of MTRDeviceControllerAbstractParameters: %@" , parameters);
167
171
if (error) {
@@ -184,6 +188,7 @@ - (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
184
188
uniqueIdentifier : (NSUUID *)uniqueIdentifier
185
189
concurrentSubscriptionPoolSize : (NSUInteger )concurrentSubscriptionPoolSize
186
190
storageBehaviorConfiguration : (MTRDeviceStorageBehaviorConfiguration *)storageBehaviorConfiguration
191
+ startSuspended : (BOOL )startSuspended
187
192
{
188
193
if (self = [super init ]) {
189
194
// Make sure our storage is all set up to work as early as possible,
@@ -195,6 +200,8 @@ - (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
195
200
_shutdownPending = NO ;
196
201
_assertionLock = OS_UNFAIR_LOCK_INIT;
197
202
203
+ _suspended = startSuspended;
204
+
198
205
if (storageDelegate != nil ) {
199
206
if (storageDelegateQueue == nil ) {
200
207
MTR_LOG_ERROR (" storageDelegate provided without storageDelegateQueue" );
@@ -331,6 +338,34 @@ - (BOOL)isRunning
331
338
return _cppCommissioner != nullptr ;
332
339
}
333
340
341
+ #pragma mark - Suspend/resume support
342
+
343
+ - (BOOL )isSuspended
344
+ {
345
+ return _suspended;
346
+ }
347
+
348
+ - (void )suspend
349
+ {
350
+ _suspended = YES ;
351
+
352
+ // TODO: In the concrete class (which is unused so far!), iterate our
353
+ // MTRDevices, tell them to tear down subscriptions. Possibly close all
354
+ // CASE sessions for our identity. Possibly try to see whether we can
355
+ // change our fabric entry to not advertise and restart advertising.
356
+
357
+ // TODO: What should happen with active commissioning sessions? Presumably
358
+ // close them?
359
+ }
360
+
361
+ - (void )resume
362
+ {
363
+ _suspended = NO ;
364
+
365
+ // TODO: In the concrete class (which is unused so far!), iterate our
366
+ // MTRDevices, tell them to restart subscriptions.
367
+ }
368
+
334
369
- (BOOL )matchesPendingShutdownControllerWithOperationalCertificate : (nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate : (nullable MTRCertificateDERBytes)rootCertificate
335
370
{
336
371
if (!operationalCertificate || !rootCertificate) {
0 commit comments