Skip to content

Commit

Permalink
Add pre-execution command callback. (#20357)
Browse files Browse the repository at this point in the history
* Added the callback that could be implemented by application uses Matter. This callback is called before every command gets executed.

* Restyled by astyle

* Restyled by clang-format

* Restyled by whitespace

* Regenerate all callback-stub.cpp and IMCLusterCommandHandler.cpp

* Restyled by astyle

* Restyled by clang-format

* Add pre-execution command callback. #20361
- move MatterPreExecuteCommandCallback() into DispatchSingleClusterCommand()
- regenerate all IMClusterCommandHandler.cpp files

* Restyled by astyle

* Restyled by clang-format

* Removed a modified MTRCallbackBridge.mm file from pull request

* Removed a modified zzz_generated/chip-tool/zap-generated/test/Commands.h file from pull request

* remove all autogenerated files from PR

* Use existing callback MatterPreCommandReceivedCallback to notify "cmd exec" (add fabricIndex parameter)

* Added parameter subjectDescriptor into callbacks Matter(Pre/Post)CommandReceivedCallback (#20361)

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
3 people authored and web-flow committed Jul 14, 2022
1 parent 89d2a6a commit cfc9d96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ CHIP_ERROR CommandHandler::ProcessCommandDataIB(CommandDataIB::Parser & aCommand
{
ChipLogDetail(DataManagement, "Received command for Endpoint=%u Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI,
concretePath.mEndpointId, ChipLogValueMEI(concretePath.mClusterId), ChipLogValueMEI(concretePath.mCommandId));
SuccessOrExit(MatterPreCommandReceivedCallback(concretePath));
SuccessOrExit(MatterPreCommandReceivedCallback(concretePath, GetSubjectDescriptor()));
mpCallback->DispatchCommand(*this, concretePath, commandDataReader);
MatterPostCommandReceivedCallback(concretePath);
MatterPostCommandReceivedCallback(concretePath, GetSubjectDescriptor());
}

exit:
Expand Down Expand Up @@ -432,12 +432,11 @@ CHIP_ERROR CommandHandler::ProcessGroupCommandDataIB(CommandDataIB::Parser & aCo
continue;
}
}

if ((err = MatterPreCommandReceivedCallback(concretePath)) == CHIP_NO_ERROR)
if ((err = MatterPreCommandReceivedCallback(concretePath, GetSubjectDescriptor())) == CHIP_NO_ERROR)
{
TLV::TLVReader dataReader(commandDataReader);
mpCallback->DispatchCommand(*this, concretePath, dataReader);
MatterPostCommandReceivedCallback(concretePath);
MatterPostCommandReceivedCallback(concretePath, GetSubjectDescriptor());
}
else
{
Expand Down Expand Up @@ -675,8 +674,10 @@ void CommandHandler::Abort()
} // namespace app
} // namespace chip

CHIP_ERROR __attribute__((weak)) MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath)
CHIP_ERROR __attribute__((weak)) MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor)
{
return CHIP_NO_ERROR;
}
void __attribute__((weak)) MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath) {}
void __attribute__((weak)) MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor) {}
6 changes: 4 additions & 2 deletions src/app/util/MatterCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ void MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & a
* This callback is called once the message has been determined to be a command, and
* before the command is dispatched to the receiver.
*/
CHIP_ERROR MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath);
CHIP_ERROR MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor);

/** @brief Matter Post Command Received
*
* This callback is called once the message has been determined to be a command, but
* after it being dispatched to the receiver.
*/
void MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath);
void MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor);

0 comments on commit cfc9d96

Please sign in to comment.