From d6fbd0a89473d81d67913806e214dfc6e0f6442d Mon Sep 17 00:00:00 2001 From: Bharat Dandu Date: Wed, 22 Mar 2023 11:28:00 -0400 Subject: [PATCH] reverting the changes to the previous commit where vendor_id was treated as an exception in the template. It is now handled through the zap in if_basic_attribute itself Github: ZAP#898 --- .../java/templates/CHIPReadCallbacks-src.zapt | 50 ------------------- .../java/templates/CHIPReadCallbacks.zapt | 26 ---------- .../java/templates/ChipClusters-java.zapt | 34 ------------- .../java/templates/ClusterInfo-java.zapt | 33 ------------ .../ClusterInfo-read-interaction.zapt | 8 --- 5 files changed, 151 deletions(-) diff --git a/src/controller/java/templates/CHIPReadCallbacks-src.zapt b/src/controller/java/templates/CHIPReadCallbacks-src.zapt index f00c4c9b05e5a1..2d1b9deb520827 100644 --- a/src/controller/java/templates/CHIPReadCallbacks-src.zapt +++ b/src/controller/java/templates/CHIPReadCallbacks-src.zapt @@ -92,32 +92,6 @@ void CHIP{{chipCallback.name}}AttributeCallback::CallbackFn(void * context, {{ch {{else}} {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} -CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback(jobject javaCallback, bool keepAlive) : - chip::Callback::Callback(CallbackFn, this), keepAlive(keepAlive) -{ - JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - - javaCallbackRef = env->NewGlobalRef(javaCallback); - if (javaCallbackRef == nullptr) { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - } -} - -CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::~CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback() { - JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not delete global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); -} - {{/if}} {{else}} CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback(jobject javaCallback, bool keepAlive) : chip::Callback::Callback(CallbackFn, this), keepAlive(keepAlive) @@ -172,30 +146,6 @@ void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallb } {{else}} {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::CallbackFn(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} value) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - - VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNI env")); - std::unique_ptr cppCallback(reinterpret_cast(context), maybeDestroy); - - // It's valid for javaCallbackRef to be nullptr if the Java code passed in a null callback. - javaCallbackRef = cppCallback.get()->javaCallbackRef; - VerifyOrReturn(javaCallbackRef != nullptr, ChipLogProgress(Zcl, "Early return from attribute callback since Java callback is null")); - - jmethodID javaMethod; - err = chip::JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "({{#if isArray}}{{else if isStruct}}{{else if isOptional}}Ljava/util/Optional;{{else if (isOctetString type)}}[B{{else if (isCharString type)}}Ljava/lang/String;{{else}}{{asJniSignatureBasic type true}}{{/if}})V", &javaMethod); - VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Could not find onSuccess() method")); - - {{>decode_value source="value" target="javaValue" cluster=(asUpperCamelCase parent.name) depth=0}} - - env->CallVoidMethod(javaCallbackRef, javaMethod, javaValue); - } - {{/if}} {{else}} void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::CallbackFn(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} value) { diff --git a/src/controller/java/templates/CHIPReadCallbacks.zapt b/src/controller/java/templates/CHIPReadCallbacks.zapt index 615d353b68b5f5..3b87cd783f82ee 100644 --- a/src/controller/java/templates/CHIPReadCallbacks.zapt +++ b/src/controller/java/templates/CHIPReadCallbacks.zapt @@ -41,32 +41,6 @@ private: {{#if_unsupported_attribute_callback type isArray ../id}} {{else}} {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} -class CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback : public chip::Callback::Callback -{ -public: - CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback(jobject javaCallback, bool keepAlive = false); - - ~CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback(); - - static void maybeDestroy(CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback * callback) { - if (!callback->keepAlive) { - callback->Cancel(); - chip::Platform::Delete(callback); - } - } - - static void CallbackFn(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} {{#if isArray}}list{{else}}value{{/if}}); - static void OnSubscriptionEstablished(void * context, chip::SubscriptionId subscriptionId) { - CHIP_ERROR err = chip::JniReferences::GetInstance().CallSubscriptionEstablished(reinterpret_cast(context)->javaCallbackRef, subscriptionId); - VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error calling onSubscriptionEstablished: %s", ErrorStr(err))); - }; - -private: - jobject javaCallbackRef; - bool keepAlive; -}; - {{/if}} {{else}} class CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback : public chip::Callback::Callback { diff --git a/src/controller/java/templates/ChipClusters-java.zapt b/src/controller/java/templates/ChipClusters-java.zapt index b58a4da23b46a1..6737840347b615 100644 --- a/src/controller/java/templates/ChipClusters-java.zapt +++ b/src/controller/java/templates/ChipClusters-java.zapt @@ -145,24 +145,6 @@ public class ChipClusters { {{#if_unsupported_attribute_callback type isArray ../id}} {{else}} {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - {{! NOTE: asJavaType ends up sniffing for isArray on the context. Since we want the type of our _entry_, force isArray to - false. }} - {{~#*inline "asJavaTypeForEntry"}}{{asJavaType type null parent.name forceNotList=true}}{{/inline~}} - {{#if isArray}} - public interface {{asUpperCamelCase name}}AttributeCallback { - void onSuccess({{#if isNullable}}@Nullable{{/if}} List<{{>asJavaTypeForEntry isArray=false}}> valueList); - void onError(Exception ex); - default void onSubscriptionEstablished(long subscriptionId) {} - } - {{else}} - public interface {{asUpperCamelCase name}}AttributeCallback { - void onSuccess({{#if isNullable}}@Nullable{{/if}} {{>asJavaTypeForEntry isArray=false}} value); - void onError(Exception ex); - default void onSubscriptionEstablished(long subscriptionId) {} - } - {{/if}} - {{/if}} {{else}} {{! NOTE: asJavaType ends up sniffing for isArray on the context. Since we want the type of our _entry_, force isArray to false. }} @@ -190,11 +172,7 @@ public class ChipClusters { public void read{{asUpperCamelCase name}}Attribute( {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - {{asUpperCamelCase name}}AttributeCallback callback - {{else}} {{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback - {{/if}} {{else}} {{asUpperCamelCase name}}AttributeCallback callback {{/if_basic_attribute}} @@ -215,11 +193,7 @@ public class ChipClusters { {{#if isReportableAttribute}} public void subscribe{{asCamelCased name false}}Attribute( {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - {{asUpperCamelCase name}}AttributeCallback callback - {{else}} {{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback - {{/if}} {{else}} {{asUpperCamelCase name}}AttributeCallback callback {{/if_basic_attribute}}, @@ -236,11 +210,7 @@ public class ChipClusters { private native void read{{asUpperCamelCase name}}Attribute(long chipClusterPtr, {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - {{asUpperCamelCase name}}AttributeCallback callback - {{else}} {{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback - {{/if}} {{else}} {{asUpperCamelCase name}}AttributeCallback callback {{/if_basic_attribute}} @@ -252,11 +222,7 @@ public class ChipClusters { {{#if isReportableAttribute}} private native void subscribe{{asCamelCased name false}}Attribute(long chipClusterPtr, {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - {{asUpperCamelCase name}}AttributeCallback callback - {{else}} {{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback - {{/if}} {{else}} {{asUpperCamelCase name}}AttributeCallback callback {{/if_basic_attribute}}, int minInterval, int maxInterval); diff --git a/src/controller/java/templates/ClusterInfo-java.zapt b/src/controller/java/templates/ClusterInfo-java.zapt index 025523c59577aa..1c18a3923438ca 100644 --- a/src/controller/java/templates/ClusterInfo-java.zapt +++ b/src/controller/java/templates/ClusterInfo-java.zapt @@ -239,39 +239,6 @@ public class ClusterInfoMapping { {{#if_unsupported_attribute_callback type isArray ../id}} {{else}} {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - public static class Delegated{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallback implements ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback, DelegatedClusterCallback { - private ClusterCommandCallback callback; - @Override - public void setCallbackDelegate(ClusterCommandCallback callback) { - this.callback = callback; - } - - {{! NOTE: asJavaType ends up sniffing for isArray on the context. Since we want the type of our _entry_, force isArray to - false. }} - {{~#*inline "asJavaTypeForEntry"}}{{asJavaType type null parent.name forceNotList=true}}{{/inline~}} - @Override - {{#if isArray}} - public void onSuccess({{#if isNullable}}@Nullable{{/if}} List<{{> asJavaTypeForEntry isArray=false}}> valueList) { - Map responseValues = new LinkedHashMap<>(); - CommandResponseInfo commandResponseInfo = new CommandResponseInfo("valueList", "List<{{> asJavaTypeForEntry isArray=false}}>"); - responseValues.put(commandResponseInfo, valueList); - callback.onSuccess(responseValues); - } - {{else}} - public void onSuccess({{#if isNullable}}@Nullable{{/if}} {{>asJavaTypeForEntry isArray=false}} value) { - Map responseValues = new LinkedHashMap<>(); - CommandResponseInfo commandResponseInfo = new CommandResponseInfo("value", "{{> asJavaTypeForEntry isArray=false}}"); - responseValues.put(commandResponseInfo, value); - callback.onSuccess(responseValues); - } - {{/if}} - @Override - public void onError(Exception ex) { - callback.onFailure(ex); - } - } - {{/if}} {{else}} public static class Delegated{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallback implements ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback, DelegatedClusterCallback { private ClusterCommandCallback callback; diff --git a/src/controller/java/templates/ClusterInfo-read-interaction.zapt b/src/controller/java/templates/ClusterInfo-read-interaction.zapt index b60c3dac24d0c3..94710e5ce9d7f3 100644 --- a/src/controller/java/templates/ClusterInfo-read-interaction.zapt +++ b/src/controller/java/templates/ClusterInfo-read-interaction.zapt @@ -24,22 +24,14 @@ public class ClusterReadMapping { (cluster, callback, commandArguments) -> { ((ChipClusters.{{asUpperCamelCase ../name}}Cluster) cluster).read{{asUpperCamelCase name}}Attribute( ({{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback - {{else}} ChipClusters.{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback - {{/if}} {{else}} ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback {{/if_basic_attribute}}) callback ); }, {{#if_basic_attribute type ../id}} - {{#if (is_str_equal 'vendor_id' type)}} - () -> new ClusterInfoMapping.Delegated{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallback(), - {{else}} () -> new ClusterInfoMapping.Delegated{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback(), - {{/if}} {{else}} () -> new ClusterInfoMapping.Delegated{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallback(), {{/if_basic_attribute}}