From 20612185a584ef0d349622bf5384958b6ac0a804 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 24 Jan 2024 14:57:24 -0500 Subject: [PATCH] Fix handling of optional struct-typed command arguments in chip-tool. (#31658) AddArgument documents that for "complex" (i.e. list and struct) arguments there is no automatic type-based handling of optionality and the "kOptional" flag needs to be passed in explicitly. But the generated code was not doing that. --- examples/chip-tool/templates/commands.zapt | 2 +- .../zap-generated/cluster/Commands.h | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/chip-tool/templates/commands.zapt b/examples/chip-tool/templates/commands.zapt index 37aaef24cc2678..bf981ec8e9e9bf 100644 --- a/examples/chip-tool/templates/commands.zapt +++ b/examples/chip-tool/templates/commands.zapt @@ -31,7 +31,7 @@ public: { {{#zcl_command_arguments}} {{#if_chip_complex}} - AddArgument("{{asUpperCamelCase label}}", &mComplex_{{asUpperCamelCase label}}); + AddArgument("{{asUpperCamelCase label}}", &mComplex_{{asUpperCamelCase label}}{{#if isOptional}}, "", Argument::kOptional{{/if}}); {{else if (isString type)}} AddArgument("{{asUpperCamelCase label}}", &mRequest.{{asLowerCamelCase label}}); {{else}} diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index 854e51ce08f135..c4eb22e920597c 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -11052,10 +11052,10 @@ class ChannelGetProgramGuide : public ClusterCommand { AddArgument("StartTime", 0, UINT32_MAX, &mRequest.startTime); AddArgument("EndTime", 0, UINT32_MAX, &mRequest.endTime); - AddArgument("ChannelList", &mComplex_ChannelList); - AddArgument("PageToken", &mComplex_PageToken); + AddArgument("ChannelList", &mComplex_ChannelList, "", Argument::kOptional); + AddArgument("PageToken", &mComplex_PageToken, "", Argument::kOptional); AddArgument("RecordingFlag", 0, UINT32_MAX, &mRequest.recordingFlag); - AddArgument("ExternalIDList", &mComplex_ExternalIDList); + AddArgument("ExternalIDList", &mComplex_ExternalIDList, "", Argument::kOptional); AddArgument("Data", &mRequest.data); ClusterCommand::AddArguments(); } @@ -12103,7 +12103,7 @@ class ContentLauncherLaunchContent : public ClusterCommand AddArgument("Search", &mComplex_Search); AddArgument("AutoPlay", 0, 1, &mRequest.autoPlay); AddArgument("Data", &mRequest.data); - AddArgument("PlaybackPreferences", &mComplex_PlaybackPreferences); + AddArgument("PlaybackPreferences", &mComplex_PlaybackPreferences, "", Argument::kOptional); AddArgument("UseCurrentContext", 0, 1, &mRequest.useCurrentContext); ClusterCommand::AddArguments(); } @@ -12147,7 +12147,7 @@ class ContentLauncherLaunchURL : public ClusterCommand { AddArgument("ContentURL", &mRequest.contentURL); AddArgument("DisplayString", &mRequest.displayString); - AddArgument("BrandingInformation", &mComplex_BrandingInformation); + AddArgument("BrandingInformation", &mComplex_BrandingInformation, "", Argument::kOptional); ClusterCommand::AddArguments(); } @@ -12303,7 +12303,7 @@ class ApplicationLauncherLaunchApp : public ClusterCommand ApplicationLauncherLaunchApp(CredentialIssuerCommands * credsIssuerConfig) : ClusterCommand("launch-app", credsIssuerConfig), mComplex_Application(&mRequest.application) { - AddArgument("Application", &mComplex_Application); + AddArgument("Application", &mComplex_Application, "", Argument::kOptional); AddArgument("Data", &mRequest.data); ClusterCommand::AddArguments(); } @@ -12344,7 +12344,7 @@ class ApplicationLauncherStopApp : public ClusterCommand ApplicationLauncherStopApp(CredentialIssuerCommands * credsIssuerConfig) : ClusterCommand("stop-app", credsIssuerConfig), mComplex_Application(&mRequest.application) { - AddArgument("Application", &mComplex_Application); + AddArgument("Application", &mComplex_Application, "", Argument::kOptional); ClusterCommand::AddArguments(); } @@ -12384,7 +12384,7 @@ class ApplicationLauncherHideApp : public ClusterCommand ApplicationLauncherHideApp(CredentialIssuerCommands * credsIssuerConfig) : ClusterCommand("hide-app", credsIssuerConfig), mComplex_Application(&mRequest.application) { - AddArgument("Application", &mComplex_Application); + AddArgument("Application", &mComplex_Application, "", Argument::kOptional); ClusterCommand::AddArguments(); } @@ -14032,11 +14032,11 @@ class UnitTestingTestComplexNullableOptionalRequest : public ClusterCommand AddArgument("OptionalString", &mRequest.optionalString); AddArgument("NullableOptionalString", &mRequest.nullableOptionalString); AddArgument("NullableStruct", &mComplex_NullableStruct); - AddArgument("OptionalStruct", &mComplex_OptionalStruct); - AddArgument("NullableOptionalStruct", &mComplex_NullableOptionalStruct); + AddArgument("OptionalStruct", &mComplex_OptionalStruct, "", Argument::kOptional); + AddArgument("NullableOptionalStruct", &mComplex_NullableOptionalStruct, "", Argument::kOptional); AddArgument("NullableList", &mComplex_NullableList); - AddArgument("OptionalList", &mComplex_OptionalList); - AddArgument("NullableOptionalList", &mComplex_NullableOptionalList); + AddArgument("OptionalList", &mComplex_OptionalList, "", Argument::kOptional); + AddArgument("NullableOptionalList", &mComplex_NullableOptionalList, "", Argument::kOptional); ClusterCommand::AddArguments(); }