From 7d2771f779f03ff589e8af9376d2cc35369bfd91 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 10 Jan 2022 15:57:47 -0500 Subject: [PATCH] Switch to having only one struct named LabelStruct. (#13380) This is shared across the fixed label and user label clusters. The struct definition is in the "detail" namespace, with alias namespaces in the two clusters that use it. Consumers are generally expected to use the per-cluster aliases. --- examples/chip-tool/templates/commands.zapt | 33 ++--- .../templates/partials/log_struct_value.zapt | 16 +++ examples/chip-tool/templates/templates.json | 4 + src/app/common/templates/templates.json | 4 + .../partials/cluster-objects-struct.zapt | 77 +++++++++++ .../templates/app/cluster-objects-src.zapt | 52 +++---- .../templates/app/cluster-objects.zapt | 53 +++----- src/app/zap-templates/templates/app/helper.js | 12 +- .../data-model/chip/fixed-label-cluster.xml | 1 + .../data-model/chip/user-label-cluster.xml | 6 - .../CHIPAttributeTLVValueDecoder.mm | 12 -- .../CHIP/zap-generated/CHIPCallbackBridge.mm | 12 -- .../CHIP/zap-generated/CHIPClustersObjc.mm | 2 - .../zap-generated/CHIPTestClustersObjc.mm | 2 - .../zap-generated/cluster-objects.cpp | 127 +++++++----------- .../zap-generated/cluster-objects.h | 68 ++++------ .../zap-generated/cluster/Commands.h | 77 ++++------- 17 files changed, 263 insertions(+), 295 deletions(-) create mode 100644 examples/chip-tool/templates/partials/log_struct_value.zapt create mode 100644 src/app/zap-templates/partials/cluster-objects-struct.zapt diff --git a/examples/chip-tool/templates/commands.zapt b/examples/chip-tool/templates/commands.zapt index 52b80012429e8f..e8d04e9c789e16 100644 --- a/examples/chip-tool/templates/commands.zapt +++ b/examples/chip-tool/templates/commands.zapt @@ -22,9 +22,17 @@ // generated ones, so are placed here. namespace { +{{#zcl_structs}} +{{#if has_more_than_one_cluster}} +CHIP_ERROR LogValue(const char * label, size_t indent, {{zapTypeToDecodableClusterObjectType name ns="detail" isArgument=true}} value); +{{/if}} +{{/zcl_structs}} + {{#zcl_clusters}} {{#zcl_structs}} +{{#unless has_more_than_one_cluster}} CHIP_ERROR LogValue(const char * label, size_t indent, {{zapTypeToDecodableClusterObjectType name ns=parent.name isArgument=true}} value); +{{/unless}} {{/zcl_structs}} {{/zcl_clusters}} @@ -145,24 +153,17 @@ CHIP_ERROR LogValue(const char * label, size_t indent, const chip::Optional & // be logging. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" +{{#zcl_structs}} +{{#if has_more_than_one_cluster}} +{{> log_struct_value ns="detail"}} +{{/if}} +{{/zcl_structs}} + {{#zcl_clusters}} {{#zcl_structs}} -CHIP_ERROR LogValue(const char * label, size_t indent, {{zapTypeToDecodableClusterObjectType name ns=parent.name isArgument=true}} value) -{ - ChipLogProgress(chipTool, "%s%s: {", IndentStr(indent).c_str(), label); -{{#zcl_struct_items}} - { - CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}}); - if (err != CHIP_NO_ERROR) - { - ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for '{{asUpperCamelCase label}}'", IndentStr(indent + 1).c_str()); - return err; - } - } -{{/zcl_struct_items}} - ChipLogProgress(chipTool, "%s}", IndentStr(indent).c_str()); - return CHIP_NO_ERROR; -} +{{#unless has_more_than_one_cluster}} +{{> log_struct_value ns=parent.name}} +{{/unless}} {{/zcl_structs}} {{/zcl_clusters}} #pragma GCC diagnostic pop diff --git a/examples/chip-tool/templates/partials/log_struct_value.zapt b/examples/chip-tool/templates/partials/log_struct_value.zapt new file mode 100644 index 00000000000000..33d6b9561cebe1 --- /dev/null +++ b/examples/chip-tool/templates/partials/log_struct_value.zapt @@ -0,0 +1,16 @@ +CHIP_ERROR LogValue(const char * label, size_t indent, {{zapTypeToDecodableClusterObjectType name ns=ns isArgument=true}} value) +{ + ChipLogProgress(chipTool, "%s%s: {", IndentStr(indent).c_str(), label); +{{#zcl_struct_items}} + { + CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}}); + if (err != CHIP_NO_ERROR) + { + ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for '{{asUpperCamelCase label}}'", IndentStr(indent + 1).c_str()); + return err; + } + } +{{/zcl_struct_items}} + ChipLogProgress(chipTool, "%s}", IndentStr(indent).c_str()); + return CHIP_NO_ERROR; +} diff --git a/examples/chip-tool/templates/templates.json b/examples/chip-tool/templates/templates.json index e56bcf9f99c1f5..cda0394f4b7ea4 100644 --- a/examples/chip-tool/templates/templates.json +++ b/examples/chip-tool/templates/templates.json @@ -35,6 +35,10 @@ { "name": "valueEquals", "path": "partials/test_cluster_value_equals.zapt" + }, + { + "name": "log_struct_value", + "path": "partials/log_struct_value.zapt" } ], "templates": [ diff --git a/src/app/common/templates/templates.json b/src/app/common/templates/templates.json index 16be724a8ae62a..a91a71c88b3af1 100644 --- a/src/app/common/templates/templates.json +++ b/src/app/common/templates/templates.json @@ -13,6 +13,10 @@ { "name": "header", "path": "../../zap-templates/partials/header.zapt" + }, + { + "name": "cluster_objects_struct", + "path": "../../zap-templates/partials/cluster-objects-struct.zapt" } ], "templates": [ diff --git a/src/app/zap-templates/partials/cluster-objects-struct.zapt b/src/app/zap-templates/partials/cluster-objects-struct.zapt new file mode 100644 index 00000000000000..8e502eb4f6e14e --- /dev/null +++ b/src/app/zap-templates/partials/cluster-objects-struct.zapt @@ -0,0 +1,77 @@ +{{#if header}} +namespace {{asUpperCamelCase name}} { + enum class Fields { + {{#zcl_struct_items}} + k{{asUpperCamelCase label}} = {{fieldIdentifier}}, + {{/zcl_struct_items}} + }; + + struct Type { + public: + {{#zcl_struct_items}} + {{zapTypeToEncodableClusterObjectType type}} {{asLowerCamelCase label}}; + {{/zcl_struct_items}} + + CHIP_ERROR Encode(TLV::TLVWriter &writer, TLV::Tag tag) const; + {{#unless struct_contains_array}} + CHIP_ERROR Decode(TLV::TLVReader &reader); + {{/unless}} + {{#if struct_is_fabric_scoped}} + bool MatchesFabricIndex(FabricIndex fabricIndex_) const { + return {{ asLowerCamelCase struct_fabric_idx_field }} == fabricIndex_; + } + {{/if}} + }; + + {{#if struct_contains_array}} + struct DecodableType { + public: + {{#zcl_struct_items}} + {{zapTypeToDecodableClusterObjectType type}} {{asLowerCamelCase label}}; + {{/zcl_struct_items}} + CHIP_ERROR Decode(TLV::TLVReader &reader); + }; + {{else}} + using DecodableType = Type; + {{/if}} + +} // namespace {{asUpperCamelCase name}} +{{else}} +namespace {{asUpperCamelCase name}} { +CHIP_ERROR Type::Encode(TLV::TLVWriter &writer, TLV::Tag tag) const{ + TLV::TLVType outer; + ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); + {{#zcl_struct_items}} + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::k{{asUpperCamelCase label}})), {{asLowerCamelCase label}})); + {{/zcl_struct_items}} + ReturnErrorOnFailure(writer.EndContainer(outer)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) { + CHIP_ERROR err = CHIP_NO_ERROR; + TLV::TLVType outer; + VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + err = reader.EnterContainer(outer); + ReturnErrorOnFailure(err); + while ((err = reader.Next()) == CHIP_NO_ERROR) { + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + switch (TLV::TagNumFromTag(reader.GetTag())) + { + {{#zcl_struct_items}} + case to_underlying(Fields::k{{asUpperCamelCase label}}): + ReturnErrorOnFailure(DataModel::Decode(reader, {{asLowerCamelCase label}})); + break; + {{/zcl_struct_items}} + default: + break; + } + } + + VerifyOrReturnError(err == CHIP_END_OF_TLV, err); + ReturnErrorOnFailure(reader.ExitContainer(outer)); + return CHIP_NO_ERROR; +} + +} // namespace {{asUpperCamelCase name}} +{{/if}} \ No newline at end of file diff --git a/src/app/zap-templates/templates/app/cluster-objects-src.zapt b/src/app/zap-templates/templates/app/cluster-objects-src.zapt index c19740f8cf8ce1..0e61078026453d 100644 --- a/src/app/zap-templates/templates/app/cluster-objects-src.zapt +++ b/src/app/zap-templates/templates/app/cluster-objects-src.zapt @@ -5,49 +5,27 @@ namespace chip { namespace app { namespace Clusters { + +namespace detail { +// Structs shared across multiple clusters. +namespace Structs { +{{#zcl_structs}} +{{#if has_more_than_one_cluster}} +{{> cluster_objects_struct header=false}} +{{/if}} +{{/zcl_structs}} +} // namespace Structs +} // namespace detail + {{#zcl_clusters}} namespace {{asUpperCamelCase name}} { {{#zcl_structs}} {{#first}} namespace Structs { {{/first}} -namespace {{asType label}} { -CHIP_ERROR Type::Encode(TLV::TLVWriter &writer, TLV::Tag tag) const{ - TLV::TLVType outer; - ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); - {{#zcl_struct_items}} - ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::k{{asUpperCamelCase label}})), {{asLowerCamelCase label}})); - {{/zcl_struct_items}} - ReturnErrorOnFailure(writer.EndContainer(outer)); - return CHIP_NO_ERROR; -} - -CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) { - CHIP_ERROR err = CHIP_NO_ERROR; - TLV::TLVType outer; - VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - err = reader.EnterContainer(outer); - ReturnErrorOnFailure(err); - while ((err = reader.Next()) == CHIP_NO_ERROR) { - VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); - switch (TLV::TagNumFromTag(reader.GetTag())) - { - {{#zcl_struct_items}} - case to_underlying(Fields::k{{asUpperCamelCase label}}): - ReturnErrorOnFailure(DataModel::Decode(reader, {{asLowerCamelCase label}})); - break; - {{/zcl_struct_items}} - default: - break; - } - } - - VerifyOrReturnError(err == CHIP_END_OF_TLV, err); - ReturnErrorOnFailure(reader.ExitContainer(outer)); - return CHIP_NO_ERROR; -} - -} // namespace {{asType label}} +{{#unless has_more_than_one_cluster}} +{{> cluster_objects_struct header=false}} +{{/unless}} {{#last}} } // namespace Structs {{/last}} diff --git a/src/app/zap-templates/templates/app/cluster-objects.zapt b/src/app/zap-templates/templates/app/cluster-objects.zapt index 32198df4eb324f..762649454499e3 100644 --- a/src/app/zap-templates/templates/app/cluster-objects.zapt +++ b/src/app/zap-templates/templates/app/cluster-objects.zapt @@ -20,6 +20,17 @@ namespace chip { namespace app { namespace Clusters { +namespace detail { +// Structs shared across multiple clusters. +namespace Structs { +{{#zcl_structs}} +{{#if has_more_than_one_cluster}} +{{> cluster_objects_struct header=true}} +{{/if}} +{{/zcl_structs}} +} // namespace Structs +} // namespace detail + {{#zcl_clusters}} namespace {{asUpperCamelCase name}} { {{#zcl_enums}} @@ -55,43 +66,11 @@ k{{asUpperCamelCase label}} = {{asHex mask}}, {{#first}} namespace Structs { {{/first}} -namespace {{asUpperCamelCase name}} { - enum class Fields { - {{#zcl_struct_items}} - k{{asUpperCamelCase label}} = {{fieldIdentifier}}, - {{/zcl_struct_items}} - }; - - struct Type { - public: - {{#zcl_struct_items}} - {{zapTypeToEncodableClusterObjectType type}} {{asLowerCamelCase label}}; - {{/zcl_struct_items}} - - CHIP_ERROR Encode(TLV::TLVWriter &writer, TLV::Tag tag) const; - {{#unless struct_contains_array}} - CHIP_ERROR Decode(TLV::TLVReader &reader); - {{/unless}} - {{#if struct_is_fabric_scoped}} - bool MatchesFabricIndex(FabricIndex fabricIndex_) const { - return {{ asLowerCamelCase struct_fabric_idx_field }} == fabricIndex_; - } - {{/if}} - }; - - {{#if struct_contains_array}} - struct DecodableType { - public: - {{#zcl_struct_items}} - {{zapTypeToDecodableClusterObjectType type}} {{asLowerCamelCase label}}; - {{/zcl_struct_items}} - CHIP_ERROR Decode(TLV::TLVReader &reader); - }; - {{else}} - using DecodableType = Type; - {{/if}} - -} // namespace {{asUpperCamelCase name}} +{{#if has_more_than_one_cluster}} +namespace {{asUpperCamelCase name}} = Clusters::detail::Structs::{{asUpperCamelCase name}}; +{{else}} +{{> cluster_objects_struct header=true}} +{{/if}} {{#last}} } // namespace Structs {{/last}} diff --git a/src/app/zap-templates/templates/app/helper.js b/src/app/zap-templates/templates/app/helper.js index b0cba01b38400e..1c4bb270720da2 100644 --- a/src/app/zap-templates/templates/app/helper.js +++ b/src/app/zap-templates/templates/app/helper.js @@ -352,6 +352,16 @@ function asMEI(prefix, suffix) return cHelper.asHex((prefix << 16) + suffix, 8); } +// Not to be exported. +function nsValueToNamespace(ns) +{ + if (ns == "detail") { + return ns; + } + + return asUpperCamelCase(ns); +} + /* * @brief * @@ -372,7 +382,7 @@ async function zapTypeToClusterObjectType(type, isDecodable, options) let passByReference = false; async function fn(pkgId) { - const ns = options.hash.ns ? ('chip::app::Clusters::' + asUpperCamelCase(options.hash.ns) + '::') : ''; + const ns = options.hash.ns ? ('chip::app::Clusters::' + nsValueToNamespace(options.hash.ns) + '::') : ''; const typeChecker = async (method) => zclHelper[method](this.global.db, type, pkgId).then(zclType => zclType != 'unknown'); if (await typeChecker('isEnum')) { diff --git a/src/app/zap-templates/zcl/data-model/chip/fixed-label-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/fixed-label-cluster.xml index 62497c43e0231e..727da449590993 100644 --- a/src/app/zap-templates/zcl/data-model/chip/fixed-label-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/fixed-label-cluster.xml @@ -19,6 +19,7 @@ limitations under the License. + diff --git a/src/app/zap-templates/zcl/data-model/chip/user-label-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/user-label-cluster.xml index d54cdef16e1f5c..6a7c5a9e67578c 100644 --- a/src/app/zap-templates/zcl/data-model/chip/user-label-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/user-label-cluster.xml @@ -17,12 +17,6 @@ limitations under the License. - - - - - - General User Label diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPAttributeTLVValueDecoder.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPAttributeTLVValueDecoder.mm index 94046a3660c397..c54917d50ef6d0 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPAttributeTLVValueDecoder.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPAttributeTLVValueDecoder.mm @@ -2889,12 +2889,6 @@ id CHIPDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() length:entry_0.label.size() encoding:NSUTF8StringEncoding]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; - newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() - length:entry_0.value.size() - encoding:NSUTF8StringEncoding]; newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() length:entry_0.value.size() encoding:NSUTF8StringEncoding]; @@ -8807,12 +8801,6 @@ id CHIPDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() length:entry_0.label.size() encoding:NSUTF8StringEncoding]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; - newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() - length:entry_0.value.size() - encoding:NSUTF8StringEncoding]; newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() length:entry_0.value.size() encoding:NSUTF8StringEncoding]; diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm index 3db41dee7cd30f..38356da0500dc8 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm @@ -2182,12 +2182,6 @@ newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() length:entry_0.label.size() encoding:NSUTF8StringEncoding]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; - newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() - length:entry_0.value.size() - encoding:NSUTF8StringEncoding]; newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() length:entry_0.value.size() encoding:NSUTF8StringEncoding]; @@ -4911,12 +4905,6 @@ newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() length:entry_0.label.size() encoding:NSUTF8StringEncoding]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; - newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() - length:entry_0.value.size() - encoding:NSUTF8StringEncoding]; newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() length:entry_0.value.size() encoding:NSUTF8StringEncoding]; diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPClustersObjc.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPClustersObjc.mm index 86c4b8bcf84d8a..1ef1774893c22f 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPClustersObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPClustersObjc.mm @@ -22033,8 +22033,6 @@ new CHIPDefaultSuccessCallbackBridge( } auto element_0 = (CHIPUserLabelClusterLabelStruct *) value[i_0]; listHolder_0->mList[i_0].label = [self asCharSpan:element_0.label]; - listHolder_0->mList[i_0].label = [self asCharSpan:element_0.label]; - listHolder_0->mList[i_0].value = [self asCharSpan:element_0.value]; listHolder_0->mList[i_0].value = [self asCharSpan:element_0.value]; } cppValue = ListType_0(listHolder_0->mList, value.count); diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm index f496d1a3e84469..1127c6d8da58f9 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm @@ -3853,8 +3853,6 @@ new CHIPDefaultSuccessCallbackBridge( } auto element_0 = (CHIPFixedLabelClusterLabelStruct *) value[i_0]; listHolder_0->mList[i_0].label = [self asCharSpan:element_0.label]; - listHolder_0->mList[i_0].label = [self asCharSpan:element_0.label]; - listHolder_0->mList[i_0].value = [self asCharSpan:element_0.value]; listHolder_0->mList[i_0].value = [self asCharSpan:element_0.value]; } cppValue = ListType_0(listHolder_0->mList, value.count); diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp index 8e9200bfb34abb..f88d21cd6be73f 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp @@ -22,6 +22,53 @@ namespace chip { namespace app { namespace Clusters { + +namespace detail { +// Structs shared across multiple clusters. +namespace Structs { +namespace LabelStruct { +CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const +{ + TLV::TLVType outer; + ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kLabel)), label)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kValue)), value)); + ReturnErrorOnFailure(writer.EndContainer(outer)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + TLV::TLVType outer; + VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + err = reader.EnterContainer(outer); + ReturnErrorOnFailure(err); + while ((err = reader.Next()) == CHIP_NO_ERROR) + { + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + switch (TLV::TagNumFromTag(reader.GetTag())) + { + case to_underlying(Fields::kLabel): + ReturnErrorOnFailure(DataModel::Decode(reader, label)); + break; + case to_underlying(Fields::kValue): + ReturnErrorOnFailure(DataModel::Decode(reader, value)); + break; + default: + break; + } + } + + VerifyOrReturnError(err == CHIP_END_OF_TLV, err); + ReturnErrorOnFailure(reader.ExitContainer(outer)); + return CHIP_NO_ERROR; +} + +} // namespace LabelStruct +} // namespace Structs +} // namespace detail + namespace PowerConfiguration { namespace Commands { @@ -10639,46 +10686,6 @@ namespace Events { } // namespace GroupKeyManagement namespace FixedLabel { namespace Structs { -namespace LabelStruct { -CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const -{ - TLV::TLVType outer; - ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kLabel)), label)); - ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kValue)), value)); - ReturnErrorOnFailure(writer.EndContainer(outer)); - return CHIP_NO_ERROR; -} - -CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - TLV::TLVType outer; - VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - err = reader.EnterContainer(outer); - ReturnErrorOnFailure(err); - while ((err = reader.Next()) == CHIP_NO_ERROR) - { - VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); - switch (TLV::TagNumFromTag(reader.GetTag())) - { - case to_underlying(Fields::kLabel): - ReturnErrorOnFailure(DataModel::Decode(reader, label)); - break; - case to_underlying(Fields::kValue): - ReturnErrorOnFailure(DataModel::Decode(reader, value)); - break; - default: - break; - } - } - - VerifyOrReturnError(err == CHIP_END_OF_TLV, err); - ReturnErrorOnFailure(reader.ExitContainer(outer)); - return CHIP_NO_ERROR; -} - -} // namespace LabelStruct } // namespace Structs namespace Commands { @@ -10715,46 +10722,6 @@ namespace Events { } // namespace FixedLabel namespace UserLabel { namespace Structs { -namespace LabelStruct { -CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const -{ - TLV::TLVType outer; - ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kLabel)), label)); - ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kValue)), value)); - ReturnErrorOnFailure(writer.EndContainer(outer)); - return CHIP_NO_ERROR; -} - -CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - TLV::TLVType outer; - VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - err = reader.EnterContainer(outer); - ReturnErrorOnFailure(err); - while ((err = reader.Next()) == CHIP_NO_ERROR) - { - VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); - switch (TLV::TagNumFromTag(reader.GetTag())) - { - case to_underlying(Fields::kLabel): - ReturnErrorOnFailure(DataModel::Decode(reader, label)); - break; - case to_underlying(Fields::kValue): - ReturnErrorOnFailure(DataModel::Decode(reader, value)); - break; - default: - break; - } - } - - VerifyOrReturnError(err == CHIP_END_OF_TLV, err); - ReturnErrorOnFailure(reader.ExitContainer(outer)); - return CHIP_NO_ERROR; -} - -} // namespace LabelStruct } // namespace Structs namespace Commands { diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index 89f5b534549069..8064d67fa1195a 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -37,6 +37,32 @@ namespace chip { namespace app { namespace Clusters { +namespace detail { +// Structs shared across multiple clusters. +namespace Structs { +namespace LabelStruct { +enum class Fields +{ + kLabel = 1, + kValue = 2, +}; + +struct Type +{ +public: + chip::CharSpan label; + chip::CharSpan value; + + CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; + +using DecodableType = Type; + +} // namespace LabelStruct +} // namespace Structs +} // namespace detail + namespace PowerConfiguration { namespace Attributes { @@ -15459,26 +15485,7 @@ struct TypeInfo namespace FixedLabel { namespace Structs { -namespace LabelStruct { -enum class Fields -{ - kLabel = 1, - kValue = 2, -}; - -struct Type -{ -public: - chip::CharSpan label; - chip::CharSpan value; - - CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; - CHIP_ERROR Decode(TLV::TLVReader & reader); -}; - -using DecodableType = Type; - -} // namespace LabelStruct +namespace LabelStruct = Clusters::detail::Structs::LabelStruct; } // namespace Structs namespace Attributes { @@ -15552,26 +15559,7 @@ struct TypeInfo namespace UserLabel { namespace Structs { -namespace LabelStruct { -enum class Fields -{ - kLabel = 1, - kValue = 2, -}; - -struct Type -{ -public: - chip::CharSpan label; - chip::CharSpan value; - - CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; - CHIP_ERROR Decode(TLV::TLVReader & reader); -}; - -using DecodableType = Type; - -} // namespace LabelStruct +namespace LabelStruct = Clusters::detail::Structs::LabelStruct; } // namespace Structs namespace Attributes { diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index 62e06a3fe67bf4..324333277943e2 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -39,6 +39,9 @@ // generated ones, so are placed here. namespace { +CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::detail::Structs::LabelStruct::DecodableType & value); + CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::Scenes::Structs::SceneExtensionFieldSet::DecodableType & value); CHIP_ERROR LogValue(const char * label, size_t indent, @@ -94,10 +97,6 @@ CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::GroupKeyManagement::Structs::GroupKey::DecodableType & value); CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::GroupKeyManagement::Structs::GroupKeySet::DecodableType & value); -CHIP_ERROR LogValue(const char * label, size_t indent, - const chip::app::Clusters::FixedLabel::Structs::LabelStruct::DecodableType & value); -CHIP_ERROR LogValue(const char * label, size_t indent, - const chip::app::Clusters::UserLabel::Structs::LabelStruct::DecodableType & value); CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::ModeSelect::Structs::ModeOptionStruct::DecodableType & value); CHIP_ERROR LogValue(const char * label, size_t indent, @@ -268,6 +267,30 @@ CHIP_ERROR LogValue(const char * label, size_t indent, const chip::Optional & // be logging. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" +CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::detail::Structs::LabelStruct::DecodableType & value) +{ + ChipLogProgress(chipTool, "%s%s: {", IndentStr(indent).c_str(), label); + { + CHIP_ERROR err = LogValue("Label", indent + 1, value.label); + if (err != CHIP_NO_ERROR) + { + ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for 'Label'", IndentStr(indent + 1).c_str()); + return err; + } + } + { + CHIP_ERROR err = LogValue("Value", indent + 1, value.value); + if (err != CHIP_NO_ERROR) + { + ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for 'Value'", IndentStr(indent + 1).c_str()); + return err; + } + } + ChipLogProgress(chipTool, "%s}", IndentStr(indent).c_str()); + return CHIP_NO_ERROR; +} + CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::Scenes::Structs::SceneExtensionFieldSet::DecodableType & value) { @@ -1552,52 +1575,6 @@ CHIP_ERROR LogValue(const char * label, size_t indent, ChipLogProgress(chipTool, "%s}", IndentStr(indent).c_str()); return CHIP_NO_ERROR; } -CHIP_ERROR LogValue(const char * label, size_t indent, - const chip::app::Clusters::FixedLabel::Structs::LabelStruct::DecodableType & value) -{ - ChipLogProgress(chipTool, "%s%s: {", IndentStr(indent).c_str(), label); - { - CHIP_ERROR err = LogValue("Label", indent + 1, value.label); - if (err != CHIP_NO_ERROR) - { - ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for 'Label'", IndentStr(indent + 1).c_str()); - return err; - } - } - { - CHIP_ERROR err = LogValue("Value", indent + 1, value.value); - if (err != CHIP_NO_ERROR) - { - ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for 'Value'", IndentStr(indent + 1).c_str()); - return err; - } - } - ChipLogProgress(chipTool, "%s}", IndentStr(indent).c_str()); - return CHIP_NO_ERROR; -} -CHIP_ERROR LogValue(const char * label, size_t indent, - const chip::app::Clusters::UserLabel::Structs::LabelStruct::DecodableType & value) -{ - ChipLogProgress(chipTool, "%s%s: {", IndentStr(indent).c_str(), label); - { - CHIP_ERROR err = LogValue("Label", indent + 1, value.label); - if (err != CHIP_NO_ERROR) - { - ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for 'Label'", IndentStr(indent + 1).c_str()); - return err; - } - } - { - CHIP_ERROR err = LogValue("Value", indent + 1, value.value); - if (err != CHIP_NO_ERROR) - { - ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for 'Value'", IndentStr(indent + 1).c_str()); - return err; - } - } - ChipLogProgress(chipTool, "%s}", IndentStr(indent).c_str()); - return CHIP_NO_ERROR; -} CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::ModeSelect::Structs::ModeOptionStruct::DecodableType & value) {