2828#if CHIP_CONFIG_ENABLE_ICD_CIP
2929#include < app/icd/server/ICDNotifier.h> // nogncheck
3030#endif
31+ #include < app/reporting/reporting.h>
3132#include < app/server/Server.h>
3233#include < app/util/attribute-storage.h>
3334
@@ -185,12 +186,6 @@ class IcdManagementFabricDelegate : public FabricTable::Delegate
185186/*
186187 * ICD Management Implementation
187188 */
188- #if CHIP_CONFIG_ENABLE_ICD_CIP
189- PersistentStorageDelegate * ICDManagementServer::mStorage = nullptr ;
190- Crypto::SymmetricKeystore * ICDManagementServer::mSymmetricKeystore = nullptr ;
191- #endif // CHIP_CONFIG_ENABLE_ICD_CIP
192-
193- ICDConfigurationData * ICDManagementServer::mICDConfigurationData = nullptr ;
194189
195190namespace {
196191IcdManagementAttributeAccess gAttribute ;
@@ -281,6 +276,14 @@ CHIP_ERROR CheckAdmin(CommandHandler * commandObj, const ConcreteCommandPath & c
281276
282277} // namespace
283278
279+ #endif // CHIP_CONFIG_ENABLE_ICD_CIP
280+
281+ namespace chip ::app::Clusters {
282+
283+ ICDManagementServer ICDManagementServer::instance;
284+
285+ #if CHIP_CONFIG_ENABLE_ICD_CIP
286+
284287Status ICDManagementServer::RegisterClient (CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
285288 const Commands::RegisterClient::DecodableType & commandData, uint32_t & icdCounter)
286289{
@@ -356,7 +359,7 @@ Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const Co
356359 // Notify subscribers that the first entry for the fabric was successfully added
357360 TriggerICDMTableUpdatedEvent ();
358361 }
359-
362+ MatterReportingAttributeChangeCallback ( kRootEndpointId , IcdManagement::Id, IcdManagement::Attributes::RegisteredClients::Id);
360363 icdCounter = mICDConfigurationData ->GetICDCounter ().GetValue ();
361364 return Status::Success;
362365}
@@ -395,6 +398,7 @@ Status ICDManagementServer::UnregisterClient(CommandHandler * commandObj, const
395398 TriggerICDMTableUpdatedEvent ();
396399 }
397400
401+ MatterReportingAttributeChangeCallback (kRootEndpointId , IcdManagement::Id, IcdManagement::Attributes::RegisteredClients::Id);
398402 return Status::Success;
399403}
400404
@@ -415,6 +419,14 @@ void ICDManagementServer::Init(PersistentStorageDelegate & storage, Crypto::Symm
415419 mICDConfigurationData = &icdConfigurationData;
416420}
417421
422+ void ICDManagementServer::OnICDModeChange ()
423+ {
424+ // Notify attribute change for OperatingMode attribute
425+ MatterReportingAttributeChangeCallback (kRootEndpointId , IcdManagement::Id, IcdManagement::Attributes::OperatingMode::Id);
426+ }
427+
428+ } // namespace chip::app::Clusters
429+
418430/* *********************************************************
419431 * Callbacks Implementation
420432 *********************************************************/
@@ -429,8 +441,7 @@ bool emberAfIcdManagementClusterRegisterClientCallback(CommandHandler * commandO
429441{
430442 uint32_t icdCounter = 0 ;
431443
432- ICDManagementServer server;
433- Status status = server.RegisterClient (commandObj, commandPath, commandData, icdCounter);
444+ Status status = ICDManagementServer::GetInstance ().RegisterClient (commandObj, commandPath, commandData, icdCounter);
434445
435446 if (Status::Success == status)
436447 {
@@ -452,8 +463,7 @@ bool emberAfIcdManagementClusterRegisterClientCallback(CommandHandler * commandO
452463bool emberAfIcdManagementClusterUnregisterClientCallback (CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
453464 const Commands::UnregisterClient::DecodableType & commandData)
454465{
455- ICDManagementServer server;
456- Status status = server.UnregisterClient (commandObj, commandPath, commandData);
466+ Status status = ICDManagementServer::GetInstance ().UnregisterClient (commandObj, commandPath, commandData);
457467
458468 commandObj->AddStatus (commandPath, status);
459469 return true ;
@@ -496,7 +506,15 @@ void MatterIcdManagementPluginServerInitCallback()
496506 AttributeAccessInterfaceRegistry::Instance ().Register (&gAttribute );
497507
498508 // Configure ICD Management
499- 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
500518}
501519
502520void MatterIcdManagementPluginServerShutdownCallback ()
@@ -507,4 +525,12 @@ void MatterIcdManagementPluginServerShutdownCallback()
507525 FabricTable & fabricTable = Server::GetInstance ().GetFabricTable ();
508526 fabricTable.RemoveFabricDelegate (&gFabricDelegate );
509527#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
510536}
0 commit comments