Skip to content

Commit

Permalink
Account for array/struct in encode_value/decode_value.
Browse files Browse the repository at this point in the history
  • Loading branch information
austinh0 committed Nov 17, 2021
1 parent 22770f7 commit 6bef481
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 71 deletions.
41 changes: 0 additions & 41 deletions src/android/CHIPTool/app/bin/src/main/cpp/native-lib.cpp

This file was deleted.

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 @@ -52,7 +52,7 @@ JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, {{asLowerCamelCase name}})
chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Type request;

{{#chip_cluster_command_arguments}}
{{>encode_value label=(asLowerCamelCase label)}}
{{>encode_value target=(concat "request." (asLowerCamelCase label)) source=(asLowerCamelCase label)}}
{{/chip_cluster_command_arguments}}

{{#*inline "callbackName"}}{{#if hasSpecificResponse}}{{asUpperCamelCase parent.name false}}Cluster{{asUpperCamelCase responseName false}}{{else}}DefaultSuccess{{/if}}{{/inline}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
{{#if isArray}}
// {{asSymbol label}}: {{asUnderlyingZclType type}}
// Conversion from this type to Java is not properly implemented yet
{{else if (isOctetString type)}}
{{#if isOptional}}Optional<{{/if}}byte[]{{#if isOptional}}>{{/if}} {{asSymbol label}}{{#notLastSupportedCommandResponseType parent.arguments}},{{/notLastSupportedCommandResponseType}}
{{else if (isShortString type)}}
{{#if isOptional}}Optional<{{/if}}String{{#if isOptional}}>{{/if}} {{asSymbol label}}{{#notLastSupportedCommandResponseType parent.arguments}},{{/notLastSupportedCommandResponseType}}
{{else}}
{{#if isOptional}}Optional<{{/if}}{{asJavaBasicTypeForZclType type true}}{{#if isOptional}}>{{/if}} {{asSymbol label}}{{#notLastSupportedCommandResponseType parent.arguments}},{{/notLastSupportedCommandResponseType}}
{{else if (isOctetString type)}}
{{#if isOptional}}Optional<{{/if}}byte[]{{#if isOptional}}>{{/if}} {{asSymbol label}}{{#notLastSupportedCommandResponseType parent.arguments}},{{/notLastSupportedCommandResponseType}}
{{else if (isShortString type)}}
{{#if isOptional}}Optional<{{/if}}String{{#if isOptional}}>{{/if}} {{asSymbol label}}{{#notLastSupportedCommandResponseType parent.arguments}},{{/notLastSupportedCommandResponseType}}
{{else}}
{{#if isOptional}}Optional<{{/if}}{{asJavaBasicTypeForZclType type true}}{{#if isOptional}}>{{/if}} {{asSymbol label}}{{#notLastSupportedCommandResponseType parent.arguments}},{{/notLastSupportedCommandResponseType}}
{{/if}}
{{/chip_cluster_response_arguments}}
2 changes: 2 additions & 0 deletions src/controller/java/templates/partials/decode_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if (dataResponse.{{asLowerCamelCase label}}.Value().IsNull()) {
{{~#*inline "item"}}dataResponse.{{asLowerCamelCase name}}{{#if isOptional}}.Value(){{/if}}{{#if isNullable}}.Value(){{/if}}{{/inline}}
{{#if isArray}}
{{asSymbol label}} = nullptr; /* Array - Conversion from this type to Java is not properly implemented yet */
{{else if isStruct}}
{{asSymbol label}} = nullptr; /* Struct - conversion from this type to Java is not properly implemented yet */
{{else if (isOctetString type)}}
{{asSymbol label}} = chip::ByteArray(env, {{>item}}).jniValue();
{{else if (isCharString type)}}
Expand Down
56 changes: 36 additions & 20 deletions src/controller/java/templates/partials/encode_value.zapt
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
{{#if isOptional}}
chip::JniReferences::GetInstance().GetOptionalValue({{label}}, {{label}});
chip::JniReferences::GetInstance().GetOptionalValue({{source}}, {{source}});
{{/if}}
{{#if isNullable}}
{{#if_chip_enum type}}
decltype(request.{{label}}) {{label}}Primitive;
if ({{label}} != nullptr) {
{{label}}Primitive = static_cast<decltype(request.{{label}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{label}}));
decltype({{target}}) {{source}}Value;
if ({{source}} != nullptr) {
{{source}}Value = static_cast<decltype({{target}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}}));
}
{{else}}
{{#if_is_bitmap type}}
decltype(request.{{label}}) {{label}}Primitive;
if ({{label}} != nullptr) {
{{label}}Primitive = static_cast<decltype(request.{{label}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{label}}));
{{#if isArray}}
{{! TODO: Support array types. }}
{{else if isStruct}}
{{! TODO: Support struct types. }}
{{else if (isOctetString type)}}
chip::ByteSpan {{source}}Value;
if ({{source}} != nullptr) {
{{source}}Value = chip::JniByteArray(env, static_cast<jbyteArray>({{source}})).byteSpan();
}
{{else}}
{{chipType}} {{label}}Primitive;
if ({{label}} != nullptr) {
{{label}}Primitive = chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{label}});
{{else if (isCharString type)}}
chip::CharSpan {{source}}Value;
if ({{source}} != nullptr) {
{{source}}Value = chip::JniUtfString(env, static_cast<jstring>({{source}})).charSpan();
}
{{/if_is_bitmap}}
{{else}}
{{#if_is_bitmap type}}
decltype({{target}}) {{source}}Value;
if ({{source}} != nullptr) {
{{source}}Value = static_cast<decltype({{target}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}}));
}
{{else}}
{{chipType}} {{source}}Value;
if ({{source}} != nullptr) {
{{source}}Value = chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}});
}
{{/if_is_bitmap}}
{{/if}}
{{/if_chip_enum}}
{{/if}}
{{#*inline "value"}}
Expand All @@ -28,27 +44,27 @@ chip::JniReferences::GetInstance().GetOptionalValue({{label}}, {{label}});
{{else if isStruct}}
{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}()
{{else if (isOctetString type)}}
chip::JniByteArray(env, static_cast<jbyteArray>({{label}})).byteSpan()
chip::JniByteArray(env, static_cast<jbyteArray>({{source}})).byteSpan()
{{else if (isCharString type)}}
chip::JniUtfString(env, static_cast<jstring>({{label}})).charSpan()
chip::JniUtfString(env, static_cast<jstring>({{source}})).charSpan()
{{else}}
{{#if_chip_enum type}}
static_cast<decltype(request.{{label}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{label}}))
static_cast<decltype({{target}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}}))
{{else}}
{{#if_is_bitmap type}}
static_cast<decltype(request.{{label}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{label}}))
static_cast<decltype({{target}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}}))
{{else}}
static_cast<decltype(request.{{label}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{label}}))
static_cast<decltype({{target}})>(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}}))
{{/if_is_bitmap}}
{{/if_chip_enum}}
{{/if}}
{{/inline}}
request.{{label}} =
{{target}} =
{{#if isOptional}}
{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}(
{{/if}}
{{#if isNullable}}
{{label}} == nullptr ? chip::app::DataModel::Nullable<{{chipType}}>() : chip::app::DataModel::Nullable<{{chipType}}>({{label}}Primitive)
{{source}} == nullptr ? chip::app::DataModel::Nullable<{{chipType}}>() : chip::app::DataModel::Nullable<{{chipType}}>({{source}}Value)
{{else}}
{{! TODO If the inline partial is indented, generation fails with "result.split is not a function". }}
{{>value}}
Expand Down
6 changes: 3 additions & 3 deletions src/controller/java/zap-generated/CHIPClusters-JNI.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6bef481

Please sign in to comment.