Skip to content

Commit

Permalink
[chip-tool] Codegen all commands/attributes for enabled client cluste…
Browse files Browse the repository at this point in the history
…rs (#14794)

* [chip-tool] Codegen all commands/attributes for enabled client clusters

* Update generated content
  • Loading branch information
vivien-apple authored and pull[bot] committed Aug 25, 2023
1 parent 67efa7a commit 1187959
Show file tree
Hide file tree
Showing 10 changed files with 20,849 additions and 8,676 deletions.
91 changes: 45 additions & 46 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@

{{> clusters_header}}

{{#chip_client_clusters}}
{{#zcl_clusters}}
{{> cluster_header}}

{{#chip_cluster_commands}}
{{#zcl_commands_source_client}}
/*
* Command {{asUpperCamelCase name}}
*/
class {{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}: public ClusterCommand
class {{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public ClusterCommand
{
public:
{{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}(CredentialIssuerCommands * credsIssuerConfig): ClusterCommand("{{asDelimitedCommand name}}", credsIssuerConfig){{#chip_cluster_command_arguments}}{{#if isComplex}}, mComplex_{{asUpperCamelCase label}}(&mRequest.{{asLowerCamelCase label}}){{/if}}{{/chip_cluster_command_arguments}}
{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(CredentialIssuerCommands * credsIssuerConfig): ClusterCommand("{{asDelimitedCommand name}}", credsIssuerConfig){{#zcl_command_arguments}}{{#if_chip_complex}}, mComplex_{{asUpperCamelCase label}}(&mRequest.{{asLowerCamelCase label}}){{/if_chip_complex}}{{/zcl_command_arguments}}
{
{{#chip_cluster_command_arguments}}
{{~#*inline "field"}}mRequest.{{asLowerCamelCase label}}{{/inline~}}
{{#if isComplex}}
{{#zcl_command_arguments}}
{{#if_chip_complex}}
AddArgument("{{asUpperCamelCase label}}", &mComplex_{{asUpperCamelCase label}});
{{else if (isString type)}}
AddArgument("{{asUpperCamelCase label}}", &{{>field}});
AddArgument("{{asUpperCamelCase label}}", &mRequest.{{asLowerCamelCase label}});
{{else}}
AddArgument("{{asUpperCamelCase label}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &{{>field}});
{{/if}}
{{/chip_cluster_command_arguments}}
AddArgument("{{asUpperCamelCase label}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &mRequest.{{asLowerCamelCase label}});
{{/if_chip_complex}}
{{/zcl_command_arguments}}
ClusterCommand::AddArguments();
}

Expand All @@ -48,30 +47,30 @@ public:

private:
chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Type mRequest;
{{#chip_cluster_command_arguments}}
{{#if isComplex}}
{{#zcl_command_arguments}}
{{#if_chip_complex}}
TypedComplexArgument<{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}> mComplex_{{asUpperCamelCase label}};
{{/if}}
{{/chip_cluster_command_arguments}}
{{/if_chip_complex}}
{{/zcl_command_arguments}}
};

{{/chip_cluster_commands}}
{{/zcl_commands_source_client}}

{{#chip_server_cluster_attributes}}
{{#if isWritableAttribute}}
{{#zcl_attributes_server}}
{{#if isWritable}}
class Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public WriteAttribute
{
public:
Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(CredentialIssuerCommands * credsIssuerConfig): WriteAttribute("{{asUpperCamelCase name}}", credsIssuerConfig){{#if isComplex}}, mComplex(&mValue){{/if}}
Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(CredentialIssuerCommands * credsIssuerConfig): WriteAttribute("{{asUpperCamelCase name}}", credsIssuerConfig){{#if_chip_complex}}, mComplex(&mValue){{/if_chip_complex}}
{
AddArgument("attr-name", "{{asDelimitedCommand (asUpperCamelCase name)}}");
{{#if isComplex}}
{{#if_chip_complex}}
AddArgument("attr-value", &mComplex);
{{else if (isString type)}}
AddArgument("attr-value", &mValue);
{{else}}
AddArgument("attr-value", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &mValue);
{{/if}}
{{/if_chip_complex}}
WriteAttribute::AddArguments();
}

Expand All @@ -83,20 +82,20 @@ public:
}

private:
{{zapTypeToEncodableClusterObjectType type ns=parent.name}} mValue;
{{#if isComplex}}
TypedComplexArgument<{{zapTypeToEncodableClusterObjectType type ns=parent.name}}> mComplex;
{{/if}}
{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}} mValue;
{{#if_chip_complex}}
TypedComplexArgument<{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}}> mComplex;
{{/if_chip_complex}}
};

{{/if}}
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}
{{/zcl_attributes_server}}
{{/zcl_clusters}}

/*----------------------------------------------------------------------------*\
| Register all Clusters commands |
\*----------------------------------------------------------------------------*/
{{#chip_client_clusters}}
{{#zcl_clusters}}
void registerCluster{{asUpperCamelCase name}}(Commands & commands, CredentialIssuerCommands * credsIssuerConfig)
{
using namespace chip::app::Clusters::{{asUpperCamelCase name}};
Expand All @@ -108,44 +107,44 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands, CredentialIss
// Commands
//
make_unique<ClusterCommand>(Id, credsIssuerConfig), //
{{#chip_cluster_commands}}
make_unique<{{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}>(credsIssuerConfig), //
{{/chip_cluster_commands}}
{{#zcl_commands_source_client}}
make_unique<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(credsIssuerConfig), //
{{/zcl_commands_source_client}}
//
// Attributes
//
make_unique<ReadAttribute>(Id, credsIssuerConfig), //
{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server}}
make_unique<ReadAttribute>(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), //
{{/chip_server_cluster_attributes}}
{{/zcl_attributes_server}}
make_unique<WriteAttribute>(Id, credsIssuerConfig), //
{{#chip_server_cluster_attributes}}
{{#if isWritableAttribute}}
{{#zcl_attributes_server}}
{{#if isWritable}}
make_unique<Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(credsIssuerConfig), //
{{/if}}
{{/chip_server_cluster_attributes}}
{{/zcl_attributes_server}}
make_unique<SubscribeAttribute>(Id, credsIssuerConfig), //
{{#chip_server_cluster_attributes}}
{{#if isReportableAttribute}}
{{#zcl_attributes_server}}
{{#if isReportable}}
make_unique<SubscribeAttribute>(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), //
{{/if}}
{{/chip_server_cluster_attributes}}
{{/zcl_attributes_server}}
//
// Events
//
make_unique<ReadEvent>(Id, credsIssuerConfig), //
{{#chip_server_cluster_events}}
{{#zcl_events}}
make_unique<ReadEvent>(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Events::{{asUpperCamelCase name}}::Id, credsIssuerConfig), //
{{/chip_server_cluster_events}}
{{/zcl_events}}
make_unique<SubscribeEvent>(Id, credsIssuerConfig), //
{{#chip_server_cluster_events}}
{{#zcl_events}}
make_unique<SubscribeEvent>(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Events::{{asUpperCamelCase name}}::Id, credsIssuerConfig), //
{{/chip_server_cluster_events}}
{{/zcl_events}}
};

commands.Register(clusterName, clusterCommands);
}
{{/chip_client_clusters}}
{{/zcl_clusters}}

void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIssuerConfig)
{
Expand All @@ -166,7 +165,7 @@ void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIss
void registerClusters(Commands & commands, CredentialIssuerCommands * credsIssuerConfig)
{
registerClusterAny(commands, credsIssuerConfig);
{{#chip_client_clusters}}
{{#zcl_clusters}}
registerCluster{{asUpperCamelCase name}}(commands, credsIssuerConfig);
{{/chip_client_clusters}}
{{/zcl_clusters}}
}
18 changes: 9 additions & 9 deletions examples/chip-tool/templates/logging/DataModelLogger-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const {{
{{/zcl_clusters}}

{{#chip_client_clusters}}
{{#chip_cluster_responses}}
{{#zcl_commands_source_server}}
CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & value)
{
DataModelLogger::LogString(label, indent, "{");
{{#chip_cluster_response_arguments}}
{{#zcl_command_arguments}}
ReturnErrorOnFailure(DataModelLogger::LogValue("{{asLowerCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}}));
{{/chip_cluster_response_arguments}}
{{/zcl_command_arguments}}
DataModelLogger::LogString(indent, "}");
return CHIP_NO_ERROR;
}
{{/chip_cluster_responses}}
{{/zcl_commands_source_server}}
{{/chip_client_clusters}}

CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data)
Expand All @@ -68,7 +68,7 @@ CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributeP
switch (path.mClusterId)
{
{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server}}
{{#first}}
case {{asUpperCamelCase parent.name}}::Id:
{
Expand All @@ -77,7 +77,7 @@ CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributeP
{{/first}}
case {{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::Id:
{
{{zapTypeToDecodableClusterObjectType type ns=parent.name}} value;
{{zapTypeToDecodableClusterObjectType type ns=parent.name forceNotOptional=true}} value;
ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value));
return DataModelLogger::LogValue("{{name}}", 1, value);
}
Expand All @@ -86,7 +86,7 @@ CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributeP
break;
}
{{/last}}
{{/chip_server_cluster_attributes}}
{{/zcl_attributes_server}}
{{/chip_client_clusters}}
default:
break;
Expand All @@ -103,7 +103,7 @@ CHIP_ERROR DataModelLogger::LogCommand(const chip::app::ConcreteCommandPath & pa
switch (path.mClusterId)
{
{{#chip_client_clusters}}
{{#chip_cluster_responses}}
{{#zcl_commands_source_server}}
{{#first}}
case {{asUpperCamelCase parent.name}}::Id:
{
Expand All @@ -121,7 +121,7 @@ CHIP_ERROR DataModelLogger::LogCommand(const chip::app::ConcreteCommandPath & pa
break;
}
{{/last}}
{{/chip_cluster_responses}}
{{/zcl_commands_source_server}}
{{/chip_client_clusters}}
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions examples/chip-tool/templates/logging/DataModelLogger.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::C
{{/zcl_clusters}}

{{#chip_client_clusters}}
{{#chip_cluster_responses}}
{{#zcl_commands_source_server}}
static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & value);
{{/chip_cluster_responses}}
{{/zcl_commands_source_server}}
{{/chip_client_clusters}}
12 changes: 6 additions & 6 deletions src/app/zap-templates/partials/cluster_header.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
{{pad (concat "| Cluster " (asUpperCamelCase name)) 70 ' '}}{{pad (concat "| " (asHex code 4)) 9 ' '}}|
{{pad "|" 79 '-'}}|
{{pad "| Commands: " 70 ' '}}{{pad "| " 9 ' '}}|
{{#chip_cluster_commands}}
{{#zcl_commands_source_client}}
{{pad (concat "| * " (asUpperCamelCase name)) 70 ' '}}{{pad (concat "| " (asHex code 2)) 9 ' '}}|
{{/chip_cluster_commands}}
{{/zcl_commands_source_client}}
{{pad "|" 79 '-'}}|
{{pad "| Attributes: " 70 ' '}}{{pad "| " 9 ' '}}|
{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server}}
{{pad (concat "| * " (asUpperCamelCase name)) 70 ' '}}{{pad (concat "| " (asHex code 4)) 9 ' '}}|
{{/chip_server_cluster_attributes}}
{{/zcl_attributes_server}}
{{pad "|" 79 '-'}}|
{{pad "| Events: " 70 ' '}}{{pad "| " 9 ' '}}|
{{#chip_server_cluster_events}}
{{#zcl_events}}
{{pad (concat "| * " (asUpperCamelCase name)) 70 ' '}}{{pad (concat "| " (asHex code 4)) 9 ' '}}|
{{/chip_server_cluster_events}}
{{/zcl_events}}
{{pad '\*' 78 '-'}}*/
4 changes: 2 additions & 2 deletions src/app/zap-templates/partials/clusters_header.zapt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{pad '/*' 78 '-'}}*\
{{pad "| Cluster Name" 70 ' '}}{{pad "| ID" 9 ' '}}|
{{pad "|" 70 '-'}}{{pad "+" 9 '-'}}|
{{#chip_clusters}}
{{#zcl_clusters}}
{{pad (concat "| " (asUpperCamelCase name)) 70 " "}}{{pad (concat "| " (asHex code 4)) 9 ' '}}|
{{/chip_clusters}}
{{/zcl_clusters}}
{{pad '\*' 78 '-'}}*/
5 changes: 5 additions & 0 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ function nsValueToNamespace(ns)
*/
async function zapTypeToClusterObjectType(type, isDecodable, options)
{
// Use the entryType as a type
if (type == 'array' && this.entryType) {
type = this.entryType;
}

let passByReference = false;
async function fn(pkgId)
{
Expand Down
28 changes: 28 additions & 0 deletions src/app/zap-templates/templates/chip/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,33 @@ async function if_chip_enum(type, options)
return templateUtil.templatePromise(this.global, result);
}

async function if_chip_complex(options)
{
// `zcl_command_arguments` has an `isArray` property and `type`
// contains the array element type.
if (this.isArray) {
return options.fn(this);
}

// zcl_attributes iterators does not expose an `isArray` property
// and `entryType` contains the array element type, while `type`
// contains the atomic type, which is array in this case.
// https://github.com/project-chip/zap/issues/412
if (this.type == 'array') {
return options.fn(this);
}

let pkgId = await templateUtil.ensureZclPackageId(this);
let checkResult = await zclHelper.isStruct(this.global.db, this.type, pkgId);
let result;
if (checkResult != 'unknown') {
result = options.fn(this);
} else {
result = options.inverse(this);
}
return templateUtil.templatePromise(this.global, result);
}

//
// Module exports
//
Expand All @@ -494,6 +521,7 @@ exports.chip_available_cluster_commands = chip_available_cl
exports.chip_endpoints = chip_endpoints;
exports.chip_endpoint_clusters = chip_endpoint_clusters;
exports.if_chip_enum = if_chip_enum;
exports.if_chip_complex = if_chip_complex;
exports.if_in_global_responses = if_in_global_responses;
exports.chip_cluster_specific_structs = chip_cluster_specific_structs;
exports.chip_shared_structs = chip_shared_structs;
Loading

0 comments on commit 1187959

Please sign in to comment.