@@ -73,41 +73,36 @@ CHIP_ERROR DeviceControllerFactory::Init(FactoryInitParams params)
73
73
return err;
74
74
}
75
75
76
- CHIP_ERROR DeviceControllerFactory::InitSystemState ()
76
+ CHIP_ERROR DeviceControllerFactory::ReinitSystemStateIfNecessary ()
77
77
{
78
+ VerifyOrReturnError (mSystemState != nullptr , CHIP_ERROR_INCORRECT_STATE);
79
+ VerifyOrReturnError (mSystemState ->IsShutdown (), CHIP_NO_ERROR);
80
+
78
81
FactoryInitParams params;
79
- if (mSystemState != nullptr )
80
- {
81
- params.systemLayer = mSystemState ->SystemLayer ();
82
- params.udpEndPointManager = mSystemState ->UDPEndPointManager ();
82
+ params.systemLayer = mSystemState ->SystemLayer ();
83
+ params.udpEndPointManager = mSystemState ->UDPEndPointManager ();
83
84
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
84
- params.tcpEndPointManager = mSystemState ->TCPEndPointManager ();
85
+ params.tcpEndPointManager = mSystemState ->TCPEndPointManager ();
85
86
#endif
86
87
#if CONFIG_NETWORK_LAYER_BLE
87
- params.bleLayer = mSystemState ->BleLayer ();
88
+ params.bleLayer = mSystemState ->BleLayer ();
88
89
#endif
89
- params.listenPort = mListenPort ;
90
- params.fabricIndependentStorage = mFabricIndependentStorage ;
91
- params.enableServerInteractions = mEnableServerInteractions ;
92
- params.groupDataProvider = mSystemState ->GetGroupDataProvider ();
93
- params.sessionKeystore = mSystemState ->GetSessionKeystore ();
94
- params.fabricTable = mSystemState ->Fabrics ();
95
- params.operationalKeystore = mOperationalKeystore ;
96
- params.opCertStore = mOpCertStore ;
97
- params.certificateValidityPolicy = mCertificateValidityPolicy ;
98
- params.sessionResumptionStorage = mSessionResumptionStorage ;
99
- }
90
+ params.listenPort = mListenPort ;
91
+ params.fabricIndependentStorage = mFabricIndependentStorage ;
92
+ params.enableServerInteractions = mEnableServerInteractions ;
93
+ params.groupDataProvider = mSystemState ->GetGroupDataProvider ();
94
+ params.sessionKeystore = mSystemState ->GetSessionKeystore ();
95
+ params.fabricTable = mSystemState ->Fabrics ();
96
+ params.operationalKeystore = mOperationalKeystore ;
97
+ params.opCertStore = mOpCertStore ;
98
+ params.certificateValidityPolicy = mCertificateValidityPolicy ;
99
+ params.sessionResumptionStorage = mSessionResumptionStorage ;
100
100
101
101
return InitSystemState (params);
102
102
}
103
103
104
104
CHIP_ERROR DeviceControllerFactory::InitSystemState (FactoryInitParams params)
105
105
{
106
- if (mSystemState != nullptr && mSystemState ->IsInitialized ())
107
- {
108
- return CHIP_NO_ERROR;
109
- }
110
-
111
106
if (mSystemState != nullptr )
112
107
{
113
108
Platform::Delete (mSystemState );
@@ -331,10 +326,8 @@ void DeviceControllerFactory::ControllerInitialized(const DeviceController & con
331
326
332
327
CHIP_ERROR DeviceControllerFactory::SetupController (SetupParams params, DeviceController & controller)
333
328
{
334
- VerifyOrReturnError (mSystemState != nullptr , CHIP_ERROR_INCORRECT_STATE);
335
329
VerifyOrReturnError (params.controllerVendorId != VendorId::Unspecified, CHIP_ERROR_INVALID_ARGUMENT);
336
-
337
- ReturnErrorOnFailure (InitSystemState ());
330
+ ReturnErrorOnFailure (ReinitSystemStateIfNecessary ());
338
331
339
332
ControllerInitParams controllerParams;
340
333
PopulateInitParams (controllerParams, params);
@@ -351,10 +344,8 @@ CHIP_ERROR DeviceControllerFactory::SetupController(SetupParams params, DeviceCo
351
344
352
345
CHIP_ERROR DeviceControllerFactory::SetupCommissioner (SetupParams params, DeviceCommissioner & commissioner)
353
346
{
354
- VerifyOrReturnError (mSystemState != nullptr , CHIP_ERROR_INCORRECT_STATE);
355
347
VerifyOrReturnError (params.controllerVendorId != VendorId::Unspecified, CHIP_ERROR_INVALID_ARGUMENT);
356
-
357
- ReturnErrorOnFailure (InitSystemState ());
348
+ ReturnErrorOnFailure (ReinitSystemStateIfNecessary ());
358
349
359
350
CommissionerInitParams commissionerParams;
360
351
@@ -397,6 +388,13 @@ bool DeviceControllerFactory::ReleaseSystemState()
397
388
return mSystemState ->Release ();
398
389
}
399
390
391
+ CHIP_ERROR DeviceControllerFactory::EnsureAndRetainSystemState ()
392
+ {
393
+ ReturnErrorOnFailure (ReinitSystemStateIfNecessary ());
394
+ RetainSystemState ();
395
+ return CHIP_NO_ERROR;
396
+ }
397
+
400
398
DeviceControllerFactory::~DeviceControllerFactory ()
401
399
{
402
400
Shutdown ();
0 commit comments