Skip to content

Commit

Permalink
Keep the jclass and the corresponding constructor jmethod inside a
Browse files Browse the repository at this point in the history
scope block to prevent duplicate declaration error when multiple
variables of the same struct type are present.
  • Loading branch information
pidarped committed Oct 5, 2024
1 parent bd3d3e1 commit e7cdfdb
Show file tree
Hide file tree
Showing 3 changed files with 4,844 additions and 4,312 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
Loading

0 comments on commit e7cdfdb

Please sign in to comment.