Skip to content

Commit

Permalink
Move treatment of args as const ref into the helper as well, so we
Browse files Browse the repository at this point in the history
don't convert a bunch of integer args to const refs in ways that the
rest of the system does not expect.
  • Loading branch information
bzbarsky-apple committed Oct 22, 2021
1 parent 90d99d1 commit 73d395f
Show file tree
Hide file tree
Showing 9 changed files with 981 additions and 1,130 deletions.
3 changes: 1 addition & 2 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void OnCharStringAttributeResponse(void * context, const chip::CharSpan v
{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#if isList}}
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse(void * context, const {{zapTypeToDecodableClusterObjectType type ns=parent.name}} & list)
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list)
{
ModelCommand * command = static_cast<ModelCommand *>(context);

Expand Down Expand Up @@ -254,7 +254,6 @@ public:
{{#chip_cluster_command_non_expanded_arguments}}
{{#if isArray}}
{{! TODO Implement complex types parsing in order to properly set the request parameters }}
{{asLowerCamelCase label}};
mRequest.{{asLowerCamelCase label}} = {{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}();
{{/if}}
{{/chip_cluster_command_non_expanded_arguments}}
Expand Down
4 changes: 2 additions & 2 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class {{filename}}: public TestCommand
{{#*inline "successCallback"}}mOnSuccessCallback_{{index}}{{/inline}}
{{#*inline "failureResponse"}}OnFailureCallback_{{index}}{{/inline}}
{{#*inline "successResponse"}}OnSuccessCallback_{{index}}{{/inline}}
{{#*inline "successArguments"}}void * context{{#chip_tests_item_response_parameters}}, const {{zapTypeToDecodableClusterObjectType type ns=parent.cluster}} & {{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}}{{/inline}}
{{#*inline "successArguments"}}void * context{{#chip_tests_item_response_parameters}}, {{zapTypeToDecodableClusterObjectType type ns=parent.cluster isArgument=true}} {{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}}{{/inline}}
{{#*inline "failureArguments"}}void * context, uint8_t status{{/inline}}

{{#chip_tests_items}}
Expand Down Expand Up @@ -102,7 +102,7 @@ class {{filename}}: public TestCommand
{{#*inline "failureResponse"}}OnFailureResponse_{{index}}{{/inline}}
{{#*inline "successResponse"}}OnSuccessResponse_{{index}}{{/inline}}
{{#*inline "failureArguments"}}uint8_t status{{/inline}}
{{#*inline "successArguments"}}{{#chip_tests_item_response_parameters}}{{#not_first}}, {{/not_first}}const {{zapTypeToDecodableClusterObjectType type ns=parent.cluster}} & {{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}}{{/inline}}
{{#*inline "successArguments"}}{{#chip_tests_item_response_parameters}}{{#not_first}}, {{/not_first}}{{zapTypeToDecodableClusterObjectType type ns=parent.cluster isArgument=true}} {{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}}{{/inline}}

CHIP_ERROR {{>testCommand}}()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{#if isArray}}

{{! forceNotList=true because we really want the type of a single item here }}
{{zapTypeToEncodableClusterObjectType type ns=ns forceNotList=true}} {{asLowerCamelCase label}}List[{{definedValue.length}}];
{{#each definedValue}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef void (*{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}C
{{#chip_server_cluster_attributes}}
{{#if isList}}
void {{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}ListAttributeFilter(chip::TLV::TLVReader * data, chip::Callback::Cancelable * onSuccessCallback, chip::Callback::Cancelable * onFailureCallback);
typedef void (*{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeCallback)(void * context, const {{zapTypeToDecodableClusterObjectType type ns=parent.name}} & data);
typedef void (*{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeCallback)(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} data);
{{/if}}
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}
8 changes: 7 additions & 1 deletion src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ function asMEI(prefix, suffix)
*/
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) + '::') : '';
Expand All @@ -364,6 +365,7 @@ async function zapTypeToClusterObjectType(type, isDecodable, options)
}

if (await typeChecker('isStruct')) {
passByReference = true;
return ns + 'Structs::' + type + '::' + (isDecodable ? 'DecodableType' : 'Type');
}

Expand All @@ -372,12 +374,16 @@ async function zapTypeToClusterObjectType(type, isDecodable, options)

let promise = templateUtil.ensureZclPackageId(this).then(fn.bind(this));
if ((this.isList || this.isArray || this.entryType) && !options.hash.forceNotList) {
let listType = isDecodable ? "DecodableList" : "List";
passByReference = true;
let listType = isDecodable ? "DecodableList" : "List";
// If we did not have a namespace provided, we can assume we're inside
// chip::app.
let listNamespace = options.hash.ns ? "chip::app::" : ""
promise = promise.then(typeStr => `${listNamespace}DataModel::${listType}<${typeStr}>`);
}
if (options.hash.isArgument && passByReference) {
promise = promise.then(typeStr => `const ${typeStr} &`);
}
return templateUtil.templatePromise(this.global, promise)
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/templates/CHIPClusters-JNI.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCall
}
}

static void CallbackFn(void * context, const {{zapTypeToDecodableClusterObjectType type ns=parent.name}} & list)
static void CallbackFn(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list)
{
chip::DeviceLayer::StackUnlock unlock;
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void OnAttributeResponse<bool>(void * /* context */, bool value)
{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#if isList}}
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse(void * context, const {{zapTypeToDecodableClusterObjectType type ns=parent.name}} & list)
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list)
{
uint16_t count = 0;
auto iter = list.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public:
{{#if (isStrEqual partial-type "Command")}}
{{#chip_cluster_response_arguments}}, {{asUnderlyingZclType type}} {{asSymbol label}}{{/chip_cluster_response_arguments}}
{{else if (isStrEqual partial-type "List")}}
, const {{zapTypeToDecodableClusterObjectType type ns=parent.name}} & list
, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list
{{else if partial-type}}
, {{asUnderlyingZclType partial-type}} value
{{else}}
Expand All @@ -22,7 +22,7 @@ void CHIP{{> @partial-block}}Bridge::OnSuccessFn(void * context
{{#if (isStrEqual partial-type "Command")}}
{{#chip_cluster_response_arguments}}, {{asUnderlyingZclType type}} {{asSymbol label}}{{/chip_cluster_response_arguments}}
{{else if (isStrEqual partial-type "List")}}
, const {{zapTypeToDecodableClusterObjectType type ns=parent.name}} & list
, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list
{{else if partial-type}}
, {{asUnderlyingZclType partial-type}} value
{{else}}
Expand Down
Loading

0 comments on commit 73d395f

Please sign in to comment.