Skip to content

Commit ff795a1

Browse files
gmarcosbandy31415
andauthored
Add support for an attribute check whether it's being done over large payload-supporting transport (project-chip#40141)
* Add support for an attribute read to check whether it's being done over a transport that supports large message payload * Review suggestions --------- Co-authored-by: Andrei Litvin <[email protected]>
1 parent b501f3b commit ff795a1

File tree

7 files changed

+41
-11
lines changed

7 files changed

+41
-11
lines changed

src/app/AttributeAccessInterface.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <app/AttributeReportBuilder.h>
2222
#include <app/AttributeValueDecoder.h>
2323
#include <app/AttributeValueEncoder.h>
24+
#include <app/data-model-provider/OperationTypes.h>
2425
#include <lib/core/CHIPError.h>
2526

2627
/**
@@ -51,7 +52,7 @@ class AttributeAccessInterface
5152
/**
5253
* Callback for reading attributes.
5354
*
54-
* @param [in] aPath indicates which exact data is being read.
55+
* @param [in] aRequest indicates which exact data is being read along with attributes of how data is being read.
5556
* @param [in] aEncoder the AttributeValueEncoder to use for encoding the
5657
* data.
5758
*
@@ -66,6 +67,17 @@ class AttributeAccessInterface
6667
* involve reading from the attribute store or external attribute
6768
* callbacks.
6869
*/
70+
virtual CHIP_ERROR Read(const DataModel::ReadAttributeRequest & aRequest, AttributeValueEncoder & aEncoder)
71+
{
72+
return Read(aRequest.path, aEncoder);
73+
}
74+
75+
/**
76+
* A simpler version of Read(const ReadAttributeRequest & request, AttributeValueEncoder & aEncoder)
77+
* which takes simply the path being read, for backwards compatibility.
78+
*
79+
* @param [in] aPath indicates which exact data is being read.
80+
*/
6981
virtual CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) = 0;
7082

