2525#include < app-common/zap-generated/ids/Clusters.h>
2626#include < app/AttributeAccessInterface.h>
2727#include < app/AttributeAccessInterfaceRegistry.h>
28- #include < app/icd/server/ICDNotifier.h>
28+
29+ #if CHIP_CONFIG_ENABLE_ICD_CIP
30+ #include < app/icd/server/ICDNotifier.h> // nogncheck
31+ #endif
32+ #include < app/reporting/reporting.h>
33+
2934#include < app/server/Server.h>
3035#include < app/util/attribute-storage.h>
3136
@@ -183,14 +188,8 @@ class IcdManagementFabricDelegate : public FabricTable::Delegate
183188/*
184189 * ICD Management Implementation
185190 */
186- #if CHIP_CONFIG_ENABLE_ICD_CIP
187- PersistentStorageDelegate * ICDManagementServer::mStorage = nullptr ;
188- Crypto::SymmetricKeystore * ICDManagementServer::mSymmetricKeystore = nullptr ;
189- #endif // CHIP_CONFIG_ENABLE_ICD_CIP
190191
191- ICDConfigurationData * ICDManagementServer::mICDConfigurationData = nullptr ;
192-
193- namespace {
192+ namespace {
194193IcdManagementAttributeAccess gAttribute ;
195194#if CHIP_CONFIG_ENABLE_ICD_CIP
196195IcdManagementFabricDelegate gFabricDelegate ;
@@ -279,6 +278,13 @@ CHIP_ERROR CheckAdmin(CommandHandler * commandObj, const ConcreteCommandPath & c
279278
280279} // namespace
281280
281+ #endif // CHIP_CONFIG_ENABLE_ICD_CIP
282+
283+ namespace chip ::app::Clusters {
284+
285+ ICDManagementServer ICDManagementServer::instance;
286+
287+ #if CHIP_CONFIG_ENABLE_ICD_CIP
282288Status ICDManagementServer::RegisterClient (CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
283289 const Commands::RegisterClient::DecodableType & commandData, uint32_t & icdCounter)
284290{
@@ -354,7 +360,7 @@ Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const Co
354360 // Notify subscribers that the first entry for the fabric was successfully added
355361 TriggerICDMTableUpdatedEvent ();
356362 }
357-
363+ MatterReportingAttributeChangeCallback ( kRootEndpointId , IcdManagement::Id, IcdManagement::Attributes::RegisteredClients::Id);
358364 icdCounter = mICDConfigurationData ->GetICDCounter ().GetValue ();
359365 return Status::Success;
360366}
@@ -393,6 +399,7 @@ Status ICDManagementServer::UnregisterClient(CommandHandler * commandObj, const
393399 TriggerICDMTableUpdatedEvent ();
394400 }
395401
402+ MatterReportingAttributeChangeCallback (kRootEndpointId , IcdManagement::Id, IcdManagement::Attributes::RegisteredClients::Id);
396403 return Status::Success;
397404}
398405
@@ -413,6 +420,14 @@ void ICDManagementServer::Init(PersistentStorageDelegate & storage, Crypto::Symm
413420 mICDConfigurationData = &icdConfigurationData;
414421}
415422
423+ void ICDManagementServer::OnICDModeChange ()
424+ {
425+ // Notify attribute change for OperatingMode attribute
426+ MatterReportingAttributeChangeCallback (kRootEndpointId , IcdManagement::Id, IcdManagement::Attributes::OperatingMode::Id);
427+ }
428+
429+ } // namespace chip::app::Clusters
430+
416431/* *********************************************************
417432 * Callbacks Implementation
418433 *********************************************************/
@@ -427,8 +442,7 @@ bool emberAfIcdManagementClusterRegisterClientCallback(CommandHandler * commandO
427442{
428443 uint32_t icdCounter = 0 ;
429444
430- ICDManagementServer server;
431- Status status = server.RegisterClient (commandObj, commandPath, commandData, icdCounter);
445+ Status status = ICDManagementServer::GetInstance ().RegisterClient (commandObj, commandPath, commandData, icdCounter);
432446
433447 if (Status::Success == status)
434448 {
@@ -450,8 +464,7 @@ bool emberAfIcdManagementClusterRegisterClientCallback(CommandHandler * commandO
450464bool emberAfIcdManagementClusterUnregisterClientCallback (CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
451465 const Commands::UnregisterClient::DecodableType & commandData)
452466{
453- ICDManagementServer server;
454- Status status = server.UnregisterClient (commandObj, commandPath, commandData);
467+ Status status = ICDManagementServer::GetInstance ().UnregisterClient (commandObj, commandPath, commandData);
455468
456469 commandObj->AddStatus (commandPath, status);
457470 return true ;
@@ -493,5 +506,31 @@ void MatterIcdManagementPluginServerInitCallback()
493506 AttributeAccessInterfaceRegistry::Instance ().Register (&gAttribute );
494507
495508 // Configure ICD Management
496- ICDManagementServer::Init (storage, symmetricKeystore, icdConfigurationData);
509+ ICDManagementServer::GetInstance ().Init (storage, symmetricKeystore, icdConfigurationData);
510+
511+ // TODO(#32321): Remove #if after issue is resolved
512+ // Note: We only need this #if statement for platform examples that enable the ICD management server without building the sample
513+ // as an ICD. Since this is not spec compliant, we should remove this #if statement once we stop compiling the ICD management
514+ // server in those examples.
515+ #if CHIP_CONFIG_ENABLE_ICD_SERVER
516+ Server::GetInstance ().GetICDManager ().RegisterObserver (&ICDManagementServer::GetInstance ());
517+ #endif // CHIP_CONFIG_ENABLE_ICD_SERVER
518+ }
519+
520+ void MatterIcdManagementPluginServerShutdownCallback ()
521+ {
522+ AttributeAccessInterfaceRegistry::Instance ().Unregister (&gAttribute );
523+
524+ #if CHIP_CONFIG_ENABLE_ICD_CIP
525+ FabricTable & fabricTable = Server::GetInstance ().GetFabricTable ();
526+ fabricTable.RemoveFabricDelegate (&gFabricDelegate );
527+ #endif // CHIP_CONFIG_ENABLE_ICD_CIP
528+
529+ // TODO(#32321): Remove #if after issue is resolved
530+ // Note: We only need this #if statement for platform examples that enable the ICD management server without building the sample
531+ // as an ICD. Since this is not spec compliant, we should remove this #if statement once we stop compiling the ICD management
532+ // server in those examples.
533+ #if CHIP_CONFIG_ENABLE_ICD_SERVER
534+ Server::GetInstance ().GetICDManager ().ReleaseObserver (&ICDManagementServer::GetInstance ());
535+ #endif // CHIP_CONFIG_ENABLE_ICD_SERVER
497536}
0 commit comments