Skip to content

Commit 4eddd6e

Browse files
Fix the matter server shutdown flow and add DataModelShutdown
1 parent f6c3c83 commit 4eddd6e

11 files changed

+118
-0
lines changed

src/app/server/Server.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ void Server::Shutdown()
651651
#if CHIP_CONFIG_ENABLE_ICD_SERVER
652652
app::DnssdServer::Instance().SetICDManager(nullptr);
653653
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
654+
655+
app::InteractionModelEngine::GetInstance()->SetDataModelProvider(nullptr);
654656
app::DnssdServer::Instance().SetCommissioningModeProvider(nullptr);
655657
Dnssd::ServiceAdvertiser::Instance().Shutdown();
656658

@@ -681,11 +683,13 @@ void Server::Shutdown()
681683
mCommissioningWindowManager.Shutdown();
682684
mMessageCounterManager.Shutdown();
683685
mExchangeMgr.Shutdown();
686+
mFabrics.RemoveFabricDelegate(&mFabricDelegate);
684687
mSessions.Shutdown();
685688
mTransports.Close();
686689
mAccessControl.Finish();
687690
Access::ResetAccessControlToDefault();
688691
Credentials::SetGroupDataProvider(nullptr);
692+
app::EventManagement::GetInstance().DestroyEventManagement();
689693
#if CHIP_CONFIG_ENABLE_ICD_SERVER
690694
// Remove Test Event Trigger Handler
691695
if (mTestEventTriggerDelegate != nullptr)
@@ -695,6 +699,7 @@ void Server::Shutdown()
695699
mICDManager.Shutdown();
696700
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
697701

702+
mFabrics.Shutdown();
698703
// TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code
699704
chip::Platform::MemoryShutdown();
700705
}

src/app/util/DataModelHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ void InitDataModelHandler()
2828
emberAfEndpointConfigure();
2929
emberAfInit();
3030
}
31+
32+
void ShutdownDataModelHandler()
33+
{
34+
emberAfShutdown();
35+
}

src/app/util/DataModelHandler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121
* data model messages.
2222
*/
2323
void InitDataModelHandler();
24+
25+
/**
26+
* Shutdown the data model.
27+
*/
28+
void ShutdownDataModelHandler();

src/app/util/attribute-storage-detail.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extern uint8_t attributeData[]; // main storage bucket for all attributes
3232

3333
void emAfCallInits();
3434

35+
void emAfCallShutdowns();
36+
3537
chip::Protocols::InteractionModel::Status emAfReadOrWriteAttribute(const EmberAfAttributeSearchRecord * attRecord,
3638
const EmberAfAttributeMetadata ** metadata, uint8_t * buffer,
3739
uint16_t readLength, bool write);

src/app/util/attribute-storage.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ static void shutdownEndpoint(EmberAfDefinedEndpoint * definedEndpoint)
458458
for (clusterIndex = 0; clusterIndex < epType->clusterCount; clusterIndex++)
459459
{
460460
const EmberAfCluster * cluster = &(epType->cluster[clusterIndex]);
461+
emberAfClusterShutdownCallback(definedEndpoint->endpoint, cluster->clusterId);
461462
EmberAfGenericClusterFunction f = emberAfFindClusterFunction(cluster, MATTER_CLUSTER_FLAG_SHUTDOWN_FUNCTION);
462463
if (f != nullptr)
463464
{
@@ -482,6 +483,19 @@ void emAfCallInits()
482483
}
483484
}
484485

