From 24902cc5b1320ad0c409c49e1d9629f0d06c8c53 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 3 Nov 2021 00:56:03 +0100 Subject: [PATCH] Add src/app/MatterCallbacks.h for allowing applications to know what is happening onto the stack (#10500) --- src/app/CommandHandler.cpp | 12 ++++++++++- src/app/WriteHandler.cpp | 13 +++++++++++- src/app/reporting/Engine.cpp | 6 ++++++ src/app/util/MatterCallbacks.h | 39 ++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/app/util/MatterCallbacks.h diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp index eaf03d3a9998c8..c2ada186d9e53d 100644 --- a/src/app/CommandHandler.cpp +++ b/src/app/CommandHandler.cpp @@ -28,6 +28,7 @@ #include "InteractionModelEngine.h" #include "messaging/ExchangeContext.h" +#include #include #include @@ -186,7 +187,10 @@ CHIP_ERROR CommandHandler::ProcessCommandDataIB(CommandDataIB::Parser & aCommand ChipLogDetail(DataManagement, "Received command for Endpoint=%" PRIu16 " Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI, endpointId, ChipLogValueMEI(clusterId), ChipLogValueMEI(commandId)); - DispatchSingleClusterCommand(ConcreteCommandPath(endpointId, clusterId, commandId), commandDataReader, this); + const ConcreteCommandPath concretePath(endpointId, clusterId, commandId); + SuccessOrExit(MatterPreCommandReceivedCallback(concretePath)); + DispatchSingleClusterCommand(concretePath, commandDataReader, this); + MatterPostCommandReceivedCallback(concretePath); } exit: @@ -341,3 +345,9 @@ TLV::TLVWriter * CommandHandler::GetCommandDataIBTLVWriter() } // namespace app } // namespace chip + +CHIP_ERROR __attribute__((weak)) MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath) +{ + return CHIP_NO_ERROR; +} +void __attribute__((weak)) MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath) {} diff --git a/src/app/WriteHandler.cpp b/src/app/WriteHandler.cpp index 34ae2281de3997..87d8a9eeb7c6c5 100644 --- a/src/app/WriteHandler.cpp +++ b/src/app/WriteHandler.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace chip { @@ -151,7 +152,14 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataList(TLV::TLVReader & aAttributeDat err = element.GetData(&dataReader); SuccessOrExit(err); - err = WriteSingleClusterData(clusterInfo, dataReader, this); + + { + const ConcreteAttributePath concretePath = + ConcreteAttributePath(clusterInfo.mEndpointId, clusterInfo.mClusterId, clusterInfo.mFieldId); + MatterPreAttributeWriteCallback(concretePath); + err = WriteSingleClusterData(clusterInfo, dataReader, this); + MatterPostAttributeWriteCallback(concretePath); + } SuccessOrExit(err); } @@ -286,3 +294,6 @@ void WriteHandler::ClearState() } // namespace app } // namespace chip + +void __attribute__((weak)) MatterPreAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {} +void __attribute__((weak)) MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {} diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 638b980dd52cbb..54bc91aac4c2af 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace chip { namespace app { @@ -80,7 +81,9 @@ Engine::RetrieveClusterData(FabricIndex aAccessingFabricIndex, AttributeDataList ChipLogDetail(DataManagement, " Cluster %" PRIx32 ", Field %" PRIx32 " is dirty", aClusterInfo.mClusterId, aClusterInfo.mFieldId); + MatterPreAttributeReadCallback(path); err = ReadSingleClusterData(aAccessingFabricIndex, path, attributeDataElementBuilder.GetWriter(), nullptr /* data exists */); + MatterPostAttributeReadCallback(path); SuccessOrExit(err); attributeDataElementBuilder.MoreClusterData(false); attributeDataElementBuilder.EndOfAttributeDataElement(); @@ -459,3 +462,6 @@ void Engine::OnReportConfirm() }; // namespace reporting }; // namespace app }; // namespace chip + +void __attribute__((weak)) MatterPreAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {} +void __attribute__((weak)) MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {} diff --git a/src/app/util/MatterCallbacks.h b/src/app/util/MatterCallbacks.h new file mode 100644 index 00000000000000..806c07c567b8ba --- /dev/null +++ b/src/app/util/MatterCallbacks.h @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// THIS FILE IS GENERATED BY ZAP + +#pragma once + +void MatterPreAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath); +void MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath); +void MatterPreAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath); +void MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath); + +/** @brief Matter Pre Command Received + * + * 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); + +/** @brief Matter Post Command Received + * + * This callback is called once the message has been determined to be a command, but + * after it beeing dispatched to the receiver. + */ +void MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath);