Skip to content

Commit 1163280

Browse files
vivien-applepull[bot]
authored andcommitted
Add src/app/MatterCallbacks.h for allowing applications to know what is happening onto the stack (#10500)
1 parent 0002457 commit 1163280

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

src/app/CommandHandler.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "InteractionModelEngine.h"
2929
#include "messaging/ExchangeContext.h"
3030

31+
#include <app/util/MatterCallbacks.h>
3132
#include <lib/support/TypeTraits.h>
3233
#include <protocols/secure_channel/Constants.h>
3334

@@ -186,7 +187,10 @@ CHIP_ERROR CommandHandler::ProcessCommandDataIB(CommandDataIB::Parser & aCommand
186187
ChipLogDetail(DataManagement,
187188
"Received command for Endpoint=%" PRIu16 " Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI,
188189
endpointId, ChipLogValueMEI(clusterId), ChipLogValueMEI(commandId));
189-
DispatchSingleClusterCommand(ConcreteCommandPath(endpointId, clusterId, commandId), commandDataReader, this);
190+
const ConcreteCommandPath concretePath(endpointId, clusterId, commandId);
191+
SuccessOrExit(MatterPreCommandReceivedCallback(concretePath));
192+
DispatchSingleClusterCommand(concretePath, commandDataReader, this);
193+
MatterPostCommandReceivedCallback(concretePath);
190194
}
191195

192196
exit:
@@ -341,3 +345,9 @@ TLV::TLVWriter * CommandHandler::GetCommandDataIBTLVWriter()
341345

342346
} // namespace app
343347
} // namespace chip
348+
349+
CHIP_ERROR __attribute__((weak)) MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath)
350+
{
351+
return CHIP_NO_ERROR;
352+
}
353+
void __attribute__((weak)) MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath) {}

src/app/WriteHandler.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <app/MessageDef/EventPathIB.h>
2222
#include <app/WriteHandler.h>
2323
#include <app/reporting/Engine.h>
24+
#include <app/util/MatterCallbacks.h>
2425
#include <lib/support/TypeTraits.h>
2526

2627
namespace chip {
@@ -151,7 +152,14 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataList(TLV::TLVReader & aAttributeDat
151152

152153
err = element.GetData(&dataReader);
153154
SuccessOrExit(err);
154-
err = WriteSingleClusterData(clusterInfo, dataReader, this);
155+
156+
{
157+
const ConcreteAttributePath concretePath =
158+
ConcreteAttributePath(clusterInfo.mEndpointId, clusterInfo.mClusterId, clusterInfo.mFieldId);
159+
MatterPreAttributeWriteCallback(concretePath);
160+
err = WriteSingleClusterData(clusterInfo, dataReader, this);
161+
MatterPostAttributeWriteCallback(concretePath);
162+
}
155163
SuccessOrExit(err);
156164
}
157165

@@ -286,3 +294,6 @@ void WriteHandler::ClearState()
286294

287295
} // namespace app
288296
} // namespace chip
297+
298+
void __attribute__((weak)) MatterPreAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {}
299+
void __attribute__((weak)) MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {}

src/app/reporting/Engine.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <app/AppBuildConfig.h>
2727
#include <app/InteractionModelEngine.h>
2828
#include <app/reporting/Engine.h>
29+
#include <app/util/MatterCallbacks.h>
2930

3031
namespace chip {
3132
namespace app {
@@ -80,7 +81,9 @@ Engine::RetrieveClusterData(FabricIndex aAccessingFabricIndex, AttributeDataList
8081
ChipLogDetail(DataManagement, "<RE:Run> Cluster %" PRIx32 ", Field %" PRIx32 " is dirty", aClusterInfo.mClusterId,
8182
aClusterInfo.mFieldId);
8283

84+
MatterPreAttributeReadCallback(path);
8385
err = ReadSingleClusterData(aAccessingFabricIndex, path, attributeDataElementBuilder.GetWriter(), nullptr /* data exists */);
86+
MatterPostAttributeReadCallback(path);
8487
SuccessOrExit(err);
8588
attributeDataElementBuilder.MoreClusterData(false);
8689
attributeDataElementBuilder.EndOfAttributeDataElement();
@@ -459,3 +462,6 @@ void Engine::OnReportConfirm()
459462
}; // namespace reporting
460463
}; // namespace app
461464
}; // namespace chip
465+
466+
void __attribute__((weak)) MatterPreAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {}
467+
void __attribute__((weak)) MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {}

src/app/util/MatterCallbacks.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*
3+
* Copyright (c) 2021 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// THIS FILE IS GENERATED BY ZAP
19+
20+
#pragma once
21+
22+
void MatterPreAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath);
23+
void MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath);
24+
void MatterPreAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath);
25+
void MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath);
26+
27+
/** @brief Matter Pre Command Received
28+
*
29+
* This callback is called once the message has been determined to be a command, and
30+
* before the command is dispatched to the receiver.
31+
*/
32+
CHIP_ERROR MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath);
33+
34+
/** @brief Matter Post Command Received
35+
*
36+
* This callback is called once the message has been determined to be a command, but
37+
* after it beeing dispatched to the receiver.
38+
*/
39+
void MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath);

0 commit comments

Comments
 (0)