Skip to content

Commit

Permalink
Keep the jclass and its corresponding constructor jmethod inside a sc…
Browse files Browse the repository at this point in the history
…ope block.

This is to prevent duplicate declaration error when multiple
variables of the same struct type are present.
  • Loading branch information
pidarped committed Oct 8, 2024
1 parent ea96fc9 commit 3f61ebb
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/controller/java/templates/partials/decode_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,30 @@ if ({{source}}.IsNull()) {
{{>decode_value target=(concat ../target "_" (asLowerCamelCase label)) source=(concat ../source "." (asLowerCamelCase label)) cluster=../cluster depth=(incrementDepth ../depth) omitDeclaration=false earlyReturn=../earlyReturn}}
{{/zcl_struct_items_by_struct_and_cluster_name}}

jclass {{asLowerCamelCase type}}StructClass_{{depth}};
err = chip::JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}}", {{asLowerCamelCase type}}StructClass_{{depth}});
if (err != CHIP_NO_ERROR) {
ChipLogError(Zcl, "Could not find class ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}}");
return {{earlyReturn}};
}
{
jclass {{asLowerCamelCase type}}StructClass_{{depth}};
err = chip::JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}}", {{asLowerCamelCase type}}StructClass_{{depth}});
if (err != CHIP_NO_ERROR) {
ChipLogError(Zcl, "Could not find class ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}}");
return {{earlyReturn}};
}

jmethodID {{asLowerCamelCase type}}StructCtor_{{depth}};
err = chip::JniReferences::GetInstance().FindMethod(
env, {{asLowerCamelCase type}}StructClass_{{depth}}, "<init>",
"({{#zcl_struct_items_by_struct_and_cluster_name type cluster}}{{asJniSignature type null (asUpperCamelCase ../cluster) true}}{{/zcl_struct_items_by_struct_and_cluster_name}})V",
&{{asLowerCamelCase type}}StructCtor_{{depth}});
if (err != CHIP_NO_ERROR || {{asLowerCamelCase type}}StructCtor_{{depth}} == nullptr) {
ChipLogError(Zcl, "Could not find ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}} constructor");
return {{earlyReturn}};
}
jmethodID {{asLowerCamelCase type}}StructCtor_{{depth}};
err = chip::JniReferences::GetInstance().FindMethod(
env, {{asLowerCamelCase type}}StructClass_{{depth}}, "<init>",
"({{#zcl_struct_items_by_struct_and_cluster_name type cluster}}{{asJniSignature type null (asUpperCamelCase ../cluster) true}}{{/zcl_struct_items_by_struct_and_cluster_name}})V",
&{{asLowerCamelCase type}}StructCtor_{{depth}});
if (err != CHIP_NO_ERROR || {{asLowerCamelCase type}}StructCtor_{{depth}} == nullptr) {
ChipLogError(Zcl, "Could not find ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}} constructor");
return {{earlyReturn}};
}

{{target}} = env->NewObject({{asLowerCamelCase type}}StructClass_{{depth}}, {{asLowerCamelCase type}}StructCtor_{{depth}}
{{#zcl_struct_items_by_struct_and_cluster_name type cluster}}
, {{../target}}_{{asLowerCamelCase label}}
{{/zcl_struct_items_by_struct_and_cluster_name}}
);
{{target}} = env->NewObject({{asLowerCamelCase type}}StructClass_{{depth}}, {{asLowerCamelCase type}}StructCtor_{{depth}}
{{#zcl_struct_items_by_struct_and_cluster_name type cluster}}
, {{../target}}_{{asLowerCamelCase label}}
{{/zcl_struct_items_by_struct_and_cluster_name}}
);
}
{{else}}
{{#if_is_strongly_typed_chip_enum type}}
std::string {{target}}ClassName = "{{asJniClassName type null (asUpperCamelCase cluster)}}";
Expand Down

0 comments on commit 3f61ebb

Please sign in to comment.