Skip to content

Commit 1e4efd5

Browse files
[CP][1.4][ICD][Server]Trigger attribute change when ICD RegisterClient/UnregisterClient succeed (#41774)
* Trigger attribute change when ICD RegisterClient/UnregisterClient succeed (#41725) * Trigger Attribute Change when ICD RegisterClient/UnregisterClient succeed Restyled by clang-format * address comments * Restyled by clang-format * fix * Restyled by clang-format * address comments * fix * address comments * Restyled by clang-format * address comments * fix compile --------- Co-authored-by: Restyled.io <[email protected]> * Address comments from PR 41725 (#41769) * Address comments from PR 41725 * address comments * Restyled by clang-format --------- Co-authored-by: Restyled.io <[email protected]> * fix build * fix compilation --------- Co-authored-by: Restyled.io <[email protected]>
1 parent 95748d5 commit 1e4efd5

File tree

2 files changed

+83
-28
lines changed

2 files changed

+83
-28
lines changed

src/app/clusters/icd-management-server/icd-management-server.cpp

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
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 {
194193
IcdManagementAttributeAccess gAttribute;
195194
#if CHIP_CONFIG_ENABLE_ICD_CIP
196195
IcdManagementFabricDelegate 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
282288
Status 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
450464
bool 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
}

src/app/clusters/icd-management-server/icd-management-server.h

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,28 @@
3434
#include <lib/core/CHIPPersistentStorageDelegate.h>
3535
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
3636

37+
#include <app/icd/server/ICDStateObserver.h>
38+
3739
namespace chip {
3840
namespace Crypto {
3941
using SymmetricKeystore = SessionKeystore;
4042
} // namespace Crypto
4143
} // namespace chip
4244

43-
class ICDManagementServer
45+
46+
namespace chip {
47+
namespace app {
48+
namespace Clusters {
49+
50+
class ICDManagementServer : public chip::app::ICDStateObserver
4451
{
4552
public:
4653
ICDManagementServer() = default;
4754

48-
static void Init(chip::PersistentStorageDelegate & storage, chip::Crypto::SymmetricKeystore * symmetricKeystore,
49-
chip::ICDConfigurationData & ICDConfigurationData);
55+
void Init(PersistentStorageDelegate & storage, Crypto::SymmetricKeystore * symmetricKeystore,
56+
ICDConfigurationData & ICDConfigurationData);
5057

58+
static ICDManagementServer & GetInstance() { return instance; };
5159
#if CHIP_CONFIG_ENABLE_ICD_CIP
5260
/**
5361
* @brief Function that executes the business logic of the RegisterClient Command
@@ -56,17 +64,17 @@ class ICDManagementServer
5664
* ICDConfigurationData If function fails, icdCounter will be unchanged
5765
* @return Status
5866
*/
59-
chip::Protocols::InteractionModel::Status
60-
RegisterClient(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
61-
const chip::app::Clusters::IcdManagement::Commands::RegisterClient::DecodableType & commandData,
62-
uint32_t & icdCounter);
63-
64-
chip::Protocols::InteractionModel::Status
65-
UnregisterClient(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
66-
const chip::app::Clusters::IcdManagement::Commands::UnregisterClient::DecodableType & commandData);
67+
Protocols::InteractionModel::Status RegisterClient(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
68+
const IcdManagement::Commands::RegisterClient::DecodableType & commandData,
69+
uint32_t & icdCounter);
70+
71+
Protocols::InteractionModel::Status
72+
UnregisterClient(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
73+
const IcdManagement::Commands::UnregisterClient::DecodableType & commandData);
6774
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
6875

6976
private:
77+
static ICDManagementServer instance;
7078
#if CHIP_CONFIG_ENABLE_ICD_CIP
7179
/**
7280
* @brief Triggers table update events to notify subscribers that an entry was added or removed
@@ -75,10 +83,18 @@ class ICDManagementServer
7583
void TriggerICDMTableUpdatedEvent();
7684
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
7785

78-
static chip::ICDConfigurationData * mICDConfigurationData;
86+
ICDConfigurationData * mICDConfigurationData;
7987

8088
#if CHIP_CONFIG_ENABLE_ICD_CIP
81-
static chip::PersistentStorageDelegate * mStorage;
82-
static chip::Crypto::SymmetricKeystore * mSymmetricKeystore;
89+
PersistentStorageDelegate * mStorage;
90+
Crypto::SymmetricKeystore * mSymmetricKeystore;
8391
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
92+
93+
void OnEnterActiveMode() override{};
94+
void OnEnterIdleMode() override{};
95+
void OnTransitionToIdle() override{};
96+
void OnICDModeChange() override;
8497
};
98+
} // namespace Clusters
99+
} // namespace app
100+
} // namespace chip

0 commit comments

Comments
 (0)