From 7f2ad58aca9b679cc7fe35312ac96984a85b708c Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 7 Apr 2022 09:40:26 -0400 Subject: [PATCH] Stop requiring a fabric index to be provided when writing fabric-scoped structs with chip-tool. (#17145) It's ignored on the server anyway, so no need to require people to send it. --- .../templates/ComplexArgumentParser-src.zapt | 9 ++ examples/chip-tool/templates/helper.js | 14 +++- .../cluster/ComplexArgumentParser.cpp | 82 ++++++++++--------- 3 files changed, 65 insertions(+), 40 deletions(-) diff --git a/examples/chip-tool/templates/ComplexArgumentParser-src.zapt b/examples/chip-tool/templates/ComplexArgumentParser-src.zapt index dbc62bf3024ca9..580118b3d014a8 100644 --- a/examples/chip-tool/templates/ComplexArgumentParser-src.zapt +++ b/examples/chip-tool/templates/ComplexArgumentParser-src.zapt @@ -9,8 +9,12 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, {{zapTypeToEncodable {{#zcl_struct_items}} {{#unless isOptional}} + {{~! Fabric index fields are not sent on writes, so don't force people to + provide them. ~}} + {{#unless (isStrEqual label ../struct_fabric_idx_field)}} ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("{{parent.name}}.{{asLowerCamelCase label}}", "{{asLowerCamelCase label}}", value.isMember("{{asLowerCamelCase label}}"))); {{/unless}} + {{/unless}} {{/zcl_struct_items}} char labelWithMember[kMaxLabelLength]; @@ -18,11 +22,16 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, {{zapTypeToEncodable {{#if isOptional}} if (value.isMember("{{asLowerCamelCase label}}")) { + {{else if (isStrEqual label ../struct_fabric_idx_field)}} + if (value.isMember("{{asLowerCamelCase label}}")) + { {{/if}} snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "{{asLowerCamelCase label}}"); ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.{{asLowerCamelCase label}}, value["{{asLowerCamelCase label}}"])); {{#if isOptional}} } + {{else if (isStrEqual label ../struct_fabric_idx_field)}} + } {{/if}} {{/zcl_struct_items}} diff --git a/examples/chip-tool/templates/helper.js b/examples/chip-tool/templates/helper.js index aa778c8a645718..a59280c155ae2d 100644 --- a/examples/chip-tool/templates/helper.js +++ b/examples/chip-tool/templates/helper.js @@ -116,13 +116,21 @@ async function structs_with_cluster_name(options) continue; } - if (s.struct_cluster_count == 1) { + s.items.forEach(i => { + if (i.type.toLowerCase() == "fabric_idx") { + s.struct_fabric_idx_field = i.label; + } + }) + + if (s.struct_cluster_count == 1) + { const clusters = await zclQuery.selectStructClusters(this.global.db, s.id); - blocks.push({ id : s.id, name : s.name, clusterName : clusters[0].name }); + blocks.push( + { id : s.id, name : s.name, struct_fabric_idx_field : s.struct_fabric_idx_field, clusterName : clusters[0].name }); } if (s.struct_cluster_count > 1) { - blocks.push({ id : s.id, name : s.name, clusterName : "detail" }); + blocks.push({ id : s.id, name : s.name, struct_fabric_idx_field : s.struct_fabric_idx_field, clusterName : "detail" }); } } diff --git a/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp b/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp index 3236459f7962e0..05b9364ab308cc 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp @@ -33,8 +33,6 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, ComplexArgumentParser::EnsureMemberExist("AccessControlEntry.subjects", "subjects", value.isMember("subjects"))); ReturnErrorOnFailure( ComplexArgumentParser::EnsureMemberExist("AccessControlEntry.targets", "targets", value.isMember("targets"))); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("AccessControlEntry.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); char labelWithMember[kMaxLabelLength]; snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "privilege"); @@ -49,8 +47,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "targets"); ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.targets, value["targets"])); - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; } @@ -546,15 +547,16 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, VerifyOrReturnError(value.isObject(), CHIP_ERROR_INVALID_ARGUMENT); ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("ExtensionEntry.data", "data", value.isMember("data"))); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("ExtensionEntry.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); char labelWithMember[kMaxLabelLength]; snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "data"); ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.data, value["data"])); - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; } @@ -578,8 +580,6 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, ComplexArgumentParser::EnsureMemberExist("FabricDescriptor.fabricId", "fabricId", value.isMember("fabricId"))); ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("FabricDescriptor.nodeId", "nodeId", value.isMember("nodeId"))); ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("FabricDescriptor.label", "label", value.isMember("label"))); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("FabricDescriptor.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); char labelWithMember[kMaxLabelLength]; snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "rootPublicKey"); @@ -597,8 +597,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "label"); ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.label, value["label"])); - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; } @@ -622,8 +625,6 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, ComplexArgumentParser::EnsureMemberExist("GroupInfoMapStruct.groupId", "groupId", value.isMember("groupId"))); ReturnErrorOnFailure( ComplexArgumentParser::EnsureMemberExist("GroupInfoMapStruct.endpoints", "endpoints", value.isMember("endpoints"))); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("GroupInfoMapStruct.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); char labelWithMember[kMaxLabelLength]; snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "groupId"); @@ -638,8 +639,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.groupName, value["groupName"])); } - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; } @@ -661,8 +665,6 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, ComplexArgumentParser::EnsureMemberExist("GroupKeyMapStruct.groupId", "groupId", value.isMember("groupId"))); ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("GroupKeyMapStruct.groupKeySetID", "groupKeySetID", value.isMember("groupKeySetID"))); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("GroupKeyMapStruct.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); char labelWithMember[kMaxLabelLength]; snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "groupId"); @@ -671,8 +673,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "groupKeySetID"); ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.groupKeySetID, value["groupKeySetID"])); - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; } @@ -906,8 +911,6 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("NOCStruct.noc", "noc", value.isMember("noc"))); ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("NOCStruct.icac", "icac", value.isMember("icac"))); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("NOCStruct.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); char labelWithMember[kMaxLabelLength]; snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "noc"); @@ -916,8 +919,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "icac"); ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.icac, value["icac"])); - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; } @@ -1516,8 +1522,6 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, value.isMember("providerNodeID"))); ReturnErrorOnFailure( ComplexArgumentParser::EnsureMemberExist("ProviderLocation.endpoint", "endpoint", value.isMember("endpoint"))); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("ProviderLocation.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); char labelWithMember[kMaxLabelLength]; snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "providerNodeID"); @@ -1526,8 +1530,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "endpoint"); ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.endpoint, value["endpoint"])); - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; } @@ -1886,9 +1893,6 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, chip::app::Clusters: { VerifyOrReturnError(value.isObject(), CHIP_ERROR_INVALID_ARGUMENT); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("TargetStruct.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); - char labelWithMember[kMaxLabelLength]; if (value.isMember("node")) { @@ -1914,8 +1918,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, chip::app::Clusters: ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.cluster, value["cluster"])); } - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; } @@ -1945,8 +1952,6 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, value.isMember("fabricSensitiveStruct"))); ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist( "TestFabricScoped.fabricSensitiveInt8uList", "fabricSensitiveInt8uList", value.isMember("fabricSensitiveInt8uList"))); - ReturnErrorOnFailure( - ComplexArgumentParser::EnsureMemberExist("TestFabricScoped.fabricIndex", "fabricIndex", value.isMember("fabricIndex"))); char labelWithMember[kMaxLabelLength]; snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricSensitiveInt8u"); @@ -1983,8 +1988,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, ReturnErrorOnFailure( ComplexArgumentParser::Setup(labelWithMember, request.fabricSensitiveInt8uList, value["fabricSensitiveInt8uList"])); - snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + if (value.isMember("fabricIndex")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "fabricIndex"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.fabricIndex, value["fabricIndex"])); + } return CHIP_NO_ERROR; }