Skip to content

Commit

Permalink
Fix chip-tool support for nullable bitmaps. (project-chip#14473)
Browse files Browse the repository at this point in the history
We're doing casting in the template, but we can just use our existing
AddArgument overloads instead.
  • Loading branch information
bzbarsky-apple authored and selissia committed Jan 28, 2022
1 parent 461e02e commit 56d3405
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 83 deletions.
8 changes: 8 additions & 0 deletions examples/chip-tool/commands/common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ class Command
return AddArgument(name, min, max, reinterpret_cast<std::underlying_type_t<T> *>(out), flags);
}

template <typename T>
size_t AddArgument(const char * name, int64_t min, uint64_t max, chip::BitFlags<T> * out, uint8_t flags = 0)
{
// This is a terrible hack that relies on BitFlags only having the one
// mValue member.
return AddArgument(name, min, max, reinterpret_cast<T *>(out), flags);
}

template <typename T>
size_t AddArgument(const char * name, chip::Optional<T> * value)
{
Expand Down
10 changes: 1 addition & 9 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ public:
{{else if (isString type)}}
AddArgument("{{asUpperCamelCase label}}", &{{>field}});
{{else}}
AddArgument("{{asUpperCamelCase label}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}},
{{~#if isNullable}}&{{>field}}
{{else}}
{{~#if ./isEnum}}reinterpret_cast<std::underlying_type_t<decltype({{>field}})> *>(&{{>field}})
{{else ./isBitmap}}reinterpret_cast<std::underlying_type_t<chip::app::Clusters::{{asUpperCamelCase parent.clusterName}}::{{asUpperCamelCase type}}> *>(&{{>field}})
{{else}}&{{>field}}
{{/if~}}
{{/if~}}
);
AddArgument("{{asUpperCamelCase label}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &{{>field}});
{{/if}}
{{/chip_cluster_command_arguments}}
ClusterCommand::AddArguments();
Expand Down
110 changes: 36 additions & 74 deletions zzz_generated/chip-tool/zap-generated/cluster/Commands.h

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

0 comments on commit 56d3405

Please sign in to comment.