From 391746833ca24fbd9082325770b07ddbee96c28f Mon Sep 17 00:00:00 2001 From: Austin Hsieh <77706079+austinh0@users.noreply.github.com> Date: Wed, 17 Nov 2021 12:21:01 -0800 Subject: [PATCH] [Android] Use InvokeCommand and support nullable/optional for commands (#11873) * Use InvokeCommand and support nullable/optional for commands. * Regenerate * Restyled by whitespace * Restyled by clang-format * Account for array/struct in encode_value/decode_value. * Add TODO for if_is_struct Co-authored-by: Restyled.io --- src/controller/java/BUILD.gn | 2 + .../java/templates/CHIPCallbackTypes.zapt | 14 + .../java/templates/CHIPClusters-JNI.zapt | 166 +- .../templates/CHIPInvokeCallbacks-src.zapt | 76 + .../java/templates/CHIPInvokeCallbacks.zapt | 29 + .../java/templates/ChipClusters-java.zapt | 60 +- .../java/templates/ClusterInfo-java.zapt | 44 +- src/controller/java/templates/helper.js | 38 +- .../templates/partials/command_arguments.zapt | 13 + .../partials/command_callback_responses.zapt | 19 + .../java/templates/partials/decode_value.zapt | 33 + .../java/templates/partials/encode_value.zapt | 75 + .../list_attribute_callback_type.zapt | 36 + src/controller/java/templates/templates.json | 43 +- .../java/zap-generated/CHIPCallbackTypes.h | 176 + .../java/zap-generated/CHIPClusters-JNI.cpp | 15602 +++++----------- .../zap-generated/CHIPInvokeCallbacks.cpp | 5250 ++++++ .../java/zap-generated/CHIPInvokeCallbacks.h | 1139 ++ .../chip/devicecontroller/ChipClusters.java | 1403 +- .../devicecontroller/ClusterInfoMapping.java | 245 +- src/lib/support/JniReferences.cpp | 57 + src/lib/support/JniReferences.h | 41 +- src/lib/support/JniTypeWrappers.h | 30 +- 23 files changed, 12308 insertions(+), 12283 deletions(-) create mode 100644 src/controller/java/templates/CHIPCallbackTypes.zapt create mode 100644 src/controller/java/templates/CHIPInvokeCallbacks-src.zapt create mode 100644 src/controller/java/templates/CHIPInvokeCallbacks.zapt create mode 100644 src/controller/java/templates/partials/command_arguments.zapt create mode 100644 src/controller/java/templates/partials/command_callback_responses.zapt create mode 100644 src/controller/java/templates/partials/decode_value.zapt create mode 100644 src/controller/java/templates/partials/encode_value.zapt create mode 100644 src/controller/java/templates/partials/list_attribute_callback_type.zapt create mode 100644 src/controller/java/zap-generated/CHIPCallbackTypes.h create mode 100644 src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp create mode 100644 src/controller/java/zap-generated/CHIPInvokeCallbacks.h diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 52e7ac01b344f9..911ebb12ad275c 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -34,6 +34,8 @@ shared_library("jni") { "CHIPDeviceController-JNI.cpp", "zap-generated/CHIPClusters-JNI.cpp", "zap-generated/CHIPClustersRead-JNI.cpp", + "zap-generated/CHIPInvokeCallbacks.cpp", + "zap-generated/CHIPInvokeCallbacks.h", "zap-generated/CHIPReadCallbacks.cpp", "zap-generated/CHIPReadCallbacks.h", ] diff --git a/src/controller/java/templates/CHIPCallbackTypes.zapt b/src/controller/java/templates/CHIPCallbackTypes.zapt new file mode 100644 index 00000000000000..3f4d648f2e102a --- /dev/null +++ b/src/controller/java/templates/CHIPCallbackTypes.zapt @@ -0,0 +1,14 @@ +{{> header}} +{{#if (chip_has_client_clusters)}} +#include +#include + +typedef void (*CHIPDefaultSuccessCallbackType)(void *, const chip::app::DataModel::NullObjectType &); +typedef void (*CHIPDefaultFailureCallbackType)(void *, EmberAfStatus); + +{{#chip_client_clusters}} +{{#chip_cluster_responses}} +typedef void (*CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}CallbackType)(void *, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType &); +{{/chip_cluster_responses}} +{{/chip_client_clusters}} +{{/if}} \ No newline at end of file diff --git a/src/controller/java/templates/CHIPClusters-JNI.zapt b/src/controller/java/templates/CHIPClusters-JNI.zapt index e733901e40a79b..6cd43c136eebca 100644 --- a/src/controller/java/templates/CHIPClusters-JNI.zapt +++ b/src/controller/java/templates/CHIPClusters-JNI.zapt @@ -1,5 +1,7 @@ {{> header}} {{#if (chip_has_client_clusters)}} +#include "CHIPCallbackTypes.h" +#include "CHIPInvokeCallbacks.h" #include "CHIPReadCallbacks.h" #include @@ -8,7 +10,6 @@ #include #include -#include #include #include #include @@ -22,110 +23,6 @@ using namespace chip; using namespace chip::Controller; -{{! TODO(#8773): Clean up callbacks. }} - -{{#chip_client_clusters}} -{{#chip_cluster_responses}} -class CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback : public Callback::Callback<{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback> -{ - public: - CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback(jobject javaCallback): Callback::Callback<{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback>(CallbackFn, this) - { - JNIEnv * env = 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}}Cluster{{asUpperCamelCase name}}Callback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context{{#chip_cluster_response_arguments}}, {{asUnderlyingZclType type}} {{asSymbol label}}{{/chip_cluster_response_arguments}}) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback * cppCallback = nullptr; - {{#chip_cluster_response_arguments}} - {{#if (isOctetString type)}} - jbyteArray {{asSymbol label}}Arr; - {{else if (isShortString type)}} - UtfString {{asSymbol label}}Str(env, {{asSymbol label}}); - {{/if}} - {{/chip_cluster_response_arguments}} - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "({{#chip_cluster_response_arguments}}{{#if isArray}}{{else if (isOctetString type)}}[B{{else if (isShortString type)}}Ljava/lang/String;{{else}}{{asJniSignature type false}}{{/if}}{{/chip_cluster_response_arguments}})V", &javaMethod); - SuccessOrExit(err); - - {{#chip_cluster_response_arguments}} - {{#if (isOctetString type)}} - {{asSymbol label}}Arr = env->NewByteArray({{asSymbol label}}.size()); - VerifyOrExit({{asSymbol label}}Arr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion({{asSymbol label}}Arr, 0, {{asSymbol label}}.size(), reinterpret_cast({{asSymbol label}}.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - {{/if}} - {{/chip_cluster_response_arguments}} - - env->CallVoidMethod(javaCallbackRef, javaMethod - {{#chip_cluster_response_arguments}} - {{#if isArray}} - // {{asSymbol label}}: {{asUnderlyingZclType type}} - // Conversion from this type to Java is not properly implemented yet - {{else if (isOctetString type)}} - , {{asSymbol label}}Arr - {{else if (isShortString type)}} - , {{asSymbol label}}Str.jniValue() - {{else}} - , static_cast<{{asJniBasicTypeForZclType type}}>({{asSymbol label}}) - {{/if}} - {{/chip_cluster_response_arguments}} - ); - - {{#chip_cluster_response_arguments}} - {{#if (isOctetString type)}} - env->DeleteLocalRef({{asSymbol label}}Arr); - {{/if}} - {{/chip_cluster_response_arguments}} - - exit: - if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) { - cppCallback->Cancel(); - delete cppCallback; - } - } - - private: - jobject javaCallbackRef; -}; - -{{/chip_cluster_responses}} -{{/chip_client_clusters}} JNI_METHOD(void, BaseChipCluster, deleteCluster)(JNIEnv * env, jobject self, jlong clusterPtr) { chip::DeviceLayer::StackLock lock; @@ -146,58 +43,37 @@ JNI_METHOD(jlong, {{asUpperCamelCase name}}Cluster, initWithDevice)(JNIEnv * env } {{#chip_cluster_commands}} -JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, {{asLowerCamelCase name}})(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback{{#chip_cluster_command_arguments_with_structs_expanded}}, {{asJniBasicType type false}} {{asLowerCamelCase label}}{{/chip_cluster_command_arguments_with_structs_expanded}}) +JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, {{asLowerCamelCase name}})(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback{{#chip_cluster_command_arguments_with_structs_expanded}}, {{asJniBasicType type true}} {{asLowerCamelCase label}}{{/chip_cluster_command_arguments_with_structs_expanded}}) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; {{asUpperCamelCase ../name}}Cluster * cppCluster; - {{#chip_cluster_command_arguments_with_structs_expanded}} - {{#if (isOctetString type)}} - JniByteArray {{asLowerCamelCase label}}Arr(env, {{asLowerCamelCase label}}); - {{else if (isCharString type)}} - JniUtfString {{asLowerCamelCase label}}Str(env, {{asLowerCamelCase label}}); - {{/if}} - {{/chip_cluster_command_arguments_with_structs_expanded}} + chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Type request; - {{#if hasSpecificResponse}} - std::unique_ptr onSuccess( - Platform::New(callback), Platform::Delete); - {{else}} - std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); - {{/if}} + {{#chip_cluster_command_arguments}} + {{>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}} + + std::unique_ptrcallbackName}}Callback, void (*)(CHIP{{>callbackName}}Callback *)> onSuccess( + Platform::NewcallbackName}}Callback>(callback), Platform::DeletecallbackName}}Callback>); std::unique_ptr onFailure(Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast<{{asUpperCamelCase ../name}}Cluster *>(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - - err = cppCluster->{{asCamelCased name false}}(onSuccess->Cancel(), onFailure->Cancel() - {{#chip_cluster_command_arguments_with_structs_expanded}}, {{#if_chip_enum type}}static_cast<{{chipType}}>({{asLowerCamelCase label}}){{else if (isOctetString type)}}{{asUnderlyingZclType type}}((const uint8_t*) {{asLowerCamelCase label}}Arr.data(), {{asLowerCamelCase label}}Arr.size()){{else if (isCharString type)}}chip::CharSpan({{asLowerCamelCase label}}Str.c_str(), strlen({{asLowerCamelCase label}}Str.c_str())){{else}}{{asLowerCamelCase label}}{{/if_chip_enum}}{{/chip_cluster_command_arguments_with_structs_expanded}}); - SuccessOrExit(err); + VerifyOrReturn(cppCluster != nullptr, AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); -exit: - if (err != CHIP_NO_ERROR) { - jthrowable exception; - jmethodID method; + auto successFn = chip::Callback::CallbackcallbackName}}CallbackType>::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", CHIP_ERROR_INCORRECT_STATE)); - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, exception); - if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } else { - onSuccess.release(); - onFailure.release(); - } + onSuccess.release(); + onFailure.release(); } {{/chip_cluster_commands}} {{#chip_server_cluster_attributes}} diff --git a/src/controller/java/templates/CHIPInvokeCallbacks-src.zapt b/src/controller/java/templates/CHIPInvokeCallbacks-src.zapt new file mode 100644 index 00000000000000..c079b4fa1a8e45 --- /dev/null +++ b/src/controller/java/templates/CHIPInvokeCallbacks-src.zapt @@ -0,0 +1,76 @@ +{{> header}} +{{#if (chip_has_client_clusters)}} +#include "CHIPCallbackTypes.h" +#include "CHIPInvokeCallbacks.h" + +#include +#include +#include +#include +#include +#include +#include + +{{! TODO(#8773): Clean up callbacks. }} + +namespace chip { + +{{#chip_client_clusters}} +{{#chip_cluster_responses}} +CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback::CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback(jobject javaCallback): Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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}}Cluster{{asUpperCamelCase name}}Callback::~CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback::CallbackFn(void * context, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete + ); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "({{#chip_cluster_response_arguments}}{{#if isArray}}{{else if isOptional}}Ljava/util/Optional;{{else if (isOctetString type)}}[B{{else if (isShortString type)}}Ljava/lang/String;{{else}}{{asJniSignature type true}}{{/if}}{{/chip_cluster_response_arguments}})V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + {{#chip_cluster_response_arguments}} + {{>decode_value}} + {{/chip_cluster_response_arguments}} + + env->CallVoidMethod(javaCallbackRef, javaMethod{{#chip_cluster_response_arguments}}, {{asSymbol label}}{{/chip_cluster_response_arguments}}); +} +{{/chip_cluster_responses}} +{{/chip_client_clusters}} +} // namespace chip +{{/if}} \ No newline at end of file diff --git a/src/controller/java/templates/CHIPInvokeCallbacks.zapt b/src/controller/java/templates/CHIPInvokeCallbacks.zapt new file mode 100644 index 00000000000000..a89db3856a66f9 --- /dev/null +++ b/src/controller/java/templates/CHIPInvokeCallbacks.zapt @@ -0,0 +1,29 @@ +{{> header}} +{{#if (chip_has_client_clusters)}} +#include "CHIPCallbackTypes.h" + +#include +#include +#include + +namespace chip { + +{{#chip_client_clusters}} +{{#chip_cluster_responses}} +class CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback : public Callback::Callback +{ +public: + CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback(jobject javaCallback); + + ~CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}Callback(); + + static void CallbackFn(void * context, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +{{/chip_cluster_responses}} +{{/chip_client_clusters}} +} // namespace chip +{{/if}} \ No newline at end of file diff --git a/src/controller/java/templates/ChipClusters-java.zapt b/src/controller/java/templates/ChipClusters-java.zapt index db9d6f57e783d8..caa278adedb25e 100644 --- a/src/controller/java/templates/ChipClusters-java.zapt +++ b/src/controller/java/templates/ChipClusters-java.zapt @@ -4,8 +4,8 @@ package chip.devicecontroller; import androidx.annotation.Nullable; -import java.util.List; import java.util.Arrays; +import java.util.List; import java.util.Optional; public class ChipClusters { @@ -78,30 +78,17 @@ public class ChipClusters { public native long initWithDevice(long devicePtr, int endpointId); {{#chip_cluster_commands}} - public void {{asLowerCamelCase name}}({{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback{{#chip_cluster_command_arguments_with_structs_expanded}}, {{asJavaBasicType type}} {{asLowerCamelCase label}}{{/chip_cluster_command_arguments_with_structs_expanded}}) { + public void {{asLowerCamelCase name}}({{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback{{>command_arguments}}) { {{asLowerCamelCase name}}(chipClusterPtr, callback{{#chip_cluster_command_arguments_with_structs_expanded}}, {{asLowerCamelCase label}}{{/chip_cluster_command_arguments_with_structs_expanded}}); } {{/chip_cluster_commands}} {{#chip_cluster_commands}} - private native void {{asLowerCamelCase name}}(long chipClusterPtr, {{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback{{#chip_cluster_command_arguments_with_structs_expanded}}, {{asJavaBasicType type}} {{asLowerCamelCase label}}{{/chip_cluster_command_arguments_with_structs_expanded}}); + private native void {{asLowerCamelCase name}}(long chipClusterPtr, {{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback{{>command_arguments}}); {{/chip_cluster_commands}} {{#chip_cluster_responses}} public interface {{asUpperCamelCase name}}Callback { - void onSuccess( -{{#chip_cluster_response_arguments}} -{{#if isArray}} - // {{asSymbol label}}: {{asUnderlyingZclType type}} - // Conversion from this type to Java is not properly implemented yet -{{else if (isOctetString type)}} - {{omitCommaForFirstNonStatusCommand parent.id index}}byte[] {{asSymbol label}} -{{else if (isShortString type)}} - {{omitCommaForFirstNonStatusCommand parent.id index}}String {{asSymbol label}} -{{else}} - {{omitCommaForFirstNonStatusCommand parent.id index}}{{asJavaBasicTypeForZclType type false}} {{asSymbol label}} -{{/if}} -{{/chip_cluster_response_arguments}} - ); + void onSuccess({{>command_callback_responses parent=..}}); void onError(Exception error); } @@ -200,44 +187,7 @@ public class ChipClusters { {{/if}} public interface {{asUpperCamelCase name}}AttributeCallback { - void onSuccess(List< - {{#if isStruct}} - {{asUpperCamelCase name}}Attribute - {{else}} - {{#if isNullable}} - {{#unless isArray}} - {{#unless isStruct}} - @Nullable - {{/unless}} - {{/unless}} - {{/if}} - {{#if isOptional}} - {{#unless isArray}} - {{#unless isStruct}} - Optional< - {{/unless}} - {{/unless}} - {{/if}} - {{#if (isOctetString type)}} - byte[] - {{else if (isCharString type)}} - // Add String field here after ByteSpan is properly emitted in C++ layer - {{else}} - {{! NOTE: asJavaBasicTypeForZclType ends up sniffing for isArray on the - context. Since we want the type of our _entry_, force isArray to - false. }} - {{~#*inline "asJavaBasicTypeForEntry"}}{{asJavaBasicTypeForZclType type true}}{{/inline~}} - {{> asJavaBasicTypeForEntry isArray=false}} - {{/if}} - {{#if isOptional}} - {{#unless isArray}} - {{#unless isStruct}} - > - {{/unless}} - {{/unless}} - {{/if}} - {{/if}} - > valueList); + void onSuccess(List<{{#>list_attribute_callback_type}}{{/list_attribute_callback_type}}> valueList); void onError(Exception ex); } {{/if}} diff --git a/src/controller/java/templates/ClusterInfo-java.zapt b/src/controller/java/templates/ClusterInfo-java.zapt index 05ea012ce6985c..7a44283ef52afa 100644 --- a/src/controller/java/templates/ClusterInfo-java.zapt +++ b/src/controller/java/templates/ClusterInfo-java.zapt @@ -4,10 +4,11 @@ package chip.devicecontroller; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; -import java.util.Map; import java.util.List; -import java.util.HashMap; +import java.util.Map; +import java.util.Optional; import chip.clusterinfo.ClusterInfo; import chip.clusterinfo.InteractionInfo; import chip.clusterinfo.CommandParameterInfo; @@ -162,20 +163,7 @@ public class ClusterInfoMapping { } @Override - public void onSuccess( - {{#chip_cluster_response_arguments}} - {{#if isArray}} - // {{asSymbol label}}: {{asUnderlyingZclType type}} - // Conversion from this type to Java is not properly implemented yet - {{else if (isOctetString type)}} - {{omitCommaForFirstNonStatusCommand parent.id index}}byte[] {{asSymbol label}} - {{else if (isShortString type)}} - {{omitCommaForFirstNonStatusCommand parent.id index}}String {{asSymbol label}} - {{else}} - {{omitCommaForFirstNonStatusCommand parent.id index}}{{asJavaBasicTypeForZclType type false}} {{asSymbol label}} - {{/if}} - {{/chip_cluster_response_arguments}} - ) { + public void onSuccess({{>command_callback_responses parent=..}}) { Map responseValues = new LinkedHashMap<>(); {{#chip_cluster_response_arguments}} {{#if isArray}} @@ -209,24 +197,7 @@ public class ClusterInfoMapping { this.callback = callback; } @Override - public void onSuccess(List< - {{#if isStruct}} - ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}Attribute - {{else}} - {{#if (isOctetString type)}} - byte[] - {{else if (isCharString type)}} - // Add String field here after ByteSpan is properly emitted in C++ layer - {{else}} - {{! NOTE: asJavaBasicTypeForZclType does not handle isArray well, so - add an inline partial to force isArray to false when we want the - types of list entries. }} - {{~#*inline "asBoxedJavaBasicType"}}{{asJavaBasicTypeForZclType type true}}{{/inline~}} - {{~#*inline "asBoxedJavaBasicTypeForEntry"}}{{> asBoxedJavaBasicType isArray=false}}{{/inline~}} - {{> asBoxedJavaBasicTypeForEntry}} - {{/if}} - {{/if}} - > valueList) { + public void onSuccess(List<{{#>list_attribute_callback_type}}ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{/list_attribute_callback_type}}> valueList) { Map responseValues = new LinkedHashMap<>(); {{#if isStruct}} CommandResponseInfo commandResponseInfo = new CommandResponseInfo("valueList", "List"); @@ -285,6 +256,7 @@ public class ClusterInfoMapping { {{/chip_client_clusters}} } + @SuppressWarnings("unchecked") public Map> getCommandMap() { Map> commandMap = new HashMap<>(); {{#chip_client_clusters}} @@ -307,7 +279,7 @@ public class ClusterInfoMapping { ((ChipClusters.{{asUpperCamelCase ../name}}Cluster) cluster) .{{asLowerCamelCase name}}((ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase responseName}}Callback) callback {{#chip_cluster_command_arguments_with_structs_expanded}}, - ({{asJavaBoxedType type}}) + ({{#if isOptional}}Optional<{{/if}}{{asJavaBoxedType type}}{{#if isOptional}}>{{/if}}) commandArguments.get("{{asLowerCamelCase label}}") {{/chip_cluster_command_arguments_with_structs_expanded}} ); @@ -321,7 +293,7 @@ public class ClusterInfoMapping { ((ChipClusters.{{asUpperCamelCase ../name}}Cluster) cluster) .{{asLowerCamelCase name}}((DefaultClusterCallback) callback {{#chip_cluster_command_arguments_with_structs_expanded}}, - ({{asJavaBoxedType type}}) + ({{#if isOptional}}Optional<{{/if}}{{asJavaBoxedType type}}{{#if isOptional}}>{{/if}}) commandArguments.get("{{asLowerCamelCase label}}") {{/chip_cluster_command_arguments_with_structs_expanded}} ); diff --git a/src/controller/java/templates/helper.js b/src/controller/java/templates/helper.js index e8bb5d7434f689..e878e0f8eda196 100644 --- a/src/controller/java/templates/helper.js +++ b/src/controller/java/templates/helper.js @@ -101,7 +101,9 @@ function asJavaBoxedType(type) function asJniBasicType(type, useBoxedTypes) { - if (StringHelper.isOctetString(type)) { + if (this.isOptional) { + return 'jobject'; + } else if (StringHelper.isOctetString(type)) { return 'jbyteArray'; } else if (StringHelper.isCharString(type)) { return 'jstring'; @@ -221,28 +223,20 @@ function notLastSupportedEntryTypes(context, options) } } -function omitCommaForFirstNonStatusCommand(id, index) +function notLastSupportedCommandResponseType(items, options) { - let promise = templateUtil.ensureZclPackageId(this) - .then((pkgId) => { return queryCommand.selectCommandArgumentsByCommandId(this.global.db, id, pkgId) }) - .catch(err => { - console.log(err); - throw err; - }) - .then((result) => { - // Currently, we omit array types, so don't count it as a valid non-status command. - let firstNonStatusCommandIndex = result.findIndex((command) => !command.isArray); - if (firstNonStatusCommandIndex == -1 || firstNonStatusCommandIndex != index) { - return ", "; - } - return ""; - }) - .catch(err => { - console.log(err); - throw err; - }); + if (items.length == 0) { + return + } - return templateUtil.templatePromise(this.global, promise); + let lastIndex = items.length - 1; + while (items[lastIndex].isArray) { + lastIndex--; + } + + if (this.index != lastIndex) { + return options.fn(this); + } } // @@ -258,5 +252,5 @@ exports.convertBasicCTypeToJniType = convertBasicCTypeToJniType; exports.convertCTypeToJniSignature = convertCTypeToJniSignature; exports.convertBasicCTypeToJavaBoxedType = convertBasicCTypeToJavaBoxedType; exports.convertAttributeCallbackTypeToJavaName = convertAttributeCallbackTypeToJavaName; -exports.omitCommaForFirstNonStatusCommand = omitCommaForFirstNonStatusCommand; exports.notLastSupportedEntryTypes = notLastSupportedEntryTypes; +exports.notLastSupportedCommandResponseType = notLastSupportedCommandResponseType; diff --git a/src/controller/java/templates/partials/command_arguments.zapt b/src/controller/java/templates/partials/command_arguments.zapt new file mode 100644 index 00000000000000..b534c0d285d26b --- /dev/null +++ b/src/controller/java/templates/partials/command_arguments.zapt @@ -0,0 +1,13 @@ +{{#chip_cluster_command_arguments_with_structs_expanded}} +, +{{#if isOptional}} +Optional< +{{else if isNullable}} +@Nullable +{{/if}} +{{asJavaBoxedType type}} +{{#if isOptional}} +> +{{/if}} +{{asLowerCamelCase label}} +{{/chip_cluster_command_arguments_with_structs_expanded}} \ No newline at end of file diff --git a/src/controller/java/templates/partials/command_callback_responses.zapt b/src/controller/java/templates/partials/command_callback_responses.zapt new file mode 100644 index 00000000000000..42ddde1188a644 --- /dev/null +++ b/src/controller/java/templates/partials/command_callback_responses.zapt @@ -0,0 +1,19 @@ +{{#chip_cluster_response_arguments}} +{{#if isNullable}} + {{#unless isArray}} + {{#unless isOptional}} + @Nullable + {{/unless}} + {{/unless}} +{{/if}} +{{#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}} +{{/if}} +{{/chip_cluster_response_arguments}} \ No newline at end of file diff --git a/src/controller/java/templates/partials/decode_value.zapt b/src/controller/java/templates/partials/decode_value.zapt new file mode 100644 index 00000000000000..954f08244e895e --- /dev/null +++ b/src/controller/java/templates/partials/decode_value.zapt @@ -0,0 +1,33 @@ +jobject {{asSymbol label}}; +{{#if isOptional}} +if (!dataResponse.{{asLowerCamelCase label}}.HasValue()) { + chip::JniReferences::GetInstance().CreateOptional(nullptr, {{asSymbol label}}); +} else { +{{#if isNullable}} +if (dataResponse.{{asLowerCamelCase label}}.Value().IsNull()) { + chip::JniReferences::GetInstance().CreateOptional(nullptr, {{asSymbol label}}); +} else { +{{/if}} +{{/if}} +{{~#*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 */ +{{! TODO: Use if_is_struct, which works better for nested types. Currently can't because inline partials aren't found in its else block. }} +{{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)}} +{{asSymbol label}} = chip::UtfString(env, {{>item}}).jniValue(); +{{else}} +std::string {{asSymbol label}}ClassName = "java/lang/{{asJavaBasicTypeForZclType type true}}"; +std::string {{asSymbol label}}CtorSignature = "({{asJniSignature type false}})V"; +chip::JniReferences::GetInstance().CreateBoxedObject<{{chipType}}>({{asSymbol label}}ClassName.c_str(), {{asSymbol label}}CtorSignature.c_str(), {{>item}}, {{asSymbol label}}); +{{/if}} +{{#if isOptional}} +chip::JniReferences::GetInstance().CreateOptional({{asSymbol label}}, {{asSymbol label}}); +{{#if isNullable}} +} +{{/if}} +} +{{/if}} \ No newline at end of file diff --git a/src/controller/java/templates/partials/encode_value.zapt b/src/controller/java/templates/partials/encode_value.zapt new file mode 100644 index 00000000000000..8cf48d1d44cdf7 --- /dev/null +++ b/src/controller/java/templates/partials/encode_value.zapt @@ -0,0 +1,75 @@ +{{#if isOptional}} +chip::JniReferences::GetInstance().GetOptionalValue({{source}}, {{source}}); +{{/if}} +{{#if isNullable}} + {{#if_chip_enum type}} + decltype({{target}}) {{source}}Value; + if ({{source}} != nullptr) { + {{source}}Value = static_cast(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}})); + } + {{else}} + {{#if isArray}} + {{! TODO: Support array types. }} + {{else if isStruct}} + {{! TODO: Use if_is_struct, which works better for nested types. Currently can't because inline partials aren't found in its else block. }} + {{! TODO: Support struct types. }} + {{else if (isOctetString type)}} + chip::ByteSpan {{source}}Value; + if ({{source}} != nullptr) { + {{source}}Value = chip::JniByteArray(env, static_cast({{source}})).byteSpan(); + } + {{else if (isCharString type)}} + chip::CharSpan {{source}}Value; + if ({{source}} != nullptr) { + {{source}}Value = chip::JniUtfString(env, static_cast({{source}})).charSpan(); + } + {{else}} + {{#if_is_bitmap type}} + decltype({{target}}) {{source}}Value; + if ({{source}} != nullptr) { + {{source}}Value = static_cast(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"}} +{{! TODO Implement complex types parsing in order to properly set the request parameters }} +{{#if isArray}} +{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}() +{{else if isStruct}} +{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}() +{{else if (isOctetString type)}} +chip::JniByteArray(env, static_cast({{source}})).byteSpan() +{{else if (isCharString type)}} +chip::JniUtfString(env, static_cast({{source}})).charSpan() +{{else}} + {{#if_chip_enum type}} + static_cast(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}})) + {{else}} + {{#if_is_bitmap type}} + static_cast(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}})) + {{else}} + static_cast(chip::JniReferences::GetInstance().{{asJavaBoxedType type}}ToPrimitive({{source}})) + {{/if_is_bitmap}} + {{/if_chip_enum}} +{{/if}} +{{/inline}} +{{target}} = +{{#if isOptional}} +{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}( +{{/if}} +{{#if isNullable}} + {{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}} +{{/if}} +{{#if isOptional}} +) +{{/if}}; diff --git a/src/controller/java/templates/partials/list_attribute_callback_type.zapt b/src/controller/java/templates/partials/list_attribute_callback_type.zapt new file mode 100644 index 00000000000000..b74884de17986b --- /dev/null +++ b/src/controller/java/templates/partials/list_attribute_callback_type.zapt @@ -0,0 +1,36 @@ +{{#if isStruct}} +{{> @partial-block }}{{asUpperCamelCase name}}Attribute +{{else}} + {{#if isNullable}} + {{#unless isArray}} + {{#unless isStruct}} + @Nullable + {{/unless}} + {{/unless}} + {{/if}} + {{#if isOptional}} + {{#unless isArray}} + {{#unless isStruct}} + Optional< + {{/unless}} + {{/unless}} + {{/if}} + {{#if (isOctetString type)}} + byte[] + {{else if (isCharString type)}} + // Add String field here after ByteSpan is properly emitted in C++ layer + {{else}} + {{! NOTE: asJavaBasicTypeForZclType ends up sniffing for isArray on the + context. Since we want the type of our _entry_, force isArray to + false. }} + {{~#*inline "asJavaBasicTypeForEntry"}}{{asJavaBasicTypeForZclType type true}}{{/inline~}} + {{> asJavaBasicTypeForEntry isArray=false}} + {{/if}} + {{#if isOptional}} + {{#unless isArray}} + {{#unless isStruct}} + > + {{/unless}} + {{/unless}} + {{/if}} +{{/if}} \ No newline at end of file diff --git a/src/controller/java/templates/templates.json b/src/controller/java/templates/templates.json index c0fa30fabdb32a..590f9a74447f35 100644 --- a/src/controller/java/templates/templates.json +++ b/src/controller/java/templates/templates.json @@ -23,9 +23,44 @@ { "name": "cluster_header", "path": "../../../app/zap-templates/partials/cluster_header.zapt" + }, + { + "name": "encode_value", + "path": "partials/encode_value.zapt" + }, + { + "name": "decode_value", + "path": "partials/decode_value.zapt" + }, + { + "name": "list_attribute_callback_type", + "path": "partials/list_attribute_callback_type.zapt" + }, + { + "name": "command_callback_responses", + "path": "partials/command_callback_responses.zapt" + }, + { + "name": "command_arguments", + "path": "partials/command_arguments.zapt" } ], "templates": [ + { + "path": "CHIPInvokeCallbacks.zapt", + "name": "CHIP cluster invoke callbacks for Java (native code)", + "output": "src/controller/java/zap-generated/CHIPInvokeCallbacks.h" + }, + { + "path": "CHIPInvokeCallbacks-src.zapt", + "name": "CHIP cluster invoke callbacks for Java (native code)", + "output": "src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp" + }, + { + "path": "CHIPCallbackTypes.zapt", + "name": "CHIP cluster callback types", + "output": "src/controller/java/zap-generated/CHIPCallbackTypes.h" + }, { "path": "CHIPClusters-JNI.zapt", "name": "CHIP ZCL API for Java (native code)", @@ -37,14 +72,14 @@ "output": "src/controller/java/zap-generated/CHIPClustersRead-JNI.cpp" }, { - "path": "CHIPReadCallbacks-src.zapt", + "path": "CHIPReadCallbacks.zapt", "name": "CHIP cluster attribute read callback for Java (native code)", - "output": "src/controller/java/zap-generated/CHIPReadCallbacks.cpp" + "output": "src/controller/java/zap-generated/CHIPReadCallbacks.h" }, { - "path": "CHIPReadCallbacks.zapt", + "path": "CHIPReadCallbacks-src.zapt", "name": "CHIP cluster attribute read callback for Java (native code)", - "output": "src/controller/java/zap-generated/CHIPReadCallbacks.h" + "output": "src/controller/java/zap-generated/CHIPReadCallbacks.cpp" }, { "path": "ChipClusters-java.zapt", diff --git a/src/controller/java/zap-generated/CHIPCallbackTypes.h b/src/controller/java/zap-generated/CHIPCallbackTypes.h new file mode 100644 index 00000000000000..feeaa68e68cc35 --- /dev/null +++ b/src/controller/java/zap-generated/CHIPCallbackTypes.h @@ -0,0 +1,176 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// THIS FILE IS GENERATED BY ZAP +#include +#include + +typedef void (*CHIPDefaultSuccessCallbackType)(void *, const chip::app::DataModel::NullObjectType &); +typedef void (*CHIPDefaultFailureCallbackType)(void *, EmberAfStatus); + +typedef void (*CHIPAccountLoginClusterGetSetupPINResponseCallbackType)( + void *, const chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::DecodableType &); +typedef void (*CHIPApplicationLauncherClusterLaunchAppResponseCallbackType)( + void *, const chip::app::Clusters::ApplicationLauncher::Commands::LaunchAppResponse::DecodableType &); +typedef void (*CHIPContentLauncherClusterLaunchContentResponseCallbackType)( + void *, const chip::app::Clusters::ContentLauncher::Commands::LaunchContentResponse::DecodableType &); +typedef void (*CHIPContentLauncherClusterLaunchURLResponseCallbackType)( + void *, const chip::app::Clusters::ContentLauncher::Commands::LaunchURLResponse::DecodableType &); +typedef void (*CHIPDiagnosticLogsClusterRetrieveLogsResponseCallbackType)( + void *, const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterClearAllPinsResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::ClearAllPinsResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterClearAllRfidsResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::ClearAllRfidsResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterClearHolidayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::ClearHolidayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterClearPinResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::ClearPinResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterClearRfidResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::ClearRfidResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterClearWeekdayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::ClearWeekdayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterClearYeardayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::ClearYeardayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterGetHolidayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::GetHolidayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterGetLogRecordResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::GetLogRecordResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterGetPinResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::GetPinResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterGetRfidResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::GetRfidResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterGetUserTypeResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::GetUserTypeResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterGetWeekdayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::GetWeekdayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterGetYeardayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::GetYeardayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterLockDoorResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::LockDoorResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterSetHolidayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::SetHolidayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterSetPinResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::SetPinResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterSetRfidResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::SetRfidResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterSetUserTypeResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::SetUserTypeResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterSetWeekdayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::SetWeekdayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterSetYeardayScheduleResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::SetYeardayScheduleResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterUnlockDoorResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::UnlockDoorResponse::DecodableType &); +typedef void (*CHIPDoorLockClusterUnlockWithTimeoutResponseCallbackType)( + void *, const chip::app::Clusters::DoorLock::Commands::UnlockWithTimeoutResponse::DecodableType &); +typedef void (*CHIPGeneralCommissioningClusterArmFailSafeResponseCallbackType)( + void *, const chip::app::Clusters::GeneralCommissioning::Commands::ArmFailSafeResponse::DecodableType &); +typedef void (*CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallbackType)( + void *, const chip::app::Clusters::GeneralCommissioning::Commands::CommissioningCompleteResponse::DecodableType &); +typedef void (*CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallbackType)( + void *, const chip::app::Clusters::GeneralCommissioning::Commands::SetRegulatoryConfigResponse::DecodableType &); +typedef void (*CHIPGroupsClusterAddGroupResponseCallbackType)( + void *, const chip::app::Clusters::Groups::Commands::AddGroupResponse::DecodableType &); +typedef void (*CHIPGroupsClusterGetGroupMembershipResponseCallbackType)( + void *, const chip::app::Clusters::Groups::Commands::GetGroupMembershipResponse::DecodableType &); +typedef void (*CHIPGroupsClusterRemoveGroupResponseCallbackType)( + void *, const chip::app::Clusters::Groups::Commands::RemoveGroupResponse::DecodableType &); +typedef void (*CHIPGroupsClusterViewGroupResponseCallbackType)( + void *, const chip::app::Clusters::Groups::Commands::ViewGroupResponse::DecodableType &); +typedef void (*CHIPIdentifyClusterIdentifyQueryResponseCallbackType)( + void *, const chip::app::Clusters::Identify::Commands::IdentifyQueryResponse::DecodableType &); +typedef void (*CHIPKeypadInputClusterSendKeyResponseCallbackType)( + void *, const chip::app::Clusters::KeypadInput::Commands::SendKeyResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaFastForwardResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaFastForwardResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaNextResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaNextResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaPauseResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaPauseResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaPlayResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaPlayResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaPreviousResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaPreviousResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaRewindResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaRewindResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaSeekResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaSeekResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaSkipBackwardResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaSkipForwardResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaSkipForwardResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaStartOverResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaStartOverResponse::DecodableType &); +typedef void (*CHIPMediaPlaybackClusterMediaStopResponseCallbackType)( + void *, const chip::app::Clusters::MediaPlayback::Commands::MediaStopResponse::DecodableType &); +typedef void (*CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallbackType)( + void *, const chip::app::Clusters::NetworkCommissioning::Commands::AddThreadNetworkResponse::DecodableType &); +typedef void (*CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallbackType)( + void *, const chip::app::Clusters::NetworkCommissioning::Commands::AddWiFiNetworkResponse::DecodableType &); +typedef void (*CHIPNetworkCommissioningClusterDisableNetworkResponseCallbackType)( + void *, const chip::app::Clusters::NetworkCommissioning::Commands::DisableNetworkResponse::DecodableType &); +typedef void (*CHIPNetworkCommissioningClusterEnableNetworkResponseCallbackType)( + void *, const chip::app::Clusters::NetworkCommissioning::Commands::EnableNetworkResponse::DecodableType &); +typedef void (*CHIPNetworkCommissioningClusterRemoveNetworkResponseCallbackType)( + void *, const chip::app::Clusters::NetworkCommissioning::Commands::RemoveNetworkResponse::DecodableType &); +typedef void (*CHIPNetworkCommissioningClusterScanNetworksResponseCallbackType)( + void *, const chip::app::Clusters::NetworkCommissioning::Commands::ScanNetworksResponse::DecodableType &); +typedef void (*CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallbackType)( + void *, const chip::app::Clusters::NetworkCommissioning::Commands::UpdateThreadNetworkResponse::DecodableType &); +typedef void (*CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallbackType)( + void *, const chip::app::Clusters::NetworkCommissioning::Commands::UpdateWiFiNetworkResponse::DecodableType &); +typedef void (*CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallbackType)( + void *, const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateResponse::DecodableType &); +typedef void (*CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallbackType)( + void *, const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::DecodableType &); +typedef void (*CHIPOperationalCredentialsClusterAttestationResponseCallbackType)( + void *, const chip::app::Clusters::OperationalCredentials::Commands::AttestationResponse::DecodableType &); +typedef void (*CHIPOperationalCredentialsClusterCertificateChainResponseCallbackType)( + void *, const chip::app::Clusters::OperationalCredentials::Commands::CertificateChainResponse::DecodableType &); +typedef void (*CHIPOperationalCredentialsClusterNOCResponseCallbackType)( + void *, const chip::app::Clusters::OperationalCredentials::Commands::NOCResponse::DecodableType &); +typedef void (*CHIPOperationalCredentialsClusterOpCSRResponseCallbackType)( + void *, const chip::app::Clusters::OperationalCredentials::Commands::OpCSRResponse::DecodableType &); +typedef void (*CHIPScenesClusterAddSceneResponseCallbackType)( + void *, const chip::app::Clusters::Scenes::Commands::AddSceneResponse::DecodableType &); +typedef void (*CHIPScenesClusterGetSceneMembershipResponseCallbackType)( + void *, const chip::app::Clusters::Scenes::Commands::GetSceneMembershipResponse::DecodableType &); +typedef void (*CHIPScenesClusterRemoveAllScenesResponseCallbackType)( + void *, const chip::app::Clusters::Scenes::Commands::RemoveAllScenesResponse::DecodableType &); +typedef void (*CHIPScenesClusterRemoveSceneResponseCallbackType)( + void *, const chip::app::Clusters::Scenes::Commands::RemoveSceneResponse::DecodableType &); +typedef void (*CHIPScenesClusterStoreSceneResponseCallbackType)( + void *, const chip::app::Clusters::Scenes::Commands::StoreSceneResponse::DecodableType &); +typedef void (*CHIPScenesClusterViewSceneResponseCallbackType)( + void *, const chip::app::Clusters::Scenes::Commands::ViewSceneResponse::DecodableType &); +typedef void (*CHIPTvChannelClusterChangeChannelResponseCallbackType)( + void *, const chip::app::Clusters::TvChannel::Commands::ChangeChannelResponse::DecodableType &); +typedef void (*CHIPTargetNavigatorClusterNavigateTargetResponseCallbackType)( + void *, const chip::app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::DecodableType &); +typedef void (*CHIPTestClusterClusterBooleanResponseCallbackType)( + void *, const chip::app::Clusters::TestCluster::Commands::BooleanResponse::DecodableType &); +typedef void (*CHIPTestClusterClusterTestAddArgumentsResponseCallbackType)( + void *, const chip::app::Clusters::TestCluster::Commands::TestAddArgumentsResponse::DecodableType &); +typedef void (*CHIPTestClusterClusterTestEnumsResponseCallbackType)( + void *, const chip::app::Clusters::TestCluster::Commands::TestEnumsResponse::DecodableType &); +typedef void (*CHIPTestClusterClusterTestListInt8UReverseResponseCallbackType)( + void *, const chip::app::Clusters::TestCluster::Commands::TestListInt8UReverseResponse::DecodableType &); +typedef void (*CHIPTestClusterClusterTestNullableOptionalResponseCallbackType)( + void *, const chip::app::Clusters::TestCluster::Commands::TestNullableOptionalResponse::DecodableType &); +typedef void (*CHIPTestClusterClusterTestSpecificResponseCallbackType)( + void *, const chip::app::Clusters::TestCluster::Commands::TestSpecificResponse::DecodableType &); diff --git a/src/controller/java/zap-generated/CHIPClusters-JNI.cpp b/src/controller/java/zap-generated/CHIPClusters-JNI.cpp index d864242bd2721e..672be94172bf6b 100644 --- a/src/controller/java/zap-generated/CHIPClusters-JNI.cpp +++ b/src/controller/java/zap-generated/CHIPClusters-JNI.cpp @@ -16,6 +16,8 @@ */ // THIS FILE IS GENERATED BY ZAP +#include "CHIPCallbackTypes.h" +#include "CHIPInvokeCallbacks.h" #include "CHIPReadCallbacks.h" #include @@ -25,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -38,5388 +39,6 @@ using namespace chip; using namespace chip::Controller; -class CHIPAccountLoginClusterGetSetupPINResponseCallback : public Callback::Callback -{ -public: - CHIPAccountLoginClusterGetSetupPINResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPAccountLoginClusterGetSetupPINResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, chip::CharSpan setupPIN) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPAccountLoginClusterGetSetupPINResponseCallback * cppCallback = nullptr; - UtfString setupPINStr(env, setupPIN); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, setupPINStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPApplicationLauncherClusterLaunchAppResponseCallback - : public Callback::Callback -{ -public: - CHIPApplicationLauncherClusterLaunchAppResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPApplicationLauncherClusterLaunchAppResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, chip::CharSpan data) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPApplicationLauncherClusterLaunchAppResponseCallback * cppCallback = nullptr; - UtfString dataStr(env, data); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), dataStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPContentLauncherClusterLaunchContentResponseCallback - : public Callback::Callback -{ -public: - CHIPContentLauncherClusterLaunchContentResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPContentLauncherClusterLaunchContentResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, chip::CharSpan data, uint8_t contentLaunchStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPContentLauncherClusterLaunchContentResponseCallback * cppCallback = nullptr; - UtfString dataStr(env, data); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, dataStr.jniValue(), static_cast(contentLaunchStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPContentLauncherClusterLaunchURLResponseCallback - : public Callback::Callback -{ -public: - CHIPContentLauncherClusterLaunchURLResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPContentLauncherClusterLaunchURLResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, chip::CharSpan data, uint8_t contentLaunchStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPContentLauncherClusterLaunchURLResponseCallback * cppCallback = nullptr; - UtfString dataStr(env, data); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, dataStr.jniValue(), static_cast(contentLaunchStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback - : public Callback::Callback -{ -public: - CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, chip::ByteSpan content, uint32_t timeStamp, uint32_t timeSinceBoot) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback * cppCallback = nullptr; - jbyteArray contentArr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I[BJJ)V", &javaMethod); - SuccessOrExit(err); - - contentArr = env->NewByteArray(content.size()); - VerifyOrExit(contentArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(contentArr, 0, content.size(), reinterpret_cast(content.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), contentArr, static_cast(timeStamp), - static_cast(timeSinceBoot)); - - env->DeleteLocalRef(contentArr); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterClearAllPinsResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterClearAllPinsResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterClearAllPinsResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterClearAllPinsResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterClearAllRfidsResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterClearAllRfidsResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterClearAllRfidsResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterClearAllRfidsResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterClearHolidayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterClearHolidayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterClearHolidayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterClearHolidayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterClearPinResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterClearPinResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterClearPinResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterClearPinResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterClearRfidResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterClearRfidResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterClearRfidResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterClearRfidResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterClearWeekdayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterClearWeekdayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterClearWeekdayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterClearWeekdayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterClearYeardayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterClearYeardayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterClearYeardayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterClearYeardayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterGetHolidayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterGetHolidayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterGetHolidayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t scheduleId, uint8_t status, uint32_t localStartTime, uint32_t localEndTime, - uint8_t operatingModeDuringHoliday) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterGetHolidayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IIJJI)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(scheduleId), static_cast(status), - static_cast(localStartTime), static_cast(localEndTime), - static_cast(operatingModeDuringHoliday)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterGetLogRecordResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterGetLogRecordResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterGetLogRecordResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint16_t logEntryId, uint32_t timestamp, uint8_t eventType, uint8_t source, - uint8_t eventIdOrAlarmCode, uint16_t userId, chip::ByteSpan pin) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterGetLogRecordResponseCallback * cppCallback = nullptr; - jbyteArray pinArr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IJIIII[B)V", &javaMethod); - SuccessOrExit(err); - - pinArr = env->NewByteArray(pin.size()); - VerifyOrExit(pinArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(pinArr, 0, pin.size(), reinterpret_cast(pin.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(logEntryId), static_cast(timestamp), - static_cast(eventType), static_cast(source), static_cast(eventIdOrAlarmCode), - static_cast(userId), pinArr); - - env->DeleteLocalRef(pinArr); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterGetPinResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterGetPinResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterGetPinResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint16_t userId, uint8_t userStatus, uint8_t userType, chip::ByteSpan pin) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterGetPinResponseCallback * cppCallback = nullptr; - jbyteArray pinArr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(III[B)V", &javaMethod); - SuccessOrExit(err); - - pinArr = env->NewByteArray(pin.size()); - VerifyOrExit(pinArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(pinArr, 0, pin.size(), reinterpret_cast(pin.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(userId), static_cast(userStatus), - static_cast(userType), pinArr); - - env->DeleteLocalRef(pinArr); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterGetRfidResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterGetRfidResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterGetRfidResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint16_t userId, uint8_t userStatus, uint8_t userType, chip::ByteSpan rfid) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterGetRfidResponseCallback * cppCallback = nullptr; - jbyteArray rfidArr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(III[B)V", &javaMethod); - SuccessOrExit(err); - - rfidArr = env->NewByteArray(rfid.size()); - VerifyOrExit(rfidArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(rfidArr, 0, rfid.size(), reinterpret_cast(rfid.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(userId), static_cast(userStatus), - static_cast(userType), rfidArr); - - env->DeleteLocalRef(rfidArr); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterGetUserTypeResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterGetUserTypeResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterGetUserTypeResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint16_t userId, uint8_t userType) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterGetUserTypeResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(userId), static_cast(userType)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterGetWeekdayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterGetWeekdayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterGetWeekdayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t scheduleId, uint16_t userId, uint8_t status, uint8_t daysMask, uint8_t startHour, - uint8_t startMinute, uint8_t endHour, uint8_t endMinute) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterGetWeekdayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IIIIIIII)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(scheduleId), static_cast(userId), - static_cast(status), static_cast(daysMask), static_cast(startHour), - static_cast(startMinute), static_cast(endHour), static_cast(endMinute)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterGetYeardayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterGetYeardayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterGetYeardayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t scheduleId, uint16_t userId, uint8_t status, uint32_t localStartTime, - uint32_t localEndTime) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterGetYeardayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IIIJJ)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(scheduleId), static_cast(userId), - static_cast(status), static_cast(localStartTime), static_cast(localEndTime)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterLockDoorResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterLockDoorResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterLockDoorResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterLockDoorResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterSetHolidayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterSetHolidayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterSetHolidayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterSetHolidayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterSetPinResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterSetPinResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterSetPinResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterSetPinResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterSetRfidResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterSetRfidResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterSetRfidResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterSetRfidResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterSetUserTypeResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterSetUserTypeResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterSetUserTypeResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterSetUserTypeResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterSetWeekdayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterSetWeekdayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterSetWeekdayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterSetWeekdayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterSetYeardayScheduleResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterSetYeardayScheduleResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterSetYeardayScheduleResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterSetYeardayScheduleResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterUnlockDoorResponseCallback : public Callback::Callback -{ -public: - CHIPDoorLockClusterUnlockDoorResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterUnlockDoorResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterUnlockDoorResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPDoorLockClusterUnlockWithTimeoutResponseCallback - : public Callback::Callback -{ -public: - CHIPDoorLockClusterUnlockWithTimeoutResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPDoorLockClusterUnlockWithTimeoutResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPDoorLockClusterUnlockWithTimeoutResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPGeneralCommissioningClusterArmFailSafeResponseCallback - : public Callback::Callback -{ -public: - CHIPGeneralCommissioningClusterArmFailSafeResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPGeneralCommissioningClusterArmFailSafeResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPGeneralCommissioningClusterArmFailSafeResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback - : public Callback::Callback -{ -public: - CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback - : public Callback::Callback -{ -public: - CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPGroupsClusterAddGroupResponseCallback : public Callback::Callback -{ -public: - CHIPGroupsClusterAddGroupResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPGroupsClusterAddGroupResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint16_t groupId) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPGroupsClusterAddGroupResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(groupId)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPGroupsClusterGetGroupMembershipResponseCallback - : public Callback::Callback -{ -public: - CHIPGroupsClusterGetGroupMembershipResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPGroupsClusterGetGroupMembershipResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t capacity, uint8_t groupCount, - /* TYPE WARNING: array array defaults to */ uint8_t * groupList) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPGroupsClusterGetGroupMembershipResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(capacity), static_cast(groupCount) - // groupList: /* TYPE WARNING: array array defaults to */ uint8_t * - // Conversion from this type to Java is not properly implemented yet - ); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPGroupsClusterRemoveGroupResponseCallback : public Callback::Callback -{ -public: - CHIPGroupsClusterRemoveGroupResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPGroupsClusterRemoveGroupResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint16_t groupId) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPGroupsClusterRemoveGroupResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(groupId)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPGroupsClusterViewGroupResponseCallback : public Callback::Callback -{ -public: - CHIPGroupsClusterViewGroupResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPGroupsClusterViewGroupResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint16_t groupId, chip::CharSpan groupName) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPGroupsClusterViewGroupResponseCallback * cppCallback = nullptr; - UtfString groupNameStr(env, groupName); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(groupId), - groupNameStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPIdentifyClusterIdentifyQueryResponseCallback : public Callback::Callback -{ -public: - CHIPIdentifyClusterIdentifyQueryResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPIdentifyClusterIdentifyQueryResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint16_t timeout) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPIdentifyClusterIdentifyQueryResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(timeout)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPKeypadInputClusterSendKeyResponseCallback : public Callback::Callback -{ -public: - CHIPKeypadInputClusterSendKeyResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPKeypadInputClusterSendKeyResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPKeypadInputClusterSendKeyResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaFastForwardResponseCallback - : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaFastForwardResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaFastForwardResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaFastForwardResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaNextResponseCallback : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaNextResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaNextResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaNextResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaPauseResponseCallback : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaPauseResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaPauseResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaPauseResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaPlayResponseCallback : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaPlayResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaPlayResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaPlayResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaPreviousResponseCallback - : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaPreviousResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaPreviousResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaPreviousResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaRewindResponseCallback - : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaRewindResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaRewindResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaRewindResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaSeekResponseCallback : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaSeekResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaSeekResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaSeekResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback - : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback - : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaStartOverResponseCallback - : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaStartOverResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaStartOverResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaStartOverResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPMediaPlaybackClusterMediaStopResponseCallback : public Callback::Callback -{ -public: - CHIPMediaPlaybackClusterMediaStopResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPMediaPlaybackClusterMediaStopResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t mediaPlaybackStatus) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPMediaPlaybackClusterMediaStopResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(mediaPlaybackStatus)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback - : public Callback::Callback -{ -public: - CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback - : public Callback::Callback -{ -public: - CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPNetworkCommissioningClusterDisableNetworkResponseCallback - : public Callback::Callback -{ -public: - CHIPNetworkCommissioningClusterDisableNetworkResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPNetworkCommissioningClusterDisableNetworkResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPNetworkCommissioningClusterDisableNetworkResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPNetworkCommissioningClusterEnableNetworkResponseCallback - : public Callback::Callback -{ -public: - CHIPNetworkCommissioningClusterEnableNetworkResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPNetworkCommissioningClusterEnableNetworkResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPNetworkCommissioningClusterEnableNetworkResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback - : public Callback::Callback -{ -public: - CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPNetworkCommissioningClusterScanNetworksResponseCallback - : public Callback::Callback -{ -public: - CHIPNetworkCommissioningClusterScanNetworksResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPNetworkCommissioningClusterScanNetworksResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText, - /* TYPE WARNING: array array defaults to */ uint8_t * wifiScanResults, - /* TYPE WARNING: array array defaults to */ uint8_t * threadScanResults) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPNetworkCommissioningClusterScanNetworksResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue() - // wifiScanResults: /* TYPE WARNING: array array defaults to */ uint8_t * - // Conversion from this type to Java is not properly implemented yet - // threadScanResults: /* TYPE WARNING: array array defaults to */ uint8_t * - // Conversion from this type to Java is not properly implemented yet - ); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback - : public Callback::Callback -{ -public: - CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback - : public Callback::Callback -{ -public: - CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t errorCode, chip::CharSpan debugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback * cppCallback = nullptr; - UtfString debugTextStr(env, debugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(errorCode), debugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback - : public Callback::Callback -{ -public: - CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t action, uint32_t delayedActionTime) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IJ)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(action), static_cast(delayedActionTime)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback - : public Callback::Callback -{ -public: - CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint32_t delayedActionTime, chip::CharSpan imageURI, - uint32_t softwareVersion, chip::CharSpan softwareVersionString, chip::ByteSpan updateToken, - bool userConsentNeeded, chip::ByteSpan metadataForRequestor) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback * cppCallback = nullptr; - UtfString imageURIStr(env, imageURI); - UtfString softwareVersionStringStr(env, softwareVersionString); - jbyteArray updateTokenArr; - jbyteArray metadataForRequestorArr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", - "(IJLjava/lang/String;JLjava/lang/String;[BZ[B)V", &javaMethod); - SuccessOrExit(err); - - updateTokenArr = env->NewByteArray(updateToken.size()); - VerifyOrExit(updateTokenArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(updateTokenArr, 0, updateToken.size(), reinterpret_cast(updateToken.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - metadataForRequestorArr = env->NewByteArray(metadataForRequestor.size()); - VerifyOrExit(metadataForRequestorArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(metadataForRequestorArr, 0, metadataForRequestor.size(), - reinterpret_cast(metadataForRequestor.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(delayedActionTime), - imageURIStr.jniValue(), static_cast(softwareVersion), softwareVersionStringStr.jniValue(), - updateTokenArr, static_cast(userConsentNeeded), metadataForRequestorArr); - - env->DeleteLocalRef(updateTokenArr); - env->DeleteLocalRef(metadataForRequestorArr); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPOperationalCredentialsClusterAttestationResponseCallback - : public Callback::Callback -{ -public: - CHIPOperationalCredentialsClusterAttestationResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPOperationalCredentialsClusterAttestationResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, chip::ByteSpan AttestationElements, chip::ByteSpan Signature) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPOperationalCredentialsClusterAttestationResponseCallback * cppCallback = nullptr; - jbyteArray AttestationElementsArr; - jbyteArray SignatureArr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B[B)V", &javaMethod); - SuccessOrExit(err); - - AttestationElementsArr = env->NewByteArray(AttestationElements.size()); - VerifyOrExit(AttestationElementsArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(AttestationElementsArr, 0, AttestationElements.size(), - reinterpret_cast(AttestationElements.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - SignatureArr = env->NewByteArray(Signature.size()); - VerifyOrExit(SignatureArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(SignatureArr, 0, Signature.size(), reinterpret_cast(Signature.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - - env->CallVoidMethod(javaCallbackRef, javaMethod, AttestationElementsArr, SignatureArr); - - env->DeleteLocalRef(AttestationElementsArr); - env->DeleteLocalRef(SignatureArr); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPOperationalCredentialsClusterCertificateChainResponseCallback - : public Callback::Callback -{ -public: - CHIPOperationalCredentialsClusterCertificateChainResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPOperationalCredentialsClusterCertificateChainResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, chip::ByteSpan Certificate) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPOperationalCredentialsClusterCertificateChainResponseCallback * cppCallback = nullptr; - jbyteArray CertificateArr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B)V", &javaMethod); - SuccessOrExit(err); - - CertificateArr = env->NewByteArray(Certificate.size()); - VerifyOrExit(CertificateArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(CertificateArr, 0, Certificate.size(), reinterpret_cast(Certificate.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - - env->CallVoidMethod(javaCallbackRef, javaMethod, CertificateArr); - - env->DeleteLocalRef(CertificateArr); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPOperationalCredentialsClusterNOCResponseCallback - : public Callback::Callback -{ -public: - CHIPOperationalCredentialsClusterNOCResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPOperationalCredentialsClusterNOCResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t StatusCode, uint8_t FabricIndex, chip::CharSpan DebugText) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPOperationalCredentialsClusterNOCResponseCallback * cppCallback = nullptr; - UtfString DebugTextStr(env, DebugText); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(StatusCode), static_cast(FabricIndex), - DebugTextStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPOperationalCredentialsClusterOpCSRResponseCallback - : public Callback::Callback -{ -public: - CHIPOperationalCredentialsClusterOpCSRResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPOperationalCredentialsClusterOpCSRResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, chip::ByteSpan NOCSRElements, chip::ByteSpan AttestationSignature) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPOperationalCredentialsClusterOpCSRResponseCallback * cppCallback = nullptr; - jbyteArray NOCSRElementsArr; - jbyteArray AttestationSignatureArr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B[B)V", &javaMethod); - SuccessOrExit(err); - - NOCSRElementsArr = env->NewByteArray(NOCSRElements.size()); - VerifyOrExit(NOCSRElementsArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(NOCSRElementsArr, 0, NOCSRElements.size(), reinterpret_cast(NOCSRElements.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - AttestationSignatureArr = env->NewByteArray(AttestationSignature.size()); - VerifyOrExit(AttestationSignatureArr != nullptr, err = CHIP_ERROR_NO_MEMORY); - env->ExceptionClear(); - env->SetByteArrayRegion(AttestationSignatureArr, 0, AttestationSignature.size(), - reinterpret_cast(AttestationSignature.data())); - VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); - - env->CallVoidMethod(javaCallbackRef, javaMethod, NOCSRElementsArr, AttestationSignatureArr); - - env->DeleteLocalRef(NOCSRElementsArr); - env->DeleteLocalRef(AttestationSignatureArr); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPScenesClusterAddSceneResponseCallback : public Callback::Callback -{ -public: - CHIPScenesClusterAddSceneResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPScenesClusterAddSceneResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint16_t groupId, uint8_t sceneId) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPScenesClusterAddSceneResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(III)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(groupId), - static_cast(sceneId)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPScenesClusterGetSceneMembershipResponseCallback - : public Callback::Callback -{ -public: - CHIPScenesClusterGetSceneMembershipResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPScenesClusterGetSceneMembershipResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint8_t capacity, uint16_t groupId, uint8_t sceneCount, - /* TYPE WARNING: array array defaults to */ uint8_t * sceneList) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPScenesClusterGetSceneMembershipResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IIII)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(capacity), - static_cast(groupId), static_cast(sceneCount) - // sceneList: /* TYPE WARNING: array array defaults to */ uint8_t * - // Conversion from this type to Java is not properly implemented yet - ); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPScenesClusterRemoveAllScenesResponseCallback : public Callback::Callback -{ -public: - CHIPScenesClusterRemoveAllScenesResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPScenesClusterRemoveAllScenesResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint16_t groupId) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPScenesClusterRemoveAllScenesResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(groupId)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPScenesClusterRemoveSceneResponseCallback : public Callback::Callback -{ -public: - CHIPScenesClusterRemoveSceneResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPScenesClusterRemoveSceneResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint16_t groupId, uint8_t sceneId) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPScenesClusterRemoveSceneResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(III)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(groupId), - static_cast(sceneId)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPScenesClusterStoreSceneResponseCallback : public Callback::Callback -{ -public: - CHIPScenesClusterStoreSceneResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPScenesClusterStoreSceneResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint16_t groupId, uint8_t sceneId) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPScenesClusterStoreSceneResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(III)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(groupId), - static_cast(sceneId)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPScenesClusterViewSceneResponseCallback : public Callback::Callback -{ -public: - CHIPScenesClusterViewSceneResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPScenesClusterViewSceneResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, uint16_t groupId, uint8_t sceneId, uint16_t transitionTime, - chip::CharSpan sceneName, /* TYPE WARNING: array array defaults to */ uint8_t * extensionFieldSets) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPScenesClusterViewSceneResponseCallback * cppCallback = nullptr; - UtfString sceneNameStr(env, sceneName); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(IIIILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), static_cast(groupId), - static_cast(sceneId), static_cast(transitionTime), sceneNameStr.jniValue() - // extensionFieldSets: /* TYPE WARNING: array array defaults to */ uint8_t * - // Conversion from this type to Java is not properly implemented yet - ); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPTvChannelClusterChangeChannelResponseCallback : public Callback::Callback -{ -public: - CHIPTvChannelClusterChangeChannelResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPTvChannelClusterChangeChannelResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, /* TYPE WARNING: array array defaults to */ uint8_t * ChannelMatch, uint8_t ErrorType) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPTvChannelClusterChangeChannelResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, - javaMethod - // ChannelMatch: /* TYPE WARNING: array array defaults to */ uint8_t * - // Conversion from this type to Java is not properly implemented yet - , - static_cast(ErrorType)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPTargetNavigatorClusterNavigateTargetResponseCallback - : public Callback::Callback -{ -public: - CHIPTargetNavigatorClusterNavigateTargetResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPTargetNavigatorClusterNavigateTargetResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t status, chip::CharSpan data) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPTargetNavigatorClusterNavigateTargetResponseCallback * cppCallback = nullptr; - UtfString dataStr(env, data); - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(status), dataStr.jniValue()); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPTestClusterClusterBooleanResponseCallback : public Callback::Callback -{ -public: - CHIPTestClusterClusterBooleanResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPTestClusterClusterBooleanResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, bool value) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPTestClusterClusterBooleanResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Z)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(value)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPTestClusterClusterTestAddArgumentsResponseCallback - : public Callback::Callback -{ -public: - CHIPTestClusterClusterTestAddArgumentsResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPTestClusterClusterTestAddArgumentsResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t returnValue) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPTestClusterClusterTestAddArgumentsResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(returnValue)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPTestClusterClusterTestEnumsResponseCallback : public Callback::Callback -{ -public: - CHIPTestClusterClusterTestEnumsResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPTestClusterClusterTestEnumsResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, chip::VendorId arg1, uint8_t arg2) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPTestClusterClusterTestEnumsResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(arg1), static_cast(arg2)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPTestClusterClusterTestListInt8UReverseResponseCallback - : public Callback::Callback -{ -public: - CHIPTestClusterClusterTestListInt8UReverseResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPTestClusterClusterTestListInt8UReverseResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, /* TYPE WARNING: array array defaults to */ uint8_t * arg1) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPTestClusterClusterTestListInt8UReverseResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod - // arg1: /* TYPE WARNING: array array defaults to */ uint8_t * - // Conversion from this type to Java is not properly implemented yet - ); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPTestClusterClusterTestNullableOptionalResponseCallback - : public Callback::Callback -{ -public: - CHIPTestClusterClusterTestNullableOptionalResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPTestClusterClusterTestNullableOptionalResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, bool wasPresent, bool wasNull, uint8_t value, uint8_t originalValue) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPTestClusterClusterTestNullableOptionalResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(ZZII)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(wasPresent), static_cast(wasNull), - static_cast(value), static_cast(originalValue)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - -class CHIPTestClusterClusterTestSpecificResponseCallback : public Callback::Callback -{ -public: - CHIPTestClusterClusterTestSpecificResponseCallback(jobject javaCallback) : - Callback::Callback(CallbackFn, this) - { - JNIEnv * env = 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"); - } - } - ~CHIPTestClusterClusterTestSpecificResponseCallback() - { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - if (env == nullptr) - { - ChipLogError(Zcl, "Could not create global reference for Java callback"); - return; - } - env->DeleteGlobalRef(javaCallbackRef); - }; - - static void CallbackFn(void * context, uint8_t returnValue) - { - chip::DeviceLayer::StackUnlock unlock; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - jobject javaCallbackRef; - jmethodID javaMethod; - CHIPTestClusterClusterTestSpecificResponseCallback * cppCallback = nullptr; - - VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); - - cppCallback = reinterpret_cast(context); - VerifyOrExit(cppCallback != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); - - javaCallbackRef = cppCallback->javaCallbackRef; - VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); - - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); - SuccessOrExit(err); - - env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(returnValue)); - - exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error invoking Java callback: %" CHIP_ERROR_FORMAT, err.Format()); - } - if (cppCallback != nullptr) - { - cppCallback->Cancel(); - delete cppCallback; - } - } - -private: - jobject javaCallbackRef; -}; - JNI_METHOD(void, BaseChipCluster, deleteCluster)(JNIEnv * env, jobject self, jlong clusterPtr) { chip::DeviceLayer::StackLock lock; @@ -5446,7 +65,9 @@ JNI_METHOD(void, AccountLoginCluster, getSetupPIN) CHIP_ERROR err = CHIP_NO_ERROR; AccountLoginCluster * cppCluster; - JniUtfString tempAccountIdentifierStr(env, tempAccountIdentifier); + chip::app::Clusters::AccountLogin::Commands::GetSetupPIN::Type request; + + request.tempAccountIdentifier = chip::JniUtfString(env, static_cast(tempAccountIdentifier)).charSpan(); std::unique_ptr @@ -5454,43 +75,29 @@ JNI_METHOD(void, AccountLoginCluster, getSetupPIN) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetSetupPIN(onSuccess->Cancel(), onFailure->Cancel(), - chip::CharSpan(tempAccountIdentifierStr.c_str(), strlen(tempAccountIdentifierStr.c_str()))); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, AccountLoginCluster, login) (JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring tempAccountIdentifier, jstring setupPIN) @@ -5499,51 +106,37 @@ JNI_METHOD(void, AccountLoginCluster, login) CHIP_ERROR err = CHIP_NO_ERROR; AccountLoginCluster * cppCluster; - JniUtfString tempAccountIdentifierStr(env, tempAccountIdentifier); - JniUtfString setupPINStr(env, setupPIN); + chip::app::Clusters::AccountLogin::Commands::Login::Type request; + + request.tempAccountIdentifier = chip::JniUtfString(env, static_cast(tempAccountIdentifier)).charSpan(); + request.setupPIN = chip::JniUtfString(env, static_cast(setupPIN)).charSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Login(onSuccess->Cancel(), onFailure->Cancel(), - chip::CharSpan(tempAccountIdentifierStr.c_str(), strlen(tempAccountIdentifierStr.c_str())), - chip::CharSpan(setupPINStr.c_str(), strlen(setupPINStr.c_str()))); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, AdministratorCommissioningCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -5555,107 +148,90 @@ JNI_METHOD(jlong, AdministratorCommissioningCluster, initWithDevice)(JNIEnv * en } JNI_METHOD(void, AdministratorCommissioningCluster, openBasicCommissioningWindow) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint commissioningTimeout) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject commissioningTimeout) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; AdministratorCommissioningCluster * cppCluster; + chip::app::Clusters::AdministratorCommissioning::Commands::OpenBasicCommissioningWindow::Type request; + + request.commissioningTimeout = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(commissioningTimeout)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->OpenBasicCommissioningWindow(onSuccess->Cancel(), onFailure->Cancel(), commissioningTimeout); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, AdministratorCommissioningCluster, openCommissioningWindow) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint commissioningTimeout, jbyteArray PAKEVerifier, - jint discriminator, jlong iterations, jbyteArray salt, jint passcodeID) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject commissioningTimeout, jbyteArray PAKEVerifier, + jobject discriminator, jobject iterations, jbyteArray salt, jobject passcodeID) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; AdministratorCommissioningCluster * cppCluster; - JniByteArray PAKEVerifierArr(env, PAKEVerifier); - JniByteArray saltArr(env, salt); + chip::app::Clusters::AdministratorCommissioning::Commands::OpenCommissioningWindow::Type request; + + request.commissioningTimeout = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(commissioningTimeout)); + request.PAKEVerifier = chip::JniByteArray(env, static_cast(PAKEVerifier)).byteSpan(); + request.discriminator = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(discriminator)); + request.iterations = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(iterations)); + request.salt = chip::JniByteArray(env, static_cast(salt)).byteSpan(); + request.passcodeID = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(passcodeID)); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->OpenCommissioningWindow(onSuccess->Cancel(), onFailure->Cancel(), commissioningTimeout, - chip::ByteSpan((const uint8_t *) PAKEVerifierArr.data(), PAKEVerifierArr.size()), - discriminator, iterations, - chip::ByteSpan((const uint8_t *) saltArr.data(), saltArr.size()), passcodeID); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, AdministratorCommissioningCluster, revokeCommissioning) (JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) @@ -5664,46 +240,34 @@ JNI_METHOD(void, AdministratorCommissioningCluster, revokeCommissioning) CHIP_ERROR err = CHIP_NO_ERROR; AdministratorCommissioningCluster * cppCluster; + chip::app::Clusters::AdministratorCommissioning::Commands::RevokeCommissioning::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RevokeCommissioning(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, ApplicationBasicCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -5714,52 +278,43 @@ JNI_METHOD(jlong, ApplicationBasicCluster, initWithDevice)(JNIEnv * env, jobject return reinterpret_cast(cppCluster); } -JNI_METHOD(void, ApplicationBasicCluster, changeStatus)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint status) +JNI_METHOD(void, ApplicationBasicCluster, changeStatus) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject status) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ApplicationBasicCluster * cppCluster; + chip::app::Clusters::ApplicationBasic::Commands::ChangeStatus::Type request; + + request.status = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(status)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ChangeStatus(onSuccess->Cancel(), onFailure->Cancel(), static_cast(status)); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, ApplicationLauncherCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -5771,14 +326,18 @@ JNI_METHOD(jlong, ApplicationLauncherCluster, initWithDevice)(JNIEnv * env, jobj } JNI_METHOD(void, ApplicationLauncherCluster, launchApp) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring data, jint catalogVendorId, jstring applicationId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring data, jobject catalogVendorId, jstring applicationId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ApplicationLauncherCluster * cppCluster; - JniUtfString dataStr(env, data); - JniUtfString applicationIdStr(env, applicationId); + chip::app::Clusters::ApplicationLauncher::Commands::LaunchApp::Type request; + + request.data = chip::JniUtfString(env, static_cast(data)).charSpan(); + request.catalogVendorId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(catalogVendorId)); + request.applicationId = chip::JniUtfString(env, static_cast(applicationId)).charSpan(); std::unique_ptr @@ -5786,43 +345,29 @@ JNI_METHOD(void, ApplicationLauncherCluster, launchApp) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->LaunchApp(onSuccess->Cancel(), onFailure->Cancel(), chip::CharSpan(dataStr.c_str(), strlen(dataStr.c_str())), - catalogVendorId, chip::CharSpan(applicationIdStr.c_str(), strlen(applicationIdStr.c_str()))); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, AudioOutputCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -5834,102 +379,80 @@ JNI_METHOD(jlong, AudioOutputCluster, initWithDevice)(JNIEnv * env, jobject self } JNI_METHOD(void, AudioOutputCluster, renameOutput) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint index, jstring name) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject index, jstring name) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; AudioOutputCluster * cppCluster; - JniUtfString nameStr(env, name); + chip::app::Clusters::AudioOutput::Commands::RenameOutput::Type request; + + request.index = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(index)); + request.name = chip::JniUtfString(env, static_cast(name)).charSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RenameOutput(onSuccess->Cancel(), onFailure->Cancel(), index, - chip::CharSpan(nameStr.c_str(), strlen(nameStr.c_str()))); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, AudioOutputCluster, selectOutput)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint index) +JNI_METHOD(void, AudioOutputCluster, selectOutput)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject index) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; AudioOutputCluster * cppCluster; + chip::app::Clusters::AudioOutput::Commands::SelectOutput::Type request; + + request.index = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(index)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SelectOutput(onSuccess->Cancel(), onFailure->Cancel(), index); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, BarrierControlCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -5941,52 +464,43 @@ JNI_METHOD(jlong, BarrierControlCluster, initWithDevice)(JNIEnv * env, jobject s } JNI_METHOD(void, BarrierControlCluster, barrierControlGoToPercent) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint percentOpen) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject percentOpen) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BarrierControlCluster * cppCluster; + chip::app::Clusters::BarrierControl::Commands::BarrierControlGoToPercent::Type request; + + request.percentOpen = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(percentOpen)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->BarrierControlGoToPercent(onSuccess->Cancel(), onFailure->Cancel(), percentOpen); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BarrierControlCluster, barrierControlStop)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -5994,46 +508,34 @@ JNI_METHOD(void, BarrierControlCluster, barrierControlStop)(JNIEnv * env, jobjec CHIP_ERROR err = CHIP_NO_ERROR; BarrierControlCluster * cppCluster; + chip::app::Clusters::BarrierControl::Commands::BarrierControlStop::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->BarrierControlStop(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, BasicCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -6050,46 +552,34 @@ JNI_METHOD(void, BasicCluster, mfgSpecificPing)(JNIEnv * env, jobject self, jlon CHIP_ERROR err = CHIP_NO_ERROR; BasicCluster * cppCluster; + chip::app::Clusters::Basic::Commands::MfgSpecificPing::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); - err = cppCluster->MfgSpecificPing(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BasicCluster, writeUserLabelAttribute) @@ -6380,100 +870,90 @@ JNI_METHOD(jlong, BindingCluster, initWithDevice)(JNIEnv * env, jobject self, jl } JNI_METHOD(void, BindingCluster, bind) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong nodeId, jint groupId, jint endpointId, jlong clusterId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject nodeId, jobject groupId, jobject endpointId, + jobject clusterId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BindingCluster * cppCluster; + chip::app::Clusters::Binding::Commands::Bind::Type request; + + request.nodeId = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(nodeId)); + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.endpointId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(endpointId)); + request.clusterId = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(clusterId)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Bind(onSuccess->Cancel(), onFailure->Cancel(), nodeId, groupId, endpointId, clusterId); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BindingCluster, unbind) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong nodeId, jint groupId, jint endpointId, jlong clusterId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject nodeId, jobject groupId, jobject endpointId, + jobject clusterId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BindingCluster * cppCluster; + chip::app::Clusters::Binding::Commands::Unbind::Type request; + + request.nodeId = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(nodeId)); + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.endpointId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(endpointId)); + request.clusterId = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(clusterId)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Unbind(onSuccess->Cancel(), onFailure->Cancel(), nodeId, groupId, endpointId, clusterId); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, BooleanStateCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -6548,580 +1028,502 @@ JNI_METHOD(jlong, BridgedActionsCluster, initWithDevice)(JNIEnv * env, jobject s } JNI_METHOD(void, BridgedActionsCluster, disableAction) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::DisableAction::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->DisableAction(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, disableActionWithDuration) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID, jlong duration) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID, jobject duration) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::DisableActionWithDuration::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + request.duration = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(duration)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->DisableActionWithDuration(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID, duration); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, enableAction) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::EnableAction::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->EnableAction(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, enableActionWithDuration) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID, jlong duration) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID, jobject duration) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::EnableActionWithDuration::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + request.duration = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(duration)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->EnableActionWithDuration(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID, duration); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, instantAction) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::InstantAction::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->InstantAction(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, instantActionWithTransition) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID, jint transitionTime) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID, jobject transitionTime) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::InstantActionWithTransition::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->InstantActionWithTransition(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID, transitionTime); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, pauseAction) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::PauseAction::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->PauseAction(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, pauseActionWithDuration) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID, jlong duration) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID, jobject duration) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::PauseActionWithDuration::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + request.duration = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(duration)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->PauseActionWithDuration(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID, duration); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, resumeAction) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::ResumeAction::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ResumeAction(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, startAction) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::StartAction::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StartAction(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, startActionWithDuration) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID, jlong duration) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID, jobject duration) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::StartActionWithDuration::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + request.duration = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(duration)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StartActionWithDuration(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID, duration); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, BridgedActionsCluster, stopAction) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint actionID, jlong invokeID) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject actionID, jobject invokeID) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; BridgedActionsCluster * cppCluster; + chip::app::Clusters::BridgedActions::Commands::StopAction::Type request; + + request.actionID = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(actionID)); + chip::JniReferences::GetInstance().GetOptionalValue(invokeID, invokeID); + request.invokeID = chip::Optional( + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(invokeID))); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StopAction(onSuccess->Cancel(), onFailure->Cancel(), actionID, invokeID); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, BridgedDeviceBasicCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -7174,948 +1576,877 @@ JNI_METHOD(jlong, ColorControlCluster, initWithDevice)(JNIEnv * env, jobject sel } JNI_METHOD(void, ColorControlCluster, colorLoopSet) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint updateFlags, jint action, jint direction, jint time, - jint startHue, jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject updateFlags, jobject action, jobject direction, + jobject time, jobject startHue, jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::ColorLoopSet::Type request; + + request.updateFlags = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(updateFlags)); + request.action = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(action)); + request.direction = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(direction)); + request.time = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(time)); + request.startHue = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(startHue)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ColorLoopSet(onSuccess->Cancel(), onFailure->Cancel(), updateFlags, static_cast(action), - static_cast(direction), time, startHue, optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, enhancedMoveHue) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate, jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject moveMode, jobject rate, jobject optionsMask, + jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::EnhancedMoveHue::Type request; + + request.moveMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(moveMode)); + request.rate = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(rate)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->EnhancedMoveHue(onSuccess->Cancel(), onFailure->Cancel(), static_cast(moveMode), rate, optionsMask, - optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, enhancedMoveToHue) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint enhancedHue, jint direction, jint transitionTime, - jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject enhancedHue, jobject direction, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::EnhancedMoveToHue::Type request; + + request.enhancedHue = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(enhancedHue)); + request.direction = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(direction)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->EnhancedMoveToHue(onSuccess->Cancel(), onFailure->Cancel(), enhancedHue, static_cast(direction), - transitionTime, optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, enhancedMoveToHueAndSaturation) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint enhancedHue, jint saturation, jint transitionTime, - jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject enhancedHue, jobject saturation, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::EnhancedMoveToHueAndSaturation::Type request; + + request.enhancedHue = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(enhancedHue)); + request.saturation = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(saturation)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->EnhancedMoveToHueAndSaturation(onSuccess->Cancel(), onFailure->Cancel(), enhancedHue, saturation, - transitionTime, optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, enhancedStepHue) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime, - jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject stepMode, jobject stepSize, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::EnhancedStepHue::Type request; + + request.stepMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepMode)); + request.stepSize = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepSize)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->EnhancedStepHue(onSuccess->Cancel(), onFailure->Cancel(), static_cast(stepMode), stepSize, - transitionTime, optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveColor) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint rateX, jint rateY, jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject rateX, jobject rateY, jobject optionsMask, + jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveColor::Type request; + + request.rateX = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(rateX)); + request.rateY = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(rateY)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveColor(onSuccess->Cancel(), onFailure->Cancel(), rateX, rateY, optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveColorTemperature) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate, jint colorTemperatureMinimum, - jint colorTemperatureMaximum, jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject moveMode, jobject rate, jobject colorTemperatureMinimum, + jobject colorTemperatureMaximum, jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveColorTemperature::Type request; + + request.moveMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(moveMode)); + request.rate = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(rate)); + request.colorTemperatureMinimum = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(colorTemperatureMinimum)); + request.colorTemperatureMaximum = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(colorTemperatureMaximum)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveColorTemperature(onSuccess->Cancel(), onFailure->Cancel(), static_cast(moveMode), rate, - colorTemperatureMinimum, colorTemperatureMaximum, optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveHue) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate, jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject moveMode, jobject rate, jobject optionsMask, + jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveHue::Type request; + + request.moveMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(moveMode)); + request.rate = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(rate)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveHue(onSuccess->Cancel(), onFailure->Cancel(), static_cast(moveMode), rate, optionsMask, - optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveSaturation) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate, jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject moveMode, jobject rate, jobject optionsMask, + jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveSaturation::Type request; + + request.moveMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(moveMode)); + request.rate = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(rate)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveSaturation(onSuccess->Cancel(), onFailure->Cancel(), static_cast(moveMode), rate, optionsMask, - optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveToColor) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint colorX, jint colorY, jint transitionTime, jint optionsMask, - jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject colorX, jobject colorY, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveToColor::Type request; + + request.colorX = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(colorX)); + request.colorY = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(colorY)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveToColor(onSuccess->Cancel(), onFailure->Cancel(), colorX, colorY, transitionTime, optionsMask, - optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveToColorTemperature) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint colorTemperature, jint transitionTime, jint optionsMask, - jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject colorTemperature, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveToColorTemperature::Type request; + + request.colorTemperature = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(colorTemperature)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveToColorTemperature(onSuccess->Cancel(), onFailure->Cancel(), colorTemperature, transitionTime, - optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveToHue) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint hue, jint direction, jint transitionTime, jint optionsMask, - jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject hue, jobject direction, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveToHue::Type request; + + request.hue = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(hue)); + request.direction = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(direction)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveToHue(onSuccess->Cancel(), onFailure->Cancel(), hue, static_cast(direction), transitionTime, - optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveToHueAndSaturation) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint hue, jint saturation, jint transitionTime, jint optionsMask, - jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject hue, jobject saturation, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveToHueAndSaturation::Type request; + + request.hue = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(hue)); + request.saturation = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(saturation)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveToHueAndSaturation(onSuccess->Cancel(), onFailure->Cancel(), hue, saturation, transitionTime, optionsMask, - optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, moveToSaturation) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint saturation, jint transitionTime, jint optionsMask, - jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject saturation, jobject transitionTime, jobject optionsMask, + jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::MoveToSaturation::Type request; + + request.saturation = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(saturation)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveToSaturation(onSuccess->Cancel(), onFailure->Cancel(), saturation, transitionTime, optionsMask, - optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, stepColor) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepX, jint stepY, jint transitionTime, jint optionsMask, - jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject stepX, jobject stepY, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::StepColor::Type request; + + request.stepX = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepX)); + request.stepY = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepY)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = - cppCluster->StepColor(onSuccess->Cancel(), onFailure->Cancel(), stepX, stepY, transitionTime, optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, stepColorTemperature) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime, - jint colorTemperatureMinimum, jint colorTemperatureMaximum, jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject stepMode, jobject stepSize, jobject transitionTime, + jobject colorTemperatureMinimum, jobject colorTemperatureMaximum, jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::StepColorTemperature::Type request; + + request.stepMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepMode)); + request.stepSize = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepSize)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.colorTemperatureMinimum = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(colorTemperatureMinimum)); + request.colorTemperatureMaximum = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(colorTemperatureMaximum)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StepColorTemperature(onSuccess->Cancel(), onFailure->Cancel(), static_cast(stepMode), stepSize, - transitionTime, colorTemperatureMinimum, colorTemperatureMaximum, optionsMask, - optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, stepHue) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime, - jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject stepMode, jobject stepSize, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::StepHue::Type request; + + request.stepMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepMode)); + request.stepSize = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepSize)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StepHue(onSuccess->Cancel(), onFailure->Cancel(), static_cast(stepMode), stepSize, transitionTime, - optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, stepSaturation) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime, - jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject stepMode, jobject stepSize, jobject transitionTime, + jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::StepSaturation::Type request; + + request.stepMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepMode)); + request.stepSize = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepSize)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StepSaturation(onSuccess->Cancel(), onFailure->Cancel(), static_cast(stepMode), stepSize, - transitionTime, optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, stopMoveStep) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint optionsMask, jint optionsOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject optionsMask, jobject optionsOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ColorControlCluster * cppCluster; + chip::app::Clusters::ColorControl::Commands::StopMoveStep::Type request; + + request.optionsMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsMask)); + request.optionsOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionsOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StopMoveStep(onSuccess->Cancel(), onFailure->Cancel(), optionsMask, optionsOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ColorControlCluster, subscribeCurrentHueAttribute) @@ -8808,13 +3139,16 @@ JNI_METHOD(jlong, ContentLauncherCluster, initWithDevice)(JNIEnv * env, jobject } JNI_METHOD(void, ContentLauncherCluster, launchContent) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jboolean autoPlay, jstring data) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject autoPlay, jstring data) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ContentLauncherCluster * cppCluster; - JniUtfString dataStr(env, data); + chip::app::Clusters::ContentLauncher::Commands::LaunchContent::Type request; + + request.autoPlay = static_cast(chip::JniReferences::GetInstance().BooleanToPrimitive(autoPlay)); + request.data = chip::JniUtfString(env, static_cast(data)).charSpan(); std::unique_ptr @@ -8822,43 +3156,29 @@ JNI_METHOD(void, ContentLauncherCluster, launchContent) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->LaunchContent(onSuccess->Cancel(), onFailure->Cancel(), autoPlay, - chip::CharSpan(dataStr.c_str(), strlen(dataStr.c_str()))); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ContentLauncherCluster, launchURL) (JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring contentURL, jstring displayString) @@ -8867,8 +3187,10 @@ JNI_METHOD(void, ContentLauncherCluster, launchURL) CHIP_ERROR err = CHIP_NO_ERROR; ContentLauncherCluster * cppCluster; - JniUtfString contentURLStr(env, contentURL); - JniUtfString displayStringStr(env, displayString); + chip::app::Clusters::ContentLauncher::Commands::LaunchURL::Type request; + + request.contentURL = chip::JniUtfString(env, static_cast(contentURL)).charSpan(); + request.displayString = chip::JniUtfString(env, static_cast(displayString)).charSpan(); std::unique_ptr @@ -8876,44 +3198,29 @@ JNI_METHOD(void, ContentLauncherCluster, launchURL) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->LaunchURL(onSuccess->Cancel(), onFailure->Cancel(), - chip::CharSpan(contentURLStr.c_str(), strlen(contentURLStr.c_str())), - chip::CharSpan(displayStringStr.c_str(), strlen(displayStringStr.c_str()))); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, DescriptorCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -8934,14 +3241,19 @@ JNI_METHOD(jlong, DiagnosticLogsCluster, initWithDevice)(JNIEnv * env, jobject s } JNI_METHOD(void, DiagnosticLogsCluster, retrieveLogsRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint intent, jint requestedProtocol, +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject intent, jobject requestedProtocol, jbyteArray transferFileDesignator) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DiagnosticLogsCluster * cppCluster; - JniByteArray transferFileDesignatorArr(env, transferFileDesignator); + chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsRequest::Type request; + + request.intent = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(intent)); + request.requestedProtocol = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(requestedProtocol)); + request.transferFileDesignator = chip::JniByteArray(env, static_cast(transferFileDesignator)).byteSpan(); std::unique_ptr @@ -8949,44 +3261,29 @@ JNI_METHOD(void, DiagnosticLogsCluster, retrieveLogsRequest) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RetrieveLogsRequest( - onSuccess->Cancel(), onFailure->Cancel(), static_cast(intent), static_cast(requestedProtocol), - chip::ByteSpan((const uint8_t *) transferFileDesignatorArr.data(), transferFileDesignatorArr.size())); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, DoorLockCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -9003,47 +3300,36 @@ JNI_METHOD(void, DoorLockCluster, clearAllPins)(JNIEnv * env, jobject self, jlon CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::ClearAllPins::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ClearAllPins(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, clearAllRfids)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -9051,635 +3337,523 @@ JNI_METHOD(void, DoorLockCluster, clearAllRfids)(JNIEnv * env, jobject self, jlo CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::ClearAllRfids::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ClearAllRfids(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, clearHolidaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::ClearHolidaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ClearHolidaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, DoorLockCluster, clearPin)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +JNI_METHOD(void, DoorLockCluster, clearPin)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::ClearPin::Type request; + + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ClearPin(onSuccess->Cancel(), onFailure->Cancel(), userId); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, DoorLockCluster, clearRfid)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +JNI_METHOD(void, DoorLockCluster, clearRfid)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::ClearRfid::Type request; + + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ClearRfid(onSuccess->Cancel(), onFailure->Cancel(), userId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, clearWeekdaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::ClearWeekdaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ClearWeekdaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, clearYeardaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::ClearYeardaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ClearYeardaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, getHolidaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::GetHolidaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetHolidaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, DoorLockCluster, getLogRecord)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint logIndex) +JNI_METHOD(void, DoorLockCluster, getLogRecord)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject logIndex) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::GetLogRecord::Type request; + + request.logIndex = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(logIndex)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetLogRecord(onSuccess->Cancel(), onFailure->Cancel(), logIndex); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, DoorLockCluster, getPin)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +JNI_METHOD(void, DoorLockCluster, getPin)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::GetPin::Type request; + + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetPin(onSuccess->Cancel(), onFailure->Cancel(), userId); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, DoorLockCluster, getRfid)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +JNI_METHOD(void, DoorLockCluster, getRfid)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::GetRfid::Type request; + + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetRfid(onSuccess->Cancel(), onFailure->Cancel(), userId); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, DoorLockCluster, getUserType)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +JNI_METHOD(void, DoorLockCluster, getUserType)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::GetUserType::Type request; + + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetUserType(onSuccess->Cancel(), onFailure->Cancel(), userId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, getWeekdaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::GetWeekdaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetWeekdaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, getYeardaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId, jobject userId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::GetYeardaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetYeardaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, lockDoor)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray pin) { @@ -9687,359 +3861,313 @@ JNI_METHOD(void, DoorLockCluster, lockDoor)(JNIEnv * env, jobject self, jlong cl CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; - JniByteArray pinArr(env, pin); + chip::app::Clusters::DoorLock::Commands::LockDoor::Type request; + + request.pin = chip::JniByteArray(env, static_cast(pin)).byteSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->LockDoor(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) pinArr.data(), pinArr.size())); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, setHolidaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jlong localStartTime, jlong localEndTime, - jint operatingModeDuringHoliday) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId, jobject localStartTime, jobject localEndTime, + jobject operatingModeDuringHoliday) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::SetHolidaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + request.localStartTime = + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(localStartTime)); + request.localEndTime = + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(localEndTime)); + request.operatingModeDuringHoliday = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(operatingModeDuringHoliday)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SetHolidaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, localStartTime, localEndTime, - operatingModeDuringHoliday); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, setPin) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId, jint userStatus, jint userType, jbyteArray pin) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject userId, jobject userStatus, jobject userType, + jbyteArray pin) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; - JniByteArray pinArr(env, pin); + chip::app::Clusters::DoorLock::Commands::SetPin::Type request; + + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + request.userStatus = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userStatus)); + request.userType = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userType)); + request.pin = chip::JniByteArray(env, static_cast(pin)).byteSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SetPin(onSuccess->Cancel(), onFailure->Cancel(), userId, static_cast(userStatus), - static_cast(userType), chip::ByteSpan((const uint8_t *) pinArr.data(), pinArr.size())); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, setRfid) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId, jint userStatus, jint userType, jbyteArray id) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject userId, jobject userStatus, jobject userType, + jbyteArray id) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; - JniByteArray idArr(env, id); + chip::app::Clusters::DoorLock::Commands::SetRfid::Type request; + + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + request.userStatus = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userStatus)); + request.userType = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userType)); + request.id = chip::JniByteArray(env, static_cast(id)).byteSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SetRfid(onSuccess->Cancel(), onFailure->Cancel(), userId, static_cast(userStatus), - static_cast(userType), chip::ByteSpan((const uint8_t *) idArr.data(), idArr.size())); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, setUserType) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId, jint userType) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject userId, jobject userType) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::SetUserType::Type request; + + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + request.userType = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userType)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SetUserType(onSuccess->Cancel(), onFailure->Cancel(), userId, static_cast(userType)); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, setWeekdaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId, jint daysMask, jint startHour, - jint startMinute, jint endHour, jint endMinute) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId, jobject userId, jobject daysMask, + jobject startHour, jobject startMinute, jobject endHour, jobject endMinute) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::SetWeekdaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + request.daysMask = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(daysMask)); + request.startHour = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(startHour)); + request.startMinute = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(startMinute)); + request.endHour = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(endHour)); + request.endMinute = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(endMinute)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SetWeekdaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId, daysMask, startHour, - startMinute, endHour, endMinute); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, setYeardaySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId, jlong localStartTime, - jlong localEndTime) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject scheduleId, jobject userId, jobject localStartTime, + jobject localEndTime) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; + chip::app::Clusters::DoorLock::Commands::SetYeardaySchedule::Type request; + + request.scheduleId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(scheduleId)); + request.userId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(userId)); + request.localStartTime = + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(localStartTime)); + request.localEndTime = + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(localEndTime)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = - cppCluster->SetYeardaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId, localStartTime, localEndTime); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, unlockDoor)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray pin) { @@ -10047,59 +4175,51 @@ JNI_METHOD(void, DoorLockCluster, unlockDoor)(JNIEnv * env, jobject self, jlong CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; - JniByteArray pinArr(env, pin); + chip::app::Clusters::DoorLock::Commands::UnlockDoor::Type request; + + request.pin = chip::JniByteArray(env, static_cast(pin)).byteSpan(); std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->UnlockDoor(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) pinArr.data(), pinArr.size())); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, unlockWithTimeout) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint timeoutInSeconds, jbyteArray pin) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject timeoutInSeconds, jbyteArray pin) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; DoorLockCluster * cppCluster; - JniByteArray pinArr(env, pin); + chip::app::Clusters::DoorLock::Commands::UnlockWithTimeout::Type request; + + request.timeoutInSeconds = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(timeoutInSeconds)); + request.pin = chip::JniByteArray(env, static_cast(pin)).byteSpan(); std::unique_ptr @@ -10107,43 +4227,29 @@ JNI_METHOD(void, DoorLockCluster, unlockWithTimeout) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->UnlockWithTimeout(onSuccess->Cancel(), onFailure->Cancel(), timeoutInSeconds, - chip::ByteSpan((const uint8_t *) pinArr.data(), pinArr.size())); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, DoorLockCluster, subscribeLockStateAttribute) @@ -10224,46 +4330,34 @@ JNI_METHOD(void, EthernetNetworkDiagnosticsCluster, resetCounts)(JNIEnv * env, j CHIP_ERROR err = CHIP_NO_ERROR; EthernetNetworkDiagnosticsCluster * cppCluster; + chip::app::Clusters::EthernetNetworkDiagnostics::Commands::ResetCounts::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ResetCounts(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, FixedLabelCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -10293,54 +4387,48 @@ JNI_METHOD(jlong, GeneralCommissioningCluster, initWithDevice)(JNIEnv * env, job } JNI_METHOD(void, GeneralCommissioningCluster, armFailSafe) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint expiryLengthSeconds, jlong breadcrumb, jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject expiryLengthSeconds, jobject breadcrumb, jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; GeneralCommissioningCluster * cppCluster; + chip::app::Clusters::GeneralCommissioning::Commands::ArmFailSafe::Type request; + + request.expiryLengthSeconds = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(expiryLengthSeconds)); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ArmFailSafe(onSuccess->Cancel(), onFailure->Cancel(), expiryLengthSeconds, breadcrumb, timeoutMs); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, GeneralCommissioningCluster, commissioningComplete)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -10348,58 +4436,53 @@ JNI_METHOD(void, GeneralCommissioningCluster, commissioningComplete)(JNIEnv * en CHIP_ERROR err = CHIP_NO_ERROR; GeneralCommissioningCluster * cppCluster; + chip::app::Clusters::GeneralCommissioning::Commands::CommissioningComplete::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->CommissioningComplete(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, GeneralCommissioningCluster, setRegulatoryConfig) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint location, jstring countryCode, jlong breadcrumb, - jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject location, jstring countryCode, jobject breadcrumb, + jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; GeneralCommissioningCluster * cppCluster; - JniUtfString countryCodeStr(env, countryCode); + chip::app::Clusters::GeneralCommissioning::Commands::SetRegulatoryConfig::Type request; + + request.location = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(location)); + request.countryCode = chip::JniUtfString(env, static_cast(countryCode)).charSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -10407,44 +4490,30 @@ JNI_METHOD(void, GeneralCommissioningCluster, setRegulatoryConfig) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SetRegulatoryConfig(onSuccess->Cancel(), onFailure->Cancel(), static_cast(location), - chip::CharSpan(countryCodeStr.c_str(), strlen(countryCodeStr.c_str())), breadcrumb, - timeoutMs); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, GeneralCommissioningCluster, writeBreadcrumbAttribute) @@ -10505,157 +4574,126 @@ JNI_METHOD(jlong, GroupsCluster, initWithDevice)(JNIEnv * env, jobject self, jlo } JNI_METHOD(void, GroupsCluster, addGroup) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jstring groupName) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId, jstring groupName) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; GroupsCluster * cppCluster; - JniUtfString groupNameStr(env, groupName); + chip::app::Clusters::Groups::Commands::AddGroup::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.groupName = chip::JniUtfString(env, static_cast(groupName)).charSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AddGroup(onSuccess->Cancel(), onFailure->Cancel(), groupId, - chip::CharSpan(groupNameStr.c_str(), strlen(groupNameStr.c_str()))); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, GroupsCluster, addGroupIfIdentifying) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jstring groupName) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId, jstring groupName) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; GroupsCluster * cppCluster; - JniUtfString groupNameStr(env, groupName); + chip::app::Clusters::Groups::Commands::AddGroupIfIdentifying::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.groupName = chip::JniUtfString(env, static_cast(groupName)).charSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AddGroupIfIdentifying(onSuccess->Cancel(), onFailure->Cancel(), groupId, - chip::CharSpan(groupNameStr.c_str(), strlen(groupNameStr.c_str()))); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, GroupsCluster, getGroupMembership) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupCount, jint groupList) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupCount, jobject groupList) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; GroupsCluster * cppCluster; + chip::app::Clusters::Groups::Commands::GetGroupMembership::Type request; + + request.groupCount = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupCount)); + request.groupList = chip::app::DataModel::List(); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetGroupMembership(onSuccess->Cancel(), onFailure->Cancel(), groupCount, groupList); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, GroupsCluster, removeAllGroups)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -10663,142 +4701,111 @@ JNI_METHOD(void, GroupsCluster, removeAllGroups)(JNIEnv * env, jobject self, jlo CHIP_ERROR err = CHIP_NO_ERROR; GroupsCluster * cppCluster; + chip::app::Clusters::Groups::Commands::RemoveAllGroups::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RemoveAllGroups(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, GroupsCluster, removeGroup)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId) +JNI_METHOD(void, GroupsCluster, removeGroup)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; GroupsCluster * cppCluster; + chip::app::Clusters::Groups::Commands::RemoveGroup::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RemoveGroup(onSuccess->Cancel(), onFailure->Cancel(), groupId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, GroupsCluster, viewGroup)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId) +JNI_METHOD(void, GroupsCluster, viewGroup)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; GroupsCluster * cppCluster; + chip::app::Clusters::Groups::Commands::ViewGroup::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ViewGroup(onSuccess->Cancel(), onFailure->Cancel(), groupId); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, IdentifyCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -10809,52 +4816,43 @@ JNI_METHOD(jlong, IdentifyCluster, initWithDevice)(JNIEnv * env, jobject self, j return reinterpret_cast(cppCluster); } -JNI_METHOD(void, IdentifyCluster, identify)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint identifyTime) +JNI_METHOD(void, IdentifyCluster, identify)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject identifyTime) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; IdentifyCluster * cppCluster; + chip::app::Clusters::Identify::Commands::Identify::Type request; + + request.identifyTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(identifyTime)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Identify(onSuccess->Cancel(), onFailure->Cancel(), identifyTime); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, IdentifyCluster, identifyQuery)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -10862,96 +4860,77 @@ JNI_METHOD(void, IdentifyCluster, identifyQuery)(JNIEnv * env, jobject self, jlo CHIP_ERROR err = CHIP_NO_ERROR; IdentifyCluster * cppCluster; + chip::app::Clusters::Identify::Commands::IdentifyQuery::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->IdentifyQuery(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, IdentifyCluster, triggerEffect) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint effectIdentifier, jint effectVariant) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject effectIdentifier, jobject effectVariant) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; IdentifyCluster * cppCluster; + chip::app::Clusters::Identify::Commands::TriggerEffect::Type request; + + request.effectIdentifier = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(effectIdentifier)); + request.effectVariant = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(effectVariant)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TriggerEffect(onSuccess->Cancel(), onFailure->Cancel(), static_cast(effectIdentifier), - static_cast(effectVariant)); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, IdentifyCluster, writeIdentifyTimeAttribute) @@ -11057,53 +5036,44 @@ JNI_METHOD(jlong, KeypadInputCluster, initWithDevice)(JNIEnv * env, jobject self return reinterpret_cast(cppCluster); } -JNI_METHOD(void, KeypadInputCluster, sendKey)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint keyCode) +JNI_METHOD(void, KeypadInputCluster, sendKey)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject keyCode) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; KeypadInputCluster * cppCluster; + chip::app::Clusters::KeypadInput::Commands::SendKey::Type request; + + request.keyCode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(keyCode)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SendKey(onSuccess->Cancel(), onFailure->Cancel(), static_cast(keyCode)); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, LevelControlCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -11115,345 +5085,300 @@ JNI_METHOD(jlong, LevelControlCluster, initWithDevice)(JNIEnv * env, jobject sel } JNI_METHOD(void, LevelControlCluster, move) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate, jint optionMask, jint optionOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject moveMode, jobject rate, jobject optionMask, + jobject optionOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; LevelControlCluster * cppCluster; + chip::app::Clusters::LevelControl::Commands::Move::Type request; + + request.moveMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(moveMode)); + request.rate = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(rate)); + request.optionMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionMask)); + request.optionOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Move(onSuccess->Cancel(), onFailure->Cancel(), static_cast(moveMode), rate, optionMask, - optionOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, LevelControlCluster, moveToLevel) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint level, jint transitionTime, jint optionMask, - jint optionOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject level, jobject transitionTime, jobject optionMask, + jobject optionOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; LevelControlCluster * cppCluster; + chip::app::Clusters::LevelControl::Commands::MoveToLevel::Type request; + + request.level = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(level)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionMask)); + request.optionOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveToLevel(onSuccess->Cancel(), onFailure->Cancel(), level, transitionTime, optionMask, optionOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, LevelControlCluster, moveToLevelWithOnOff) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint level, jint transitionTime) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject level, jobject transitionTime) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; LevelControlCluster * cppCluster; + chip::app::Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Type request; + + request.level = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(level)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveToLevelWithOnOff(onSuccess->Cancel(), onFailure->Cancel(), level, transitionTime); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, LevelControlCluster, moveWithOnOff) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject moveMode, jobject rate) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; LevelControlCluster * cppCluster; + chip::app::Clusters::LevelControl::Commands::MoveWithOnOff::Type request; + + request.moveMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(moveMode)); + request.rate = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(rate)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MoveWithOnOff(onSuccess->Cancel(), onFailure->Cancel(), static_cast(moveMode), rate); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, LevelControlCluster, step) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime, jint optionMask, - jint optionOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject stepMode, jobject stepSize, jobject transitionTime, + jobject optionMask, jobject optionOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; LevelControlCluster * cppCluster; + chip::app::Clusters::LevelControl::Commands::Step::Type request; + + request.stepMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepMode)); + request.stepSize = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepSize)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.optionMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionMask)); + request.optionOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Step(onSuccess->Cancel(), onFailure->Cancel(), static_cast(stepMode), stepSize, transitionTime, - optionMask, optionOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, LevelControlCluster, stepWithOnOff) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject stepMode, jobject stepSize, jobject transitionTime) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; LevelControlCluster * cppCluster; + chip::app::Clusters::LevelControl::Commands::StepWithOnOff::Type request; + + request.stepMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepMode)); + request.stepSize = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(stepSize)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StepWithOnOff(onSuccess->Cancel(), onFailure->Cancel(), static_cast(stepMode), stepSize, - transitionTime); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, LevelControlCluster, stop) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint optionMask, jint optionOverride) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject optionMask, jobject optionOverride) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; LevelControlCluster * cppCluster; + chip::app::Clusters::LevelControl::Commands::Stop::Type request; + + request.optionMask = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionMask)); + request.optionOverride = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(optionOverride)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Stop(onSuccess->Cancel(), onFailure->Cancel(), optionMask, optionOverride); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, LevelControlCluster, stopWithOnOff)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -11461,46 +5386,34 @@ JNI_METHOD(void, LevelControlCluster, stopWithOnOff)(JNIEnv * env, jobject self, CHIP_ERROR err = CHIP_NO_ERROR; LevelControlCluster * cppCluster; + chip::app::Clusters::LevelControl::Commands::StopWithOnOff::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StopWithOnOff(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, LevelControlCluster, subscribeCurrentLevelAttribute) @@ -11789,46 +5702,34 @@ JNI_METHOD(void, LowPowerCluster, sleep)(JNIEnv * env, jobject self, jlong clust CHIP_ERROR err = CHIP_NO_ERROR; LowPowerCluster * cppCluster; + chip::app::Clusters::LowPower::Commands::Sleep::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Sleep(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, MediaInputCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -11845,144 +5746,110 @@ JNI_METHOD(void, MediaInputCluster, hideInputStatus)(JNIEnv * env, jobject self, CHIP_ERROR err = CHIP_NO_ERROR; MediaInputCluster * cppCluster; + chip::app::Clusters::MediaInput::Commands::HideInputStatus::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->HideInputStatus(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaInputCluster, renameInput) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint index, jstring name) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject index, jstring name) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; MediaInputCluster * cppCluster; - JniUtfString nameStr(env, name); + chip::app::Clusters::MediaInput::Commands::RenameInput::Type request; + + request.index = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(index)); + request.name = chip::JniUtfString(env, static_cast(name)).charSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RenameInput(onSuccess->Cancel(), onFailure->Cancel(), index, - chip::CharSpan(nameStr.c_str(), strlen(nameStr.c_str()))); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, MediaInputCluster, selectInput)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint index) +JNI_METHOD(void, MediaInputCluster, selectInput)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject index) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; MediaInputCluster * cppCluster; + chip::app::Clusters::MediaInput::Commands::SelectInput::Type request; + + request.index = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(index)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SelectInput(onSuccess->Cancel(), onFailure->Cancel(), index); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaInputCluster, showInputStatus)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -11990,46 +5857,34 @@ JNI_METHOD(void, MediaInputCluster, showInputStatus)(JNIEnv * env, jobject self, CHIP_ERROR err = CHIP_NO_ERROR; MediaInputCluster * cppCluster; + chip::app::Clusters::MediaInput::Commands::ShowInputStatus::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ShowInputStatus(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, MediaPlaybackCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -12046,48 +5901,37 @@ JNI_METHOD(void, MediaPlaybackCluster, mediaFastForward)(JNIEnv * env, jobject s CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaFastForward::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaFastForward(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaNext)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -12095,48 +5939,37 @@ JNI_METHOD(void, MediaPlaybackCluster, mediaNext)(JNIEnv * env, jobject self, jl CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaNext::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaNext(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaPause)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -12144,48 +5977,37 @@ JNI_METHOD(void, MediaPlaybackCluster, mediaPause)(JNIEnv * env, jobject self, j CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaPause::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaPause(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaPlay)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -12193,48 +6015,37 @@ JNI_METHOD(void, MediaPlaybackCluster, mediaPlay)(JNIEnv * env, jobject self, jl CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaPlay::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaPlay(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaPrevious)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -12242,48 +6053,37 @@ JNI_METHOD(void, MediaPlaybackCluster, mediaPrevious)(JNIEnv * env, jobject self CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaPrevious::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaPrevious(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaRewind)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -12291,197 +6091,161 @@ JNI_METHOD(void, MediaPlaybackCluster, mediaRewind)(JNIEnv * env, jobject self, CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaRewind::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaRewind(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, MediaPlaybackCluster, mediaSeek)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong position) +JNI_METHOD(void, MediaPlaybackCluster, mediaSeek)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject position) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaSeek::Type request; + + request.position = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(position)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaSeek(onSuccess->Cancel(), onFailure->Cancel(), position); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaSkipBackward) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong deltaPositionMilliseconds) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject deltaPositionMilliseconds) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaSkipBackward::Type request; + + request.deltaPositionMilliseconds = static_cast( + chip::JniReferences::GetInstance().LongToPrimitive(deltaPositionMilliseconds)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaSkipBackward(onSuccess->Cancel(), onFailure->Cancel(), deltaPositionMilliseconds); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaSkipForward) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong deltaPositionMilliseconds) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject deltaPositionMilliseconds) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaSkipForward::Type request; + + request.deltaPositionMilliseconds = static_cast( + chip::JniReferences::GetInstance().LongToPrimitive(deltaPositionMilliseconds)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaSkipForward(onSuccess->Cancel(), onFailure->Cancel(), deltaPositionMilliseconds); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaStartOver)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -12489,48 +6253,37 @@ JNI_METHOD(void, MediaPlaybackCluster, mediaStartOver)(JNIEnv * env, jobject sel CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaStartOver::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaStartOver(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, MediaPlaybackCluster, mediaStop)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -12538,48 +6291,37 @@ JNI_METHOD(void, MediaPlaybackCluster, mediaStop)(JNIEnv * env, jobject self, jl CHIP_ERROR err = CHIP_NO_ERROR; MediaPlaybackCluster * cppCluster; + chip::app::Clusters::MediaPlayback::Commands::MediaStop::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->MediaStop(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, ModeSelectCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -12590,52 +6332,42 @@ JNI_METHOD(jlong, ModeSelectCluster, initWithDevice)(JNIEnv * env, jobject self, return reinterpret_cast(cppCluster); } -JNI_METHOD(void, ModeSelectCluster, changeToMode)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint newMode) +JNI_METHOD(void, ModeSelectCluster, changeToMode)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject newMode) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ModeSelectCluster * cppCluster; + chip::app::Clusters::ModeSelect::Commands::ChangeToMode::Type request; + + request.newMode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(newMode)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ChangeToMode(onSuccess->Cancel(), onFailure->Cancel(), newMode); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ModeSelectCluster, subscribeCurrentModeAttribute) @@ -12733,13 +6465,18 @@ JNI_METHOD(jlong, NetworkCommissioningCluster, initWithDevice)(JNIEnv * env, job } JNI_METHOD(void, NetworkCommissioningCluster, addThreadNetwork) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray operationalDataset, jlong breadcrumb, jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray operationalDataset, jobject breadcrumb, + jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; NetworkCommissioningCluster * cppCluster; - JniByteArray operationalDatasetArr(env, operationalDataset); + chip::app::Clusters::NetworkCommissioning::Commands::AddThreadNetwork::Type request; + + request.operationalDataset = chip::JniByteArray(env, static_cast(operationalDataset)).byteSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -12747,55 +6484,44 @@ JNI_METHOD(void, NetworkCommissioningCluster, addThreadNetwork) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AddThreadNetwork(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) operationalDatasetArr.data(), operationalDatasetArr.size()), - breadcrumb, timeoutMs); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, NetworkCommissioningCluster, addWiFiNetwork) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jbyteArray credentials, jlong breadcrumb, - jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jbyteArray credentials, jobject breadcrumb, + jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; NetworkCommissioningCluster * cppCluster; - JniByteArray ssidArr(env, ssid); - JniByteArray credentialsArr(env, credentials); + chip::app::Clusters::NetworkCommissioning::Commands::AddWiFiNetwork::Type request; + + request.ssid = chip::JniByteArray(env, static_cast(ssid)).byteSpan(); + request.credentials = chip::JniByteArray(env, static_cast(credentials)).byteSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -12803,53 +6529,42 @@ JNI_METHOD(void, NetworkCommissioningCluster, addWiFiNetwork) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AddWiFiNetwork( - onSuccess->Cancel(), onFailure->Cancel(), chip::ByteSpan((const uint8_t *) ssidArr.data(), ssidArr.size()), - chip::ByteSpan((const uint8_t *) credentialsArr.data(), credentialsArr.size()), breadcrumb, timeoutMs); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, NetworkCommissioningCluster, disableNetwork) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jlong breadcrumb, jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jobject breadcrumb, jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; NetworkCommissioningCluster * cppCluster; - JniByteArray networkIDArr(env, networkID); + chip::app::Clusters::NetworkCommissioning::Commands::DisableNetwork::Type request; + + request.networkID = chip::JniByteArray(env, static_cast(networkID)).byteSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -12857,53 +6572,42 @@ JNI_METHOD(void, NetworkCommissioningCluster, disableNetwork) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->DisableNetwork(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) networkIDArr.data(), networkIDArr.size()), breadcrumb, - timeoutMs); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, NetworkCommissioningCluster, enableNetwork) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jlong breadcrumb, jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jobject breadcrumb, jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; NetworkCommissioningCluster * cppCluster; - JniByteArray networkIDArr(env, networkID); + chip::app::Clusters::NetworkCommissioning::Commands::EnableNetwork::Type request; + + request.networkID = chip::JniByteArray(env, static_cast(networkID)).byteSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -12911,53 +6615,42 @@ JNI_METHOD(void, NetworkCommissioningCluster, enableNetwork) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->EnableNetwork(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) networkIDArr.data(), networkIDArr.size()), breadcrumb, - timeoutMs); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, NetworkCommissioningCluster, removeNetwork) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jlong breadcrumb, jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jobject breadcrumb, jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; NetworkCommissioningCluster * cppCluster; - JniByteArray networkIDArr(env, networkID); + chip::app::Clusters::NetworkCommissioning::Commands::RemoveNetwork::Type request; + + request.networkID = chip::JniByteArray(env, static_cast(networkID)).byteSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -12965,53 +6658,42 @@ JNI_METHOD(void, NetworkCommissioningCluster, removeNetwork) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RemoveNetwork(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) networkIDArr.data(), networkIDArr.size()), breadcrumb, - timeoutMs); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, NetworkCommissioningCluster, scanNetworks) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jlong breadcrumb, jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jobject breadcrumb, jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; NetworkCommissioningCluster * cppCluster; - JniByteArray ssidArr(env, ssid); + chip::app::Clusters::NetworkCommissioning::Commands::ScanNetworks::Type request; + + request.ssid = chip::JniByteArray(env, static_cast(ssid)).byteSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -13019,52 +6701,43 @@ JNI_METHOD(void, NetworkCommissioningCluster, scanNetworks) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ScanNetworks(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) ssidArr.data(), ssidArr.size()), breadcrumb, timeoutMs); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, NetworkCommissioningCluster, updateThreadNetwork) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray operationalDataset, jlong breadcrumb, jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray operationalDataset, jobject breadcrumb, + jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; NetworkCommissioningCluster * cppCluster; - JniByteArray operationalDatasetArr(env, operationalDataset); + chip::app::Clusters::NetworkCommissioning::Commands::UpdateThreadNetwork::Type request; + + request.operationalDataset = chip::JniByteArray(env, static_cast(operationalDataset)).byteSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -13072,55 +6745,45 @@ JNI_METHOD(void, NetworkCommissioningCluster, updateThreadNetwork) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->UpdateThreadNetwork( - onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) operationalDatasetArr.data(), operationalDatasetArr.size()), breadcrumb, timeoutMs); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, NetworkCommissioningCluster, updateWiFiNetwork) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jbyteArray credentials, jlong breadcrumb, - jlong timeoutMs) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jbyteArray credentials, jobject breadcrumb, + jobject timeoutMs) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; NetworkCommissioningCluster * cppCluster; - JniByteArray ssidArr(env, ssid); - JniByteArray credentialsArr(env, credentials); + chip::app::Clusters::NetworkCommissioning::Commands::UpdateWiFiNetwork::Type request; + + request.ssid = chip::JniByteArray(env, static_cast(ssid)).byteSpan(); + request.credentials = chip::JniByteArray(env, static_cast(credentials)).byteSpan(); + request.breadcrumb = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(breadcrumb)); + request.timeoutMs = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(timeoutMs)); std::unique_ptr @@ -13128,44 +6791,29 @@ JNI_METHOD(void, NetworkCommissioningCluster, updateWiFiNetwork) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->UpdateWiFiNetwork( - onSuccess->Cancel(), onFailure->Cancel(), chip::ByteSpan((const uint8_t *) ssidArr.data(), ssidArr.size()), - chip::ByteSpan((const uint8_t *) credentialsArr.data(), credentialsArr.size()), breadcrumb, timeoutMs); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, OtaSoftwareUpdateProviderCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -13177,13 +6825,16 @@ JNI_METHOD(jlong, OtaSoftwareUpdateProviderCluster, initWithDevice)(JNIEnv * env } JNI_METHOD(void, OtaSoftwareUpdateProviderCluster, applyUpdateRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray updateToken, jlong newVersion) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray updateToken, jobject newVersion) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OtaSoftwareUpdateProviderCluster * cppCluster; - JniByteArray updateTokenArr(env, updateToken); + chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateRequest::Type request; + + request.updateToken = chip::JniByteArray(env, static_cast(updateToken)).byteSpan(); + request.newVersion = static_cast(chip::JniReferences::GetInstance().LongToPrimitive(newVersion)); std::unique_ptr @@ -13191,107 +6842,97 @@ JNI_METHOD(void, OtaSoftwareUpdateProviderCluster, applyUpdateRequest) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = - cppCluster->ApplyUpdateRequest(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) updateTokenArr.data(), updateTokenArr.size()), newVersion); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OtaSoftwareUpdateProviderCluster, notifyUpdateApplied) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray updateToken, jlong softwareVersion) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray updateToken, jobject softwareVersion) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OtaSoftwareUpdateProviderCluster * cppCluster; - JniByteArray updateTokenArr(env, updateToken); + chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::NotifyUpdateApplied::Type request; + + request.updateToken = chip::JniByteArray(env, static_cast(updateToken)).byteSpan(); + request.softwareVersion = + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(softwareVersion)); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->NotifyUpdateApplied(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) updateTokenArr.data(), updateTokenArr.size()), - softwareVersion); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OtaSoftwareUpdateProviderCluster, queryImage) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint vendorId, jint productId, jlong softwareVersion, - jint protocolsSupported, jint hardwareVersion, jstring location, jboolean requestorCanConsent, jbyteArray metadataForProvider) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject vendorId, jobject productId, jobject softwareVersion, + jobject protocolsSupported, jobject hardwareVersion, jobject location, jobject requestorCanConsent, jobject metadataForProvider) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OtaSoftwareUpdateProviderCluster * cppCluster; - JniUtfString locationStr(env, location); - JniByteArray metadataForProviderArr(env, metadataForProvider); + chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImage::Type request; + + request.vendorId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(vendorId)); + request.productId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(productId)); + request.softwareVersion = + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(softwareVersion)); + request.protocolsSupported = + chip::app::DataModel::List(); + chip::JniReferences::GetInstance().GetOptionalValue(hardwareVersion, hardwareVersion); + request.hardwareVersion = chip::Optional( + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(hardwareVersion))); + chip::JniReferences::GetInstance().GetOptionalValue(location, location); + request.location = chip::Optional(chip::JniUtfString(env, static_cast(location)).charSpan()); + chip::JniReferences::GetInstance().GetOptionalValue(requestorCanConsent, requestorCanConsent); + request.requestorCanConsent = chip::Optional(static_cast( + chip::JniReferences::GetInstance().BooleanToPrimitive(requestorCanConsent))); + chip::JniReferences::GetInstance().GetOptionalValue(metadataForProvider, metadataForProvider); + request.metadataForProvider = + chip::Optional(chip::JniByteArray(env, static_cast(metadataForProvider)).byteSpan()); std::unique_ptr @@ -13299,45 +6940,29 @@ JNI_METHOD(void, OtaSoftwareUpdateProviderCluster, queryImage) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->QueryImage(onSuccess->Cancel(), onFailure->Cancel(), static_cast(vendorId), productId, - softwareVersion, static_cast(protocolsSupported), hardwareVersion, - chip::CharSpan(locationStr.c_str(), strlen(locationStr.c_str())), requestorCanConsent, - chip::ByteSpan((const uint8_t *) metadataForProviderArr.data(), metadataForProviderArr.size())); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, OtaSoftwareUpdateRequestorCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -13349,57 +6974,50 @@ JNI_METHOD(jlong, OtaSoftwareUpdateRequestorCluster, initWithDevice)(JNIEnv * en } JNI_METHOD(void, OtaSoftwareUpdateRequestorCluster, announceOtaProvider) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong providerLocation, jint vendorId, jint announcementReason, - jbyteArray metadataForNode) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject providerLocation, jobject vendorId, + jobject announcementReason, jobject metadataForNode) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OtaSoftwareUpdateRequestorCluster * cppCluster; - JniByteArray metadataForNodeArr(env, metadataForNode); + chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::Type request; + + request.providerLocation = + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(providerLocation)); + request.vendorId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(vendorId)); + request.announcementReason = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(announcementReason)); + chip::JniReferences::GetInstance().GetOptionalValue(metadataForNode, metadataForNode); + request.metadataForNode = + chip::Optional(chip::JniByteArray(env, static_cast(metadataForNode)).byteSpan()); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AnnounceOtaProvider(onSuccess->Cancel(), onFailure->Cancel(), providerLocation, - static_cast(vendorId), static_cast(announcementReason), - chip::ByteSpan((const uint8_t *) metadataForNodeArr.data(), metadataForNodeArr.size())); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OtaSoftwareUpdateRequestorCluster, writeDefaultOtaProviderAttribute) @@ -13512,95 +7130,74 @@ JNI_METHOD(void, OnOffCluster, off)(JNIEnv * env, jobject self, jlong clusterPtr CHIP_ERROR err = CHIP_NO_ERROR; OnOffCluster * cppCluster; + chip::app::Clusters::OnOff::Commands::Off::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Off(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OnOffCluster, offWithEffect) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint effectId, jint effectVariant) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject effectId, jobject effectVariant) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OnOffCluster * cppCluster; + chip::app::Clusters::OnOff::Commands::OffWithEffect::Type request; + + request.effectId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(effectId)); + request.effectVariant = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(effectVariant)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->OffWithEffect(onSuccess->Cancel(), onFailure->Cancel(), static_cast(effectId), - static_cast(effectVariant)); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OnOffCluster, on)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -13608,46 +7205,34 @@ JNI_METHOD(void, OnOffCluster, on)(JNIEnv * env, jobject self, jlong clusterPtr, CHIP_ERROR err = CHIP_NO_ERROR; OnOffCluster * cppCluster; + chip::app::Clusters::OnOff::Commands::On::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->On(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OnOffCluster, onWithRecallGlobalScene)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -13655,94 +7240,76 @@ JNI_METHOD(void, OnOffCluster, onWithRecallGlobalScene)(JNIEnv * env, jobject se CHIP_ERROR err = CHIP_NO_ERROR; OnOffCluster * cppCluster; + chip::app::Clusters::OnOff::Commands::OnWithRecallGlobalScene::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->OnWithRecallGlobalScene(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OnOffCluster, onWithTimedOff) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint onOffControl, jint onTime, jint offWaitTime) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject onOffControl, jobject onTime, jobject offWaitTime) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OnOffCluster * cppCluster; + chip::app::Clusters::OnOff::Commands::OnWithTimedOff::Type request; + + request.onOffControl = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(onOffControl)); + request.onTime = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(onTime)); + request.offWaitTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(offWaitTime)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->OnWithTimedOff(onSuccess->Cancel(), onFailure->Cancel(), onOffControl, onTime, offWaitTime); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OnOffCluster, toggle)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -13750,46 +7317,34 @@ JNI_METHOD(void, OnOffCluster, toggle)(JNIEnv * env, jobject self, jlong cluster CHIP_ERROR err = CHIP_NO_ERROR; OnOffCluster * cppCluster; + chip::app::Clusters::OnOff::Commands::Toggle::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Toggle(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OnOffCluster, subscribeOnOffAttribute) @@ -13987,16 +7542,23 @@ JNI_METHOD(jlong, OperationalCredentialsCluster, initWithDevice)(JNIEnv * env, j } JNI_METHOD(void, OperationalCredentialsCluster, addNOC) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray NOCValue, jbyteArray ICACValue, jbyteArray IPKValue, - jlong caseAdminNode, jint adminVendorId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray NOCValue, jobject ICACValue, jbyteArray IPKValue, + jobject caseAdminNode, jobject adminVendorId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; - JniByteArray NOCValueArr(env, NOCValue); - JniByteArray ICACValueArr(env, ICACValue); - JniByteArray IPKValueArr(env, IPKValue); + chip::app::Clusters::OperationalCredentials::Commands::AddNOC::Type request; + + request.NOCValue = chip::JniByteArray(env, static_cast(NOCValue)).byteSpan(); + chip::JniReferences::GetInstance().GetOptionalValue(ICACValue, ICACValue); + request.ICACValue = chip::Optional(chip::JniByteArray(env, static_cast(ICACValue)).byteSpan()); + request.IPKValue = chip::JniByteArray(env, static_cast(IPKValue)).byteSpan(); + request.caseAdminNode = + static_cast(chip::JniReferences::GetInstance().LongToPrimitive(caseAdminNode)); + request.adminVendorId = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(adminVendorId)); std::unique_ptr @@ -14004,45 +7566,29 @@ JNI_METHOD(void, OperationalCredentialsCluster, addNOC) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AddNOC( - onSuccess->Cancel(), onFailure->Cancel(), chip::ByteSpan((const uint8_t *) NOCValueArr.data(), NOCValueArr.size()), - chip::ByteSpan((const uint8_t *) ICACValueArr.data(), ICACValueArr.size()), - chip::ByteSpan((const uint8_t *) IPKValueArr.data(), IPKValueArr.size()), caseAdminNode, adminVendorId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OperationalCredentialsCluster, addTrustedRootCertificate) (JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray rootCertificate) @@ -14051,50 +7597,36 @@ JNI_METHOD(void, OperationalCredentialsCluster, addTrustedRootCertificate) CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; - JniByteArray rootCertificateArr(env, rootCertificate); + chip::app::Clusters::OperationalCredentials::Commands::AddTrustedRootCertificate::Type request; + + request.rootCertificate = chip::JniByteArray(env, static_cast(rootCertificate)).byteSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AddTrustedRootCertificate( - onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) rootCertificateArr.data(), rootCertificateArr.size())); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OperationalCredentialsCluster, attestationRequest) (JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray attestationNonce) @@ -14103,7 +7635,9 @@ JNI_METHOD(void, OperationalCredentialsCluster, attestationRequest) CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; - JniByteArray attestationNonceArr(env, attestationNonce); + chip::app::Clusters::OperationalCredentials::Commands::AttestationRequest::Type request; + + request.attestationNonce = chip::JniByteArray(env, static_cast(attestationNonce)).byteSpan(); std::unique_ptr @@ -14111,93 +7645,72 @@ JNI_METHOD(void, OperationalCredentialsCluster, attestationRequest) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AttestationRequest(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) attestationNonceArr.data(), attestationNonceArr.size())); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OperationalCredentialsCluster, certificateChainRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint certificateType) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject certificateType) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; + chip::app::Clusters::OperationalCredentials::Commands::CertificateChainRequest::Type request; + + request.certificateType = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(certificateType)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->CertificateChainRequest(onSuccess->Cancel(), onFailure->Cancel(), certificateType); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OperationalCredentialsCluster, opCSRRequest) (JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray CSRNonce) @@ -14206,7 +7719,9 @@ JNI_METHOD(void, OperationalCredentialsCluster, opCSRRequest) CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; - JniByteArray CSRNonceArr(env, CSRNonce); + chip::app::Clusters::OperationalCredentials::Commands::OpCSRRequest::Type request; + + request.CSRNonce = chip::JniByteArray(env, static_cast(CSRNonce)).byteSpan(); std::unique_ptr @@ -14214,93 +7729,71 @@ JNI_METHOD(void, OperationalCredentialsCluster, opCSRRequest) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->OpCSRRequest(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) CSRNonceArr.data(), CSRNonceArr.size())); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OperationalCredentialsCluster, removeFabric) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint fabricIndex) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject fabricIndex) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; + chip::app::Clusters::OperationalCredentials::Commands::RemoveFabric::Type request; + + request.fabricIndex = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(fabricIndex)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RemoveFabric(onSuccess->Cancel(), onFailure->Cancel(), fabricIndex); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OperationalCredentialsCluster, removeTrustedRootCertificate) (JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray trustedRootIdentifier) @@ -14309,50 +7802,36 @@ JNI_METHOD(void, OperationalCredentialsCluster, removeTrustedRootCertificate) CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; - JniByteArray trustedRootIdentifierArr(env, trustedRootIdentifier); + chip::app::Clusters::OperationalCredentials::Commands::RemoveTrustedRootCertificate::Type request; + + request.trustedRootIdentifier = chip::JniByteArray(env, static_cast(trustedRootIdentifier)).byteSpan(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RemoveTrustedRootCertificate( - onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) trustedRootIdentifierArr.data(), trustedRootIdentifierArr.size())); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OperationalCredentialsCluster, updateFabricLabel) (JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring label) @@ -14361,7 +7840,9 @@ JNI_METHOD(void, OperationalCredentialsCluster, updateFabricLabel) CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; - JniUtfString labelStr(env, label); + chip::app::Clusters::OperationalCredentials::Commands::UpdateFabricLabel::Type request; + + request.label = chip::JniUtfString(env, static_cast(label)).charSpan(); std::unique_ptr @@ -14369,53 +7850,42 @@ JNI_METHOD(void, OperationalCredentialsCluster, updateFabricLabel) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->UpdateFabricLabel(onSuccess->Cancel(), onFailure->Cancel(), - chip::CharSpan(labelStr.c_str(), strlen(labelStr.c_str()))); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, OperationalCredentialsCluster, updateNOC) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray NOCValue, jbyteArray ICACValue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray NOCValue, jobject ICACValue) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; OperationalCredentialsCluster * cppCluster; - JniByteArray NOCValueArr(env, NOCValue); - JniByteArray ICACValueArr(env, ICACValue); + chip::app::Clusters::OperationalCredentials::Commands::UpdateNOC::Type request; + + request.NOCValue = chip::JniByteArray(env, static_cast(NOCValue)).byteSpan(); + chip::JniReferences::GetInstance().GetOptionalValue(ICACValue, ICACValue); + request.ICACValue = chip::Optional(chip::JniByteArray(env, static_cast(ICACValue)).byteSpan()); std::unique_ptr @@ -14423,44 +7893,29 @@ JNI_METHOD(void, OperationalCredentialsCluster, updateNOC) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->UpdateNOC(onSuccess->Cancel(), onFailure->Cancel(), - chip::ByteSpan((const uint8_t *) NOCValueArr.data(), NOCValueArr.size()), - chip::ByteSpan((const uint8_t *) ICACValueArr.data(), ICACValueArr.size())); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, PowerSourceCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -14847,349 +8302,291 @@ JNI_METHOD(jlong, ScenesCluster, initWithDevice)(JNIEnv * env, jobject self, jlo } JNI_METHOD(void, ScenesCluster, addScene) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId, jint transitionTime, jstring sceneName, - jlong clusterId, jint length, jint value) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId, jobject sceneId, jobject transitionTime, + jstring sceneName, jobject clusterId, jobject length, jobject value) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ScenesCluster * cppCluster; - JniUtfString sceneNameStr(env, sceneName); + chip::app::Clusters::Scenes::Commands::AddScene::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.sceneId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(sceneId)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + request.sceneName = chip::JniUtfString(env, static_cast(sceneName)).charSpan(); + request.extensionFieldSets = + chip::app::DataModel::List(); std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->AddScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId, transitionTime, - chip::CharSpan(sceneNameStr.c_str(), strlen(sceneNameStr.c_str())), clusterId, length, value); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, ScenesCluster, getSceneMembership)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId) +JNI_METHOD(void, ScenesCluster, getSceneMembership)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ScenesCluster * cppCluster; + chip::app::Clusters::Scenes::Commands::GetSceneMembership::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetSceneMembership(onSuccess->Cancel(), onFailure->Cancel(), groupId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ScenesCluster, recallScene) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId, jint transitionTime) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId, jobject sceneId, jobject transitionTime) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ScenesCluster * cppCluster; + chip::app::Clusters::Scenes::Commands::RecallScene::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.sceneId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(sceneId)); + request.transitionTime = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(transitionTime)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RecallScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId, transitionTime); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, ScenesCluster, removeAllScenes)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId) +JNI_METHOD(void, ScenesCluster, removeAllScenes)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ScenesCluster * cppCluster; + chip::app::Clusters::Scenes::Commands::RemoveAllScenes::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RemoveAllScenes(onSuccess->Cancel(), onFailure->Cancel(), groupId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ScenesCluster, removeScene) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId, jobject sceneId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ScenesCluster * cppCluster; + chip::app::Clusters::Scenes::Commands::RemoveScene::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.sceneId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(sceneId)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->RemoveScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ScenesCluster, storeScene) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId, jobject sceneId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ScenesCluster * cppCluster; + chip::app::Clusters::Scenes::Commands::StoreScene::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.sceneId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(sceneId)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StoreScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ScenesCluster, viewScene) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject groupId, jobject sceneId) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ScenesCluster * cppCluster; + chip::app::Clusters::Scenes::Commands::ViewScene::Type request; + + request.groupId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(groupId)); + request.sceneId = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(sceneId)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ViewScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, SoftwareDiagnosticsCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -15206,46 +8603,34 @@ JNI_METHOD(void, SoftwareDiagnosticsCluster, resetWatermarks)(JNIEnv * env, jobj CHIP_ERROR err = CHIP_NO_ERROR; SoftwareDiagnosticsCluster * cppCluster; + chip::app::Clusters::SoftwareDiagnostics::Commands::ResetWatermarks::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ResetWatermarks(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, SwitchCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -15325,7 +8710,9 @@ JNI_METHOD(void, TvChannelCluster, changeChannel)(JNIEnv * env, jobject self, jl CHIP_ERROR err = CHIP_NO_ERROR; TvChannelCluster * cppCluster; - JniUtfString matchStr(env, match); + chip::app::Clusters::TvChannel::Commands::ChangeChannel::Type request; + + request.match = chip::JniUtfString(env, static_cast(match)).charSpan(); std::unique_ptr @@ -15333,138 +8720,107 @@ JNI_METHOD(void, TvChannelCluster, changeChannel)(JNIEnv * env, jobject self, jl Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ChangeChannel(onSuccess->Cancel(), onFailure->Cancel(), - chip::CharSpan(matchStr.c_str(), strlen(matchStr.c_str()))); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TvChannelCluster, changeChannelByNumber) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint majorNumber, jint minorNumber) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject majorNumber, jobject minorNumber) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TvChannelCluster * cppCluster; + chip::app::Clusters::TvChannel::Commands::ChangeChannelByNumber::Type request; + + request.majorNumber = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(majorNumber)); + request.minorNumber = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(minorNumber)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ChangeChannelByNumber(onSuccess->Cancel(), onFailure->Cancel(), majorNumber, minorNumber); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } -JNI_METHOD(void, TvChannelCluster, skipChannel)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint count) +JNI_METHOD(void, TvChannelCluster, skipChannel)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject count) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TvChannelCluster * cppCluster; + chip::app::Clusters::TvChannel::Commands::SkipChannel::Type request; + + request.count = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(count)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SkipChannel(onSuccess->Cancel(), onFailure->Cancel(), count); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, TargetNavigatorCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -15476,13 +8832,16 @@ JNI_METHOD(jlong, TargetNavigatorCluster, initWithDevice)(JNIEnv * env, jobject } JNI_METHOD(void, TargetNavigatorCluster, navigateTarget) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint target, jstring data) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject target, jstring data) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TargetNavigatorCluster * cppCluster; - JniUtfString dataStr(env, data); + chip::app::Clusters::TargetNavigator::Commands::NavigateTarget::Type request; + + request.target = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(target)); + request.data = chip::JniUtfString(env, static_cast(data)).charSpan(); std::unique_ptr @@ -15490,43 +8849,29 @@ JNI_METHOD(void, TargetNavigatorCluster, navigateTarget) Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->NavigateTarget(onSuccess->Cancel(), onFailure->Cancel(), target, - chip::CharSpan(dataStr.c_str(), strlen(dataStr.c_str()))); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, TemperatureMeasurementCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -15663,299 +9008,239 @@ JNI_METHOD(void, TestClusterCluster, test)(JNIEnv * env, jobject self, jlong clu CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::Test::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->Test(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testAddArguments) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint arg1, jint arg2) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject arg1, jobject arg2) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::TestAddArguments::Type request; + + request.arg1 = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(arg1)); + request.arg2 = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(arg2)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestAddArguments(onSuccess->Cancel(), onFailure->Cancel(), arg1, arg2); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testEnumsRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint arg1, jint arg2) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject arg1, jobject arg2) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::TestEnumsRequest::Type request; + + request.arg1 = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(arg1)); + request.arg2 = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(arg2)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestEnumsRequest(onSuccess->Cancel(), onFailure->Cancel(), static_cast(arg1), - static_cast(arg2)); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testListInt8UArgumentRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint arg1) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject arg1) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::TestListInt8UArgumentRequest::Type request; + + request.arg1 = chip::app::DataModel::List(); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestListInt8UArgumentRequest(onSuccess->Cancel(), onFailure->Cancel(), arg1); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testListInt8UReverseRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint arg1) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject arg1) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::TestListInt8UReverseRequest::Type request; + + request.arg1 = chip::app::DataModel::List(); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestListInt8UReverseRequest(onSuccess->Cancel(), onFailure->Cancel(), arg1); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); + + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testListStructArgumentRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint a, jboolean b, jint c, jbyteArray d, jstring e, jint f) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject a, jobject b, jobject c, jbyteArray d, jstring e, + jobject f) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; - JniByteArray dArr(env, d); - JniUtfString eStr(env, e); + chip::app::Clusters::TestCluster::Commands::TestListStructArgumentRequest::Type request; + + request.arg1 = chip::app::DataModel::List(); std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestListStructArgumentRequest(onSuccess->Cancel(), onFailure->Cancel(), a, b, static_cast(c), - chip::ByteSpan((const uint8_t *) dArr.data(), dArr.size()), - chip::CharSpan(eStr.c_str(), strlen(eStr.c_str())), f); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testNotHandled)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -15963,96 +9248,82 @@ JNI_METHOD(void, TestClusterCluster, testNotHandled)(JNIEnv * env, jobject self, CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::TestNotHandled::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestNotHandled(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testNullableOptionalRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint arg1) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject arg1) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::TestNullableOptionalRequest::Type request; + + chip::JniReferences::GetInstance().GetOptionalValue(arg1, arg1); + uint8_t arg1Value; + if (arg1 != nullptr) + { + arg1Value = chip::JniReferences::GetInstance().IntegerToPrimitive(arg1); + } + request.arg1 = chip::Optional>( + arg1 == nullptr ? chip::app::DataModel::Nullable() : chip::app::DataModel::Nullable(arg1Value)); + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestNullableOptionalRequest(onSuccess->Cancel(), onFailure->Cancel(), arg1); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable( + onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testSpecific)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -16060,102 +9331,78 @@ JNI_METHOD(void, TestClusterCluster, testSpecific)(JNIEnv * env, jobject self, j CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::TestSpecific::Type request; + std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestSpecific(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testStructArgumentRequest) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint a, jboolean b, jint c, jbyteArray d, jstring e, jint f) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject a, jobject b, jobject c, jbyteArray d, jstring e, + jobject f) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; - JniByteArray dArr(env, d); - JniUtfString eStr(env, e); + chip::app::Clusters::TestCluster::Commands::TestStructArgumentRequest::Type request; + + request.arg1 = chip::app::Clusters::TestCluster::Structs::SimpleStruct::Type(); std::unique_ptr onSuccess(Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestStructArgumentRequest(onSuccess->Cancel(), onFailure->Cancel(), a, b, static_cast(c), - chip::ByteSpan((const uint8_t *) dArr.data(), dArr.size()), - chip::CharSpan(eStr.c_str(), strlen(eStr.c_str())), f); - SuccessOrExit(err); + auto successFn = + chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, testUnknownCommand)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -16163,46 +9410,34 @@ JNI_METHOD(void, TestClusterCluster, testUnknownCommand)(JNIEnv * env, jobject s CHIP_ERROR err = CHIP_NO_ERROR; TestClusterCluster * cppCluster; + chip::app::Clusters::TestCluster::Commands::TestUnknownCommand::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->TestUnknownCommand(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, TestClusterCluster, writeBooleanAttribute) @@ -17471,46 +10706,34 @@ JNI_METHOD(void, ThermostatCluster, clearWeeklySchedule)(JNIEnv * env, jobject s CHIP_ERROR err = CHIP_NO_ERROR; ThermostatCluster * cppCluster; + chip::app::Clusters::Thermostat::Commands::ClearWeeklySchedule::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ClearWeeklySchedule(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ThermostatCluster, getRelayStatusLog)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -17518,192 +10741,159 @@ JNI_METHOD(void, ThermostatCluster, getRelayStatusLog)(JNIEnv * env, jobject sel CHIP_ERROR err = CHIP_NO_ERROR; ThermostatCluster * cppCluster; + chip::app::Clusters::Thermostat::Commands::GetRelayStatusLog::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetRelayStatusLog(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ThermostatCluster, getWeeklySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint daysToReturn, jint modeToReturn) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject daysToReturn, jobject modeToReturn) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ThermostatCluster * cppCluster; + chip::app::Clusters::Thermostat::Commands::GetWeeklySchedule::Type request; + + request.daysToReturn = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(daysToReturn)); + request.modeToReturn = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(modeToReturn)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GetWeeklySchedule(onSuccess->Cancel(), onFailure->Cancel(), daysToReturn, modeToReturn); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ThermostatCluster, setWeeklySchedule) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint numberOfTransitionsForSequence, jint dayOfWeekForSequence, - jint modeForSequence, jint payload) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject numberOfTransitionsForSequence, + jobject dayOfWeekForSequence, jobject modeForSequence, jobject payload) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ThermostatCluster * cppCluster; + chip::app::Clusters::Thermostat::Commands::SetWeeklySchedule::Type request; + + request.numberOfTransitionsForSequence = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(numberOfTransitionsForSequence)); + request.dayOfWeekForSequence = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(dayOfWeekForSequence)); + request.modeForSequence = + static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(modeForSequence)); + request.payload = chip::app::DataModel::List(); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SetWeeklySchedule(onSuccess->Cancel(), onFailure->Cancel(), numberOfTransitionsForSequence, - dayOfWeekForSequence, modeForSequence, payload); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ThermostatCluster, setpointRaiseLower) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint mode, jint amount) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject mode, jobject amount) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; ThermostatCluster * cppCluster; + chip::app::Clusters::Thermostat::Commands::SetpointRaiseLower::Type request; + + request.mode = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(mode)); + request.amount = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(amount)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->SetpointRaiseLower(onSuccess->Cancel(), onFailure->Cancel(), static_cast(mode), amount); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, ThermostatCluster, subscribeLocalTemperatureAttribute) @@ -18161,46 +11351,34 @@ JNI_METHOD(void, ThreadNetworkDiagnosticsCluster, resetCounts)(JNIEnv * env, job CHIP_ERROR err = CHIP_NO_ERROR; ThreadNetworkDiagnosticsCluster * cppCluster; + chip::app::Clusters::ThreadNetworkDiagnostics::Commands::ResetCounts::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ResetCounts(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, WakeOnLanCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -18226,46 +11404,34 @@ JNI_METHOD(void, WiFiNetworkDiagnosticsCluster, resetCounts)(JNIEnv * env, jobje CHIP_ERROR err = CHIP_NO_ERROR; WiFiNetworkDiagnosticsCluster * cppCluster; + chip::app::Clusters::WiFiNetworkDiagnostics::Commands::ResetCounts::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->ResetCounts(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(jlong, WindowCoveringCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) { @@ -18282,238 +11448,192 @@ JNI_METHOD(void, WindowCoveringCluster, downOrClose)(JNIEnv * env, jobject self, CHIP_ERROR err = CHIP_NO_ERROR; WindowCoveringCluster * cppCluster; + chip::app::Clusters::WindowCovering::Commands::DownOrClose::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->DownOrClose(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, WindowCoveringCluster, goToLiftPercentage) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint liftPercentageValue, jint liftPercent100thsValue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject liftPercentageValue, jobject liftPercent100thsValue) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; WindowCoveringCluster * cppCluster; + chip::app::Clusters::WindowCovering::Commands::GoToLiftPercentage::Type request; + + request.liftPercentageValue = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(liftPercentageValue)); + request.liftPercent100thsValue = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(liftPercent100thsValue)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GoToLiftPercentage(onSuccess->Cancel(), onFailure->Cancel(), liftPercentageValue, liftPercent100thsValue); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, WindowCoveringCluster, goToLiftValue) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint liftValue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject liftValue) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; WindowCoveringCluster * cppCluster; + chip::app::Clusters::WindowCovering::Commands::GoToLiftValue::Type request; + + request.liftValue = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(liftValue)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GoToLiftValue(onSuccess->Cancel(), onFailure->Cancel(), liftValue); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, WindowCoveringCluster, goToTiltPercentage) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint tiltPercentageValue, jint tiltPercent100thsValue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject tiltPercentageValue, jobject tiltPercent100thsValue) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; WindowCoveringCluster * cppCluster; + chip::app::Clusters::WindowCovering::Commands::GoToTiltPercentage::Type request; + + request.tiltPercentageValue = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(tiltPercentageValue)); + request.tiltPercent100thsValue = static_cast( + chip::JniReferences::GetInstance().IntegerToPrimitive(tiltPercent100thsValue)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GoToTiltPercentage(onSuccess->Cancel(), onFailure->Cancel(), tiltPercentageValue, tiltPercent100thsValue); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, WindowCoveringCluster, goToTiltValue) -(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint tiltValue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jobject tiltValue) { chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CHIP_NO_ERROR; WindowCoveringCluster * cppCluster; + chip::app::Clusters::WindowCovering::Commands::GoToTiltValue::Type request; + + request.tiltValue = static_cast(chip::JniReferences::GetInstance().IntegerToPrimitive(tiltValue)); + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->GoToTiltValue(onSuccess->Cancel(), onFailure->Cancel(), tiltValue); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, WindowCoveringCluster, stopMotion)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -18521,46 +11641,34 @@ JNI_METHOD(void, WindowCoveringCluster, stopMotion)(JNIEnv * env, jobject self, CHIP_ERROR err = CHIP_NO_ERROR; WindowCoveringCluster * cppCluster; + chip::app::Clusters::WindowCovering::Commands::StopMotion::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->StopMotion(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, WindowCoveringCluster, upOrOpen)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) { @@ -18568,46 +11676,34 @@ JNI_METHOD(void, WindowCoveringCluster, upOrOpen)(JNIEnv * env, jobject self, jl CHIP_ERROR err = CHIP_NO_ERROR; WindowCoveringCluster * cppCluster; + chip::app::Clusters::WindowCovering::Commands::UpOrOpen::Type request; + std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); std::unique_ptr onFailure( Platform::New(callback), Platform::Delete); - VerifyOrExit(onSuccess.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(onFailure.get() != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(onSuccess.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); + VerifyOrReturn(onFailure.get() != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); cppCluster = reinterpret_cast(clusterPtr); - VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturn(cppCluster != nullptr, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException( + env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); - err = cppCluster->UpOrOpen(onSuccess->Cancel(), onFailure->Cancel()); - SuccessOrExit(err); + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); -exit: - if (err != CHIP_NO_ERROR) - { - jthrowable exception; - jmethodID method; - - err = JniReferences::GetInstance().FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - - err = chip::AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, "Error invoking cluster", err, - exception); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Error throwing IllegalStateException %" CHIP_ERROR_FORMAT, err.Format()); - return; - } - env->CallVoidMethod(callback, method, exception); - } - else - { - onSuccess.release(); - onFailure.release(); - } + err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, + AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", + CHIP_ERROR_INCORRECT_STATE)); + + onSuccess.release(); + onFailure.release(); } JNI_METHOD(void, WindowCoveringCluster, subscribeCurrentPositionLiftPercentageAttribute) diff --git a/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp b/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp new file mode 100644 index 00000000000000..4f81a6f70e1004 --- /dev/null +++ b/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp @@ -0,0 +1,5250 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// THIS FILE IS GENERATED BY ZAP +#include "CHIPInvokeCallbacks.h" +#include "CHIPCallbackTypes.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace chip { + +CHIPAccountLoginClusterGetSetupPINResponseCallback::CHIPAccountLoginClusterGetSetupPINResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPAccountLoginClusterGetSetupPINResponseCallback::~CHIPAccountLoginClusterGetSetupPINResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPAccountLoginClusterGetSetupPINResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject setupPIN; + + setupPIN = chip::UtfString(env, dataResponse.setupPIN).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, setupPIN); +} +CHIPApplicationLauncherClusterLaunchAppResponseCallback::CHIPApplicationLauncherClusterLaunchAppResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPApplicationLauncherClusterLaunchAppResponseCallback::~CHIPApplicationLauncherClusterLaunchAppResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPApplicationLauncherClusterLaunchAppResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ApplicationLauncher::Commands::LaunchAppResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject data; + + data = chip::UtfString(env, dataResponse.data).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, data); +} +CHIPContentLauncherClusterLaunchContentResponseCallback::CHIPContentLauncherClusterLaunchContentResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPContentLauncherClusterLaunchContentResponseCallback::~CHIPContentLauncherClusterLaunchContentResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPContentLauncherClusterLaunchContentResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ContentLauncher::Commands::LaunchContentResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject data; + + data = chip::UtfString(env, dataResponse.data).jniValue(); + jobject contentLaunchStatus; + + std::string contentLaunchStatusClassName = "java/lang/Integer"; + std::string contentLaunchStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(contentLaunchStatusClassName.c_str(), + contentLaunchStatusCtorSignature.c_str(), + dataResponse.contentLaunchStatus, contentLaunchStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, data, contentLaunchStatus); +} +CHIPContentLauncherClusterLaunchURLResponseCallback::CHIPContentLauncherClusterLaunchURLResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPContentLauncherClusterLaunchURLResponseCallback::~CHIPContentLauncherClusterLaunchURLResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPContentLauncherClusterLaunchURLResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ContentLauncher::Commands::LaunchURLResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject data; + + data = chip::UtfString(env, dataResponse.data).jniValue(); + jobject contentLaunchStatus; + + std::string contentLaunchStatusClassName = "java/lang/Integer"; + std::string contentLaunchStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(contentLaunchStatusClassName.c_str(), + contentLaunchStatusCtorSignature.c_str(), + dataResponse.contentLaunchStatus, contentLaunchStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, data, contentLaunchStatus); +} +CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback::CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback::~CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;[BLjava/lang/Long;Ljava/lang/Long;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject content; + + content = chip::ByteArray(env, dataResponse.content).jniValue(); + jobject timeStamp; + + std::string timeStampClassName = "java/lang/Long"; + std::string timeStampCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(timeStampClassName.c_str(), timeStampCtorSignature.c_str(), + dataResponse.timeStamp, timeStamp); + jobject timeSinceBoot; + + std::string timeSinceBootClassName = "java/lang/Long"; + std::string timeSinceBootCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + timeSinceBootClassName.c_str(), timeSinceBootCtorSignature.c_str(), dataResponse.timeSinceBoot, timeSinceBoot); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, content, timeStamp, timeSinceBoot); +} +CHIPDoorLockClusterClearAllPinsResponseCallback::CHIPDoorLockClusterClearAllPinsResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterClearAllPinsResponseCallback::~CHIPDoorLockClusterClearAllPinsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterClearAllPinsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::ClearAllPinsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterClearAllRfidsResponseCallback::CHIPDoorLockClusterClearAllRfidsResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterClearAllRfidsResponseCallback::~CHIPDoorLockClusterClearAllRfidsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterClearAllRfidsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::ClearAllRfidsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterClearHolidayScheduleResponseCallback::CHIPDoorLockClusterClearHolidayScheduleResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterClearHolidayScheduleResponseCallback::~CHIPDoorLockClusterClearHolidayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterClearHolidayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::ClearHolidayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterClearPinResponseCallback::CHIPDoorLockClusterClearPinResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterClearPinResponseCallback::~CHIPDoorLockClusterClearPinResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterClearPinResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::ClearPinResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterClearRfidResponseCallback::CHIPDoorLockClusterClearRfidResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterClearRfidResponseCallback::~CHIPDoorLockClusterClearRfidResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterClearRfidResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::ClearRfidResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterClearWeekdayScheduleResponseCallback::CHIPDoorLockClusterClearWeekdayScheduleResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterClearWeekdayScheduleResponseCallback::~CHIPDoorLockClusterClearWeekdayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterClearWeekdayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::ClearWeekdayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterClearYeardayScheduleResponseCallback::CHIPDoorLockClusterClearYeardayScheduleResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterClearYeardayScheduleResponseCallback::~CHIPDoorLockClusterClearYeardayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterClearYeardayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::ClearYeardayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterGetHolidayScheduleResponseCallback::CHIPDoorLockClusterGetHolidayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterGetHolidayScheduleResponseCallback::~CHIPDoorLockClusterGetHolidayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetHolidayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetHolidayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject scheduleId; + + std::string scheduleIdClassName = "java/lang/Integer"; + std::string scheduleIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(scheduleIdClassName.c_str(), scheduleIdCtorSignature.c_str(), + dataResponse.scheduleId, scheduleId); + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject localStartTime; + + std::string localStartTimeClassName = "java/lang/Long"; + std::string localStartTimeCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + localStartTimeClassName.c_str(), localStartTimeCtorSignature.c_str(), dataResponse.localStartTime, localStartTime); + jobject localEndTime; + + std::string localEndTimeClassName = "java/lang/Long"; + std::string localEndTimeCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(localEndTimeClassName.c_str(), localEndTimeCtorSignature.c_str(), + dataResponse.localEndTime, localEndTime); + jobject operatingModeDuringHoliday; + + std::string operatingModeDuringHolidayClassName = "java/lang/Integer"; + std::string operatingModeDuringHolidayCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + operatingModeDuringHolidayClassName.c_str(), operatingModeDuringHolidayCtorSignature.c_str(), + dataResponse.operatingModeDuringHoliday, operatingModeDuringHoliday); + + env->CallVoidMethod(javaCallbackRef, javaMethod, scheduleId, status, localStartTime, localEndTime, operatingModeDuringHoliday); +} +CHIPDoorLockClusterGetLogRecordResponseCallback::CHIPDoorLockClusterGetLogRecordResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterGetLogRecordResponseCallback::~CHIPDoorLockClusterGetLogRecordResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetLogRecordResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetLogRecordResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Long;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;[B)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject logEntryId; + + std::string logEntryIdClassName = "java/lang/Integer"; + std::string logEntryIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(logEntryIdClassName.c_str(), logEntryIdCtorSignature.c_str(), + dataResponse.logEntryId, logEntryId); + jobject timestamp; + + std::string timestampClassName = "java/lang/Long"; + std::string timestampCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(timestampClassName.c_str(), timestampCtorSignature.c_str(), + dataResponse.timestamp, timestamp); + jobject eventType; + + std::string eventTypeClassName = "java/lang/Integer"; + std::string eventTypeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(eventTypeClassName.c_str(), eventTypeCtorSignature.c_str(), + dataResponse.eventType, eventType); + jobject source; + + std::string sourceClassName = "java/lang/Integer"; + std::string sourceCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(sourceClassName.c_str(), sourceCtorSignature.c_str(), + dataResponse.source, source); + jobject eventIdOrAlarmCode; + + std::string eventIdOrAlarmCodeClassName = "java/lang/Integer"; + std::string eventIdOrAlarmCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(eventIdOrAlarmCodeClassName.c_str(), + eventIdOrAlarmCodeCtorSignature.c_str(), + dataResponse.eventIdOrAlarmCode, eventIdOrAlarmCode); + jobject userId; + + std::string userIdClassName = "java/lang/Integer"; + std::string userIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userIdClassName.c_str(), userIdCtorSignature.c_str(), + dataResponse.userId, userId); + jobject pin; + + pin = chip::ByteArray(env, dataResponse.pin).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, logEntryId, timestamp, eventType, source, eventIdOrAlarmCode, userId, pin); +} +CHIPDoorLockClusterGetPinResponseCallback::CHIPDoorLockClusterGetPinResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterGetPinResponseCallback::~CHIPDoorLockClusterGetPinResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetPinResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetPinResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;[B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject userId; + + std::string userIdClassName = "java/lang/Integer"; + std::string userIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userIdClassName.c_str(), userIdCtorSignature.c_str(), + dataResponse.userId, userId); + jobject userStatus; + + std::string userStatusClassName = "java/lang/Integer"; + std::string userStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userStatusClassName.c_str(), userStatusCtorSignature.c_str(), + dataResponse.userStatus, userStatus); + jobject userType; + + std::string userTypeClassName = "java/lang/Integer"; + std::string userTypeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userTypeClassName.c_str(), userTypeCtorSignature.c_str(), + dataResponse.userType, userType); + jobject pin; + + pin = chip::ByteArray(env, dataResponse.pin).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, userId, userStatus, userType, pin); +} +CHIPDoorLockClusterGetRfidResponseCallback::CHIPDoorLockClusterGetRfidResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterGetRfidResponseCallback::~CHIPDoorLockClusterGetRfidResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetRfidResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetRfidResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;[B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject userId; + + std::string userIdClassName = "java/lang/Integer"; + std::string userIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userIdClassName.c_str(), userIdCtorSignature.c_str(), + dataResponse.userId, userId); + jobject userStatus; + + std::string userStatusClassName = "java/lang/Integer"; + std::string userStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userStatusClassName.c_str(), userStatusCtorSignature.c_str(), + dataResponse.userStatus, userStatus); + jobject userType; + + std::string userTypeClassName = "java/lang/Integer"; + std::string userTypeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userTypeClassName.c_str(), userTypeCtorSignature.c_str(), + dataResponse.userType, userType); + jobject rfid; + + rfid = chip::ByteArray(env, dataResponse.rfid).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, userId, userStatus, userType, rfid); +} +CHIPDoorLockClusterGetUserTypeResponseCallback::CHIPDoorLockClusterGetUserTypeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterGetUserTypeResponseCallback::~CHIPDoorLockClusterGetUserTypeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetUserTypeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetUserTypeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject userId; + + std::string userIdClassName = "java/lang/Integer"; + std::string userIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userIdClassName.c_str(), userIdCtorSignature.c_str(), + dataResponse.userId, userId); + jobject userType; + + std::string userTypeClassName = "java/lang/Integer"; + std::string userTypeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userTypeClassName.c_str(), userTypeCtorSignature.c_str(), + dataResponse.userType, userType); + + env->CallVoidMethod(javaCallbackRef, javaMethod, userId, userType); +} +CHIPDoorLockClusterGetWeekdayScheduleResponseCallback::CHIPDoorLockClusterGetWeekdayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterGetWeekdayScheduleResponseCallback::~CHIPDoorLockClusterGetWeekdayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetWeekdayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetWeekdayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/" + "lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject scheduleId; + + std::string scheduleIdClassName = "java/lang/Integer"; + std::string scheduleIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(scheduleIdClassName.c_str(), scheduleIdCtorSignature.c_str(), + dataResponse.scheduleId, scheduleId); + jobject userId; + + std::string userIdClassName = "java/lang/Integer"; + std::string userIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userIdClassName.c_str(), userIdCtorSignature.c_str(), + dataResponse.userId, userId); + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject daysMask; + + std::string daysMaskClassName = "java/lang/Integer"; + std::string daysMaskCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(daysMaskClassName.c_str(), daysMaskCtorSignature.c_str(), + dataResponse.daysMask, daysMask); + jobject startHour; + + std::string startHourClassName = "java/lang/Integer"; + std::string startHourCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(startHourClassName.c_str(), startHourCtorSignature.c_str(), + dataResponse.startHour, startHour); + jobject startMinute; + + std::string startMinuteClassName = "java/lang/Integer"; + std::string startMinuteCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(startMinuteClassName.c_str(), startMinuteCtorSignature.c_str(), + dataResponse.startMinute, startMinute); + jobject endHour; + + std::string endHourClassName = "java/lang/Integer"; + std::string endHourCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(endHourClassName.c_str(), endHourCtorSignature.c_str(), + dataResponse.endHour, endHour); + jobject endMinute; + + std::string endMinuteClassName = "java/lang/Integer"; + std::string endMinuteCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(endMinuteClassName.c_str(), endMinuteCtorSignature.c_str(), + dataResponse.endMinute, endMinute); + + env->CallVoidMethod(javaCallbackRef, javaMethod, scheduleId, userId, status, daysMask, startHour, startMinute, endHour, + endMinute); +} +CHIPDoorLockClusterGetYeardayScheduleResponseCallback::CHIPDoorLockClusterGetYeardayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterGetYeardayScheduleResponseCallback::~CHIPDoorLockClusterGetYeardayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetYeardayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetYeardayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Long;Ljava/lang/Long;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject scheduleId; + + std::string scheduleIdClassName = "java/lang/Integer"; + std::string scheduleIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(scheduleIdClassName.c_str(), scheduleIdCtorSignature.c_str(), + dataResponse.scheduleId, scheduleId); + jobject userId; + + std::string userIdClassName = "java/lang/Integer"; + std::string userIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userIdClassName.c_str(), userIdCtorSignature.c_str(), + dataResponse.userId, userId); + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject localStartTime; + + std::string localStartTimeClassName = "java/lang/Long"; + std::string localStartTimeCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + localStartTimeClassName.c_str(), localStartTimeCtorSignature.c_str(), dataResponse.localStartTime, localStartTime); + jobject localEndTime; + + std::string localEndTimeClassName = "java/lang/Long"; + std::string localEndTimeCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(localEndTimeClassName.c_str(), localEndTimeCtorSignature.c_str(), + dataResponse.localEndTime, localEndTime); + + env->CallVoidMethod(javaCallbackRef, javaMethod, scheduleId, userId, status, localStartTime, localEndTime); +} +CHIPDoorLockClusterLockDoorResponseCallback::CHIPDoorLockClusterLockDoorResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterLockDoorResponseCallback::~CHIPDoorLockClusterLockDoorResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterLockDoorResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::LockDoorResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterSetHolidayScheduleResponseCallback::CHIPDoorLockClusterSetHolidayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterSetHolidayScheduleResponseCallback::~CHIPDoorLockClusterSetHolidayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterSetHolidayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::SetHolidayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterSetPinResponseCallback::CHIPDoorLockClusterSetPinResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterSetPinResponseCallback::~CHIPDoorLockClusterSetPinResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterSetPinResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::SetPinResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterSetRfidResponseCallback::CHIPDoorLockClusterSetRfidResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterSetRfidResponseCallback::~CHIPDoorLockClusterSetRfidResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterSetRfidResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::SetRfidResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterSetUserTypeResponseCallback::CHIPDoorLockClusterSetUserTypeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterSetUserTypeResponseCallback::~CHIPDoorLockClusterSetUserTypeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterSetUserTypeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::SetUserTypeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterSetWeekdayScheduleResponseCallback::CHIPDoorLockClusterSetWeekdayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterSetWeekdayScheduleResponseCallback::~CHIPDoorLockClusterSetWeekdayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterSetWeekdayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::SetWeekdayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterSetYeardayScheduleResponseCallback::CHIPDoorLockClusterSetYeardayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterSetYeardayScheduleResponseCallback::~CHIPDoorLockClusterSetYeardayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterSetYeardayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::SetYeardayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterUnlockDoorResponseCallback::CHIPDoorLockClusterUnlockDoorResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterUnlockDoorResponseCallback::~CHIPDoorLockClusterUnlockDoorResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterUnlockDoorResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::UnlockDoorResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPDoorLockClusterUnlockWithTimeoutResponseCallback::CHIPDoorLockClusterUnlockWithTimeoutResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPDoorLockClusterUnlockWithTimeoutResponseCallback::~CHIPDoorLockClusterUnlockWithTimeoutResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterUnlockWithTimeoutResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::UnlockWithTimeoutResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPGeneralCommissioningClusterArmFailSafeResponseCallback::CHIPGeneralCommissioningClusterArmFailSafeResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPGeneralCommissioningClusterArmFailSafeResponseCallback::~CHIPGeneralCommissioningClusterArmFailSafeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGeneralCommissioningClusterArmFailSafeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::GeneralCommissioning::Commands::ArmFailSafeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback:: + CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback:: + ~CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::GeneralCommissioning::Commands::CommissioningCompleteResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback:: + CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback:: + ~CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::GeneralCommissioning::Commands::SetRegulatoryConfigResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPGroupsClusterAddGroupResponseCallback::CHIPGroupsClusterAddGroupResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPGroupsClusterAddGroupResponseCallback::~CHIPGroupsClusterAddGroupResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupsClusterAddGroupResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Groups::Commands::AddGroupResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, groupId); +} +CHIPGroupsClusterGetGroupMembershipResponseCallback::CHIPGroupsClusterGetGroupMembershipResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPGroupsClusterGetGroupMembershipResponseCallback::~CHIPGroupsClusterGetGroupMembershipResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupsClusterGetGroupMembershipResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Groups::Commands::GetGroupMembershipResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject capacity; + + std::string capacityClassName = "java/lang/Integer"; + std::string capacityCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(capacityClassName.c_str(), capacityCtorSignature.c_str(), + dataResponse.capacity, capacity); + jobject groupCount; + + std::string groupCountClassName = "java/lang/Integer"; + std::string groupCountCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupCountClassName.c_str(), groupCountCtorSignature.c_str(), + dataResponse.groupCount, groupCount); + jobject groupList; + + groupList = nullptr; /* Array - Conversion from this type to Java is not properly implemented yet */ + + env->CallVoidMethod(javaCallbackRef, javaMethod, capacity, groupCount, groupList); +} +CHIPGroupsClusterRemoveGroupResponseCallback::CHIPGroupsClusterRemoveGroupResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPGroupsClusterRemoveGroupResponseCallback::~CHIPGroupsClusterRemoveGroupResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupsClusterRemoveGroupResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Groups::Commands::RemoveGroupResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, groupId); +} +CHIPGroupsClusterViewGroupResponseCallback::CHIPGroupsClusterViewGroupResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPGroupsClusterViewGroupResponseCallback::~CHIPGroupsClusterViewGroupResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupsClusterViewGroupResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Groups::Commands::ViewGroupResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + jobject groupName; + + groupName = chip::UtfString(env, dataResponse.groupName).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, groupId, groupName); +} +CHIPIdentifyClusterIdentifyQueryResponseCallback::CHIPIdentifyClusterIdentifyQueryResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPIdentifyClusterIdentifyQueryResponseCallback::~CHIPIdentifyClusterIdentifyQueryResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPIdentifyClusterIdentifyQueryResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Identify::Commands::IdentifyQueryResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject timeout; + + std::string timeoutClassName = "java/lang/Integer"; + std::string timeoutCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(timeoutClassName.c_str(), timeoutCtorSignature.c_str(), + dataResponse.timeout, timeout); + + env->CallVoidMethod(javaCallbackRef, javaMethod, timeout); +} +CHIPKeypadInputClusterSendKeyResponseCallback::CHIPKeypadInputClusterSendKeyResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPKeypadInputClusterSendKeyResponseCallback::~CHIPKeypadInputClusterSendKeyResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPKeypadInputClusterSendKeyResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::KeypadInput::Commands::SendKeyResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status); +} +CHIPMediaPlaybackClusterMediaFastForwardResponseCallback::CHIPMediaPlaybackClusterMediaFastForwardResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaFastForwardResponseCallback::~CHIPMediaPlaybackClusterMediaFastForwardResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaFastForwardResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaFastForwardResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaNextResponseCallback::CHIPMediaPlaybackClusterMediaNextResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaNextResponseCallback::~CHIPMediaPlaybackClusterMediaNextResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaNextResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaNextResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaPauseResponseCallback::CHIPMediaPlaybackClusterMediaPauseResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaPauseResponseCallback::~CHIPMediaPlaybackClusterMediaPauseResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaPauseResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaPauseResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaPlayResponseCallback::CHIPMediaPlaybackClusterMediaPlayResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaPlayResponseCallback::~CHIPMediaPlaybackClusterMediaPlayResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaPlayResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaPlayResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaPreviousResponseCallback::CHIPMediaPlaybackClusterMediaPreviousResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaPreviousResponseCallback::~CHIPMediaPlaybackClusterMediaPreviousResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaPreviousResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaPreviousResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaRewindResponseCallback::CHIPMediaPlaybackClusterMediaRewindResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaRewindResponseCallback::~CHIPMediaPlaybackClusterMediaRewindResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaRewindResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaRewindResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaSeekResponseCallback::CHIPMediaPlaybackClusterMediaSeekResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaSeekResponseCallback::~CHIPMediaPlaybackClusterMediaSeekResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaSeekResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaSeekResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback::CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback::~CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaSkipBackwardResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback::CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback::~CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaSkipForwardResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaStartOverResponseCallback::CHIPMediaPlaybackClusterMediaStartOverResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaStartOverResponseCallback::~CHIPMediaPlaybackClusterMediaStartOverResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaStartOverResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaStartOverResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPMediaPlaybackClusterMediaStopResponseCallback::CHIPMediaPlaybackClusterMediaStopResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPMediaPlaybackClusterMediaStopResponseCallback::~CHIPMediaPlaybackClusterMediaStopResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterMediaStopResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::MediaStopResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject mediaPlaybackStatus; + + std::string mediaPlaybackStatusClassName = "java/lang/Integer"; + std::string mediaPlaybackStatusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(mediaPlaybackStatusClassName.c_str(), + mediaPlaybackStatusCtorSignature.c_str(), + dataResponse.mediaPlaybackStatus, mediaPlaybackStatus); + + env->CallVoidMethod(javaCallbackRef, javaMethod, mediaPlaybackStatus); +} +CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback::CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback::~CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::AddThreadNetworkResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback::CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback::~CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::AddWiFiNetworkResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPNetworkCommissioningClusterDisableNetworkResponseCallback::CHIPNetworkCommissioningClusterDisableNetworkResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPNetworkCommissioningClusterDisableNetworkResponseCallback::~CHIPNetworkCommissioningClusterDisableNetworkResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterDisableNetworkResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::DisableNetworkResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPNetworkCommissioningClusterEnableNetworkResponseCallback::CHIPNetworkCommissioningClusterEnableNetworkResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPNetworkCommissioningClusterEnableNetworkResponseCallback::~CHIPNetworkCommissioningClusterEnableNetworkResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterEnableNetworkResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::EnableNetworkResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback::CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback::~CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::RemoveNetworkResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPNetworkCommissioningClusterScanNetworksResponseCallback::CHIPNetworkCommissioningClusterScanNetworksResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPNetworkCommissioningClusterScanNetworksResponseCallback::~CHIPNetworkCommissioningClusterScanNetworksResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterScanNetworksResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::ScanNetworksResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + jobject wifiScanResults; + + wifiScanResults = nullptr; /* Array - Conversion from this type to Java is not properly implemented yet */ + jobject threadScanResults; + + threadScanResults = nullptr; /* Array - Conversion from this type to Java is not properly implemented yet */ + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText, wifiScanResults, threadScanResults); +} +CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback:: + CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback:: + ~CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::UpdateThreadNetworkResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback::CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback:: + ~CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::UpdateWiFiNetworkResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject errorCode; + + std::string errorCodeClassName = "java/lang/Integer"; + std::string errorCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(errorCodeClassName.c_str(), errorCodeCtorSignature.c_str(), + dataResponse.errorCode, errorCode); + jobject debugText; + + debugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, errorCode, debugText); +} +CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback::CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback::~CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Long;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject action; + + std::string actionClassName = "java/lang/Integer"; + std::string actionCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(actionClassName.c_str(), actionCtorSignature.c_str(), + dataResponse.action, action); + jobject delayedActionTime; + + std::string delayedActionTimeClassName = "java/lang/Long"; + std::string delayedActionTimeCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(delayedActionTimeClassName.c_str(), + delayedActionTimeCtorSignature.c_str(), + dataResponse.delayedActionTime, delayedActionTime); + + env->CallVoidMethod(javaCallbackRef, javaMethod, action, delayedActionTime); +} +CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback::CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback::~CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/" + "Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject delayedActionTime; + if (!dataResponse.delayedActionTime.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, delayedActionTime); + } + else + { + + std::string delayedActionTimeClassName = "java/lang/Long"; + std::string delayedActionTimeCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(delayedActionTimeClassName.c_str(), + delayedActionTimeCtorSignature.c_str(), + dataResponse.delayedActionTime.Value(), delayedActionTime); + chip::JniReferences::GetInstance().CreateOptional(delayedActionTime, delayedActionTime); + } + jobject imageURI; + if (!dataResponse.imageURI.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, imageURI); + } + else + { + + imageURI = chip::UtfString(env, dataResponse.imageURI.Value()).jniValue(); + chip::JniReferences::GetInstance().CreateOptional(imageURI, imageURI); + } + jobject softwareVersion; + if (!dataResponse.softwareVersion.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, softwareVersion); + } + else + { + + std::string softwareVersionClassName = "java/lang/Long"; + std::string softwareVersionCtorSignature = "(J)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(softwareVersionClassName.c_str(), + softwareVersionCtorSignature.c_str(), + dataResponse.softwareVersion.Value(), softwareVersion); + chip::JniReferences::GetInstance().CreateOptional(softwareVersion, softwareVersion); + } + jobject softwareVersionString; + if (!dataResponse.softwareVersionString.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, softwareVersionString); + } + else + { + + softwareVersionString = chip::UtfString(env, dataResponse.softwareVersionString.Value()).jniValue(); + chip::JniReferences::GetInstance().CreateOptional(softwareVersionString, softwareVersionString); + } + jobject updateToken; + if (!dataResponse.updateToken.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, updateToken); + } + else + { + + updateToken = chip::ByteArray(env, dataResponse.updateToken.Value()).jniValue(); + chip::JniReferences::GetInstance().CreateOptional(updateToken, updateToken); + } + jobject userConsentNeeded; + if (!dataResponse.userConsentNeeded.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, userConsentNeeded); + } + else + { + + std::string userConsentNeededClassName = "java/lang/Boolean"; + std::string userConsentNeededCtorSignature = "(Z)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(userConsentNeededClassName.c_str(), + userConsentNeededCtorSignature.c_str(), + dataResponse.userConsentNeeded.Value(), userConsentNeeded); + chip::JniReferences::GetInstance().CreateOptional(userConsentNeeded, userConsentNeeded); + } + jobject metadataForRequestor; + if (!dataResponse.metadataForRequestor.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, metadataForRequestor); + } + else + { + + metadataForRequestor = chip::ByteArray(env, dataResponse.metadataForRequestor.Value()).jniValue(); + chip::JniReferences::GetInstance().CreateOptional(metadataForRequestor, metadataForRequestor); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, delayedActionTime, imageURI, softwareVersion, softwareVersionString, + updateToken, userConsentNeeded, metadataForRequestor); +} +CHIPOperationalCredentialsClusterAttestationResponseCallback::CHIPOperationalCredentialsClusterAttestationResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPOperationalCredentialsClusterAttestationResponseCallback::~CHIPOperationalCredentialsClusterAttestationResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalCredentialsClusterAttestationResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::OperationalCredentials::Commands::AttestationResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B[B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject AttestationElements; + + AttestationElements = chip::ByteArray(env, dataResponse.attestationElements).jniValue(); + jobject Signature; + + Signature = chip::ByteArray(env, dataResponse.signature).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, AttestationElements, Signature); +} +CHIPOperationalCredentialsClusterCertificateChainResponseCallback:: + CHIPOperationalCredentialsClusterCertificateChainResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPOperationalCredentialsClusterCertificateChainResponseCallback:: + ~CHIPOperationalCredentialsClusterCertificateChainResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalCredentialsClusterCertificateChainResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::OperationalCredentials::Commands::CertificateChainResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Certificate; + + Certificate = chip::ByteArray(env, dataResponse.certificate).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Certificate); +} +CHIPOperationalCredentialsClusterNOCResponseCallback::CHIPOperationalCredentialsClusterNOCResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPOperationalCredentialsClusterNOCResponseCallback::~CHIPOperationalCredentialsClusterNOCResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalCredentialsClusterNOCResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::OperationalCredentials::Commands::NOCResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject StatusCode; + + std::string StatusCodeClassName = "java/lang/Integer"; + std::string StatusCodeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(StatusCodeClassName.c_str(), StatusCodeCtorSignature.c_str(), + dataResponse.statusCode, StatusCode); + jobject FabricIndex; + + std::string FabricIndexClassName = "java/lang/Integer"; + std::string FabricIndexCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(FabricIndexClassName.c_str(), FabricIndexCtorSignature.c_str(), + dataResponse.fabricIndex, FabricIndex); + jobject DebugText; + + DebugText = chip::UtfString(env, dataResponse.debugText).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, StatusCode, FabricIndex, DebugText); +} +CHIPOperationalCredentialsClusterOpCSRResponseCallback::CHIPOperationalCredentialsClusterOpCSRResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPOperationalCredentialsClusterOpCSRResponseCallback::~CHIPOperationalCredentialsClusterOpCSRResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalCredentialsClusterOpCSRResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::OperationalCredentials::Commands::OpCSRResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B[B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject NOCSRElements; + + NOCSRElements = chip::ByteArray(env, dataResponse.NOCSRElements).jniValue(); + jobject AttestationSignature; + + AttestationSignature = chip::ByteArray(env, dataResponse.attestationSignature).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, NOCSRElements, AttestationSignature); +} +CHIPScenesClusterAddSceneResponseCallback::CHIPScenesClusterAddSceneResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPScenesClusterAddSceneResponseCallback::~CHIPScenesClusterAddSceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesClusterAddSceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Scenes::Commands::AddSceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + jobject sceneId; + + std::string sceneIdClassName = "java/lang/Integer"; + std::string sceneIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(sceneIdClassName.c_str(), sceneIdCtorSignature.c_str(), + dataResponse.sceneId, sceneId); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, groupId, sceneId); +} +CHIPScenesClusterGetSceneMembershipResponseCallback::CHIPScenesClusterGetSceneMembershipResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPScenesClusterGetSceneMembershipResponseCallback::~CHIPScenesClusterGetSceneMembershipResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesClusterGetSceneMembershipResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Scenes::Commands::GetSceneMembershipResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject capacity; + + std::string capacityClassName = "java/lang/Integer"; + std::string capacityCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(capacityClassName.c_str(), capacityCtorSignature.c_str(), + dataResponse.capacity, capacity); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + jobject sceneCount; + + std::string sceneCountClassName = "java/lang/Integer"; + std::string sceneCountCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(sceneCountClassName.c_str(), sceneCountCtorSignature.c_str(), + dataResponse.sceneCount, sceneCount); + jobject sceneList; + + sceneList = nullptr; /* Array - Conversion from this type to Java is not properly implemented yet */ + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, capacity, groupId, sceneCount, sceneList); +} +CHIPScenesClusterRemoveAllScenesResponseCallback::CHIPScenesClusterRemoveAllScenesResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPScenesClusterRemoveAllScenesResponseCallback::~CHIPScenesClusterRemoveAllScenesResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesClusterRemoveAllScenesResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Scenes::Commands::RemoveAllScenesResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, groupId); +} +CHIPScenesClusterRemoveSceneResponseCallback::CHIPScenesClusterRemoveSceneResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPScenesClusterRemoveSceneResponseCallback::~CHIPScenesClusterRemoveSceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesClusterRemoveSceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Scenes::Commands::RemoveSceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + jobject sceneId; + + std::string sceneIdClassName = "java/lang/Integer"; + std::string sceneIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(sceneIdClassName.c_str(), sceneIdCtorSignature.c_str(), + dataResponse.sceneId, sceneId); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, groupId, sceneId); +} +CHIPScenesClusterStoreSceneResponseCallback::CHIPScenesClusterStoreSceneResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPScenesClusterStoreSceneResponseCallback::~CHIPScenesClusterStoreSceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesClusterStoreSceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Scenes::Commands::StoreSceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + jobject sceneId; + + std::string sceneIdClassName = "java/lang/Integer"; + std::string sceneIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(sceneIdClassName.c_str(), sceneIdCtorSignature.c_str(), + dataResponse.sceneId, sceneId); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, groupId, sceneId); +} +CHIPScenesClusterViewSceneResponseCallback::CHIPScenesClusterViewSceneResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPScenesClusterViewSceneResponseCallback::~CHIPScenesClusterViewSceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesClusterViewSceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Scenes::Commands::ViewSceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject groupId; + + std::string groupIdClassName = "java/lang/Integer"; + std::string groupIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(groupIdClassName.c_str(), groupIdCtorSignature.c_str(), + dataResponse.groupId, groupId); + jobject sceneId; + + std::string sceneIdClassName = "java/lang/Integer"; + std::string sceneIdCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(sceneIdClassName.c_str(), sceneIdCtorSignature.c_str(), + dataResponse.sceneId, sceneId); + jobject transitionTime; + + std::string transitionTimeClassName = "java/lang/Integer"; + std::string transitionTimeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + transitionTimeClassName.c_str(), transitionTimeCtorSignature.c_str(), dataResponse.transitionTime, transitionTime); + jobject sceneName; + + sceneName = chip::UtfString(env, dataResponse.sceneName).jniValue(); + jobject extensionFieldSets; + + extensionFieldSets = nullptr; /* Array - Conversion from this type to Java is not properly implemented yet */ + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, groupId, sceneId, transitionTime, sceneName, extensionFieldSets); +} +CHIPTvChannelClusterChangeChannelResponseCallback::CHIPTvChannelClusterChangeChannelResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPTvChannelClusterChangeChannelResponseCallback::~CHIPTvChannelClusterChangeChannelResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTvChannelClusterChangeChannelResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TvChannel::Commands::ChangeChannelResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject ChannelMatch; + + ChannelMatch = nullptr; /* Array - Conversion from this type to Java is not properly implemented yet */ + jobject ErrorType; + + std::string ErrorTypeClassName = "java/lang/Integer"; + std::string ErrorTypeCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(ErrorTypeClassName.c_str(), ErrorTypeCtorSignature.c_str(), + dataResponse.errorType, ErrorType); + + env->CallVoidMethod(javaCallbackRef, javaMethod, ChannelMatch, ErrorType); +} +CHIPTargetNavigatorClusterNavigateTargetResponseCallback::CHIPTargetNavigatorClusterNavigateTargetResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPTargetNavigatorClusterNavigateTargetResponseCallback::~CHIPTargetNavigatorClusterNavigateTargetResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTargetNavigatorClusterNavigateTargetResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject status; + + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), + dataResponse.status, status); + jobject data; + + data = chip::UtfString(env, dataResponse.data).jniValue(); + + env->CallVoidMethod(javaCallbackRef, javaMethod, status, data); +} +CHIPTestClusterClusterBooleanResponseCallback::CHIPTestClusterClusterBooleanResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPTestClusterClusterBooleanResponseCallback::~CHIPTestClusterClusterBooleanResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTestClusterClusterBooleanResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TestCluster::Commands::BooleanResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Boolean;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject value; + + std::string valueClassName = "java/lang/Boolean"; + std::string valueCtorSignature = "(Z)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), + dataResponse.value, value); + + env->CallVoidMethod(javaCallbackRef, javaMethod, value); +} +CHIPTestClusterClusterTestAddArgumentsResponseCallback::CHIPTestClusterClusterTestAddArgumentsResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPTestClusterClusterTestAddArgumentsResponseCallback::~CHIPTestClusterClusterTestAddArgumentsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTestClusterClusterTestAddArgumentsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TestCluster::Commands::TestAddArgumentsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject returnValue; + + std::string returnValueClassName = "java/lang/Integer"; + std::string returnValueCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(returnValueClassName.c_str(), returnValueCtorSignature.c_str(), + dataResponse.returnValue, returnValue); + + env->CallVoidMethod(javaCallbackRef, javaMethod, returnValue); +} +CHIPTestClusterClusterTestEnumsResponseCallback::CHIPTestClusterClusterTestEnumsResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPTestClusterClusterTestEnumsResponseCallback::~CHIPTestClusterClusterTestEnumsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTestClusterClusterTestEnumsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TestCluster::Commands::TestEnumsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject arg1; + + std::string arg1ClassName = "java/lang/Integer"; + std::string arg1CtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(arg1ClassName.c_str(), arg1CtorSignature.c_str(), + dataResponse.arg1, arg1); + jobject arg2; + + std::string arg2ClassName = "java/lang/Integer"; + std::string arg2CtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(arg2ClassName.c_str(), arg2CtorSignature.c_str(), + dataResponse.arg2, arg2); + + env->CallVoidMethod(javaCallbackRef, javaMethod, arg1, arg2); +} +CHIPTestClusterClusterTestListInt8UReverseResponseCallback::CHIPTestClusterClusterTestListInt8UReverseResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPTestClusterClusterTestListInt8UReverseResponseCallback::~CHIPTestClusterClusterTestListInt8UReverseResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTestClusterClusterTestListInt8UReverseResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TestCluster::Commands::TestListInt8UReverseResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject arg1; + + arg1 = nullptr; /* Array - Conversion from this type to Java is not properly implemented yet */ + + env->CallVoidMethod(javaCallbackRef, javaMethod, arg1); +} +CHIPTestClusterClusterTestNullableOptionalResponseCallback::CHIPTestClusterClusterTestNullableOptionalResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPTestClusterClusterTestNullableOptionalResponseCallback::~CHIPTestClusterClusterTestNullableOptionalResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTestClusterClusterTestNullableOptionalResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TestCluster::Commands::TestNullableOptionalResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Ljava/lang/Boolean;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject wasPresent; + + std::string wasPresentClassName = "java/lang/Boolean"; + std::string wasPresentCtorSignature = "(Z)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(wasPresentClassName.c_str(), wasPresentCtorSignature.c_str(), + dataResponse.wasPresent, wasPresent); + jobject wasNull; + if (!dataResponse.wasNull.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, wasNull); + } + else + { + + std::string wasNullClassName = "java/lang/Boolean"; + std::string wasNullCtorSignature = "(Z)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(wasNullClassName.c_str(), wasNullCtorSignature.c_str(), + dataResponse.wasNull.Value(), wasNull); + chip::JniReferences::GetInstance().CreateOptional(wasNull, wasNull); + } + jobject value; + if (!dataResponse.value.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, value); + } + else + { + + std::string valueClassName = "java/lang/Integer"; + std::string valueCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), + dataResponse.value.Value(), value); + chip::JniReferences::GetInstance().CreateOptional(value, value); + } + jobject originalValue; + if (!dataResponse.originalValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, originalValue); + } + else + { + if (dataResponse.originalValue.Value().IsNull()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, originalValue); + } + else + { + + std::string originalValueClassName = "java/lang/Integer"; + std::string originalValueCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + originalValueClassName.c_str(), originalValueCtorSignature.c_str(), dataResponse.originalValue.Value().Value(), + originalValue); + chip::JniReferences::GetInstance().CreateOptional(originalValue, originalValue); + } + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, wasPresent, wasNull, value, originalValue); +} +CHIPTestClusterClusterTestSpecificResponseCallback::CHIPTestClusterClusterTestSpecificResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = 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"); + } +} + +CHIPTestClusterClusterTestSpecificResponseCallback::~CHIPTestClusterClusterTestSpecificResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTestClusterClusterTestSpecificResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TestCluster::Commands::TestSpecificResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject returnValue; + + std::string returnValueClassName = "java/lang/Integer"; + std::string returnValueCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(returnValueClassName.c_str(), returnValueCtorSignature.c_str(), + dataResponse.returnValue, returnValue); + + env->CallVoidMethod(javaCallbackRef, javaMethod, returnValue); +} +} // namespace chip diff --git a/src/controller/java/zap-generated/CHIPInvokeCallbacks.h b/src/controller/java/zap-generated/CHIPInvokeCallbacks.h new file mode 100644 index 00000000000000..ed66dbd7eee44e --- /dev/null +++ b/src/controller/java/zap-generated/CHIPInvokeCallbacks.h @@ -0,0 +1,1139 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// THIS FILE IS GENERATED BY ZAP +#include "CHIPCallbackTypes.h" + +#include +#include +#include + +namespace chip { + +class CHIPAccountLoginClusterGetSetupPINResponseCallback + : public Callback::Callback +{ +public: + CHIPAccountLoginClusterGetSetupPINResponseCallback(jobject javaCallback); + + ~CHIPAccountLoginClusterGetSetupPINResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPApplicationLauncherClusterLaunchAppResponseCallback + : public Callback::Callback +{ +public: + CHIPApplicationLauncherClusterLaunchAppResponseCallback(jobject javaCallback); + + ~CHIPApplicationLauncherClusterLaunchAppResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::ApplicationLauncher::Commands::LaunchAppResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPContentLauncherClusterLaunchContentResponseCallback + : public Callback::Callback +{ +public: + CHIPContentLauncherClusterLaunchContentResponseCallback(jobject javaCallback); + + ~CHIPContentLauncherClusterLaunchContentResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::ContentLauncher::Commands::LaunchContentResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPContentLauncherClusterLaunchURLResponseCallback + : public Callback::Callback +{ +public: + CHIPContentLauncherClusterLaunchURLResponseCallback(jobject javaCallback); + + ~CHIPContentLauncherClusterLaunchURLResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::ContentLauncher::Commands::LaunchURLResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback + : public Callback::Callback +{ +public: + CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback(jobject javaCallback); + + ~CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterClearAllPinsResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterClearAllPinsResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterClearAllPinsResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::ClearAllPinsResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterClearAllRfidsResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterClearAllRfidsResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterClearAllRfidsResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::ClearAllRfidsResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterClearHolidayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterClearHolidayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterClearHolidayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::ClearHolidayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterClearPinResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterClearPinResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterClearPinResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::DoorLock::Commands::ClearPinResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterClearRfidResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterClearRfidResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterClearRfidResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::DoorLock::Commands::ClearRfidResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterClearWeekdayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterClearWeekdayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterClearWeekdayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::ClearWeekdayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterClearYeardayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterClearYeardayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterClearYeardayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::ClearYeardayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterGetHolidayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterGetHolidayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterGetHolidayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::GetHolidayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterGetLogRecordResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterGetLogRecordResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterGetLogRecordResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::GetLogRecordResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterGetPinResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterGetPinResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterGetPinResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::DoorLock::Commands::GetPinResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterGetRfidResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterGetRfidResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterGetRfidResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::DoorLock::Commands::GetRfidResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterGetUserTypeResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterGetUserTypeResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterGetUserTypeResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::GetUserTypeResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterGetWeekdayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterGetWeekdayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterGetWeekdayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::GetWeekdayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterGetYeardayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterGetYeardayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterGetYeardayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::GetYeardayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterLockDoorResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterLockDoorResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterLockDoorResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::DoorLock::Commands::LockDoorResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterSetHolidayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterSetHolidayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterSetHolidayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::SetHolidayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterSetPinResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterSetPinResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterSetPinResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::DoorLock::Commands::SetPinResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterSetRfidResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterSetRfidResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterSetRfidResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::DoorLock::Commands::SetRfidResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterSetUserTypeResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterSetUserTypeResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterSetUserTypeResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::SetUserTypeResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterSetWeekdayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterSetWeekdayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterSetWeekdayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::SetWeekdayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterSetYeardayScheduleResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterSetYeardayScheduleResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterSetYeardayScheduleResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::SetYeardayScheduleResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterUnlockDoorResponseCallback : public Callback::Callback +{ +public: + CHIPDoorLockClusterUnlockDoorResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterUnlockDoorResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::DoorLock::Commands::UnlockDoorResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPDoorLockClusterUnlockWithTimeoutResponseCallback + : public Callback::Callback +{ +public: + CHIPDoorLockClusterUnlockWithTimeoutResponseCallback(jobject javaCallback); + + ~CHIPDoorLockClusterUnlockWithTimeoutResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::DoorLock::Commands::UnlockWithTimeoutResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPGeneralCommissioningClusterArmFailSafeResponseCallback + : public Callback::Callback +{ +public: + CHIPGeneralCommissioningClusterArmFailSafeResponseCallback(jobject javaCallback); + + ~CHIPGeneralCommissioningClusterArmFailSafeResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::GeneralCommissioning::Commands::ArmFailSafeResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback + : public Callback::Callback +{ +public: + CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback(jobject javaCallback); + + ~CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback(); + + static void + CallbackFn(void * context, + const chip::app::Clusters::GeneralCommissioning::Commands::CommissioningCompleteResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback + : public Callback::Callback +{ +public: + CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback(jobject javaCallback); + + ~CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback(); + + static void + CallbackFn(void * context, + const chip::app::Clusters::GeneralCommissioning::Commands::SetRegulatoryConfigResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPGroupsClusterAddGroupResponseCallback : public Callback::Callback +{ +public: + CHIPGroupsClusterAddGroupResponseCallback(jobject javaCallback); + + ~CHIPGroupsClusterAddGroupResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::Groups::Commands::AddGroupResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPGroupsClusterGetGroupMembershipResponseCallback + : public Callback::Callback +{ +public: + CHIPGroupsClusterGetGroupMembershipResponseCallback(jobject javaCallback); + + ~CHIPGroupsClusterGetGroupMembershipResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::Groups::Commands::GetGroupMembershipResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPGroupsClusterRemoveGroupResponseCallback : public Callback::Callback +{ +public: + CHIPGroupsClusterRemoveGroupResponseCallback(jobject javaCallback); + + ~CHIPGroupsClusterRemoveGroupResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::Groups::Commands::RemoveGroupResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPGroupsClusterViewGroupResponseCallback : public Callback::Callback +{ +public: + CHIPGroupsClusterViewGroupResponseCallback(jobject javaCallback); + + ~CHIPGroupsClusterViewGroupResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::Groups::Commands::ViewGroupResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPIdentifyClusterIdentifyQueryResponseCallback + : public Callback::Callback +{ +public: + CHIPIdentifyClusterIdentifyQueryResponseCallback(jobject javaCallback); + + ~CHIPIdentifyClusterIdentifyQueryResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::Identify::Commands::IdentifyQueryResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPKeypadInputClusterSendKeyResponseCallback : public Callback::Callback +{ +public: + CHIPKeypadInputClusterSendKeyResponseCallback(jobject javaCallback); + + ~CHIPKeypadInputClusterSendKeyResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::KeypadInput::Commands::SendKeyResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaFastForwardResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaFastForwardResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaFastForwardResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaFastForwardResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaNextResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaNextResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaNextResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaNextResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaPauseResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaPauseResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaPauseResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaPauseResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaPlayResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaPlayResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaPlayResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaPlayResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaPreviousResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaPreviousResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaPreviousResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaPreviousResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaRewindResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaRewindResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaRewindResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaRewindResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaSeekResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaSeekResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaSeekResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaSeekResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaSkipBackwardResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaSkipForwardResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaStartOverResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaStartOverResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaStartOverResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaStartOverResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaStopResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaStopResponseCallback(jobject javaCallback); + + ~CHIPMediaPlaybackClusterMediaStopResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::MediaPlayback::Commands::MediaStopResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback + : public Callback::Callback +{ +public: + CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback(jobject javaCallback); + + ~CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback(); + + static void + CallbackFn(void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::AddThreadNetworkResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback + : public Callback::Callback +{ +public: + CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback(jobject javaCallback); + + ~CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::AddWiFiNetworkResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPNetworkCommissioningClusterDisableNetworkResponseCallback + : public Callback::Callback +{ +public: + CHIPNetworkCommissioningClusterDisableNetworkResponseCallback(jobject javaCallback); + + ~CHIPNetworkCommissioningClusterDisableNetworkResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::DisableNetworkResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPNetworkCommissioningClusterEnableNetworkResponseCallback + : public Callback::Callback +{ +public: + CHIPNetworkCommissioningClusterEnableNetworkResponseCallback(jobject javaCallback); + + ~CHIPNetworkCommissioningClusterEnableNetworkResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::EnableNetworkResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback + : public Callback::Callback +{ +public: + CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback(jobject javaCallback); + + ~CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::RemoveNetworkResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPNetworkCommissioningClusterScanNetworksResponseCallback + : public Callback::Callback +{ +public: + CHIPNetworkCommissioningClusterScanNetworksResponseCallback(jobject javaCallback); + + ~CHIPNetworkCommissioningClusterScanNetworksResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::ScanNetworksResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback + : public Callback::Callback +{ +public: + CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback(jobject javaCallback); + + ~CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback(); + + static void + CallbackFn(void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::UpdateThreadNetworkResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback + : public Callback::Callback +{ +public: + CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback(jobject javaCallback); + + ~CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback(); + + static void + CallbackFn(void * context, + const chip::app::Clusters::NetworkCommissioning::Commands::UpdateWiFiNetworkResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback + : public Callback::Callback +{ +public: + CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback(jobject javaCallback); + + ~CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback(); + + static void + CallbackFn(void * context, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback + : public Callback::Callback +{ +public: + CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback(jobject javaCallback); + + ~CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback(); + + static void + CallbackFn(void * context, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPOperationalCredentialsClusterAttestationResponseCallback + : public Callback::Callback +{ +public: + CHIPOperationalCredentialsClusterAttestationResponseCallback(jobject javaCallback); + + ~CHIPOperationalCredentialsClusterAttestationResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::OperationalCredentials::Commands::AttestationResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPOperationalCredentialsClusterCertificateChainResponseCallback + : public Callback::Callback +{ +public: + CHIPOperationalCredentialsClusterCertificateChainResponseCallback(jobject javaCallback); + + ~CHIPOperationalCredentialsClusterCertificateChainResponseCallback(); + + static void + CallbackFn(void * context, + const chip::app::Clusters::OperationalCredentials::Commands::CertificateChainResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPOperationalCredentialsClusterNOCResponseCallback + : public Callback::Callback +{ +public: + CHIPOperationalCredentialsClusterNOCResponseCallback(jobject javaCallback); + + ~CHIPOperationalCredentialsClusterNOCResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::OperationalCredentials::Commands::NOCResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPOperationalCredentialsClusterOpCSRResponseCallback + : public Callback::Callback +{ +public: + CHIPOperationalCredentialsClusterOpCSRResponseCallback(jobject javaCallback); + + ~CHIPOperationalCredentialsClusterOpCSRResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::OperationalCredentials::Commands::OpCSRResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPScenesClusterAddSceneResponseCallback : public Callback::Callback +{ +public: + CHIPScenesClusterAddSceneResponseCallback(jobject javaCallback); + + ~CHIPScenesClusterAddSceneResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::Scenes::Commands::AddSceneResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPScenesClusterGetSceneMembershipResponseCallback + : public Callback::Callback +{ +public: + CHIPScenesClusterGetSceneMembershipResponseCallback(jobject javaCallback); + + ~CHIPScenesClusterGetSceneMembershipResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::Scenes::Commands::GetSceneMembershipResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPScenesClusterRemoveAllScenesResponseCallback + : public Callback::Callback +{ +public: + CHIPScenesClusterRemoveAllScenesResponseCallback(jobject javaCallback); + + ~CHIPScenesClusterRemoveAllScenesResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::Scenes::Commands::RemoveAllScenesResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPScenesClusterRemoveSceneResponseCallback : public Callback::Callback +{ +public: + CHIPScenesClusterRemoveSceneResponseCallback(jobject javaCallback); + + ~CHIPScenesClusterRemoveSceneResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::Scenes::Commands::RemoveSceneResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPScenesClusterStoreSceneResponseCallback : public Callback::Callback +{ +public: + CHIPScenesClusterStoreSceneResponseCallback(jobject javaCallback); + + ~CHIPScenesClusterStoreSceneResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::Scenes::Commands::StoreSceneResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPScenesClusterViewSceneResponseCallback : public Callback::Callback +{ +public: + CHIPScenesClusterViewSceneResponseCallback(jobject javaCallback); + + ~CHIPScenesClusterViewSceneResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::Scenes::Commands::ViewSceneResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPTvChannelClusterChangeChannelResponseCallback + : public Callback::Callback +{ +public: + CHIPTvChannelClusterChangeChannelResponseCallback(jobject javaCallback); + + ~CHIPTvChannelClusterChangeChannelResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::TvChannel::Commands::ChangeChannelResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPTargetNavigatorClusterNavigateTargetResponseCallback + : public Callback::Callback +{ +public: + CHIPTargetNavigatorClusterNavigateTargetResponseCallback(jobject javaCallback); + + ~CHIPTargetNavigatorClusterNavigateTargetResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPTestClusterClusterBooleanResponseCallback : public Callback::Callback +{ +public: + CHIPTestClusterClusterBooleanResponseCallback(jobject javaCallback); + + ~CHIPTestClusterClusterBooleanResponseCallback(); + + static void CallbackFn(void * context, const chip::app::Clusters::TestCluster::Commands::BooleanResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPTestClusterClusterTestAddArgumentsResponseCallback + : public Callback::Callback +{ +public: + CHIPTestClusterClusterTestAddArgumentsResponseCallback(jobject javaCallback); + + ~CHIPTestClusterClusterTestAddArgumentsResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::TestCluster::Commands::TestAddArgumentsResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPTestClusterClusterTestEnumsResponseCallback + : public Callback::Callback +{ +public: + CHIPTestClusterClusterTestEnumsResponseCallback(jobject javaCallback); + + ~CHIPTestClusterClusterTestEnumsResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::TestCluster::Commands::TestEnumsResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPTestClusterClusterTestListInt8UReverseResponseCallback + : public Callback::Callback +{ +public: + CHIPTestClusterClusterTestListInt8UReverseResponseCallback(jobject javaCallback); + + ~CHIPTestClusterClusterTestListInt8UReverseResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::TestCluster::Commands::TestListInt8UReverseResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPTestClusterClusterTestNullableOptionalResponseCallback + : public Callback::Callback +{ +public: + CHIPTestClusterClusterTestNullableOptionalResponseCallback(jobject javaCallback); + + ~CHIPTestClusterClusterTestNullableOptionalResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::TestCluster::Commands::TestNullableOptionalResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +class CHIPTestClusterClusterTestSpecificResponseCallback + : public Callback::Callback +{ +public: + CHIPTestClusterClusterTestSpecificResponseCallback(jobject javaCallback); + + ~CHIPTestClusterClusterTestSpecificResponseCallback(); + + static void CallbackFn(void * context, + const chip::app::Clusters::TestCluster::Commands::TestSpecificResponse::DecodableType & data); + +private: + jobject javaCallbackRef; +}; + +} // namespace chip diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java index 9ca0f757d61a91..ccb067acf8a720 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java @@ -143,18 +143,18 @@ public static long clusterId() { public native long initWithDevice(long devicePtr, int endpointId); public void openBasicCommissioningWindow( - DefaultClusterCallback callback, int commissioningTimeout) { + DefaultClusterCallback callback, Integer commissioningTimeout) { openBasicCommissioningWindow(chipClusterPtr, callback, commissioningTimeout); } public void openCommissioningWindow( DefaultClusterCallback callback, - int commissioningTimeout, + Integer commissioningTimeout, byte[] PAKEVerifier, - int discriminator, - long iterations, + Integer discriminator, + Long iterations, byte[] salt, - int passcodeID) { + Integer passcodeID) { openCommissioningWindow( chipClusterPtr, callback, @@ -171,17 +171,17 @@ public void revokeCommissioning(DefaultClusterCallback callback) { } private native void openBasicCommissioningWindow( - long chipClusterPtr, DefaultClusterCallback callback, int commissioningTimeout); + long chipClusterPtr, DefaultClusterCallback callback, Integer commissioningTimeout); private native void openCommissioningWindow( long chipClusterPtr, DefaultClusterCallback callback, - int commissioningTimeout, + Integer commissioningTimeout, byte[] PAKEVerifier, - int discriminator, - long iterations, + Integer discriminator, + Long iterations, byte[] salt, - int passcodeID); + Integer passcodeID); private native void revokeCommissioning(long chipClusterPtr, DefaultClusterCallback callback); @@ -205,12 +205,12 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void changeStatus(DefaultClusterCallback callback, int status) { + public void changeStatus(DefaultClusterCallback callback, Integer status) { changeStatus(chipClusterPtr, callback, status); } private native void changeStatus( - long chipClusterPtr, DefaultClusterCallback callback, int status); + long chipClusterPtr, DefaultClusterCallback callback, Integer status); public void readVendorNameAttribute(CharStringAttributeCallback callback) { readVendorNameAttribute(chipClusterPtr, callback); @@ -284,7 +284,7 @@ public static long clusterId() { public void launchApp( LaunchAppResponseCallback callback, String data, - int catalogVendorId, + Integer catalogVendorId, String applicationId) { launchApp(chipClusterPtr, callback, data, catalogVendorId, applicationId); } @@ -293,11 +293,11 @@ private native void launchApp( long chipClusterPtr, LaunchAppResponseCallback callback, String data, - int catalogVendorId, + Integer catalogVendorId, String applicationId); public interface LaunchAppResponseCallback { - void onSuccess(int status, String data); + void onSuccess(Integer status, String data); void onError(Exception error); } @@ -350,19 +350,19 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void renameOutput(DefaultClusterCallback callback, int index, String name) { + public void renameOutput(DefaultClusterCallback callback, Integer index, String name) { renameOutput(chipClusterPtr, callback, index, name); } - public void selectOutput(DefaultClusterCallback callback, int index) { + public void selectOutput(DefaultClusterCallback callback, Integer index) { selectOutput(chipClusterPtr, callback, index); } private native void renameOutput( - long chipClusterPtr, DefaultClusterCallback callback, int index, String name); + long chipClusterPtr, DefaultClusterCallback callback, Integer index, String name); private native void selectOutput( - long chipClusterPtr, DefaultClusterCallback callback, int index); + long chipClusterPtr, DefaultClusterCallback callback, Integer index); public static class AudioOutputListAttribute { public Integer index; @@ -434,7 +434,7 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void barrierControlGoToPercent(DefaultClusterCallback callback, int percentOpen) { + public void barrierControlGoToPercent(DefaultClusterCallback callback, Integer percentOpen) { barrierControlGoToPercent(chipClusterPtr, callback, percentOpen); } @@ -443,7 +443,7 @@ public void barrierControlStop(DefaultClusterCallback callback) { } private native void barrierControlGoToPercent( - long chipClusterPtr, DefaultClusterCallback callback, int percentOpen); + long chipClusterPtr, DefaultClusterCallback callback, Integer percentOpen); private native void barrierControlStop(long chipClusterPtr, DefaultClusterCallback callback); @@ -754,30 +754,38 @@ public static long clusterId() { public native long initWithDevice(long devicePtr, int endpointId); public void bind( - DefaultClusterCallback callback, long nodeId, int groupId, int endpointId, long clusterId) { + DefaultClusterCallback callback, + Long nodeId, + Integer groupId, + Integer endpointId, + Long clusterId) { bind(chipClusterPtr, callback, nodeId, groupId, endpointId, clusterId); } public void unbind( - DefaultClusterCallback callback, long nodeId, int groupId, int endpointId, long clusterId) { + DefaultClusterCallback callback, + Long nodeId, + Integer groupId, + Integer endpointId, + Long clusterId) { unbind(chipClusterPtr, callback, nodeId, groupId, endpointId, clusterId); } private native void bind( long chipClusterPtr, DefaultClusterCallback callback, - long nodeId, - int groupId, - int endpointId, - long clusterId); + Long nodeId, + Integer groupId, + Integer endpointId, + Long clusterId); private native void unbind( long chipClusterPtr, DefaultClusterCallback callback, - long nodeId, - int groupId, - int endpointId, - long clusterId); + Long nodeId, + Integer groupId, + Integer endpointId, + Long clusterId); public void readClusterRevisionAttribute(IntegerAttributeCallback callback) { readClusterRevisionAttribute(chipClusterPtr, callback); @@ -841,114 +849,145 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void disableAction(DefaultClusterCallback callback, int actionID, long invokeID) { + public void disableAction( + DefaultClusterCallback callback, Integer actionID, Optional invokeID) { disableAction(chipClusterPtr, callback, actionID, invokeID); } public void disableActionWithDuration( - DefaultClusterCallback callback, int actionID, long invokeID, long duration) { + DefaultClusterCallback callback, Integer actionID, Optional invokeID, Long duration) { disableActionWithDuration(chipClusterPtr, callback, actionID, invokeID, duration); } - public void enableAction(DefaultClusterCallback callback, int actionID, long invokeID) { + public void enableAction( + DefaultClusterCallback callback, Integer actionID, Optional invokeID) { enableAction(chipClusterPtr, callback, actionID, invokeID); } public void enableActionWithDuration( - DefaultClusterCallback callback, int actionID, long invokeID, long duration) { + DefaultClusterCallback callback, Integer actionID, Optional invokeID, Long duration) { enableActionWithDuration(chipClusterPtr, callback, actionID, invokeID, duration); } - public void instantAction(DefaultClusterCallback callback, int actionID, long invokeID) { + public void instantAction( + DefaultClusterCallback callback, Integer actionID, Optional invokeID) { instantAction(chipClusterPtr, callback, actionID, invokeID); } public void instantActionWithTransition( - DefaultClusterCallback callback, int actionID, long invokeID, int transitionTime) { + DefaultClusterCallback callback, + Integer actionID, + Optional invokeID, + Integer transitionTime) { instantActionWithTransition(chipClusterPtr, callback, actionID, invokeID, transitionTime); } - public void pauseAction(DefaultClusterCallback callback, int actionID, long invokeID) { + public void pauseAction( + DefaultClusterCallback callback, Integer actionID, Optional invokeID) { pauseAction(chipClusterPtr, callback, actionID, invokeID); } public void pauseActionWithDuration( - DefaultClusterCallback callback, int actionID, long invokeID, long duration) { + DefaultClusterCallback callback, Integer actionID, Optional invokeID, Long duration) { pauseActionWithDuration(chipClusterPtr, callback, actionID, invokeID, duration); } - public void resumeAction(DefaultClusterCallback callback, int actionID, long invokeID) { + public void resumeAction( + DefaultClusterCallback callback, Integer actionID, Optional invokeID) { resumeAction(chipClusterPtr, callback, actionID, invokeID); } - public void startAction(DefaultClusterCallback callback, int actionID, long invokeID) { + public void startAction( + DefaultClusterCallback callback, Integer actionID, Optional invokeID) { startAction(chipClusterPtr, callback, actionID, invokeID); } public void startActionWithDuration( - DefaultClusterCallback callback, int actionID, long invokeID, long duration) { + DefaultClusterCallback callback, Integer actionID, Optional invokeID, Long duration) { startActionWithDuration(chipClusterPtr, callback, actionID, invokeID, duration); } - public void stopAction(DefaultClusterCallback callback, int actionID, long invokeID) { + public void stopAction( + DefaultClusterCallback callback, Integer actionID, Optional invokeID) { stopAction(chipClusterPtr, callback, actionID, invokeID); } private native void disableAction( - long chipClusterPtr, DefaultClusterCallback callback, int actionID, long invokeID); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer actionID, + Optional invokeID); private native void disableActionWithDuration( long chipClusterPtr, DefaultClusterCallback callback, - int actionID, - long invokeID, - long duration); + Integer actionID, + Optional invokeID, + Long duration); private native void enableAction( - long chipClusterPtr, DefaultClusterCallback callback, int actionID, long invokeID); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer actionID, + Optional invokeID); private native void enableActionWithDuration( long chipClusterPtr, DefaultClusterCallback callback, - int actionID, - long invokeID, - long duration); + Integer actionID, + Optional invokeID, + Long duration); private native void instantAction( - long chipClusterPtr, DefaultClusterCallback callback, int actionID, long invokeID); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer actionID, + Optional invokeID); private native void instantActionWithTransition( long chipClusterPtr, DefaultClusterCallback callback, - int actionID, - long invokeID, - int transitionTime); + Integer actionID, + Optional invokeID, + Integer transitionTime); private native void pauseAction( - long chipClusterPtr, DefaultClusterCallback callback, int actionID, long invokeID); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer actionID, + Optional invokeID); private native void pauseActionWithDuration( long chipClusterPtr, DefaultClusterCallback callback, - int actionID, - long invokeID, - long duration); + Integer actionID, + Optional invokeID, + Long duration); private native void resumeAction( - long chipClusterPtr, DefaultClusterCallback callback, int actionID, long invokeID); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer actionID, + Optional invokeID); private native void startAction( - long chipClusterPtr, DefaultClusterCallback callback, int actionID, long invokeID); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer actionID, + Optional invokeID); private native void startActionWithDuration( long chipClusterPtr, DefaultClusterCallback callback, - int actionID, - long invokeID, - long duration); + Integer actionID, + Optional invokeID, + Long duration); private native void stopAction( - long chipClusterPtr, DefaultClusterCallback callback, int actionID, long invokeID); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer actionID, + Optional invokeID); public static class ActionListAttribute { public Integer actionID; @@ -1221,13 +1260,13 @@ public static long clusterId() { public void colorLoopSet( DefaultClusterCallback callback, - int updateFlags, - int action, - int direction, - int time, - int startHue, - int optionsMask, - int optionsOverride) { + Integer updateFlags, + Integer action, + Integer direction, + Integer time, + Integer startHue, + Integer optionsMask, + Integer optionsOverride) { colorLoopSet( chipClusterPtr, callback, @@ -1242,20 +1281,20 @@ public void colorLoopSet( public void enhancedMoveHue( DefaultClusterCallback callback, - int moveMode, - int rate, - int optionsMask, - int optionsOverride) { + Integer moveMode, + Integer rate, + Integer optionsMask, + Integer optionsOverride) { enhancedMoveHue(chipClusterPtr, callback, moveMode, rate, optionsMask, optionsOverride); } public void enhancedMoveToHue( DefaultClusterCallback callback, - int enhancedHue, - int direction, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer enhancedHue, + Integer direction, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { enhancedMoveToHue( chipClusterPtr, callback, @@ -1268,11 +1307,11 @@ public void enhancedMoveToHue( public void enhancedMoveToHueAndSaturation( DefaultClusterCallback callback, - int enhancedHue, - int saturation, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer enhancedHue, + Integer saturation, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { enhancedMoveToHueAndSaturation( chipClusterPtr, callback, @@ -1285,11 +1324,11 @@ public void enhancedMoveToHueAndSaturation( public void enhancedStepHue( DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { enhancedStepHue( chipClusterPtr, callback, @@ -1302,21 +1341,21 @@ public void enhancedStepHue( public void moveColor( DefaultClusterCallback callback, - int rateX, - int rateY, - int optionsMask, - int optionsOverride) { + Integer rateX, + Integer rateY, + Integer optionsMask, + Integer optionsOverride) { moveColor(chipClusterPtr, callback, rateX, rateY, optionsMask, optionsOverride); } public void moveColorTemperature( DefaultClusterCallback callback, - int moveMode, - int rate, - int colorTemperatureMinimum, - int colorTemperatureMaximum, - int optionsMask, - int optionsOverride) { + Integer moveMode, + Integer rate, + Integer colorTemperatureMinimum, + Integer colorTemperatureMaximum, + Integer optionsMask, + Integer optionsOverride) { moveColorTemperature( chipClusterPtr, callback, @@ -1330,95 +1369,95 @@ public void moveColorTemperature( public void moveHue( DefaultClusterCallback callback, - int moveMode, - int rate, - int optionsMask, - int optionsOverride) { + Integer moveMode, + Integer rate, + Integer optionsMask, + Integer optionsOverride) { moveHue(chipClusterPtr, callback, moveMode, rate, optionsMask, optionsOverride); } public void moveSaturation( DefaultClusterCallback callback, - int moveMode, - int rate, - int optionsMask, - int optionsOverride) { + Integer moveMode, + Integer rate, + Integer optionsMask, + Integer optionsOverride) { moveSaturation(chipClusterPtr, callback, moveMode, rate, optionsMask, optionsOverride); } public void moveToColor( DefaultClusterCallback callback, - int colorX, - int colorY, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer colorX, + Integer colorY, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { moveToColor( chipClusterPtr, callback, colorX, colorY, transitionTime, optionsMask, optionsOverride); } public void moveToColorTemperature( DefaultClusterCallback callback, - int colorTemperature, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer colorTemperature, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { moveToColorTemperature( chipClusterPtr, callback, colorTemperature, transitionTime, optionsMask, optionsOverride); } public void moveToHue( DefaultClusterCallback callback, - int hue, - int direction, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer hue, + Integer direction, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { moveToHue( chipClusterPtr, callback, hue, direction, transitionTime, optionsMask, optionsOverride); } public void moveToHueAndSaturation( DefaultClusterCallback callback, - int hue, - int saturation, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer hue, + Integer saturation, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { moveToHueAndSaturation( chipClusterPtr, callback, hue, saturation, transitionTime, optionsMask, optionsOverride); } public void moveToSaturation( DefaultClusterCallback callback, - int saturation, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer saturation, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { moveToSaturation( chipClusterPtr, callback, saturation, transitionTime, optionsMask, optionsOverride); } public void stepColor( DefaultClusterCallback callback, - int stepX, - int stepY, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer stepX, + Integer stepY, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { stepColor( chipClusterPtr, callback, stepX, stepY, transitionTime, optionsMask, optionsOverride); } public void stepColorTemperature( DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int colorTemperatureMinimum, - int colorTemperatureMaximum, - int optionsMask, - int optionsOverride) { + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer colorTemperatureMinimum, + Integer colorTemperatureMaximum, + Integer optionsMask, + Integer optionsOverride) { stepColorTemperature( chipClusterPtr, callback, @@ -1433,11 +1472,11 @@ public void stepColorTemperature( public void stepHue( DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { stepHue( chipClusterPtr, callback, @@ -1450,11 +1489,11 @@ public void stepHue( public void stepSaturation( DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int optionsMask, - int optionsOverride) { + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride) { stepSaturation( chipClusterPtr, callback, @@ -1466,173 +1505,176 @@ public void stepSaturation( } public void stopMoveStep( - DefaultClusterCallback callback, int optionsMask, int optionsOverride) { + DefaultClusterCallback callback, Integer optionsMask, Integer optionsOverride) { stopMoveStep(chipClusterPtr, callback, optionsMask, optionsOverride); } private native void colorLoopSet( long chipClusterPtr, DefaultClusterCallback callback, - int updateFlags, - int action, - int direction, - int time, - int startHue, - int optionsMask, - int optionsOverride); + Integer updateFlags, + Integer action, + Integer direction, + Integer time, + Integer startHue, + Integer optionsMask, + Integer optionsOverride); private native void enhancedMoveHue( long chipClusterPtr, DefaultClusterCallback callback, - int moveMode, - int rate, - int optionsMask, - int optionsOverride); + Integer moveMode, + Integer rate, + Integer optionsMask, + Integer optionsOverride); private native void enhancedMoveToHue( long chipClusterPtr, DefaultClusterCallback callback, - int enhancedHue, - int direction, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer enhancedHue, + Integer direction, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void enhancedMoveToHueAndSaturation( long chipClusterPtr, DefaultClusterCallback callback, - int enhancedHue, - int saturation, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer enhancedHue, + Integer saturation, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void enhancedStepHue( long chipClusterPtr, DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void moveColor( long chipClusterPtr, DefaultClusterCallback callback, - int rateX, - int rateY, - int optionsMask, - int optionsOverride); + Integer rateX, + Integer rateY, + Integer optionsMask, + Integer optionsOverride); private native void moveColorTemperature( long chipClusterPtr, DefaultClusterCallback callback, - int moveMode, - int rate, - int colorTemperatureMinimum, - int colorTemperatureMaximum, - int optionsMask, - int optionsOverride); + Integer moveMode, + Integer rate, + Integer colorTemperatureMinimum, + Integer colorTemperatureMaximum, + Integer optionsMask, + Integer optionsOverride); private native void moveHue( long chipClusterPtr, DefaultClusterCallback callback, - int moveMode, - int rate, - int optionsMask, - int optionsOverride); + Integer moveMode, + Integer rate, + Integer optionsMask, + Integer optionsOverride); private native void moveSaturation( long chipClusterPtr, DefaultClusterCallback callback, - int moveMode, - int rate, - int optionsMask, - int optionsOverride); + Integer moveMode, + Integer rate, + Integer optionsMask, + Integer optionsOverride); private native void moveToColor( long chipClusterPtr, DefaultClusterCallback callback, - int colorX, - int colorY, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer colorX, + Integer colorY, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void moveToColorTemperature( long chipClusterPtr, DefaultClusterCallback callback, - int colorTemperature, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer colorTemperature, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void moveToHue( long chipClusterPtr, DefaultClusterCallback callback, - int hue, - int direction, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer hue, + Integer direction, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void moveToHueAndSaturation( long chipClusterPtr, DefaultClusterCallback callback, - int hue, - int saturation, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer hue, + Integer saturation, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void moveToSaturation( long chipClusterPtr, DefaultClusterCallback callback, - int saturation, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer saturation, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void stepColor( long chipClusterPtr, DefaultClusterCallback callback, - int stepX, - int stepY, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer stepX, + Integer stepY, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void stepColorTemperature( long chipClusterPtr, DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int colorTemperatureMinimum, - int colorTemperatureMaximum, - int optionsMask, - int optionsOverride); + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer colorTemperatureMinimum, + Integer colorTemperatureMaximum, + Integer optionsMask, + Integer optionsOverride); private native void stepHue( long chipClusterPtr, DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void stepSaturation( long chipClusterPtr, DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int optionsMask, - int optionsOverride); + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer optionsMask, + Integer optionsOverride); private native void stopMoveStep( - long chipClusterPtr, DefaultClusterCallback callback, int optionsMask, int optionsOverride); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer optionsMask, + Integer optionsOverride); public void readCurrentHueAttribute(IntegerAttributeCallback callback) { readCurrentHueAttribute(chipClusterPtr, callback); @@ -2186,7 +2228,7 @@ public static long clusterId() { public native long initWithDevice(long devicePtr, int endpointId); public void launchContent( - LaunchContentResponseCallback callback, boolean autoPlay, String data) { + LaunchContentResponseCallback callback, Boolean autoPlay, String data) { launchContent(chipClusterPtr, callback, autoPlay, data); } @@ -2196,7 +2238,7 @@ public void launchURL( } private native void launchContent( - long chipClusterPtr, LaunchContentResponseCallback callback, boolean autoPlay, String data); + long chipClusterPtr, LaunchContentResponseCallback callback, Boolean autoPlay, String data); private native void launchURL( long chipClusterPtr, @@ -2205,13 +2247,13 @@ private native void launchURL( String displayString); public interface LaunchContentResponseCallback { - void onSuccess(String data, int contentLaunchStatus); + void onSuccess(String data, Integer contentLaunchStatus); void onError(Exception error); } public interface LaunchURLResponseCallback { - void onSuccess(String data, int contentLaunchStatus); + void onSuccess(String data, Integer contentLaunchStatus); void onError(Exception error); } @@ -2361,8 +2403,8 @@ public static long clusterId() { public void retrieveLogsRequest( RetrieveLogsResponseCallback callback, - int intent, - int requestedProtocol, + Integer intent, + Integer requestedProtocol, byte[] transferFileDesignator) { retrieveLogsRequest( chipClusterPtr, callback, intent, requestedProtocol, transferFileDesignator); @@ -2371,12 +2413,12 @@ public void retrieveLogsRequest( private native void retrieveLogsRequest( long chipClusterPtr, RetrieveLogsResponseCallback callback, - int intent, - int requestedProtocol, + Integer intent, + Integer requestedProtocol, byte[] transferFileDesignator); public interface RetrieveLogsResponseCallback { - void onSuccess(int status, byte[] content, long timeStamp, long timeSinceBoot); + void onSuccess(Integer status, byte[] content, Long timeStamp, Long timeSinceBoot); void onError(Exception error); } @@ -2403,55 +2445,56 @@ public void clearAllRfids(ClearAllRfidsResponseCallback callback) { } public void clearHolidaySchedule( - ClearHolidayScheduleResponseCallback callback, int scheduleId) { + ClearHolidayScheduleResponseCallback callback, Integer scheduleId) { clearHolidaySchedule(chipClusterPtr, callback, scheduleId); } - public void clearPin(ClearPinResponseCallback callback, int userId) { + public void clearPin(ClearPinResponseCallback callback, Integer userId) { clearPin(chipClusterPtr, callback, userId); } - public void clearRfid(ClearRfidResponseCallback callback, int userId) { + public void clearRfid(ClearRfidResponseCallback callback, Integer userId) { clearRfid(chipClusterPtr, callback, userId); } public void clearWeekdaySchedule( - ClearWeekdayScheduleResponseCallback callback, int scheduleId, int userId) { + ClearWeekdayScheduleResponseCallback callback, Integer scheduleId, Integer userId) { clearWeekdaySchedule(chipClusterPtr, callback, scheduleId, userId); } public void clearYeardaySchedule( - ClearYeardayScheduleResponseCallback callback, int scheduleId, int userId) { + ClearYeardayScheduleResponseCallback callback, Integer scheduleId, Integer userId) { clearYeardaySchedule(chipClusterPtr, callback, scheduleId, userId); } - public void getHolidaySchedule(GetHolidayScheduleResponseCallback callback, int scheduleId) { + public void getHolidaySchedule( + GetHolidayScheduleResponseCallback callback, Integer scheduleId) { getHolidaySchedule(chipClusterPtr, callback, scheduleId); } - public void getLogRecord(GetLogRecordResponseCallback callback, int logIndex) { + public void getLogRecord(GetLogRecordResponseCallback callback, Integer logIndex) { getLogRecord(chipClusterPtr, callback, logIndex); } - public void getPin(GetPinResponseCallback callback, int userId) { + public void getPin(GetPinResponseCallback callback, Integer userId) { getPin(chipClusterPtr, callback, userId); } - public void getRfid(GetRfidResponseCallback callback, int userId) { + public void getRfid(GetRfidResponseCallback callback, Integer userId) { getRfid(chipClusterPtr, callback, userId); } - public void getUserType(GetUserTypeResponseCallback callback, int userId) { + public void getUserType(GetUserTypeResponseCallback callback, Integer userId) { getUserType(chipClusterPtr, callback, userId); } public void getWeekdaySchedule( - GetWeekdayScheduleResponseCallback callback, int scheduleId, int userId) { + GetWeekdayScheduleResponseCallback callback, Integer scheduleId, Integer userId) { getWeekdaySchedule(chipClusterPtr, callback, scheduleId, userId); } public void getYeardaySchedule( - GetYeardayScheduleResponseCallback callback, int scheduleId, int userId) { + GetYeardayScheduleResponseCallback callback, Integer scheduleId, Integer userId) { getYeardaySchedule(chipClusterPtr, callback, scheduleId, userId); } @@ -2461,10 +2504,10 @@ public void lockDoor(LockDoorResponseCallback callback, byte[] pin) { public void setHolidaySchedule( SetHolidayScheduleResponseCallback callback, - int scheduleId, - long localStartTime, - long localEndTime, - int operatingModeDuringHoliday) { + Integer scheduleId, + Long localStartTime, + Long localEndTime, + Integer operatingModeDuringHoliday) { setHolidaySchedule( chipClusterPtr, callback, @@ -2475,28 +2518,37 @@ public void setHolidaySchedule( } public void setPin( - SetPinResponseCallback callback, int userId, int userStatus, int userType, byte[] pin) { + SetPinResponseCallback callback, + Integer userId, + Integer userStatus, + Integer userType, + byte[] pin) { setPin(chipClusterPtr, callback, userId, userStatus, userType, pin); } public void setRfid( - SetRfidResponseCallback callback, int userId, int userStatus, int userType, byte[] id) { + SetRfidResponseCallback callback, + Integer userId, + Integer userStatus, + Integer userType, + byte[] id) { setRfid(chipClusterPtr, callback, userId, userStatus, userType, id); } - public void setUserType(SetUserTypeResponseCallback callback, int userId, int userType) { + public void setUserType( + SetUserTypeResponseCallback callback, Integer userId, Integer userType) { setUserType(chipClusterPtr, callback, userId, userType); } public void setWeekdaySchedule( SetWeekdayScheduleResponseCallback callback, - int scheduleId, - int userId, - int daysMask, - int startHour, - int startMinute, - int endHour, - int endMinute) { + Integer scheduleId, + Integer userId, + Integer daysMask, + Integer startHour, + Integer startMinute, + Integer endHour, + Integer endMinute) { setWeekdaySchedule( chipClusterPtr, callback, @@ -2511,10 +2563,10 @@ public void setWeekdaySchedule( public void setYeardaySchedule( SetYeardayScheduleResponseCallback callback, - int scheduleId, - int userId, - long localStartTime, - long localEndTime) { + Integer scheduleId, + Integer userId, + Long localStartTime, + Long localEndTime) { setYeardaySchedule( chipClusterPtr, callback, scheduleId, userId, localStartTime, localEndTime); } @@ -2524,7 +2576,7 @@ public void unlockDoor(UnlockDoorResponseCallback callback, byte[] pin) { } public void unlockWithTimeout( - UnlockWithTimeoutResponseCallback callback, int timeoutInSeconds, byte[] pin) { + UnlockWithTimeoutResponseCallback callback, Integer timeoutInSeconds, byte[] pin) { unlockWithTimeout(chipClusterPtr, callback, timeoutInSeconds, pin); } @@ -2533,50 +2585,52 @@ public void unlockWithTimeout( private native void clearAllRfids(long chipClusterPtr, ClearAllRfidsResponseCallback callback); private native void clearHolidaySchedule( - long chipClusterPtr, ClearHolidayScheduleResponseCallback callback, int scheduleId); + long chipClusterPtr, ClearHolidayScheduleResponseCallback callback, Integer scheduleId); private native void clearPin( - long chipClusterPtr, ClearPinResponseCallback callback, int userId); + long chipClusterPtr, ClearPinResponseCallback callback, Integer userId); private native void clearRfid( - long chipClusterPtr, ClearRfidResponseCallback callback, int userId); + long chipClusterPtr, ClearRfidResponseCallback callback, Integer userId); private native void clearWeekdaySchedule( long chipClusterPtr, ClearWeekdayScheduleResponseCallback callback, - int scheduleId, - int userId); + Integer scheduleId, + Integer userId); private native void clearYeardaySchedule( long chipClusterPtr, ClearYeardayScheduleResponseCallback callback, - int scheduleId, - int userId); + Integer scheduleId, + Integer userId); private native void getHolidaySchedule( - long chipClusterPtr, GetHolidayScheduleResponseCallback callback, int scheduleId); + long chipClusterPtr, GetHolidayScheduleResponseCallback callback, Integer scheduleId); private native void getLogRecord( - long chipClusterPtr, GetLogRecordResponseCallback callback, int logIndex); + long chipClusterPtr, GetLogRecordResponseCallback callback, Integer logIndex); - private native void getPin(long chipClusterPtr, GetPinResponseCallback callback, int userId); + private native void getPin( + long chipClusterPtr, GetPinResponseCallback callback, Integer userId); - private native void getRfid(long chipClusterPtr, GetRfidResponseCallback callback, int userId); + private native void getRfid( + long chipClusterPtr, GetRfidResponseCallback callback, Integer userId); private native void getUserType( - long chipClusterPtr, GetUserTypeResponseCallback callback, int userId); + long chipClusterPtr, GetUserTypeResponseCallback callback, Integer userId); private native void getWeekdaySchedule( long chipClusterPtr, GetWeekdayScheduleResponseCallback callback, - int scheduleId, - int userId); + Integer scheduleId, + Integer userId); private native void getYeardaySchedule( long chipClusterPtr, GetYeardayScheduleResponseCallback callback, - int scheduleId, - int userId); + Integer scheduleId, + Integer userId); private native void lockDoor( long chipClusterPtr, LockDoorResponseCallback callback, byte[] pin); @@ -2584,48 +2638,51 @@ private native void lockDoor( private native void setHolidaySchedule( long chipClusterPtr, SetHolidayScheduleResponseCallback callback, - int scheduleId, - long localStartTime, - long localEndTime, - int operatingModeDuringHoliday); + Integer scheduleId, + Long localStartTime, + Long localEndTime, + Integer operatingModeDuringHoliday); private native void setPin( long chipClusterPtr, SetPinResponseCallback callback, - int userId, - int userStatus, - int userType, + Integer userId, + Integer userStatus, + Integer userType, byte[] pin); private native void setRfid( long chipClusterPtr, SetRfidResponseCallback callback, - int userId, - int userStatus, - int userType, + Integer userId, + Integer userStatus, + Integer userType, byte[] id); private native void setUserType( - long chipClusterPtr, SetUserTypeResponseCallback callback, int userId, int userType); + long chipClusterPtr, + SetUserTypeResponseCallback callback, + Integer userId, + Integer userType); private native void setWeekdaySchedule( long chipClusterPtr, SetWeekdayScheduleResponseCallback callback, - int scheduleId, - int userId, - int daysMask, - int startHour, - int startMinute, - int endHour, - int endMinute); + Integer scheduleId, + Integer userId, + Integer daysMask, + Integer startHour, + Integer startMinute, + Integer endHour, + Integer endMinute); private native void setYeardaySchedule( long chipClusterPtr, SetYeardayScheduleResponseCallback callback, - int scheduleId, - int userId, - long localStartTime, - long localEndTime); + Integer scheduleId, + Integer userId, + Long localStartTime, + Long localEndTime); private native void unlockDoor( long chipClusterPtr, UnlockDoorResponseCallback callback, byte[] pin); @@ -2633,164 +2690,168 @@ private native void unlockDoor( private native void unlockWithTimeout( long chipClusterPtr, UnlockWithTimeoutResponseCallback callback, - int timeoutInSeconds, + Integer timeoutInSeconds, byte[] pin); public interface ClearAllPinsResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface ClearAllRfidsResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface ClearHolidayScheduleResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface ClearPinResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface ClearRfidResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface ClearWeekdayScheduleResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface ClearYeardayScheduleResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface GetHolidayScheduleResponseCallback { void onSuccess( - int scheduleId, - int status, - long localStartTime, - long localEndTime, - int operatingModeDuringHoliday); + Integer scheduleId, + Integer status, + Long localStartTime, + Long localEndTime, + Integer operatingModeDuringHoliday); void onError(Exception error); } public interface GetLogRecordResponseCallback { void onSuccess( - int logEntryId, - long timestamp, - int eventType, - int source, - int eventIdOrAlarmCode, - int userId, + Integer logEntryId, + Long timestamp, + Integer eventType, + Integer source, + Integer eventIdOrAlarmCode, + Integer userId, byte[] pin); void onError(Exception error); } public interface GetPinResponseCallback { - void onSuccess(int userId, int userStatus, int userType, byte[] pin); + void onSuccess(Integer userId, Integer userStatus, Integer userType, byte[] pin); void onError(Exception error); } public interface GetRfidResponseCallback { - void onSuccess(int userId, int userStatus, int userType, byte[] rfid); + void onSuccess(Integer userId, Integer userStatus, Integer userType, byte[] rfid); void onError(Exception error); } public interface GetUserTypeResponseCallback { - void onSuccess(int userId, int userType); + void onSuccess(Integer userId, Integer userType); void onError(Exception error); } public interface GetWeekdayScheduleResponseCallback { void onSuccess( - int scheduleId, - int userId, - int status, - int daysMask, - int startHour, - int startMinute, - int endHour, - int endMinute); + Integer scheduleId, + Integer userId, + Integer status, + Integer daysMask, + Integer startHour, + Integer startMinute, + Integer endHour, + Integer endMinute); void onError(Exception error); } public interface GetYeardayScheduleResponseCallback { void onSuccess( - int scheduleId, int userId, int status, long localStartTime, long localEndTime); + Integer scheduleId, + Integer userId, + Integer status, + Long localStartTime, + Long localEndTime); void onError(Exception error); } public interface LockDoorResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface SetHolidayScheduleResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface SetPinResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface SetRfidResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface SetUserTypeResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface SetWeekdayScheduleResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface SetYeardayScheduleResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface UnlockDoorResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } public interface UnlockWithTimeoutResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } @@ -3144,9 +3205,9 @@ public static long clusterId() { public void armFailSafe( ArmFailSafeResponseCallback callback, - int expiryLengthSeconds, - long breadcrumb, - long timeoutMs) { + Integer expiryLengthSeconds, + Long breadcrumb, + Long timeoutMs) { armFailSafe(chipClusterPtr, callback, expiryLengthSeconds, breadcrumb, timeoutMs); } @@ -3156,19 +3217,19 @@ public void commissioningComplete(CommissioningCompleteResponseCallback callback public void setRegulatoryConfig( SetRegulatoryConfigResponseCallback callback, - int location, + Integer location, String countryCode, - long breadcrumb, - long timeoutMs) { + Long breadcrumb, + Long timeoutMs) { setRegulatoryConfig(chipClusterPtr, callback, location, countryCode, breadcrumb, timeoutMs); } private native void armFailSafe( long chipClusterPtr, ArmFailSafeResponseCallback callback, - int expiryLengthSeconds, - long breadcrumb, - long timeoutMs); + Integer expiryLengthSeconds, + Long breadcrumb, + Long timeoutMs); private native void commissioningComplete( long chipClusterPtr, CommissioningCompleteResponseCallback callback); @@ -3176,25 +3237,25 @@ private native void commissioningComplete( private native void setRegulatoryConfig( long chipClusterPtr, SetRegulatoryConfigResponseCallback callback, - int location, + Integer location, String countryCode, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); public interface ArmFailSafeResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } public interface CommissioningCompleteResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } public interface SetRegulatoryConfigResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } @@ -3540,17 +3601,17 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void addGroup(AddGroupResponseCallback callback, int groupId, String groupName) { + public void addGroup(AddGroupResponseCallback callback, Integer groupId, String groupName) { addGroup(chipClusterPtr, callback, groupId, groupName); } public void addGroupIfIdentifying( - DefaultClusterCallback callback, int groupId, String groupName) { + DefaultClusterCallback callback, Integer groupId, String groupName) { addGroupIfIdentifying(chipClusterPtr, callback, groupId, groupName); } public void getGroupMembership( - GetGroupMembershipResponseCallback callback, int groupCount, int groupList) { + GetGroupMembershipResponseCallback callback, Integer groupCount, Integer groupList) { getGroupMembership(chipClusterPtr, callback, groupCount, groupList); } @@ -3558,42 +3619,42 @@ public void removeAllGroups(DefaultClusterCallback callback) { removeAllGroups(chipClusterPtr, callback); } - public void removeGroup(RemoveGroupResponseCallback callback, int groupId) { + public void removeGroup(RemoveGroupResponseCallback callback, Integer groupId) { removeGroup(chipClusterPtr, callback, groupId); } - public void viewGroup(ViewGroupResponseCallback callback, int groupId) { + public void viewGroup(ViewGroupResponseCallback callback, Integer groupId) { viewGroup(chipClusterPtr, callback, groupId); } private native void addGroup( - long chipClusterPtr, AddGroupResponseCallback callback, int groupId, String groupName); + long chipClusterPtr, AddGroupResponseCallback callback, Integer groupId, String groupName); private native void addGroupIfIdentifying( - long chipClusterPtr, DefaultClusterCallback callback, int groupId, String groupName); + long chipClusterPtr, DefaultClusterCallback callback, Integer groupId, String groupName); private native void getGroupMembership( long chipClusterPtr, GetGroupMembershipResponseCallback callback, - int groupCount, - int groupList); + Integer groupCount, + Integer groupList); private native void removeAllGroups(long chipClusterPtr, DefaultClusterCallback callback); private native void removeGroup( - long chipClusterPtr, RemoveGroupResponseCallback callback, int groupId); + long chipClusterPtr, RemoveGroupResponseCallback callback, Integer groupId); private native void viewGroup( - long chipClusterPtr, ViewGroupResponseCallback callback, int groupId); + long chipClusterPtr, ViewGroupResponseCallback callback, Integer groupId); public interface AddGroupResponseCallback { - void onSuccess(int status, int groupId); + void onSuccess(Integer status, Integer groupId); void onError(Exception error); } public interface GetGroupMembershipResponseCallback { - void onSuccess(int capacity, int groupCount + void onSuccess(Integer capacity, Integer groupCount // groupList: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet ); @@ -3602,13 +3663,13 @@ void onSuccess(int capacity, int groupCount } public interface RemoveGroupResponseCallback { - void onSuccess(int status, int groupId); + void onSuccess(Integer status, Integer groupId); void onError(Exception error); } public interface ViewGroupResponseCallback { - void onSuccess(int status, int groupId, String groupName); + void onSuccess(Integer status, Integer groupId, String groupName); void onError(Exception error); } @@ -3640,7 +3701,7 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void identify(DefaultClusterCallback callback, int identifyTime) { + public void identify(DefaultClusterCallback callback, Integer identifyTime) { identify(chipClusterPtr, callback, identifyTime); } @@ -3649,23 +3710,23 @@ public void identifyQuery(IdentifyQueryResponseCallback callback) { } public void triggerEffect( - DefaultClusterCallback callback, int effectIdentifier, int effectVariant) { + DefaultClusterCallback callback, Integer effectIdentifier, Integer effectVariant) { triggerEffect(chipClusterPtr, callback, effectIdentifier, effectVariant); } private native void identify( - long chipClusterPtr, DefaultClusterCallback callback, int identifyTime); + long chipClusterPtr, DefaultClusterCallback callback, Integer identifyTime); private native void identifyQuery(long chipClusterPtr, IdentifyQueryResponseCallback callback); private native void triggerEffect( long chipClusterPtr, DefaultClusterCallback callback, - int effectIdentifier, - int effectVariant); + Integer effectIdentifier, + Integer effectVariant); public interface IdentifyQueryResponseCallback { - void onSuccess(int timeout); + void onSuccess(Integer timeout); void onError(Exception error); } @@ -3781,14 +3842,15 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void sendKey(SendKeyResponseCallback callback, int keyCode) { + public void sendKey(SendKeyResponseCallback callback, Integer keyCode) { sendKey(chipClusterPtr, callback, keyCode); } - private native void sendKey(long chipClusterPtr, SendKeyResponseCallback callback, int keyCode); + private native void sendKey( + long chipClusterPtr, SendKeyResponseCallback callback, Integer keyCode); public interface SendKeyResponseCallback { - void onSuccess(int status); + void onSuccess(Integer status); void onError(Exception error); } @@ -3815,48 +3877,51 @@ public static long clusterId() { public void move( DefaultClusterCallback callback, - int moveMode, - int rate, - int optionMask, - int optionOverride) { + Integer moveMode, + Integer rate, + Integer optionMask, + Integer optionOverride) { move(chipClusterPtr, callback, moveMode, rate, optionMask, optionOverride); } public void moveToLevel( DefaultClusterCallback callback, - int level, - int transitionTime, - int optionMask, - int optionOverride) { + Integer level, + Integer transitionTime, + Integer optionMask, + Integer optionOverride) { moveToLevel(chipClusterPtr, callback, level, transitionTime, optionMask, optionOverride); } public void moveToLevelWithOnOff( - DefaultClusterCallback callback, int level, int transitionTime) { + DefaultClusterCallback callback, Integer level, Integer transitionTime) { moveToLevelWithOnOff(chipClusterPtr, callback, level, transitionTime); } - public void moveWithOnOff(DefaultClusterCallback callback, int moveMode, int rate) { + public void moveWithOnOff(DefaultClusterCallback callback, Integer moveMode, Integer rate) { moveWithOnOff(chipClusterPtr, callback, moveMode, rate); } public void step( DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int optionMask, - int optionOverride) { + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer optionMask, + Integer optionOverride) { step( chipClusterPtr, callback, stepMode, stepSize, transitionTime, optionMask, optionOverride); } public void stepWithOnOff( - DefaultClusterCallback callback, int stepMode, int stepSize, int transitionTime) { + DefaultClusterCallback callback, + Integer stepMode, + Integer stepSize, + Integer transitionTime) { stepWithOnOff(chipClusterPtr, callback, stepMode, stepSize, transitionTime); } - public void stop(DefaultClusterCallback callback, int optionMask, int optionOverride) { + public void stop(DefaultClusterCallback callback, Integer optionMask, Integer optionOverride) { stop(chipClusterPtr, callback, optionMask, optionOverride); } @@ -3867,43 +3932,49 @@ public void stopWithOnOff(DefaultClusterCallback callback) { private native void move( long chipClusterPtr, DefaultClusterCallback callback, - int moveMode, - int rate, - int optionMask, - int optionOverride); + Integer moveMode, + Integer rate, + Integer optionMask, + Integer optionOverride); private native void moveToLevel( long chipClusterPtr, DefaultClusterCallback callback, - int level, - int transitionTime, - int optionMask, - int optionOverride); + Integer level, + Integer transitionTime, + Integer optionMask, + Integer optionOverride); private native void moveToLevelWithOnOff( - long chipClusterPtr, DefaultClusterCallback callback, int level, int transitionTime); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer level, + Integer transitionTime); private native void moveWithOnOff( - long chipClusterPtr, DefaultClusterCallback callback, int moveMode, int rate); + long chipClusterPtr, DefaultClusterCallback callback, Integer moveMode, Integer rate); private native void step( long chipClusterPtr, DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime, - int optionMask, - int optionOverride); + Integer stepMode, + Integer stepSize, + Integer transitionTime, + Integer optionMask, + Integer optionOverride); private native void stepWithOnOff( long chipClusterPtr, DefaultClusterCallback callback, - int stepMode, - int stepSize, - int transitionTime); + Integer stepMode, + Integer stepSize, + Integer transitionTime); private native void stop( - long chipClusterPtr, DefaultClusterCallback callback, int optionMask, int optionOverride); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer optionMask, + Integer optionOverride); private native void stopWithOnOff(long chipClusterPtr, DefaultClusterCallback callback); @@ -4119,11 +4190,11 @@ public void hideInputStatus(DefaultClusterCallback callback) { hideInputStatus(chipClusterPtr, callback); } - public void renameInput(DefaultClusterCallback callback, int index, String name) { + public void renameInput(DefaultClusterCallback callback, Integer index, String name) { renameInput(chipClusterPtr, callback, index, name); } - public void selectInput(DefaultClusterCallback callback, int index) { + public void selectInput(DefaultClusterCallback callback, Integer index) { selectInput(chipClusterPtr, callback, index); } @@ -4134,10 +4205,10 @@ public void showInputStatus(DefaultClusterCallback callback) { private native void hideInputStatus(long chipClusterPtr, DefaultClusterCallback callback); private native void renameInput( - long chipClusterPtr, DefaultClusterCallback callback, int index, String name); + long chipClusterPtr, DefaultClusterCallback callback, Integer index, String name); private native void selectInput( - long chipClusterPtr, DefaultClusterCallback callback, int index); + long chipClusterPtr, DefaultClusterCallback callback, Integer index); private native void showInputStatus(long chipClusterPtr, DefaultClusterCallback callback); @@ -4242,17 +4313,17 @@ public void mediaRewind(MediaRewindResponseCallback callback) { mediaRewind(chipClusterPtr, callback); } - public void mediaSeek(MediaSeekResponseCallback callback, long position) { + public void mediaSeek(MediaSeekResponseCallback callback, Long position) { mediaSeek(chipClusterPtr, callback, position); } public void mediaSkipBackward( - MediaSkipBackwardResponseCallback callback, long deltaPositionMilliseconds) { + MediaSkipBackwardResponseCallback callback, Long deltaPositionMilliseconds) { mediaSkipBackward(chipClusterPtr, callback, deltaPositionMilliseconds); } public void mediaSkipForward( - MediaSkipForwardResponseCallback callback, long deltaPositionMilliseconds) { + MediaSkipForwardResponseCallback callback, Long deltaPositionMilliseconds) { mediaSkipForward(chipClusterPtr, callback, deltaPositionMilliseconds); } @@ -4278,17 +4349,17 @@ private native void mediaFastForward( private native void mediaRewind(long chipClusterPtr, MediaRewindResponseCallback callback); private native void mediaSeek( - long chipClusterPtr, MediaSeekResponseCallback callback, long position); + long chipClusterPtr, MediaSeekResponseCallback callback, Long position); private native void mediaSkipBackward( long chipClusterPtr, MediaSkipBackwardResponseCallback callback, - long deltaPositionMilliseconds); + Long deltaPositionMilliseconds); private native void mediaSkipForward( long chipClusterPtr, MediaSkipForwardResponseCallback callback, - long deltaPositionMilliseconds); + Long deltaPositionMilliseconds); private native void mediaStartOver( long chipClusterPtr, MediaStartOverResponseCallback callback); @@ -4296,67 +4367,67 @@ private native void mediaStartOver( private native void mediaStop(long chipClusterPtr, MediaStopResponseCallback callback); public interface MediaFastForwardResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaNextResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaPauseResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaPlayResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaPreviousResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaRewindResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaSeekResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaSkipBackwardResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaSkipForwardResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaStartOverResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } public interface MediaStopResponseCallback { - void onSuccess(int mediaPlaybackStatus); + void onSuccess(Integer mediaPlaybackStatus); void onError(Exception error); } @@ -4434,12 +4505,12 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void changeToMode(DefaultClusterCallback callback, int newMode) { + public void changeToMode(DefaultClusterCallback callback, Integer newMode) { changeToMode(chipClusterPtr, callback, newMode); } private native void changeToMode( - long chipClusterPtr, DefaultClusterCallback callback, int newMode); + long chipClusterPtr, DefaultClusterCallback callback, Integer newMode); public static class SupportedModesAttribute { public String label; @@ -4556,8 +4627,8 @@ public static long clusterId() { public void addThreadNetwork( AddThreadNetworkResponseCallback callback, byte[] operationalDataset, - long breadcrumb, - long timeoutMs) { + Long breadcrumb, + Long timeoutMs) { addThreadNetwork(chipClusterPtr, callback, operationalDataset, breadcrumb, timeoutMs); } @@ -4565,39 +4636,39 @@ public void addWiFiNetwork( AddWiFiNetworkResponseCallback callback, byte[] ssid, byte[] credentials, - long breadcrumb, - long timeoutMs) { + Long breadcrumb, + Long timeoutMs) { addWiFiNetwork(chipClusterPtr, callback, ssid, credentials, breadcrumb, timeoutMs); } public void disableNetwork( DisableNetworkResponseCallback callback, byte[] networkID, - long breadcrumb, - long timeoutMs) { + Long breadcrumb, + Long timeoutMs) { disableNetwork(chipClusterPtr, callback, networkID, breadcrumb, timeoutMs); } public void enableNetwork( - EnableNetworkResponseCallback callback, byte[] networkID, long breadcrumb, long timeoutMs) { + EnableNetworkResponseCallback callback, byte[] networkID, Long breadcrumb, Long timeoutMs) { enableNetwork(chipClusterPtr, callback, networkID, breadcrumb, timeoutMs); } public void removeNetwork( - RemoveNetworkResponseCallback callback, byte[] networkID, long breadcrumb, long timeoutMs) { + RemoveNetworkResponseCallback callback, byte[] networkID, Long breadcrumb, Long timeoutMs) { removeNetwork(chipClusterPtr, callback, networkID, breadcrumb, timeoutMs); } public void scanNetworks( - ScanNetworksResponseCallback callback, byte[] ssid, long breadcrumb, long timeoutMs) { + ScanNetworksResponseCallback callback, byte[] ssid, Long breadcrumb, Long timeoutMs) { scanNetworks(chipClusterPtr, callback, ssid, breadcrumb, timeoutMs); } public void updateThreadNetwork( UpdateThreadNetworkResponseCallback callback, byte[] operationalDataset, - long breadcrumb, - long timeoutMs) { + Long breadcrumb, + Long timeoutMs) { updateThreadNetwork(chipClusterPtr, callback, operationalDataset, breadcrumb, timeoutMs); } @@ -4605,8 +4676,8 @@ public void updateWiFiNetwork( UpdateWiFiNetworkResponseCallback callback, byte[] ssid, byte[] credentials, - long breadcrumb, - long timeoutMs) { + Long breadcrumb, + Long timeoutMs) { updateWiFiNetwork(chipClusterPtr, callback, ssid, credentials, breadcrumb, timeoutMs); } @@ -4614,92 +4685,92 @@ private native void addThreadNetwork( long chipClusterPtr, AddThreadNetworkResponseCallback callback, byte[] operationalDataset, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); private native void addWiFiNetwork( long chipClusterPtr, AddWiFiNetworkResponseCallback callback, byte[] ssid, byte[] credentials, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); private native void disableNetwork( long chipClusterPtr, DisableNetworkResponseCallback callback, byte[] networkID, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); private native void enableNetwork( long chipClusterPtr, EnableNetworkResponseCallback callback, byte[] networkID, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); private native void removeNetwork( long chipClusterPtr, RemoveNetworkResponseCallback callback, byte[] networkID, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); private native void scanNetworks( long chipClusterPtr, ScanNetworksResponseCallback callback, byte[] ssid, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); private native void updateThreadNetwork( long chipClusterPtr, UpdateThreadNetworkResponseCallback callback, byte[] operationalDataset, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); private native void updateWiFiNetwork( long chipClusterPtr, UpdateWiFiNetworkResponseCallback callback, byte[] ssid, byte[] credentials, - long breadcrumb, - long timeoutMs); + Long breadcrumb, + Long timeoutMs); public interface AddThreadNetworkResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } public interface AddWiFiNetworkResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } public interface DisableNetworkResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } public interface EnableNetworkResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } public interface RemoveNetworkResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } public interface ScanNetworksResponseCallback { - void onSuccess(int errorCode, String debugText + void onSuccess(Integer errorCode, String debugText // wifiScanResults: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet // threadScanResults: /* TYPE WARNING: array array defaults to */ uint8_t * @@ -4710,13 +4781,13 @@ void onSuccess(int errorCode, String debugText } public interface UpdateThreadNetworkResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } public interface UpdateWiFiNetworkResponseCallback { - void onSuccess(int errorCode, String debugText); + void onSuccess(Integer errorCode, String debugText); void onError(Exception error); } @@ -4749,25 +4820,25 @@ public static long clusterId() { public native long initWithDevice(long devicePtr, int endpointId); public void applyUpdateRequest( - ApplyUpdateResponseCallback callback, byte[] updateToken, long newVersion) { + ApplyUpdateResponseCallback callback, byte[] updateToken, Long newVersion) { applyUpdateRequest(chipClusterPtr, callback, updateToken, newVersion); } public void notifyUpdateApplied( - DefaultClusterCallback callback, byte[] updateToken, long softwareVersion) { + DefaultClusterCallback callback, byte[] updateToken, Long softwareVersion) { notifyUpdateApplied(chipClusterPtr, callback, updateToken, softwareVersion); } public void queryImage( QueryImageResponseCallback callback, - int vendorId, - int productId, - long softwareVersion, - int protocolsSupported, - int hardwareVersion, - String location, - boolean requestorCanConsent, - byte[] metadataForProvider) { + Integer vendorId, + Integer productId, + Long softwareVersion, + Integer protocolsSupported, + Optional hardwareVersion, + Optional location, + Optional requestorCanConsent, + Optional metadataForProvider) { queryImage( chipClusterPtr, callback, @@ -4785,42 +4856,42 @@ private native void applyUpdateRequest( long chipClusterPtr, ApplyUpdateResponseCallback callback, byte[] updateToken, - long newVersion); + Long newVersion); private native void notifyUpdateApplied( long chipClusterPtr, DefaultClusterCallback callback, byte[] updateToken, - long softwareVersion); + Long softwareVersion); private native void queryImage( long chipClusterPtr, QueryImageResponseCallback callback, - int vendorId, - int productId, - long softwareVersion, - int protocolsSupported, - int hardwareVersion, - String location, - boolean requestorCanConsent, - byte[] metadataForProvider); + Integer vendorId, + Integer productId, + Long softwareVersion, + Integer protocolsSupported, + Optional hardwareVersion, + Optional location, + Optional requestorCanConsent, + Optional metadataForProvider); public interface ApplyUpdateResponseCallback { - void onSuccess(int action, long delayedActionTime); + void onSuccess(Integer action, Long delayedActionTime); void onError(Exception error); } public interface QueryImageResponseCallback { void onSuccess( - int status, - long delayedActionTime, - String imageURI, - long softwareVersion, - String softwareVersionString, - byte[] updateToken, - boolean userConsentNeeded, - byte[] metadataForRequestor); + Integer status, + Optional delayedActionTime, + Optional imageURI, + Optional softwareVersion, + Optional softwareVersionString, + Optional updateToken, + Optional userConsentNeeded, + Optional metadataForRequestor); void onError(Exception error); } @@ -4847,10 +4918,10 @@ public static long clusterId() { public void announceOtaProvider( DefaultClusterCallback callback, - long providerLocation, - int vendorId, - int announcementReason, - byte[] metadataForNode) { + Long providerLocation, + Integer vendorId, + Integer announcementReason, + Optional metadataForNode) { announceOtaProvider( chipClusterPtr, callback, @@ -4863,10 +4934,10 @@ public void announceOtaProvider( private native void announceOtaProvider( long chipClusterPtr, DefaultClusterCallback callback, - long providerLocation, - int vendorId, - int announcementReason, - byte[] metadataForNode); + Long providerLocation, + Integer vendorId, + Integer announcementReason, + Optional metadataForNode); public void readDefaultOtaProviderAttribute(OctetStringAttributeCallback callback) { readDefaultOtaProviderAttribute(chipClusterPtr, callback); @@ -4969,7 +5040,8 @@ public void off(DefaultClusterCallback callback) { off(chipClusterPtr, callback); } - public void offWithEffect(DefaultClusterCallback callback, int effectId, int effectVariant) { + public void offWithEffect( + DefaultClusterCallback callback, Integer effectId, Integer effectVariant) { offWithEffect(chipClusterPtr, callback, effectId, effectVariant); } @@ -4982,7 +5054,10 @@ public void onWithRecallGlobalScene(DefaultClusterCallback callback) { } public void onWithTimedOff( - DefaultClusterCallback callback, int onOffControl, int onTime, int offWaitTime) { + DefaultClusterCallback callback, + Integer onOffControl, + Integer onTime, + Integer offWaitTime) { onWithTimedOff(chipClusterPtr, callback, onOffControl, onTime, offWaitTime); } @@ -4993,7 +5068,10 @@ public void toggle(DefaultClusterCallback callback) { private native void off(long chipClusterPtr, DefaultClusterCallback callback); private native void offWithEffect( - long chipClusterPtr, DefaultClusterCallback callback, int effectId, int effectVariant); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer effectId, + Integer effectVariant); private native void on(long chipClusterPtr, DefaultClusterCallback callback); @@ -5003,9 +5081,9 @@ private native void onWithRecallGlobalScene( private native void onWithTimedOff( long chipClusterPtr, DefaultClusterCallback callback, - int onOffControl, - int onTime, - int offWaitTime); + Integer onOffControl, + Integer onTime, + Integer offWaitTime); private native void toggle(long chipClusterPtr, DefaultClusterCallback callback); @@ -5149,10 +5227,10 @@ public static long clusterId() { public void addNOC( NOCResponseCallback callback, byte[] NOCValue, - byte[] ICACValue, + Optional ICACValue, byte[] IPKValue, - long caseAdminNode, - int adminVendorId) { + Long caseAdminNode, + Integer adminVendorId) { addNOC(chipClusterPtr, callback, NOCValue, ICACValue, IPKValue, caseAdminNode, adminVendorId); } @@ -5165,7 +5243,7 @@ public void attestationRequest(AttestationResponseCallback callback, byte[] atte } public void certificateChainRequest( - CertificateChainResponseCallback callback, int certificateType) { + CertificateChainResponseCallback callback, Integer certificateType) { certificateChainRequest(chipClusterPtr, callback, certificateType); } @@ -5173,7 +5251,7 @@ public void opCSRRequest(OpCSRResponseCallback callback, byte[] CSRNonce) { opCSRRequest(chipClusterPtr, callback, CSRNonce); } - public void removeFabric(NOCResponseCallback callback, int fabricIndex) { + public void removeFabric(NOCResponseCallback callback, Integer fabricIndex) { removeFabric(chipClusterPtr, callback, fabricIndex); } @@ -5186,7 +5264,8 @@ public void updateFabricLabel(NOCResponseCallback callback, String label) { updateFabricLabel(chipClusterPtr, callback, label); } - public void updateNOC(NOCResponseCallback callback, byte[] NOCValue, byte[] ICACValue) { + public void updateNOC( + NOCResponseCallback callback, byte[] NOCValue, Optional ICACValue) { updateNOC(chipClusterPtr, callback, NOCValue, ICACValue); } @@ -5194,10 +5273,10 @@ private native void addNOC( long chipClusterPtr, NOCResponseCallback callback, byte[] NOCValue, - byte[] ICACValue, + Optional ICACValue, byte[] IPKValue, - long caseAdminNode, - int adminVendorId); + Long caseAdminNode, + Integer adminVendorId); private native void addTrustedRootCertificate( long chipClusterPtr, DefaultClusterCallback callback, byte[] rootCertificate); @@ -5206,13 +5285,13 @@ private native void attestationRequest( long chipClusterPtr, AttestationResponseCallback callback, byte[] attestationNonce); private native void certificateChainRequest( - long chipClusterPtr, CertificateChainResponseCallback callback, int certificateType); + long chipClusterPtr, CertificateChainResponseCallback callback, Integer certificateType); private native void opCSRRequest( long chipClusterPtr, OpCSRResponseCallback callback, byte[] CSRNonce); private native void removeFabric( - long chipClusterPtr, NOCResponseCallback callback, int fabricIndex); + long chipClusterPtr, NOCResponseCallback callback, Integer fabricIndex); private native void removeTrustedRootCertificate( long chipClusterPtr, DefaultClusterCallback callback, byte[] trustedRootIdentifier); @@ -5221,7 +5300,10 @@ private native void updateFabricLabel( long chipClusterPtr, NOCResponseCallback callback, String label); private native void updateNOC( - long chipClusterPtr, NOCResponseCallback callback, byte[] NOCValue, byte[] ICACValue); + long chipClusterPtr, + NOCResponseCallback callback, + byte[] NOCValue, + Optional ICACValue); public interface AttestationResponseCallback { void onSuccess(byte[] AttestationElements, byte[] Signature); @@ -5236,7 +5318,7 @@ public interface CertificateChainResponseCallback { } public interface NOCResponseCallback { - void onSuccess(int StatusCode, int FabricIndex, String DebugText); + void onSuccess(Integer StatusCode, Integer FabricIndex, String DebugText); void onError(Exception error); } @@ -5823,13 +5905,13 @@ public static long clusterId() { public void addScene( AddSceneResponseCallback callback, - int groupId, - int sceneId, - int transitionTime, + Integer groupId, + Integer sceneId, + Integer transitionTime, String sceneName, - long clusterId, - int length, - int value) { + Long clusterId, + Integer length, + Integer value) { addScene( chipClusterPtr, callback, @@ -5842,72 +5924,76 @@ public void addScene( value); } - public void getSceneMembership(GetSceneMembershipResponseCallback callback, int groupId) { + public void getSceneMembership(GetSceneMembershipResponseCallback callback, Integer groupId) { getSceneMembership(chipClusterPtr, callback, groupId); } public void recallScene( - DefaultClusterCallback callback, int groupId, int sceneId, int transitionTime) { + DefaultClusterCallback callback, Integer groupId, Integer sceneId, Integer transitionTime) { recallScene(chipClusterPtr, callback, groupId, sceneId, transitionTime); } - public void removeAllScenes(RemoveAllScenesResponseCallback callback, int groupId) { + public void removeAllScenes(RemoveAllScenesResponseCallback callback, Integer groupId) { removeAllScenes(chipClusterPtr, callback, groupId); } - public void removeScene(RemoveSceneResponseCallback callback, int groupId, int sceneId) { + public void removeScene( + RemoveSceneResponseCallback callback, Integer groupId, Integer sceneId) { removeScene(chipClusterPtr, callback, groupId, sceneId); } - public void storeScene(StoreSceneResponseCallback callback, int groupId, int sceneId) { + public void storeScene(StoreSceneResponseCallback callback, Integer groupId, Integer sceneId) { storeScene(chipClusterPtr, callback, groupId, sceneId); } - public void viewScene(ViewSceneResponseCallback callback, int groupId, int sceneId) { + public void viewScene(ViewSceneResponseCallback callback, Integer groupId, Integer sceneId) { viewScene(chipClusterPtr, callback, groupId, sceneId); } private native void addScene( long chipClusterPtr, AddSceneResponseCallback callback, - int groupId, - int sceneId, - int transitionTime, + Integer groupId, + Integer sceneId, + Integer transitionTime, String sceneName, - long clusterId, - int length, - int value); + Long clusterId, + Integer length, + Integer value); private native void getSceneMembership( - long chipClusterPtr, GetSceneMembershipResponseCallback callback, int groupId); + long chipClusterPtr, GetSceneMembershipResponseCallback callback, Integer groupId); private native void recallScene( long chipClusterPtr, DefaultClusterCallback callback, - int groupId, - int sceneId, - int transitionTime); + Integer groupId, + Integer sceneId, + Integer transitionTime); private native void removeAllScenes( - long chipClusterPtr, RemoveAllScenesResponseCallback callback, int groupId); + long chipClusterPtr, RemoveAllScenesResponseCallback callback, Integer groupId); private native void removeScene( - long chipClusterPtr, RemoveSceneResponseCallback callback, int groupId, int sceneId); + long chipClusterPtr, + RemoveSceneResponseCallback callback, + Integer groupId, + Integer sceneId); private native void storeScene( - long chipClusterPtr, StoreSceneResponseCallback callback, int groupId, int sceneId); + long chipClusterPtr, StoreSceneResponseCallback callback, Integer groupId, Integer sceneId); private native void viewScene( - long chipClusterPtr, ViewSceneResponseCallback callback, int groupId, int sceneId); + long chipClusterPtr, ViewSceneResponseCallback callback, Integer groupId, Integer sceneId); public interface AddSceneResponseCallback { - void onSuccess(int status, int groupId, int sceneId); + void onSuccess(Integer status, Integer groupId, Integer sceneId); void onError(Exception error); } public interface GetSceneMembershipResponseCallback { - void onSuccess(int status, int capacity, int groupId, int sceneCount + void onSuccess(Integer status, Integer capacity, Integer groupId, Integer sceneCount // sceneList: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet ); @@ -5916,25 +6002,26 @@ void onSuccess(int status, int capacity, int groupId, int sceneCount } public interface RemoveAllScenesResponseCallback { - void onSuccess(int status, int groupId); + void onSuccess(Integer status, Integer groupId); void onError(Exception error); } public interface RemoveSceneResponseCallback { - void onSuccess(int status, int groupId, int sceneId); + void onSuccess(Integer status, Integer groupId, Integer sceneId); void onError(Exception error); } public interface StoreSceneResponseCallback { - void onSuccess(int status, int groupId, int sceneId); + void onSuccess(Integer status, Integer groupId, Integer sceneId); void onError(Exception error); } public interface ViewSceneResponseCallback { - void onSuccess(int status, int groupId, int sceneId, int transitionTime, String sceneName + void onSuccess( + Integer status, Integer groupId, Integer sceneId, Integer transitionTime, String sceneName // extensionFieldSets: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet ); @@ -6168,11 +6255,11 @@ public void changeChannel(ChangeChannelResponseCallback callback, String match) } public void changeChannelByNumber( - DefaultClusterCallback callback, int majorNumber, int minorNumber) { + DefaultClusterCallback callback, Integer majorNumber, Integer minorNumber) { changeChannelByNumber(chipClusterPtr, callback, majorNumber, minorNumber); } - public void skipChannel(DefaultClusterCallback callback, int count) { + public void skipChannel(DefaultClusterCallback callback, Integer count) { skipChannel(chipClusterPtr, callback, count); } @@ -6180,16 +6267,18 @@ private native void changeChannel( long chipClusterPtr, ChangeChannelResponseCallback callback, String match); private native void changeChannelByNumber( - long chipClusterPtr, DefaultClusterCallback callback, int majorNumber, int minorNumber); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer majorNumber, + Integer minorNumber); private native void skipChannel( - long chipClusterPtr, DefaultClusterCallback callback, int count); + long chipClusterPtr, DefaultClusterCallback callback, Integer count); public interface ChangeChannelResponseCallback { - void onSuccess( - // ChannelMatch: /* TYPE WARNING: array array defaults to */ uint8_t * + void onSuccess( // ChannelMatch: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet - int ErrorType); + Integer ErrorType); void onError(Exception error); } @@ -6288,15 +6377,16 @@ public static long clusterId() { @Override public native long initWithDevice(long devicePtr, int endpointId); - public void navigateTarget(NavigateTargetResponseCallback callback, int target, String data) { + public void navigateTarget( + NavigateTargetResponseCallback callback, Integer target, String data) { navigateTarget(chipClusterPtr, callback, target, data); } private native void navigateTarget( - long chipClusterPtr, NavigateTargetResponseCallback callback, int target, String data); + long chipClusterPtr, NavigateTargetResponseCallback callback, Integer target, String data); public interface NavigateTargetResponseCallback { - void onSuccess(int status, String data); + void onSuccess(Integer status, String data); void onError(Exception error); } @@ -6440,25 +6530,32 @@ public void test(DefaultClusterCallback callback) { test(chipClusterPtr, callback); } - public void testAddArguments(TestAddArgumentsResponseCallback callback, int arg1, int arg2) { + public void testAddArguments( + TestAddArgumentsResponseCallback callback, Integer arg1, Integer arg2) { testAddArguments(chipClusterPtr, callback, arg1, arg2); } - public void testEnumsRequest(TestEnumsResponseCallback callback, int arg1, int arg2) { + public void testEnumsRequest(TestEnumsResponseCallback callback, Integer arg1, Integer arg2) { testEnumsRequest(chipClusterPtr, callback, arg1, arg2); } - public void testListInt8UArgumentRequest(BooleanResponseCallback callback, int arg1) { + public void testListInt8UArgumentRequest(BooleanResponseCallback callback, Integer arg1) { testListInt8UArgumentRequest(chipClusterPtr, callback, arg1); } public void testListInt8UReverseRequest( - TestListInt8UReverseResponseCallback callback, int arg1) { + TestListInt8UReverseResponseCallback callback, Integer arg1) { testListInt8UReverseRequest(chipClusterPtr, callback, arg1); } public void testListStructArgumentRequest( - BooleanResponseCallback callback, int a, boolean b, int c, byte[] d, String e, int f) { + BooleanResponseCallback callback, + Integer a, + Boolean b, + Integer c, + byte[] d, + String e, + Integer f) { testListStructArgumentRequest(chipClusterPtr, callback, a, b, c, d, e, f); } @@ -6467,7 +6564,7 @@ public void testNotHandled(DefaultClusterCallback callback) { } public void testNullableOptionalRequest( - TestNullableOptionalResponseCallback callback, int arg1) { + TestNullableOptionalResponseCallback callback, Optional arg1) { testNullableOptionalRequest(chipClusterPtr, callback, arg1); } @@ -6476,7 +6573,13 @@ public void testSpecific(TestSpecificResponseCallback callback) { } public void testStructArgumentRequest( - BooleanResponseCallback callback, int a, boolean b, int c, byte[] d, String e, int f) { + BooleanResponseCallback callback, + Integer a, + Boolean b, + Integer c, + byte[] d, + String e, + Integer f) { testStructArgumentRequest(chipClusterPtr, callback, a, b, c, d, e, f); } @@ -6487,67 +6590,66 @@ public void testUnknownCommand(DefaultClusterCallback callback) { private native void test(long chipClusterPtr, DefaultClusterCallback callback); private native void testAddArguments( - long chipClusterPtr, TestAddArgumentsResponseCallback callback, int arg1, int arg2); + long chipClusterPtr, TestAddArgumentsResponseCallback callback, Integer arg1, Integer arg2); private native void testEnumsRequest( - long chipClusterPtr, TestEnumsResponseCallback callback, int arg1, int arg2); + long chipClusterPtr, TestEnumsResponseCallback callback, Integer arg1, Integer arg2); private native void testListInt8UArgumentRequest( - long chipClusterPtr, BooleanResponseCallback callback, int arg1); + long chipClusterPtr, BooleanResponseCallback callback, Integer arg1); private native void testListInt8UReverseRequest( - long chipClusterPtr, TestListInt8UReverseResponseCallback callback, int arg1); + long chipClusterPtr, TestListInt8UReverseResponseCallback callback, Integer arg1); private native void testListStructArgumentRequest( long chipClusterPtr, BooleanResponseCallback callback, - int a, - boolean b, - int c, + Integer a, + Boolean b, + Integer c, byte[] d, String e, - int f); + Integer f); private native void testNotHandled(long chipClusterPtr, DefaultClusterCallback callback); private native void testNullableOptionalRequest( - long chipClusterPtr, TestNullableOptionalResponseCallback callback, int arg1); + long chipClusterPtr, TestNullableOptionalResponseCallback callback, Optional arg1); private native void testSpecific(long chipClusterPtr, TestSpecificResponseCallback callback); private native void testStructArgumentRequest( long chipClusterPtr, BooleanResponseCallback callback, - int a, - boolean b, - int c, + Integer a, + Boolean b, + Integer c, byte[] d, String e, - int f); + Integer f); private native void testUnknownCommand(long chipClusterPtr, DefaultClusterCallback callback); public interface BooleanResponseCallback { - void onSuccess(boolean value); + void onSuccess(Boolean value); void onError(Exception error); } public interface TestAddArgumentsResponseCallback { - void onSuccess(int returnValue); + void onSuccess(Integer returnValue); void onError(Exception error); } public interface TestEnumsResponseCallback { - void onSuccess(int arg1, int arg2); + void onSuccess(Integer arg1, Integer arg2); void onError(Exception error); } public interface TestListInt8UReverseResponseCallback { - void onSuccess( - // arg1: /* TYPE WARNING: array array defaults to */ uint8_t * + void onSuccess( // arg1: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet ); @@ -6555,13 +6657,17 @@ void onSuccess( } public interface TestNullableOptionalResponseCallback { - void onSuccess(boolean wasPresent, boolean wasNull, int value, int originalValue); + void onSuccess( + Boolean wasPresent, + Optional wasNull, + Optional value, + Optional originalValue); void onError(Exception error); } public interface TestSpecificResponseCallback { - void onSuccess(int returnValue); + void onSuccess(Integer returnValue); void onError(Exception error); } @@ -7250,16 +7356,16 @@ public void getRelayStatusLog(DefaultClusterCallback callback) { } public void getWeeklySchedule( - DefaultClusterCallback callback, int daysToReturn, int modeToReturn) { + DefaultClusterCallback callback, Integer daysToReturn, Integer modeToReturn) { getWeeklySchedule(chipClusterPtr, callback, daysToReturn, modeToReturn); } public void setWeeklySchedule( DefaultClusterCallback callback, - int numberOfTransitionsForSequence, - int dayOfWeekForSequence, - int modeForSequence, - int payload) { + Integer numberOfTransitionsForSequence, + Integer dayOfWeekForSequence, + Integer modeForSequence, + Integer payload) { setWeeklySchedule( chipClusterPtr, callback, @@ -7269,7 +7375,7 @@ public void setWeeklySchedule( payload); } - public void setpointRaiseLower(DefaultClusterCallback callback, int mode, int amount) { + public void setpointRaiseLower(DefaultClusterCallback callback, Integer mode, Integer amount) { setpointRaiseLower(chipClusterPtr, callback, mode, amount); } @@ -7278,18 +7384,21 @@ public void setpointRaiseLower(DefaultClusterCallback callback, int mode, int am private native void getRelayStatusLog(long chipClusterPtr, DefaultClusterCallback callback); private native void getWeeklySchedule( - long chipClusterPtr, DefaultClusterCallback callback, int daysToReturn, int modeToReturn); + long chipClusterPtr, + DefaultClusterCallback callback, + Integer daysToReturn, + Integer modeToReturn); private native void setWeeklySchedule( long chipClusterPtr, DefaultClusterCallback callback, - int numberOfTransitionsForSequence, - int dayOfWeekForSequence, - int modeForSequence, - int payload); + Integer numberOfTransitionsForSequence, + Integer dayOfWeekForSequence, + Integer modeForSequence, + Integer payload); private native void setpointRaiseLower( - long chipClusterPtr, DefaultClusterCallback callback, int mode, int amount); + long chipClusterPtr, DefaultClusterCallback callback, Integer mode, Integer amount); public void readLocalTemperatureAttribute(IntegerAttributeCallback callback) { readLocalTemperatureAttribute(chipClusterPtr, callback); @@ -8536,20 +8645,24 @@ public void downOrClose(DefaultClusterCallback callback) { } public void goToLiftPercentage( - DefaultClusterCallback callback, int liftPercentageValue, int liftPercent100thsValue) { + DefaultClusterCallback callback, + Integer liftPercentageValue, + Integer liftPercent100thsValue) { goToLiftPercentage(chipClusterPtr, callback, liftPercentageValue, liftPercent100thsValue); } - public void goToLiftValue(DefaultClusterCallback callback, int liftValue) { + public void goToLiftValue(DefaultClusterCallback callback, Integer liftValue) { goToLiftValue(chipClusterPtr, callback, liftValue); } public void goToTiltPercentage( - DefaultClusterCallback callback, int tiltPercentageValue, int tiltPercent100thsValue) { + DefaultClusterCallback callback, + Integer tiltPercentageValue, + Integer tiltPercent100thsValue) { goToTiltPercentage(chipClusterPtr, callback, tiltPercentageValue, tiltPercent100thsValue); } - public void goToTiltValue(DefaultClusterCallback callback, int tiltValue) { + public void goToTiltValue(DefaultClusterCallback callback, Integer tiltValue) { goToTiltValue(chipClusterPtr, callback, tiltValue); } @@ -8566,20 +8679,20 @@ public void upOrOpen(DefaultClusterCallback callback) { private native void goToLiftPercentage( long chipClusterPtr, DefaultClusterCallback callback, - int liftPercentageValue, - int liftPercent100thsValue); + Integer liftPercentageValue, + Integer liftPercent100thsValue); private native void goToLiftValue( - long chipClusterPtr, DefaultClusterCallback callback, int liftValue); + long chipClusterPtr, DefaultClusterCallback callback, Integer liftValue); private native void goToTiltPercentage( long chipClusterPtr, DefaultClusterCallback callback, - int tiltPercentageValue, - int tiltPercent100thsValue); + Integer tiltPercentageValue, + Integer tiltPercent100thsValue); private native void goToTiltValue( - long chipClusterPtr, DefaultClusterCallback callback, int tiltValue); + long chipClusterPtr, DefaultClusterCallback callback, Integer tiltValue); private native void stopMotion(long chipClusterPtr, DefaultClusterCallback callback); diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java b/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java index 2d405e24069506..d7d9492ee33005 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java @@ -30,6 +30,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; public class ClusterInfoMapping { @@ -208,7 +209,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, String data) { + public void onSuccess(Integer status, String data) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -343,7 +344,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(String data, int contentLaunchStatus) { + public void onSuccess(String data, Integer contentLaunchStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo dataResponseValue = new CommandResponseInfo("data", "String"); responseValues.put(dataResponseValue, data); @@ -370,7 +371,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(String data, int contentLaunchStatus) { + public void onSuccess(String data, Integer contentLaunchStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo dataResponseValue = new CommandResponseInfo("data", "String"); responseValues.put(dataResponseValue, data); @@ -552,7 +553,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, byte[] content, long timeStamp, long timeSinceBoot) { + public void onSuccess(Integer status, byte[] content, Long timeStamp, Long timeSinceBoot) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -583,7 +584,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -607,7 +608,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -631,7 +632,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -654,7 +655,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -677,7 +678,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -701,7 +702,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -725,7 +726,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -750,11 +751,11 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { @Override public void onSuccess( - int scheduleId, - int status, - long localStartTime, - long localEndTime, - int operatingModeDuringHoliday) { + Integer scheduleId, + Integer status, + Long localStartTime, + Long localEndTime, + Integer operatingModeDuringHoliday) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo scheduleIdResponseValue = new CommandResponseInfo("scheduleId", "int"); responseValues.put(scheduleIdResponseValue, scheduleId); @@ -790,12 +791,12 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { @Override public void onSuccess( - int logEntryId, - long timestamp, - int eventType, - int source, - int eventIdOrAlarmCode, - int userId, + Integer logEntryId, + Long timestamp, + Integer eventType, + Integer source, + Integer eventIdOrAlarmCode, + Integer userId, byte[] pin) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo logEntryIdResponseValue = new CommandResponseInfo("logEntryId", "int"); @@ -832,7 +833,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int userId, int userStatus, int userType, byte[] pin) { + public void onSuccess(Integer userId, Integer userStatus, Integer userType, byte[] pin) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo userIdResponseValue = new CommandResponseInfo("userId", "int"); responseValues.put(userIdResponseValue, userId); @@ -861,7 +862,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int userId, int userStatus, int userType, byte[] rfid) { + public void onSuccess(Integer userId, Integer userStatus, Integer userType, byte[] rfid) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo userIdResponseValue = new CommandResponseInfo("userId", "int"); responseValues.put(userIdResponseValue, userId); @@ -891,7 +892,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int userId, int userType) { + public void onSuccess(Integer userId, Integer userType) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo userIdResponseValue = new CommandResponseInfo("userId", "int"); responseValues.put(userIdResponseValue, userId); @@ -918,14 +919,14 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { @Override public void onSuccess( - int scheduleId, - int userId, - int status, - int daysMask, - int startHour, - int startMinute, - int endHour, - int endMinute) { + Integer scheduleId, + Integer userId, + Integer status, + Integer daysMask, + Integer startHour, + Integer startMinute, + Integer endHour, + Integer endMinute) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo scheduleIdResponseValue = new CommandResponseInfo("scheduleId", "int"); responseValues.put(scheduleIdResponseValue, scheduleId); @@ -964,7 +965,11 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { @Override public void onSuccess( - int scheduleId, int userId, int status, long localStartTime, long localEndTime) { + Integer scheduleId, + Integer userId, + Integer status, + Long localStartTime, + Long localEndTime) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo scheduleIdResponseValue = new CommandResponseInfo("scheduleId", "int"); responseValues.put(scheduleIdResponseValue, scheduleId); @@ -997,7 +1002,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1021,7 +1026,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1044,7 +1049,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1067,7 +1072,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1091,7 +1096,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1115,7 +1120,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1139,7 +1144,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1162,7 +1167,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1186,7 +1191,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1237,7 +1242,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -1263,7 +1268,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -1289,7 +1294,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -1507,7 +1512,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int groupId) { + public void onSuccess(Integer status, Integer groupId) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1533,7 +1538,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int capacity, int groupCount + public void onSuccess(Integer capacity, Integer groupCount // groupList: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet ) { @@ -1563,7 +1568,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int groupId) { + public void onSuccess(Integer status, Integer groupId) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1588,7 +1593,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int groupId, String groupName) { + public void onSuccess(Integer status, Integer groupId, String groupName) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1616,7 +1621,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int timeout) { + public void onSuccess(Integer timeout) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo timeoutResponseValue = new CommandResponseInfo("timeout", "int"); responseValues.put(timeoutResponseValue, timeout); @@ -1639,7 +1644,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status) { + public void onSuccess(Integer status) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -1690,7 +1695,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1715,7 +1720,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1740,7 +1745,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1765,7 +1770,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1790,7 +1795,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1815,7 +1820,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1840,7 +1845,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1865,7 +1870,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1890,7 +1895,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1915,7 +1920,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1940,7 +1945,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int mediaPlaybackStatus) { + public void onSuccess(Integer mediaPlaybackStatus) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo mediaPlaybackStatusResponseValue = new CommandResponseInfo("mediaPlaybackStatus", "int"); @@ -1992,7 +1997,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -2018,7 +2023,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -2044,7 +2049,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -2070,7 +2075,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -2096,7 +2101,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -2122,7 +2127,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText + public void onSuccess(Integer errorCode, String debugText // wifiScanResults: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet // threadScanResults: /* TYPE WARNING: array array defaults to */ uint8_t * @@ -2157,7 +2162,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -2183,7 +2188,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int errorCode, String debugText) { + public void onSuccess(Integer errorCode, String debugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo errorCodeResponseValue = new CommandResponseInfo("errorCode", "int"); responseValues.put(errorCodeResponseValue, errorCode); @@ -2209,7 +2214,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int action, long delayedActionTime) { + public void onSuccess(Integer action, Long delayedActionTime) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo actionResponseValue = new CommandResponseInfo("action", "int"); responseValues.put(actionResponseValue, action); @@ -2237,14 +2242,14 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { @Override public void onSuccess( - int status, - long delayedActionTime, - String imageURI, - long softwareVersion, - String softwareVersionString, - byte[] updateToken, - boolean userConsentNeeded, - byte[] metadataForRequestor) { + Integer status, + Optional delayedActionTime, + Optional imageURI, + Optional softwareVersion, + Optional softwareVersionString, + Optional updateToken, + Optional userConsentNeeded, + Optional metadataForRequestor) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -2340,7 +2345,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int StatusCode, int FabricIndex, String DebugText) { + public void onSuccess(Integer StatusCode, Integer FabricIndex, String DebugText) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo StatusCodeResponseValue = new CommandResponseInfo("StatusCode", "int"); responseValues.put(StatusCodeResponseValue, StatusCode); @@ -2476,7 +2481,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int groupId, int sceneId) { + public void onSuccess(Integer status, Integer groupId, Integer sceneId) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -2504,7 +2509,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int capacity, int groupId, int sceneCount + public void onSuccess(Integer status, Integer capacity, Integer groupId, Integer sceneCount // sceneList: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet ) { @@ -2539,7 +2544,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int groupId) { + public void onSuccess(Integer status, Integer groupId) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -2564,7 +2569,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int groupId, int sceneId) { + public void onSuccess(Integer status, Integer groupId, Integer sceneId) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -2591,7 +2596,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int groupId, int sceneId) { + public void onSuccess(Integer status, Integer groupId, Integer sceneId) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -2618,7 +2623,8 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, int groupId, int sceneId, int transitionTime, String sceneName + public void onSuccess( + Integer status, Integer groupId, Integer sceneId, Integer transitionTime, String sceneName // extensionFieldSets: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet ) { @@ -2684,10 +2690,9 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess( - // ChannelMatch: /* TYPE WARNING: array array defaults to */ uint8_t * + public void onSuccess( // ChannelMatch: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet - int ErrorType) { + Integer ErrorType) { Map responseValues = new LinkedHashMap<>(); // ChannelMatch: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet @@ -2740,7 +2745,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int status, String data) { + public void onSuccess(Integer status, String data) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo statusResponseValue = new CommandResponseInfo("status", "int"); responseValues.put(statusResponseValue, status); @@ -2794,7 +2799,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(boolean value) { + public void onSuccess(Boolean value) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo valueResponseValue = new CommandResponseInfo("value", "boolean"); responseValues.put(valueResponseValue, value); @@ -2818,7 +2823,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int returnValue) { + public void onSuccess(Integer returnValue) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo returnValueResponseValue = new CommandResponseInfo("returnValue", "int"); responseValues.put(returnValueResponseValue, returnValue); @@ -2842,7 +2847,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int arg1, int arg2) { + public void onSuccess(Integer arg1, Integer arg2) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo arg1ResponseValue = new CommandResponseInfo("arg1", "int"); responseValues.put(arg1ResponseValue, arg1); @@ -2868,8 +2873,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess( - // arg1: /* TYPE WARNING: array array defaults to */ uint8_t * + public void onSuccess( // arg1: /* TYPE WARNING: array array defaults to */ uint8_t * // Conversion from this type to Java is not properly implemented yet ) { Map responseValues = new LinkedHashMap<>(); @@ -2895,7 +2899,11 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(boolean wasPresent, boolean wasNull, int value, int originalValue) { + public void onSuccess( + Boolean wasPresent, + Optional wasNull, + Optional value, + Optional originalValue) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo wasPresentResponseValue = new CommandResponseInfo("wasPresent", "boolean"); @@ -2927,7 +2935,7 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(int returnValue) { + public void onSuccess(Integer returnValue) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo returnValueResponseValue = new CommandResponseInfo("returnValue", "int"); responseValues.put(returnValueResponseValue, returnValue); @@ -3577,6 +3585,7 @@ public void combineCommand( destination.get("windowCovering").combineCommands(source.get("windowCovering")); } + @SuppressWarnings("unchecked") public Map> getCommandMap() { Map> commandMap = new HashMap<>(); Map accountLoginClusterInteractionInfoMap = new LinkedHashMap<>(); @@ -3973,7 +3982,7 @@ public Map> getCommandMap() { .disableAction( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID")); + (Optional) commandArguments.get("invokeID")); }, () -> new DelegatedDefaultClusterCallback(), bridgedActionsdisableActionCommandParams); @@ -4004,7 +4013,7 @@ public Map> getCommandMap() { .disableActionWithDuration( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID"), + (Optional) commandArguments.get("invokeID"), (Long) commandArguments.get("duration")); }, () -> new DelegatedDefaultClusterCallback(), @@ -4031,7 +4040,7 @@ public Map> getCommandMap() { .enableAction( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID")); + (Optional) commandArguments.get("invokeID")); }, () -> new DelegatedDefaultClusterCallback(), bridgedActionsenableActionCommandParams); @@ -4062,7 +4071,7 @@ public Map> getCommandMap() { .enableActionWithDuration( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID"), + (Optional) commandArguments.get("invokeID"), (Long) commandArguments.get("duration")); }, () -> new DelegatedDefaultClusterCallback(), @@ -4089,7 +4098,7 @@ public Map> getCommandMap() { .instantAction( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID")); + (Optional) commandArguments.get("invokeID")); }, () -> new DelegatedDefaultClusterCallback(), bridgedActionsinstantActionCommandParams); @@ -4122,7 +4131,7 @@ public Map> getCommandMap() { .instantActionWithTransition( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID"), + (Optional) commandArguments.get("invokeID"), (Integer) commandArguments.get("transitionTime")); }, () -> new DelegatedDefaultClusterCallback(), @@ -4149,7 +4158,7 @@ public Map> getCommandMap() { .pauseAction( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID")); + (Optional) commandArguments.get("invokeID")); }, () -> new DelegatedDefaultClusterCallback(), bridgedActionspauseActionCommandParams); @@ -4180,7 +4189,7 @@ public Map> getCommandMap() { .pauseActionWithDuration( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID"), + (Optional) commandArguments.get("invokeID"), (Long) commandArguments.get("duration")); }, () -> new DelegatedDefaultClusterCallback(), @@ -4207,7 +4216,7 @@ public Map> getCommandMap() { .resumeAction( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID")); + (Optional) commandArguments.get("invokeID")); }, () -> new DelegatedDefaultClusterCallback(), bridgedActionsresumeActionCommandParams); @@ -4233,7 +4242,7 @@ public Map> getCommandMap() { .startAction( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID")); + (Optional) commandArguments.get("invokeID")); }, () -> new DelegatedDefaultClusterCallback(), bridgedActionsstartActionCommandParams); @@ -4264,7 +4273,7 @@ public Map> getCommandMap() { .startActionWithDuration( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID"), + (Optional) commandArguments.get("invokeID"), (Long) commandArguments.get("duration")); }, () -> new DelegatedDefaultClusterCallback(), @@ -4291,7 +4300,7 @@ public Map> getCommandMap() { .stopAction( (DefaultClusterCallback) callback, (Integer) commandArguments.get("actionID"), - (Long) commandArguments.get("invokeID")); + (Optional) commandArguments.get("invokeID")); }, () -> new DelegatedDefaultClusterCallback(), bridgedActionsstopActionCommandParams); @@ -7018,10 +7027,10 @@ public Map> getCommandMap() { (Integer) commandArguments.get("productId"), (Long) commandArguments.get("softwareVersion"), (Integer) commandArguments.get("protocolsSupported"), - (Integer) commandArguments.get("hardwareVersion"), - (String) commandArguments.get("location"), - (Boolean) commandArguments.get("requestorCanConsent"), - (byte[]) commandArguments.get("metadataForProvider")); + (Optional) commandArguments.get("hardwareVersion"), + (Optional) commandArguments.get("location"), + (Optional) commandArguments.get("requestorCanConsent"), + (Optional) commandArguments.get("metadataForProvider")); }, () -> new DelegatedQueryImageResponseCallback(), otaSoftwareUpdateProviderqueryImageCommandParams); @@ -7068,7 +7077,7 @@ public Map> getCommandMap() { (Long) commandArguments.get("providerLocation"), (Integer) commandArguments.get("vendorId"), (Integer) commandArguments.get("announcementReason"), - (byte[]) commandArguments.get("metadataForNode")); + (Optional) commandArguments.get("metadataForNode")); }, () -> new DelegatedDefaultClusterCallback(), otaSoftwareUpdateRequestorannounceOtaProviderCommandParams); @@ -7220,7 +7229,7 @@ public Map> getCommandMap() { .addNOC( (ChipClusters.OperationalCredentialsCluster.NOCResponseCallback) callback, (byte[]) commandArguments.get("NOCValue"), - (byte[]) commandArguments.get("ICACValue"), + (Optional) commandArguments.get("ICACValue"), (byte[]) commandArguments.get("IPKValue"), (Long) commandArguments.get("caseAdminNode"), (Integer) commandArguments.get("adminVendorId")); @@ -7402,7 +7411,7 @@ public Map> getCommandMap() { .updateNOC( (ChipClusters.OperationalCredentialsCluster.NOCResponseCallback) callback, (byte[]) commandArguments.get("NOCValue"), - (byte[]) commandArguments.get("ICACValue")); + (Optional) commandArguments.get("ICACValue")); }, () -> new DelegatedNOCResponseCallback(), operationalCredentialsupdateNOCCommandParams); @@ -7906,7 +7915,7 @@ public Map> getCommandMap() { .testNullableOptionalRequest( (ChipClusters.TestClusterCluster.TestNullableOptionalResponseCallback) callback, - (Integer) commandArguments.get("arg1")); + (Optional) commandArguments.get("arg1")); }, () -> new DelegatedTestNullableOptionalResponseCallback(), testClustertestNullableOptionalRequestCommandParams); diff --git a/src/lib/support/JniReferences.cpp b/src/lib/support/JniReferences.cpp index 29d0b39b27fb41..6fd6d89955c808 100644 --- a/src/lib/support/JniReferences.cpp +++ b/src/lib/support/JniReferences.cpp @@ -196,4 +196,61 @@ CHIP_ERROR JniReferences::CreateOptional(jobject objectToWrap, jobject & outOpti return CHIP_NO_ERROR; } +CHIP_ERROR JniReferences::GetOptionalValue(jobject optionalObj, jobject & optionalValue) +{ + JNIEnv * env = GetEnvForCurrentThread(); + jclass optionalCls; + chip::JniReferences::GetInstance().GetClassRef(env, "java/util/Optional", optionalCls); + VerifyOrReturnError(optionalCls != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND); + chip::JniClass jniClass(optionalCls); + + jmethodID isPresentMethod = env->GetMethodID(optionalCls, "isPresent", "()Z"); + VerifyOrReturnError(isPresentMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND); + jboolean isPresent = env->CallBooleanMethod(optionalObj, isPresentMethod); + + if (!isPresent) + { + optionalValue = nullptr; + return CHIP_NO_ERROR; + } + + jmethodID getMethod = env->GetMethodID(optionalCls, "get", "()Ljava/lang/Object;"); + VerifyOrReturnError(getMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND); + optionalValue = env->CallObjectMethod(optionalObj, getMethod); + return CHIP_NO_ERROR; +} + +jint JniReferences::IntegerToPrimitive(jobject boxedInteger) +{ + JNIEnv * env = GetEnvForCurrentThread(); + jclass boxedTypeCls; + chip::JniReferences::GetInstance().GetClassRef(env, "java/lang/Integer", boxedTypeCls); + chip::JniClass jniClass(boxedTypeCls); + + jmethodID valueMethod = env->GetMethodID(boxedTypeCls, "intValue", "()I"); + return env->CallIntMethod(boxedInteger, valueMethod); +} + +jlong JniReferences::LongToPrimitive(jobject boxedLong) +{ + JNIEnv * env = GetEnvForCurrentThread(); + jclass boxedTypeCls; + chip::JniReferences::GetInstance().GetClassRef(env, "java/lang/Long", boxedTypeCls); + chip::JniClass jniClass(boxedTypeCls); + + jmethodID valueMethod = env->GetMethodID(boxedTypeCls, "longValue", "()J"); + return env->CallLongMethod(boxedLong, valueMethod); +} + +jboolean JniReferences::BooleanToPrimitive(jobject boxedBoolean) +{ + JNIEnv * env = GetEnvForCurrentThread(); + jclass boxedTypeCls; + chip::JniReferences::GetInstance().GetClassRef(env, "java/lang/Boolean", boxedTypeCls); + chip::JniClass jniClass(boxedTypeCls); + + jmethodID valueMethod = env->GetMethodID(boxedTypeCls, "booleanValue", "()Z"); + return env->CallBooleanMethod(boxedBoolean, valueMethod); +} + } // namespace chip diff --git a/src/lib/support/JniReferences.h b/src/lib/support/JniReferences.h index 4bc9145af1edf1..a45cb3f0d15004 100644 --- a/src/lib/support/JniReferences.h +++ b/src/lib/support/JniReferences.h @@ -20,7 +20,6 @@ #include #include #include -#include #include namespace chip { @@ -82,6 +81,46 @@ class JniReferences */ CHIP_ERROR CreateOptional(jobject objectToWrap, jobject & outOptional); + /** + * Retrieve the value of a java.util.Optional, or nullptr if the Optional is empty. + */ + CHIP_ERROR GetOptionalValue(jobject optionalObj, jobject & optionalValue); + + /** + * Get a primitive jint from the Java boxed type Integer, using intValue(). + */ + jint IntegerToPrimitive(jobject boxedObject); + + /** + * Get a primitive jlong from the Java boxed type Long, using longValue(). + */ + jlong LongToPrimitive(jobject boxedObject); + + /** + * Get a primitive jboolean from the Java boxed type Booelan, using booleanValue(). + */ + jboolean BooleanToPrimitive(jobject boxedObject); + + /** + * Creates a boxed type (e.g. java.lang.Integer) based on the the class name ("java/lang/Integer"), constructor JNI signature + * ("(I)V"), and value. + */ + template + CHIP_ERROR CreateBoxedObject(std::string boxedTypeClsName, std::string constructorSignature, T value, jobject & outObj) + { + JNIEnv * env = GetEnvForCurrentThread(); + CHIP_ERROR err = CHIP_NO_ERROR; + jclass boxedTypeCls; + err = GetClassRef(env, boxedTypeClsName.c_str(), boxedTypeCls); + VerifyOrReturnError(err == CHIP_NO_ERROR, err); + + jmethodID boxedTypeConstructor = env->GetMethodID(boxedTypeCls, "", constructorSignature.c_str()); + outObj = env->NewObject(boxedTypeCls, boxedTypeConstructor, value); + env->DeleteGlobalRef(boxedTypeCls); + + return err; + } + private: JniReferences() {} diff --git a/src/lib/support/JniTypeWrappers.h b/src/lib/support/JniTypeWrappers.h index 25d620764ecd02..64d03301333b5a 100644 --- a/src/lib/support/JniTypeWrappers.h +++ b/src/lib/support/JniTypeWrappers.h @@ -17,27 +17,39 @@ #pragma once -#include "JniReferences.h" #include - #include +#include #include -#include +#include namespace chip { /// Exposes the underlying UTF string from a jni string class JniUtfString { public: - JniUtfString(JNIEnv * env, jstring string) : mEnv(env), mString(string) { mChars = env->GetStringUTFChars(string, 0); } + JniUtfString(JNIEnv * env, jstring string) : mEnv(env), mString(string) + { + if (string == nullptr) + { + return; + } + mChars = env->GetStringUTFChars(string, 0); + mDataLength = env->GetStringUTFLength(string); + } ~JniUtfString() { mEnv->ReleaseStringUTFChars(mString, mChars); } const char * c_str() const { return mChars; } + chip::CharSpan charSpan() const { return chip::CharSpan(c_str(), static_cast(size())); } + + jsize size() const { return mDataLength; } + private: JNIEnv * mEnv; jstring mString; const char * mChars; + jsize mDataLength; }; /// Exposes the underlying binary data from a jni byte array @@ -50,10 +62,12 @@ class JniByteArray ~JniByteArray() { mEnv->ReleaseByteArrayElements(mArray, mData, 0); } const jbyte * data() const { return mData; } + chip::ByteSpan byteSpan() const { return chip::ByteSpan(reinterpret_cast(data()), static_cast(size())); } + jsize size() const { return mDataLength; } private: @@ -94,6 +108,14 @@ class ByteArray env->SetByteArrayRegion(mArray, 0, dataLen, data); } } + ByteArray(JNIEnv * env, chip::ByteSpan data) : mEnv(env) + { + mArray = mEnv->NewByteArray(static_cast(data.size())); + if (mArray != nullptr) + { + env->SetByteArrayRegion(mArray, 0, static_cast(data.size()), reinterpret_cast(data.data())); + } + } ~ByteArray() { mEnv->DeleteLocalRef(mArray); } jbyteArray jniValue() { return mArray; }