Skip to content

Commit 2772305

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Make MTRDecodeAttributeValue support global attributes in custom clusters. (#29022)
For global attributes we know the schema even if the cluster is custom.
1 parent c38d87b commit 2772305

File tree

3 files changed

+6316
-18255
lines changed

3 files changed

+6316
-18255
lines changed

src/darwin/Framework/CHIP/templates/MTRAttributeTLVValueDecoder-src.zapt

+44
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,56 @@
1212
#include <app-common/zap-generated/ids/Attributes.h>
1313
#include <app-common/zap-generated/ids/Clusters.h>
1414
#include <lib/support/TypeTraits.h>
15+
#include <lib/core/DataModelTypes.h>
1516

1617
using namespace chip;
1718
using namespace chip::app;
1819

20+
static id _Nullable DecodeGlobalAttributeValue(AttributeId aAttributeId, TLV::TLVReader & aReader, CHIP_ERROR * aError)
21+
{
22+
using namespace Clusters::Globals;
23+
switch (aAttributeId) {
24+
{{#zcl_attributes_server removeKeys='isOptional'}}
25+
{{#unless clusterRef}}
26+
{{#if (isSupported "" globalAttribute=(asUpperCamelCase name preserveAcronyms=true))}}
27+
{{#if (isProvisional "" globalAttribute=(asUpperCamelCase name preserveAcronyms=true))}}
28+
#if MTR_ENABLE_PROVISIONAL
29+
{{/if}}
30+
case Attributes::{{asUpperCamelCase name}}::Id: {
31+
using TypeInfo = Attributes::{{asUpperCamelCase name}}::TypeInfo;
32+
TypeInfo::DecodableType cppValue;
33+
*aError = DataModel::Decode(aReader, cppValue);
34+
if (*aError != CHIP_NO_ERROR)
35+
{
36+
return nil;
37+
}
38+
{{asObjectiveCType type ""}} value;
39+
{{>decode_value target="value" source="cppValue" cluster="" errorCode="*aError = err; return nil;" depth=0}}
40+
return value;
41+
}
42+
{{#if (isProvisional "" globalAttribute=(asUpperCamelCase name preserveAcronyms=true))}}
43+
#endif // MTR_ENABLE_PROVISIONAL
44+
{{/if}}
45+
{{/if}}
46+
{{/unless}}
47+
{{/zcl_attributes_server}}
48+
default: {
49+
break;
50+
}
51+
}
52+
53+
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
54+
return nil;
55+
}
56+
1957
{{#zcl_clusters}}
2058
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
2159
static id _Nullable DecodeAttributeValueFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(AttributeId aAttributeId, TLV::TLVReader & aReader, CHIP_ERROR * aError)
2260
{
2361
using namespace Clusters::{{asUpperCamelCase name}};
2462
switch (aAttributeId) {
2563
{{#zcl_attributes_server removeKeys='isOptional'}}
64+
{{#if clusterRef}}
2665
{{#if (isSupported (asUpperCamelCase ../name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
2766
{{#if (isProvisional (asUpperCamelCase ../name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
2867
#if MTR_ENABLE_PROVISIONAL
@@ -43,6 +82,7 @@ static id _Nullable DecodeAttributeValueFor{{asUpperCamelCase name preserveAcron
4382
#endif // MTR_ENABLE_PROVISIONAL
4483
{{/if}}
4584
{{/if}}
85+
{{/if}}
4686
{{/zcl_attributes_server}}
4787
default: {
4888
break;
@@ -57,6 +97,10 @@ static id _Nullable DecodeAttributeValueFor{{asUpperCamelCase name preserveAcron
5797

5898
id _Nullable MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
5999
{
100+
if (IsGlobalAttribute(aPath.mAttributeId)) {
101+
return DecodeGlobalAttributeValue(aPath.mAttributeId, aReader, aError);
102+
}
103+
60104
switch (aPath.mClusterId) {
61105
{{#zcl_clusters}}
62106
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}

0 commit comments

Comments
 (0)