7183
/**

src/app/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static_library("attribute-access") {
314314
"${chip_root}/src/access:types",
315315
"${chip_root}/src/app/MessageDef",
316316
"${chip_root}/src/app/data-model",
317+
"${chip_root}/src/app/data-model-provider:core",
317318
"${chip_root}/src/app/util:af-types",
318319
"${chip_root}/src/lib/core",
319320
"${chip_root}/src/lib/support",

src/app/ReadHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ class ReadHandler : public Messaging::ExchangeDelegate
432432

433433
Transport::SecureSession * GetSession() const;
434434
SubjectDescriptor GetSubjectDescriptor() const { return GetSession()->GetSubjectDescriptor(); }
435+
bool AllowsLargePayload() const { return GetSession()->AllowsLargePayload(); }
435436

436437
auto GetTransactionStartGeneration() const { return mTransactionStartGeneration; }
437438

src/app/data-model-provider/BUILD.gn

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ source_set("metadata") {
2424
]
2525
}
2626

27+
source_set("core") {
28+
public = [ "OperationTypes.h" ]
29+
30+
public_deps = [
31+
"${chip_root}/src/access:types",
32+
"${chip_root}/src/app:paths",
33+
"${chip_root}/src/app/data-model",
34+
]
35+
}
36+
2737
source_set("data-model-provider") {
2838
sources = [
2939
"ActionContext.h",
@@ -33,14 +43,14 @@ source_set("data-model-provider") {
3343
"EventsGenerator.h",
3444
"MetadataLookup.cpp",
3545
"MetadataLookup.h",
36-
"OperationTypes.h",
3746
"Provider.h",
3847
"ProviderChangeListener.h",
3948
"ProviderMetadataTree.cpp",
4049
"ProviderMetadataTree.h",
4150
]
4251

4352
public_deps = [
53+
":core",
4454
":metadata",
4555
"${chip_root}/src/app:attribute-access",
4656
"${chip_root}/src/app:command-handler",

src/app/data-model-provider/OperationTypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ struct OperationRequest
7070

7171
enum class ReadFlags : uint32_t
7272
{
73-
kFabricFiltered = 0x0001, // reading is performed fabric-filtered
73+
kFabricFiltered = 0x0001, // reading is performed fabric-filtered
74+
kAllowsLargePayload = 0x0002, // reading is performed over a transport supporting large payload
7475
};
7576

7677
enum class ListWriteOperation : uint8_t

src/app/reporting/Engine.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace app {
5050
namespace reporting {
5151
namespace {
5252

53+
using DataModel::ReadFlags;
5354
using Protocols::InteractionModel::Status;
5455

5556
/// Returns the status of ACL validation.
@@ -148,7 +149,7 @@ std::optional<Status> ValidateAttributeIsReadable(DataModel::Provider * dataMode
148149
}
149150

150151
DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataModel, const SubjectDescriptor & subjectDescriptor,
151-
bool isFabricFiltered, AttributeReportIBs::Builder & reportBuilder,
152+
BitFlags<ReadFlags> flags, AttributeReportIBs::Builder & reportBuilder,
152153
const ConcreteReadAttributePath & path, AttributeEncodeState * encoderState)
153154
{
154155
ChipLogDetail(DataManagement, "<RE:Run> Cluster %" PRIx32 ", Attribute %" PRIx32 " is dirty", path.mClusterId,
@@ -158,7 +159,7 @@ DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataMode
158159

159160
DataModel::ReadAttributeRequest readRequest;
160161

161-
readRequest.readFlags.Set(DataModel::ReadFlags::kFabricFiltered, isFabricFiltered);
162+
readRequest.readFlags = flags;
162163
readRequest.subjectDescriptor = &subjectDescriptor;
163164
readRequest.path = path;
164165

@@ -178,6 +179,7 @@ DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataMode
178179
reportBuilder.Checkpoint(checkpoint);
179180

180181
DataModel::ActionReturnStatus status(CHIP_NO_ERROR);
182+
bool isFabricFiltered = flags.Has(ReadFlags::kFabricFiltered);
181183
AttributeValueEncoder attributeValueEncoder(reportBuilder, subjectDescriptor, path, version, isFabricFiltered, encoderState);
182184

183185
// TODO: we explicitly DO NOT validate that path is a valid cluster path (even more, above serverClusterFinder
@@ -472,9 +474,12 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Bu
472474
ConcreteReadAttributePath pathForRetrieval(readPath);
473475
// Load the saved state from previous encoding session for chunking of one single attribute (list chunking).
474476
AttributeEncodeState encodeState = apReadHandler->GetAttributeEncodeState();
477+
BitFlags<ReadFlags> flags;
478+
flags.Set(ReadFlags::kFabricFiltered, apReadHandler->IsFabricFiltered());
479+
flags.Set(ReadFlags::kAllowsLargePayload, apReadHandler->AllowsLargePayload());
475480
DataModel::ActionReturnStatus status =
476-
RetrieveClusterData(mpImEngine->GetDataModelProvider(), apReadHandler->GetSubjectDescriptor(),
477-
apReadHandler->IsFabricFiltered(), attributeReportIBs, pathForRetrieval, &encodeState);
481+
RetrieveClusterData(mpImEngine->GetDataModelProvider(), apReadHandler->GetSubjectDescriptor(), flags,
482+
attributeReportIBs, pathForRetrieval, &encodeState);
478483
if (status.IsError())
479484
{
480485
// Operation error set, since this will affect early return or override on status encoding

src/data-model-providers/codegen/CodegenDataModelProvider_Read.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ using Protocols::InteractionModel::Status;
5656
///
5757
/// If it returns std::nullopt, then there is no AAI to handle the given path
5858
/// and processing should figure out the value otherwise (generally from other ember data)
59-
std::optional<CHIP_ERROR> TryReadViaAccessInterface(const ConcreteAttributePath & path, AttributeAccessInterface * aai,
59+
std::optional<CHIP_ERROR> TryReadViaAccessInterface(const DataModel::ReadAttributeRequest & request, AttributeAccessInterface * aai,
6060
AttributeValueEncoder & encoder)
6161
{
6262
// Processing can happen only if an attribute access interface actually exists..
@@ -65,12 +65,12 @@ std::optional<CHIP_ERROR> TryReadViaAccessInterface(const ConcreteAttributePath
6565
return std::nullopt;
6666
}
6767

68-
CHIP_ERROR err = aai->Read(path, encoder);
68+
CHIP_ERROR err = aai->Read(request, encoder);
6969

7070
if (err != CHIP_NO_ERROR)
7171
{
7272
// Implementation of 8.4.3.2 of the spec for path expansion
73-
if (path.mExpanded && (err == CHIP_IM_GLOBAL_STATUS(UnsupportedRead)))
73+
if (request.path.mExpanded && (err == CHIP_IM_GLOBAL_STATUS(UnsupportedRead)))
7474
{
7575
return CHIP_NO_ERROR;
7676
}
@@ -115,7 +115,7 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::ReadAttribute(const Data
115115

116116
// Read via AAI
117117
std::optional<CHIP_ERROR> aai_result = TryReadViaAccessInterface(
118-
request.path, AttributeAccessInterfaceRegistry::Instance().Get(request.path.mEndpointId, request.path.mClusterId), encoder);
118+
request, AttributeAccessInterfaceRegistry::Instance().Get(request.path.mEndpointId, request.path.mClusterId), encoder);
119119
VerifyOrReturnError(!aai_result.has_value(), *aai_result);
120120

121121
// At this point, we have to use ember directly to read the data.

0 commit comments

Comments
 (0)