Skip to content

Commit e7cdfdb

Browse files
committed
Keep the jclass and the corresponding constructor jmethod inside a
scope block to prevent duplicate declaration error when multiple variables of the same struct type are present.
1 parent bd3d3e1 commit e7cdfdb

File tree

3 files changed

+4844
-4312
lines changed

3 files changed

+4844
-4312
lines changed

src/controller/java/templates/partials/decode_value.zapt

+22-20
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,30 @@ if ({{source}}.IsNull()) {
3131
{{>decode_value target=(concat ../target "_" (asLowerCamelCase label)) source=(concat ../source "." (asLowerCamelCase label)) cluster=../cluster depth=(incrementDepth ../depth) omitDeclaration=false earlyReturn=../earlyReturn}}
3232
{{/zcl_struct_items_by_struct_and_cluster_name}}
3333

34-
jclass {{asLowerCamelCase type}}StructClass_{{depth}};
35-
err = chip::JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}}", {{asLowerCamelCase type}}StructClass_{{depth}});
36-
if (err != CHIP_NO_ERROR) {
37-
ChipLogError(Zcl, "Could not find class ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}}");
38-
return {{earlyReturn}};
39-
}
34+
{
35+
jclass {{asLowerCamelCase type}}StructClass_{{depth}};
36+
err = chip::JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}}", {{asLowerCamelCase type}}StructClass_{{depth}});
37+
if (err != CHIP_NO_ERROR) {
38+
ChipLogError(Zcl, "Could not find class ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}}");
39+
return {{earlyReturn}};
40+
}
4041

41-
jmethodID {{asLowerCamelCase type}}StructCtor_{{depth}};
42-
err = chip::JniReferences::GetInstance().FindMethod(
43-
env, {{asLowerCamelCase type}}StructClass_{{depth}}, "<init>",
44-
"({{#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",
45-
&{{asLowerCamelCase type}}StructCtor_{{depth}});
46-
if (err != CHIP_NO_ERROR || {{asLowerCamelCase type}}StructCtor_{{depth}} == nullptr) {
47-
ChipLogError(Zcl, "Could not find ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}} constructor");
48-
return {{earlyReturn}};
49-
}
42+
jmethodID {{asLowerCamelCase type}}StructCtor_{{depth}};
43+
err = chip::JniReferences::GetInstance().FindMethod(
44+
env, {{asLowerCamelCase type}}StructClass_{{depth}}, "<init>",
45+
"({{#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",
46+
&{{asLowerCamelCase type}}StructCtor_{{depth}});
47+
if (err != CHIP_NO_ERROR || {{asLowerCamelCase type}}StructCtor_{{depth}} == nullptr) {
48+
ChipLogError(Zcl, "Could not find ChipStructs${{asUpperCamelCase cluster}}Cluster{{asUpperCamelCase type}} constructor");
49+
return {{earlyReturn}};
50+
}
5051

51-
{{target}} = env->NewObject({{asLowerCamelCase type}}StructClass_{{depth}}, {{asLowerCamelCase type}}StructCtor_{{depth}}
52-
{{#zcl_struct_items_by_struct_and_cluster_name type cluster}}
53-
, {{../target}}_{{asLowerCamelCase label}}
54-
{{/zcl_struct_items_by_struct_and_cluster_name}}
55-
);
52+
{{target}} = env->NewObject({{asLowerCamelCase type}}StructClass_{{depth}}, {{asLowerCamelCase type}}StructCtor_{{depth}}
53+
{{#zcl_struct_items_by_struct_and_cluster_name type cluster}}
54+
, {{../target}}_{{asLowerCamelCase label}}
55+
{{/zcl_struct_items_by_struct_and_cluster_name}}
56+
);
57+
}
5658
{{else}}
5759
{{#if_is_strongly_typed_chip_enum type}}
5860
std::string {{target}}ClassName = "{{asJniClassName type null (asUpperCamelCase cluster)}}";

0 commit comments

Comments
 (0)