Skip to content

Commit

Permalink
Enums that are not used as a type in XML suppresses codegen intended …
Browse files Browse the repository at this point in the history
…for DataModel::Decode (#29739)


Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Dec 17, 2023
1 parent d08cb5b commit faff91a
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 168 deletions.
13 changes: 13 additions & 0 deletions src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ WeakEnums:
- PHYRateEnum
- StepMode

EnumsNotUsedAsTypeInXML:
# List of enums that are not used as a type in XML. By adding an enum
# to this list you prevent incorrectly assuming from code that you are
# able to use kUnknownEnumValue safely. This happens for derived clusters
# such as ModeBase where there are CommonTag, DerivedClusterTags, MfgTags.
- "DishwasherMode::ModeTag"
- "LaundryWasherMode::ModeTag"
- "RefrigeratorAndTemperatureControlledCabinetMode::ModeTag"
- "RvcRunMode::ModeTag"
- "RvcRunMode::StatusCode"
- "RvcCleanMode::ModeTag"
- "RvcCleanMode::StatusCode"

CommandHandlerInterfaceOnlyClusters:
# List of clusters that are implemented entirely with
# CommandHandlerInterface and hence do not need generated command dispatch.
Expand Down
2 changes: 2 additions & 0 deletions src/app/zap-templates/templates/app/cluster-enums-check.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace app {
namespace Clusters {
{{#zcl_clusters}}
{{#zcl_enums}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../name}}::{{asType label}} val)
{
using EnumType = {{asUpperCamelCase ../name}}::{{asType label}};
Expand All @@ -33,6 +34,7 @@ static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../n
return static_cast<EnumType>({{first_unused_enum_value mode="first_unused"}});
}
}
{{/unless}}
{{/zcl_enums}}

{{/zcl_clusters}}
Expand Down
8 changes: 8 additions & 0 deletions src/app/zap-templates/templates/app/cluster-enums.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ enum class {{asType label}} : {{asUnderlyingZclType name}} {
{{#zcl_enum_items}}
k{{asUpperCamelCase label}} = {{asHex value 2}},
{{/zcl_enum_items}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
// All received enum values that are not listed above will be mapped
// to kUnknownEnumValue. This is a helper enum value that should only
// be used by code to process how it handles receiving and unknown
// enum value. This specific should never be transmitted.
kUnknownEnumValue = {{first_unused_enum_value mode="first_unused"}},
{{else}}
// kUnknownEnumValue intentionally not defined. This enum never goes
// through DataModel::Decode, likely because it is a part of a derived
// cluster. As a result having kUnknownEnumValue in this enum is error
// prone, and was removed. See
// src/app/common/templates/config-data.yaml.
{{/unless}}
};
{{#if (isInConfigList label "WeakEnums")}}
#else // CHIP_USE_ENUM_CLASS_FOR_IM_ENUM
Expand Down
70 changes: 35 additions & 35 deletions src/controller/python/chip/clusters/Objects.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ class {{asUpperCamelCase name}}(Cluster):
{{#zcl_enum_items}}
k{{asUpperCamelCase label}} = {{asHex value 2}}
{{/zcl_enum_items}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
# All received enum values that are not listed above will be mapped
# to kUnknownEnumValue. This is a helper enum value that should only
# be used by code to process how it handles receiving and unknown
# enum value. This specific should never be transmitted.
kUnknownEnumValue = {{first_unused_enum_value mode="first_unused"}},
{{else}}
# kUnknownEnumValue intentionally not defined. This enum never goes
# through DataModel::Decode, likely because it is a part of a derived
# cluster. As a result having kUnknownEnumValue in this enum is error
# prone, and was removed. See
# src/app/common/templates/config-data.yaml.
{{/unless}}

{{#last}}
{{/last}}
Expand Down
3 changes: 3 additions & 0 deletions src/controller/python/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"templates/chip/helper.js",
"controller/python/templates/helper.js"
],
"resources": {
"config-data": "../../../../src/app/common/templates/config-data.yaml"
},
"override": "../../../../src/app/zap-templates/common/override.js",
"partials": [
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit faff91a

Please sign in to comment.