486+
// Calls the shutdown functions.
487+
void emAfCallShutdowns()
488+
{
489+
uint16_t index;
490+
for (index = 0; index < emberAfEndpointCount(); index++)
491+
{
492+
if (emberAfEndpointIndexIsEnabled(index))
493+
{
494+
shutdownEndpoint(&(emAfEndpoints[index]));
495+
}
496+
}
497+
}
498+
485499
// Returns the pointer to metadata, or null if it is not found
486500
const EmberAfAttributeMetadata * emberAfLocateAttributeMetadata(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId)
487501
{

src/app/util/generic-callbacks.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
*/
3636
void emberAfClusterInitCallback(chip::EndpointId endpoint, chip::ClusterId clusterId);
3737

38+
/** @brief Cluster Shutdown
39+
*
40+
* This function is called when a specific cluster is shutdown. It gives the
41+
* application an opportunity to take care of cluster shutdown procedures.
42+
* It is called exactly once for each endpoint where cluster is present.
43+
*
44+
* @param endpoint Ver.: always
45+
* @param clusterId Ver.: always
46+
*/
47+
void emberAfClusterShutdownCallback(chip::EndpointId endpoint, chip::ClusterId clusterId);
48+
3849
/** @brief Attribute Read Access
3950
*
4051
* This function is called whenever the Application Framework needs to check

src/app/util/util.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ void emberAfInit()
8484
emAfCallInits();
8585
}
8686

87+
// ****************************************
88+
// Shutdown Clusters
89+
// ****************************************
90+
void emberAfShutdown()
91+
{
92+
emAfCallShutdowns();
93+
MATTER_PLUGINS_SHUTDOWN
94+
}
95+
8796
// Cluster init functions that don't have a cluster implementation to define
8897
// them in.
8998
void MatterBallastConfigurationPluginServerInitCallback() {}
@@ -142,6 +151,63 @@ void MatterWaterHeaterManagementPluginServerInitCallback() {}
142151
void MatterWaterHeaterModePluginServerInitCallback() {}
143152
void MatterCommodityPricePluginServerInitCallback() {}
144153

154+
// Cluster shutdown functions that don't have a cluster implementation to define
155+
// them in.
156+
void MatterBallastConfigurationPluginServerShutdownCallback() {}
157+
void MatterBooleanStatePluginServerShutdownCallback() {}
158+
void MatterRelativeHumidityMeasurementPluginServerShutdownCallback() {}
159+
void MatterIlluminanceMeasurementPluginServerShutdownCallback() {}
160+
void MatterBinaryInputBasicPluginServerShutdownCallback() {}
161+
void MatterPressureMeasurementPluginServerShutdownCallback() {}
162+
void MatterTemperatureMeasurementPluginServerShutdownCallback() {}
163+
void MatterFlowMeasurementPluginServerShutdownCallback() {}
164+
void MatterThermostatUserInterfaceConfigurationPluginServerShutdownCallback() {}
165+
void MatterBridgedDeviceBasicInformationPluginServerShutdownCallback() {}
166+
void MatterPowerConfigurationPluginServerShutdownCallback() {}
167+
void MatterPowerProfilePluginServerShutdownCallback() {}
168+
void MatterPulseWidthModulationPluginServerShutdownCallback() {}
169+
void MatterAlarmsPluginServerShutdownCallback() {}
170+
void MatterTimePluginServerShutdownCallback() {}
171+
void MatterAclPluginServerShutdownCallback() {}
172+
void MatterPollControlPluginServerShutdownCallback() {}
173+
void MatterUnitLocalizationPluginServerShutdownCallback() {}
174+
void MatterProxyValidPluginServerShutdownCallback() {}
175+
void MatterProxyDiscoveryPluginServerShutdownCallback() {}
176+
void MatterProxyConfigurationPluginServerShutdownCallback() {}
177+
void MatterFanControlPluginServerShutdownCallback() {}
178+
void MatterActivatedCarbonFilterMonitoringPluginServerShutdownCallback() {}
179+
void MatterHepaFilterMonitoringPluginServerShutdownCallback() {}
180+
void MatterAirQualityPluginServerShutdownCallback() {}
181+
void MatterCarbonMonoxideConcentrationMeasurementPluginServerShutdownCallback() {}
182+
void MatterCarbonDioxideConcentrationMeasurementPluginServerShutdownCallback() {}
183+
void MatterFormaldehydeConcentrationMeasurementPluginServerShutdownCallback() {}
184+
void MatterNitrogenDioxideConcentrationMeasurementPluginServerShutdownCallback() {}
185+
void MatterOzoneConcentrationMeasurementPluginServerShutdownCallback() {}
186+
void MatterPm10ConcentrationMeasurementPluginServerShutdownCallback() {}
187+
void MatterPm1ConcentrationMeasurementPluginServerShutdownCallback() {}
188+
void MatterPm25ConcentrationMeasurementPluginServerShutdownCallback() {}
189+
void MatterRadonConcentrationMeasurementPluginServerShutdownCallback() {}
190+
void MatterTotalVolatileOrganicCompoundsConcentrationMeasurementPluginServerShutdownCallback() {}
191+
void MatterRvcRunModePluginServerShutdownCallback() {}
192+
void MatterRvcCleanModePluginServerShutdownCallback() {}
193+
void MatterDishwasherModePluginServerShutdownCallback() {}
194+
void MatterLaundryWasherModePluginServerShutdownCallback() {}
195+
void MatterRefrigeratorAndTemperatureControlledCabinetModePluginServerShutdownCallback() {}
196+
void MatterOperationalStatePluginServerShutdownCallback() {}
197+
void MatterRvcOperationalStatePluginServerShutdownCallback() {}
198+
void MatterOvenModePluginServerShutdownCallback() {}
199+
void MatterOvenCavityOperationalStatePluginServerShutdownCallback() {}
200+
void MatterDishwasherAlarmPluginServerShutdownCallback() {}
201+
void MatterMicrowaveOvenModePluginServerShutdownCallback() {}
202+
void MatterDeviceEnergyManagementModePluginServerShutdownCallback() {}
203+
void MatterEnergyEvseModePluginServerShutdownCallback() {}
204+
void MatterPowerTopologyPluginServerShutdownCallback() {}
205+
void MatterElectricalEnergyMeasurementPluginServerShutdownCallback() {}
206+
void MatterElectricalPowerMeasurementPluginServerShutdownCallback() {}
207+
void MatterServiceAreaPluginServerShutdownCallback() {}
208+
void MatterWaterHeaterManagementPluginServerShutdownCallback() {}
209+
void MatterWaterHeaterModePluginServerShutdownCallback() {}
210+
145211
bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId)
146212
{
147213
return (emberAfGetServerAttributeIndexByAttributeId(endpoint, clusterId, attributeId) != UINT16_MAX);

src/app/util/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
void emberAfInit();
2727

28+
void emberAfShutdown();
2829
/**
2930
* Retrieves the difference between the two passed values.
3031
* This function assumes that the two values have the same endianness.

src/credentials/FabricTable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ void FabricTable::Shutdown()
11681168
delegate->next = nullptr;
11691169
delegate = temp;
11701170
}
1171+
mDelegateListRoot = nullptr;
11711172

11721173
RevertPendingFabricData();
11731174
for (FabricInfo & fabricInfo : mStates)

src/data-model-providers/codegen/CodegenDataModelProvider.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ DefaultAttributePersistenceProvider gDefaultAttributePersistence;
133133
CHIP_ERROR CodegenDataModelProvider::Shutdown()
134134
{
135135
Reset();
136+
ShutdownDataModelForTesting();
136137
mRegistry.ClearContext();
137138
return CHIP_NO_ERROR;
138139
}
@@ -602,6 +603,12 @@ void CodegenDataModelProvider::InitDataModelForTesting()
602603
InitDataModelHandler();
603604
}
604605

606+
void CodegenDataModelProvider::ShutdownDataModelForTesting()
607+
{
608+
// Call the Ember-specific ShutdownDataModelHandler
609+
ShutdownDataModelHandler();
610+
}
611+
605612
CHIP_ERROR CodegenDataModelProvider::DeviceTypes(EndpointId endpointId, ReadOnlyBufferBuilder<DataModel::DeviceTypeEntry> & builder)
606613
{
607614
std::optional<unsigned> endpoint_index = TryFindEndpointIndex(endpointId);

src/data-model-providers/codegen/CodegenDataModelProvider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class CodegenDataModelProvider : public DataModel::Provider
8484
// This method serves as a placeholder and should NOT be used outside of specific tests.
8585
// It is expected to be removed or replaced with a proper implementation in the future.TODO:(#36837).
8686
virtual void InitDataModelForTesting();
87+
virtual void ShutdownDataModelForTesting();
8788

8889
private:
8990
// Iteration is often done in a tight loop going through all values.

0 commit comments

Comments
 (0)