Skip to content

Commit f902558

Browse files
[CP][1.4.2][ICD][Server]Trigger attribute change when ICD RegisterClient/UnregisterClient succeed (project-chip#41775)
* Trigger attribute change when ICD RegisterClient/UnregisterClient succeed (project-chip#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 (project-chip#41769) * Address comments from PR 41725 * address comments * Restyled by clang-format --------- Co-authored-by: Restyled.io <[email protected]> * fix compilation * Restyled by clang-format * fix compilation --------- Co-authored-by: Restyled.io <[email protected]>
1 parent a7f4785 commit f902558

File tree

2 files changed

+68
-26
lines changed

2 files changed

+68
-26
lines changed

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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

195190
namespace {
196191
IcdManagementAttributeAccess 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+
284287
Status 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
452463
bool 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

502520
void 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
}

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,27 @@
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+
namespace chip {
46+
namespace app {
47+
namespace Clusters {
48+
49+
class ICDManagementServer : public chip::app::ICDStateObserver
4450
{
4551
public:
4652
ICDManagementServer() = default;
4753

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

57+
static ICDManagementServer & GetInstance() { return instance; };
5158
#if CHIP_CONFIG_ENABLE_ICD_CIP
5259
/**
5360
* @brief Function that executes the business logic of the RegisterClient Command
@@ -56,17 +63,17 @@ class ICDManagementServer
5663
* ICDConfigurationData If function fails, icdCounter will be unchanged
5764
* @return Status
5865
*/
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);
66+
Protocols::InteractionModel::Status RegisterClient(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
67+
const IcdManagement::Commands::RegisterClient::DecodableType & commandData,
68+
uint32_t & icdCounter);
69+
70+
Protocols::InteractionModel::Status
71+
UnregisterClient(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
72+
const IcdManagement::Commands::UnregisterClient::DecodableType & commandData);
6773
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
6874

6975
private:
76+
static ICDManagementServer instance;
7077
#if CHIP_CONFIG_ENABLE_ICD_CIP
7178
/**
7279
* @brief Triggers table update events to notify subscribers that an entry was added or removed
@@ -75,10 +82,19 @@ class ICDManagementServer
7582
void TriggerICDMTableUpdatedEvent();
7683
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
7784

78-
static chip::ICDConfigurationData * mICDConfigurationData;
85+
ICDConfigurationData * mICDConfigurationData;
7986

8087
#if CHIP_CONFIG_ENABLE_ICD_CIP
81-
static chip::PersistentStorageDelegate * mStorage;
82-
static chip::Crypto::SymmetricKeystore * mSymmetricKeystore;
88+
PersistentStorageDelegate * mStorage;
89+
Crypto::SymmetricKeystore * mSymmetricKeystore;
8390
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
91+
92+
void OnEnterActiveMode() override{};
93+
void OnEnterIdleMode() override{};
94+
void OnTransitionToIdle() override{};
95+
void OnICDModeChange() override;
8496
};
97+
98+
} // namespace Clusters
99+
} // namespace app
100+
} // namespace chip

0 commit comments

Comments
 (0)