Skip to content

Commit

Permalink
Make MTRDecodeAttributeValue support global attributes in custom clus…
Browse files Browse the repository at this point in the history
…ters.

For global attributes we know the schema even if the cluster is custom.
  • Loading branch information
bzbarsky-apple committed Sep 1, 2023
1 parent 3e6fec6 commit fd273cf
Show file tree
Hide file tree
Showing 3 changed files with 6,313 additions and 18,252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,56 @@
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <lib/support/TypeTraits.h>
#include <lib/core/DataModelTypes.h>

using namespace chip;
using namespace chip::app;

static id _Nullable DecodeGlobalAttributeValue(AttributeId aAttributeId, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{
using namespace Clusters::Globals;
switch (aAttributeId) {
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#unless clusterRef}}
{{#if (isSupported "" globalAttribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isProvisional "" globalAttribute=(asUpperCamelCase name preserveAcronyms=true))}}
#if MTR_ENABLE_PROVISIONAL
{{/if}}
case Attributes::{{asUpperCamelCase name}}::Id: {
using TypeInfo = Attributes::{{asUpperCamelCase name}}::TypeInfo;
TypeInfo::DecodableType cppValue;
*aError = DataModel::Decode(aReader, cppValue);
if (*aError != CHIP_NO_ERROR)
{
return nil;
}
{{asObjectiveCType type ""}} value;
{{>decode_value target="value" source="cppValue" cluster="" errorCode="*aError = err; return nil;" depth=0}}
return value;
}
{{#if (isProvisional "" globalAttribute=(asUpperCamelCase name preserveAcronyms=true))}}
#endif // MTR_ENABLE_PROVISIONAL
{{/if}}
{{/if}}
{{/unless}}
{{/zcl_attributes_server}}
default: {
break;
}
}

*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
return nil;
}

{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
static id _Nullable DecodeAttributeValueFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(AttributeId aAttributeId, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{
using namespace Clusters::{{asUpperCamelCase name}};
switch (aAttributeId) {
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#if clusterRef}}
{{#if (isSupported (asUpperCamelCase ../name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isProvisional (asUpperCamelCase ../name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
#if MTR_ENABLE_PROVISIONAL
Expand All @@ -43,6 +82,7 @@ static id _Nullable DecodeAttributeValueFor{{asUpperCamelCase name preserveAcron
#endif // MTR_ENABLE_PROVISIONAL
{{/if}}
{{/if}}
{{/if}}
{{/zcl_attributes_server}}
default: {
break;
Expand All @@ -57,6 +97,10 @@ static id _Nullable DecodeAttributeValueFor{{asUpperCamelCase name preserveAcron

id _Nullable MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{
if (IsGlobalAttribute(aPath.mAttributeId)) {
return DecodeGlobalAttributeValue(aPath.mAttributeId, aReader, aError);
}

switch (aPath.mClusterId) {
{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
Expand Down
Loading

0 comments on commit fd273cf

Please sign in to comment.