Skip to content

Commit

Permalink
Add event generation to ICDM cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed Jan 10, 2024
1 parent 1b6a04a commit 7e7b2a4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ template("chip_data_model") {
deps += [
"${chip_root}/src/app/icd:configuration-data",
"${chip_root}/src/app/icd:icd_config",
"${chip_root}/src/app/icd:manager",
"${chip_root}/src/app/icd:monitoring-table",
"${chip_root}/src/app/icd:notifier",
"${chip_root}/src/app/icd:observer",
]
} else if (cluster == "resource-monitoring-server") {
sources += [
Expand Down
36 changes: 25 additions & 11 deletions src/app/clusters/icd-management-server/icd-management-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/AttributeAccessInterface.h>
#include <app/EventLogging.h>
#include <app/icd/ICDManager.h>
#include <app/icd/ICDMonitoringTable.h>
#include <app/icd/ICDNotifier.h>
#include <app/server/Server.h>
Expand Down Expand Up @@ -218,9 +220,7 @@ CHIP_ERROR CheckAdmin(CommandHandler * commandObj, const ConcreteCommandPath & c
* ICD Management Implementation
*/

PersistentStorageDelegate * ICDManagementServer::mStorage = nullptr;
Crypto::SymmetricKeystore * ICDManagementServer::mSymmetricKeystore = nullptr;
ICDConfigurationData * ICDManagementServer::mICDConfigurationData = nullptr;
ICDManagementServer ICDManagementServer::sICDManagementServer;

Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::RegisterClient::DecodableType & commandData, uint32_t & icdCounter)
Expand Down Expand Up @@ -354,6 +354,20 @@ void ICDManagementServer::Init(PersistentStorageDelegate & storage, Crypto::Symm
mICDConfigurationData = &icdConfigurationData;
}

void ICDManagementServer::OnEnterActiveMode()
{
ChipLogProgress(Zcl, "ICDManagementServer: OnTransitionToActiveMode");

// Record OnTransitionToActiveMode event
EventNumber eventNumber;
Events::OnTransitionToActiveMode::Type event;

if (CHIP_NO_ERROR != LogEvent(event, kRootEndpointId, eventNumber))
{
ChipLogError(Zcl, "ICDManagementServer: Failed to record OnTransitionToActiveMode event");
}
}

/**********************************************************
* Callbacks Implementation
*********************************************************/
Expand All @@ -366,9 +380,8 @@ bool emberAfIcdManagementClusterRegisterClientCallback(CommandHandler * commandO
const Commands::RegisterClient::DecodableType & commandData)
{
uint32_t icdCounter = 0;

ICDManagementServer server;
InteractionModel::Status status = server.RegisterClient(commandObj, commandPath, commandData, icdCounter);
InteractionModel::Status status =
ICDManagementServer::GetInstance().RegisterClient(commandObj, commandPath, commandData, icdCounter);

if (InteractionModel::Status::Success == status)
{
Expand All @@ -390,8 +403,7 @@ bool emberAfIcdManagementClusterRegisterClientCallback(CommandHandler * commandO
bool emberAfIcdManagementClusterUnregisterClientCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::UnregisterClient::DecodableType & commandData)
{
ICDManagementServer server;
InteractionModel::Status status = server.UnregisterClient(commandObj, commandPath, commandData);
InteractionModel::Status status = ICDManagementServer::GetInstance().UnregisterClient(commandObj, commandPath, commandData);

commandObj->AddStatus(commandPath, status);
return true;
Expand All @@ -403,8 +415,7 @@ bool emberAfIcdManagementClusterUnregisterClientCallback(CommandHandler * comman
bool emberAfIcdManagementClusterStayActiveRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::StayActiveRequest::DecodableType & commandData)
{
ICDManagementServer server;
InteractionModel::Status status = server.StayActiveRequest(commandObj->GetAccessingFabricIndex());
InteractionModel::Status status = ICDManagementServer::GetInstance().StayActiveRequest(commandObj->GetAccessingFabricIndex());

commandObj->AddStatus(commandPath, status);
return true;
Expand All @@ -426,5 +437,8 @@ void MatterIcdManagementPluginServerInitCallback()
registerAttributeAccessOverride(&gAttribute);

// Configure ICD Management
ICDManagementServer::Init(storage, symmetricKeystore, icdConfigurationData);
ICDManagementServer::GetInstance().Init(storage, symmetricKeystore, icdConfigurationData);

// Register ICD Management Server with ICD Manager
Server::GetInstance().GetICDManager().RegisterObserver(&ICDManagementServer::GetInstance());
}
27 changes: 20 additions & 7 deletions src/app/clusters/icd-management-server/icd-management-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <app/ConcreteAttributePath.h>
#include <app/icd/ICDConfigurationData.h>
#include <app/icd/ICDMonitoringTable.h>
#include <app/icd/ICDStateObserver.h>
#include <app/util/basic-types.h>
#include <crypto/SessionKeystore.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>
Expand All @@ -31,13 +32,13 @@

using chip::Protocols::InteractionModel::Status;

class ICDManagementServer
class ICDManagementServer : public chip::app::ICDStateObserver
{
public:
ICDManagementServer() = default;
static ICDManagementServer & GetInstance() { return sICDManagementServer; };

static void Init(chip::PersistentStorageDelegate & storage, chip::Crypto::SymmetricKeystore * symmetricKeystore,
chip::ICDConfigurationData & ICDConfigurationData);
void Init(chip::PersistentStorageDelegate & storage, chip::Crypto::SymmetricKeystore * symmetricKeystore,
chip::ICDConfigurationData & ICDConfigurationData);

/**
* @brief Function that executes the business logic of the RegisterClient Command
Expand All @@ -55,14 +56,26 @@ class ICDManagementServer

Status StayActiveRequest(chip::FabricIndex fabricIndex);

/**
* @brief Called when the ICD goes from Idle to Active mode
* Triggers the onTransitionToActiveMode event
*/
void OnEnterActiveMode();

void OnTransitionToIdle(){ /* Do Nothing */ };
void OnICDModeChange(){ /* Do Nothing*/ };

private:
/**
* @brief Triggers table update events to notify subscribers that an entry was added or removed
* from the ICDMonitoringTable.
*/
void TriggerICDMTableUpdatedEvent();
ICDManagementServer() = default;

static ICDManagementServer sICDManagementServer;

static chip::PersistentStorageDelegate * mStorage;
static chip::Crypto::SymmetricKeystore * mSymmetricKeystore;
static chip::ICDConfigurationData * mICDConfigurationData;
chip::PersistentStorageDelegate * mStorage;
chip::Crypto::SymmetricKeystore * mSymmetricKeystore;
chip::ICDConfigurationData * mICDConfigurationData;
};

0 comments on commit 7e7b2a4

Please sign in to comment.