69
69
70
70
static NSString * const kErrorPersistentStorageInit = @" Init failure while creating a persistent storage delegate" ;
71
71
static NSString * const kErrorSessionResumptionStorageInit = @" Init failure while creating a session resumption storage delegate" ;
72
- static NSString * const kErrorGroupProviderInit = @" Init failure while initializing group data provider" ;
73
- static NSString * const kErrorControllersInit = @" Init controllers array failure" ;
74
- static NSString * const kErrorCertificateValidityPolicyInit = @" Init certificate validity policy failure" ;
75
72
static NSString * const kErrorControllerFactoryInit = @" Init failure while initializing controller factory" ;
76
73
static NSString * const kErrorKeystoreInit = @" Init failure while initializing persistent storage keystore" ;
77
74
static NSString * const kErrorCertStoreInit = @" Init failure while initializing persistent storage operational certificate store" ;
78
- static NSString * const kErrorSessionKeystoreInit = @" Init failure while initializing session keystore" ;
79
75
80
76
static bool sExitHandlerRegistered = false ;
81
77
static void ShutdownOnExit ()
@@ -97,13 +93,13 @@ @implementation MTRDeviceControllerFactory {
97
93
dispatch_queue_t _chipWorkQueue;
98
94
DeviceControllerFactory * _controllerFactory;
99
95
100
- Credentials::IgnoreCertificateValidityPeriodPolicy * _certificateValidityPolicy;
101
- Crypto::RawKeySessionKeystore * _sessionKeystore;
96
+ Credentials::IgnoreCertificateValidityPeriodPolicy _certificateValidityPolicy;
97
+ Crypto::RawKeySessionKeystore _sessionKeystore;
102
98
// We use TestPersistentStorageDelegate just to get an in-memory store to back
103
99
// our group data provider impl. We initialize this store correctly on every
104
100
// controller startup, so don't need to actually persist it.
105
- TestPersistentStorageDelegate * _groupStorageDelegate;
106
- Credentials::GroupDataProviderImpl * _groupDataProvider;
101
+ TestPersistentStorageDelegate _groupStorageDelegate;
102
+ Credentials::GroupDataProviderImpl _groupDataProvider;
107
103
108
104
// _usingPerControllerStorage is only written once, during controller
109
105
// factory start. After that it is only read, and can be read from
@@ -201,54 +197,30 @@ - (instancetype)init
201
197
// cost to having an idle dispatch queue, and it simplifies our logic.
202
198
DeviceLayer::PlatformMgrImpl ().StartEventLoopTask ();
203
199
204
- _running = NO ;
205
200
_chipWorkQueue = DeviceLayer::PlatformMgrImpl ().GetWorkQueue ();
206
201
_controllerFactory = &DeviceControllerFactory::GetInstance ();
207
- _controllersLock = OS_UNFAIR_LOCK_INIT;
208
-
209
- _sessionKeystore = new chip::Crypto::RawKeySessionKeystore ();
210
- if ([self checkForInitError: (_sessionKeystore != nullptr ) logMsg: kErrorSessionKeystoreInit ]) {
211
- return nil ;
212
- }
213
-
214
- _groupStorageDelegate = new chip::TestPersistentStorageDelegate ();
215
- if ([self checkForInitError: (_groupStorageDelegate != nullptr ) logMsg: kErrorGroupProviderInit ]) {
216
- return nil ;
217
- }
218
202
203
+ // Initialize our default-constructed GroupDataProviderImpl.
219
204
// For now default args are fine, since we are just using this for the IPK.
220
- _groupDataProvider = new chip::Credentials::GroupDataProviderImpl ();
221
- if ([self checkForInitError: (_groupDataProvider != nullptr ) logMsg: kErrorGroupProviderInit ]) {
222
- return nil ;
223
- }
224
-
225
- _groupDataProvider->SetStorageDelegate (_groupStorageDelegate);
226
- _groupDataProvider->SetSessionKeystore (_sessionKeystore);
227
- CHIP_ERROR errorCode = _groupDataProvider->Init ();
228
- if ([self checkForInitError: (CHIP_NO_ERROR == errorCode) logMsg: kErrorGroupProviderInit ]) {
229
- return nil ;
230
- }
205
+ _groupDataProvider.SetStorageDelegate (&_groupStorageDelegate);
206
+ _groupDataProvider.SetSessionKeystore (&_sessionKeystore);
207
+ CHIP_ERROR err = _groupDataProvider.Init ();
208
+ VerifyOrDieWithMsg (err == CHIP_NO_ERROR, NotSpecified,
209
+ " GroupDataProviderImpl::Init() failed: %" CHIP_ERROR_FORMAT, err.Format ());
231
210
211
+ _controllersLock = OS_UNFAIR_LOCK_INIT;
232
212
_controllers = [[NSMutableArray alloc ] init ];
233
- if ([self checkForInitError: (_controllers != nil ) logMsg: kErrorControllersInit ]) {
234
- return nil ;
235
- }
236
213
237
- _certificateValidityPolicy = new Credentials::IgnoreCertificateValidityPeriodPolicy ();
238
- if ([self checkForInitError: (_certificateValidityPolicy != nil ) logMsg: kErrorCertificateValidityPolicyInit ]) {
239
- return nil ;
240
- }
241
-
242
- _serverEndpoints = [[NSMutableArray alloc ] init ];
243
214
_serverEndpointsLock = OS_UNFAIR_LOCK_INIT;
215
+ _serverEndpoints = [[NSMutableArray alloc ] init ];
244
216
245
217
return self;
246
218
}
247
219
248
220
- (void )dealloc
249
221
{
250
222
[self stopControllerFactory ];
251
- [ self cleanupInitObjects ] ;
223
+ _groupDataProvider. Finish () ;
252
224
}
253
225
254
226
- (void )_assertCurrentQueueIsNotMatterQueue
@@ -271,45 +243,6 @@ - (BOOL)checkIsRunning:(NSError * __autoreleasing *)error
271
243
return NO ;
272
244
}
273
245
274
- - (BOOL )checkForInitError : (BOOL )condition logMsg : (NSString *)logMsg
275
- {
276
- if (condition) {
277
- return NO ;
278
- }
279
-
280
- MTR_LOG_ERROR (" Error: %@" , logMsg);
281
-
282
- [self cleanupInitObjects ];
283
-
284
- return YES ;
285
- }
286
-
287
- - (void )cleanupInitObjects
288
- {
289
- _controllers = nil ;
290
-
291
- if (_groupDataProvider) {
292
- _groupDataProvider->Finish ();
293
- delete _groupDataProvider;
294
- _groupDataProvider = nullptr ;
295
- }
296
-
297
- if (_groupStorageDelegate) {
298
- delete _groupStorageDelegate;
299
- _groupStorageDelegate = nullptr ;
300
- }
301
-
302
- if (_sessionKeystore) {
303
- delete _sessionKeystore;
304
- _sessionKeystore = nullptr ;
305
- }
306
-
307
- if (_certificateValidityPolicy) {
308
- delete _certificateValidityPolicy;
309
- _certificateValidityPolicy = nullptr ;
310
- }
311
- }
312
-
313
246
- (void )cleanupStartupObjects
314
247
{
315
248
assertChipStackLockedByCurrentThread ();
@@ -485,12 +418,12 @@ - (BOOL)_startControllerFactory:(MTRDeviceControllerFactoryParams *)startupParam
485
418
}
486
419
params.enableServerInteractions = startupParams.shouldStartServer ;
487
420
488
- params.groupDataProvider = _groupDataProvider;
489
- params.sessionKeystore = _sessionKeystore;
421
+ params.groupDataProvider = & _groupDataProvider;
422
+ params.sessionKeystore = & _sessionKeystore;
490
423
params.fabricIndependentStorage = _persistentStorageDelegate;
491
424
params.operationalKeystore = _keystore;
492
425
params.opCertStore = _opCertStore;
493
- params.certificateValidityPolicy = _certificateValidityPolicy;
426
+ params.certificateValidityPolicy = & _certificateValidityPolicy;
494
427
params.sessionResumptionStorage = _sessionResumptionStorage;
495
428
errorCode = _controllerFactory->Init (params);
496
429
if (errorCode != CHIP_NO_ERROR) {
@@ -1025,7 +958,7 @@ - (void)controllerShuttingDown:(MTRDeviceController *)controller
1025
958
// Clear out out group keys for this fabric index, in case fabric
1026
959
// indices get reused later. If a new controller is started on the
1027
960
// same fabric it will be handed the IPK at that point.
1028
- self->_groupDataProvider -> RemoveGroupKeys (fabricIndex);
961
+ self->_groupDataProvider . RemoveGroupKeys (fabricIndex);
1029
962
}
1030
963
1031
964
// If there are no other controllers left, we can shut down some things.
@@ -1269,9 +1202,9 @@ - (PersistentStorageDelegate *)storageDelegate
1269
1202
return _persistentStorageDelegate;
1270
1203
}
1271
1204
1272
- - (Credentials::GroupDataProvider *)groupData
1205
+ - (Credentials::GroupDataProvider *)groupDataProvider
1273
1206
{
1274
- return _groupDataProvider;
1207
+ return & _groupDataProvider;
1275
1208
}
1276
1209
1277
1210
@end
0 commit comments