Skip to content

Commit

Permalink
Merge branch 'project-chip:master' into arl-xml-regen
Browse files Browse the repository at this point in the history
  • Loading branch information
tleacmcsa authored Jul 29, 2024
2 parents 0e0609d + a98234f commit d1f83af
Show file tree
Hide file tree
Showing 25 changed files with 860 additions and 524 deletions.
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/ComplexArgumentParser-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_parser_impl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_parser_impl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}

Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/ComplexArgumentParser.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_parser_decl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_parser_decl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}

Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/logging/DataModelLogger-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using namespace chip::app::Clusters;
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_impl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_logger_impl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}

Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/logging/DataModelLogger.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_decl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_logger_decl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}

Expand Down
4 changes: 4 additions & 0 deletions src/app/common/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"name": "cluster_enums_enum",
"path": "../../zap-templates/partials/cluster-enums-enum.zapt"
},
{
"name": "cluster_enums_ensure_known_value",
"path": "../../zap-templates/partials/cluster-enums-ensure-known-value.zapt"
},
{
"name": "cluster_objects_field_init",
"path": "../../zap-templates/partials/cluster-objects-field-init.zapt"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{#unless (isInConfigList (concat ns "::" label) "EnumsNotUsedAsTypeInXML")}}
static auto __attribute__((unused)) EnsureKnownEnumValue({{ns}}::{{asType label}} val)
{
using EnumType = {{ns}}::{{asType label}};
switch (val) {
{{#zcl_enum_items}}
case EnumType::k{{asUpperCamelCase label}}:
{{/zcl_enum_items}}
return val;
default:
return EnumType::kUnknownEnumValue;
}
}
{{/unless}}
33 changes: 5 additions & 28 deletions src/app/zap-templates/templates/app/cluster-enums-check.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,17 @@ namespace app {
namespace Clusters {
{{#zcl_enums}}
{{#if has_more_than_one_cluster}}
{{#unless (isInConfigList (concat "::" label) "EnumsNotUsedAsTypeInXML")}}
static auto __attribute__((unused)) EnsureKnownEnumValue(detail::{{asType label}} val)
{
using EnumType = detail::{{asType label}};
switch (val) {
{{#zcl_enum_items}}
case EnumType::k{{asUpperCamelCase label}}:
{{/zcl_enum_items}}
return val;
default:
return EnumType::kUnknownEnumValue;
}
}
{{/unless}}
{{> cluster_enums_ensure_known_value ns="detail"}}
{{else if has_no_clusters}}
{{> cluster_enums_ensure_known_value ns="Globals"}}

{{/if}}
{{/zcl_enums}}

{{#zcl_clusters}}
{{#zcl_enums}}
{{#unless has_more_than_one_cluster}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../name}}::{{asType label}} val)
{
using EnumType = {{asUpperCamelCase ../name}}::{{asType label}};
switch (val) {
{{#zcl_enum_items}}
case EnumType::k{{asUpperCamelCase label}}:
{{/zcl_enum_items}}
return val;
default:
return EnumType::kUnknownEnumValue;
}
}
{{/unless}}
{{> cluster_enums_ensure_known_value ns=(asUpperCamelCase ../name)}}
{{/unless}}
{{/zcl_enums}}

Expand Down
31 changes: 31 additions & 0 deletions src/app/zap-templates/templates/app/cluster-enums.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ k{{asUpperCamelCase label}} = {{asHex mask}},

} // namespace detail

namespace Globals {
// Global enums.
{{#zcl_enums}}

{{#if has_no_clusters}}

{{> cluster_enums_enum ns=""}}

{{/if}}
{{/zcl_enums}}

// Global bitmaps.
{{#zcl_bitmaps}}

{{#if has_no_clusters}}
{{! Work around https://github.com/project-chip/zap/issues/1370 and manually filter out built-in bitmap types. }}
{{#if_is_atomic label}}
{{else}}

// Bitmap for {{label}}
enum class {{asType label}} : {{asUnderlyingZclType name}} {
{{#zcl_bitmap_items}}
k{{asUpperCamelCase label}} = {{asHex mask}},
{{/zcl_bitmap_items}}
};

{{/if_is_atomic}}
{{/if}}
{{/zcl_bitmaps}}

} // namespace Globals

{{#zcl_clusters}}
namespace {{asUpperCamelCase name}} {
Expand Down
12 changes: 12 additions & 0 deletions src/app/zap-templates/templates/app/cluster-objects-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ namespace Structs {
} // namespace Structs
} // namespace detail

namespace Globals {
// Global structs
namespace Structs {
{{#zcl_structs}}
{{#if has_no_clusters}}
{{> cluster_objects_struct header=false}}

{{/if}}
{{/zcl_structs}}
} // namespace Structs
} // namespace Globals

{{#zcl_clusters}}
namespace {{asUpperCamelCase name}} {
{{#zcl_structs}}
Expand Down
12 changes: 12 additions & 0 deletions src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ namespace Structs {
} // namespace detail

namespace Globals {

// Global structs.
namespace Structs {

{{#zcl_structs}}
{{#if has_no_clusters}}
{{> cluster_objects_struct header=true}}

{{/if}}
{{/zcl_structs}}
} // namespace Structs

namespace Attributes {
{{#zcl_attributes_server}}
{{#unless clusterRef}}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def _BuildClusterIndex():
''' Build internal cluster index for locating the corresponding cluster object by path in the future.
'''
for clusterName, obj in inspect.getmembers(sys.modules['chip.clusters.Objects']):
if ('chip.clusters.Objects' in str(obj)) and inspect.isclass(obj):
if ('chip.clusters.Objects' in str(obj)) and inspect.isclass(obj) and issubclass(obj, Cluster):
_ClusterIndex[obj.id] = obj


Expand Down
Loading

0 comments on commit d1f83af

Please sign in to comment.