Skip to content

Commit

Permalink
[OperationalCredentials]: Reporting change for the attributes not man…
Browse files Browse the repository at this point in the history
…aged by the attribute store. (#11155)

* Reporting OperationalCredentials Attribute Change

* Update src/app/reporting/Engine.h

Co-authored-by: Jerry Johns <[email protected]>

* Update src/app/util/ember-compatibility-functions.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Address review comments

Co-authored-by: Jerry Johns <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed May 24, 2022
1 parent 49b7166 commit 1492837
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <app/AttributeAccessInterface.h>
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>
#include <app/reporting/reporting.h>
#include <app/server/Dnssd.h>
#include <app/server/Server.h>
#include <app/util/af.h>
Expand Down Expand Up @@ -263,6 +264,10 @@ CHIP_ERROR writeFabricsIntoFabricsListAttribute()
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}

// Currently, we only manage FabricsList attribute in endpoint 0, OperationalCredentials cluster is always required to be on
// EP0.
MatterReportingAttributeChangeCallback(0, OperationalCredentials::Id, OperationalCredentials::Attributes::FabricsList::Id);

return err;
}

Expand Down Expand Up @@ -785,6 +790,11 @@ bool emberAfOperationalCredentialsClusterAddTrustedRootCertificateCallback(
gFabricBeingCommissioned.Reset();
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Failed AddTrustedRootCert request.");
}
else
{
MatterReportingAttributeChangeCallback(commandPath.mEndpointId, OperationalCredentials::Id,
OperationalCredentials::Attributes::TrustedRootCertificates::Id);
}

return true;
}
Expand All @@ -795,5 +805,9 @@ bool emberAfOperationalCredentialsClusterRemoveTrustedRootCertificateCallback(
{
EmberAfStatus status = EMBER_ZCL_STATUS_FAILURE;
emberAfSendImmediateDefaultResponse(status);

MatterReportingAttributeChangeCallback(commandPath.mEndpointId, OperationalCredentials::Id,
OperationalCredentials::Attributes::TrustedRootCertificates::Id);

return true;
}
8 changes: 8 additions & 0 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,14 @@ void Engine::Run(System::Layer * aSystemLayer, void * apAppState)

CHIP_ERROR Engine::ScheduleRun()
{
if (mRunScheduled)
{
return CHIP_NO_ERROR;
}

if (InteractionModelEngine::GetInstance()->GetExchangeManager() != nullptr)
{
mRunScheduled = true;
return InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->ScheduleWork(Run,
this);
}
Expand All @@ -352,6 +358,8 @@ void Engine::Run()
InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance();
ReadHandler * readHandler = imEngine->mReadHandlers + mCurReadHandlerIdx;

mRunScheduled = false;

while ((mNumReportsInFlight < CHIP_IM_MAX_REPORTS_IN_FLIGHT) && (numReadHandled < CHIP_IM_MAX_NUM_READ_HANDLER))
{
if (readHandler->IsReportable())
Expand Down
7 changes: 7 additions & 0 deletions src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ class Engine
*/
bool mMoreChunkedMessages = false;

/**
* Boolean to indicate if ScheduleRun is pending. This flag is used to prevent calling ScheduleRun multiple times
* within the same execution context to avoid applying too much pressure on platforms that use small, fixed size event queues.
*
*/
bool mRunScheduled = false;

/**
* The number of report date request in flight
*
Expand Down
5 changes: 5 additions & 0 deletions src/app/util/ember-compatibility-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,9 @@ void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clust
info.mFlags.Set(ClusterInfo::Flags::kFieldIdValid);

InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);

// Schedule work to run asynchronously on the CHIP thread. The scheduled work won't execute until the current execution context
// has completed. This ensures that we can 'gather up' multiple attribute changes that have occurred in the same execution
// context without requiring any explicit 'start' or 'end' change calls into the engine to book-end the change.
InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun();
}

0 comments on commit 1492837

Please sign in to comment.