| {{> header}} | |
| {{#if (chip_has_client_clusters)}} | |
| #include "CHIPCallbackTypes.h" | |
| #include "CHIPInvokeCallbacks.h" | |
| #include "CHIPReadCallbacks.h" | |
| #include <app-common/zap-generated/cluster-objects.h> | |
| #include <zap-generated/CHIPClusters.h> | |
| #include <zap-generated/CHIPClientCallbacks.h> | |
| #include <controller/java/AndroidCallbacks.h> | |
| #include <controller/java/AndroidClusterExceptions.h> | |
| #include <controller/java/CHIPDefaultCallbacks.h> | |
| #include <lib/support/JniReferences.h> | |
| #include <lib/support/JniTypeWrappers.h> | |
| #include <jni.h> | |
| #include <lib/support/CHIPListUtils.h> | |
| #include <lib/support/CodeUtils.h> | |
| #include <lib/support/Span.h> | |
| #include <platform/PlatformManager.h> | |
| #include <vector> | |
| #pragma clang diagnostic push | |
| #pragma clang diagnostic ignored "-Wshorten-64-to-32" | |
| #define JNI_METHOD(RETURN, CLASS_NAME, METHOD_NAME) \ | |
| extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_ChipClusters_00024##CLASS_NAME##_##METHOD_NAME | |
| using namespace chip; | |
| using namespace chip::Controller; | |
| {{#chip_client_clusters}} | |
| {{#chip_server_cluster_attributes}} | |
| {{#unless (isStrEqual chipCallback.name "Unsupported")}} | |
| {{#if isWritableAttribute}} | |
| JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, write{{asUpperCamelCase name}}Attribute)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, {{asJniBasicType type true}} value, jobject timedWriteTimeoutMs) | |
| { | |
| chip::DeviceLayer::StackLock lock; | |
| ListFreer listFreer; | |
| using TypeInfo = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo; | |
| TypeInfo::Type cppValue; | |
| std::vector<Platform::UniquePtr<JniByteArray>> cleanupByteArrays; | |
| std::vector<Platform::UniquePtr<JniUtfString>> cleanupStrings; | |
| {{>encode_value target="cppValue" source="value" cluster=(asUpperCamelCase parent.name) depth=0}} | |
| std::unique_ptr<CHIPDefaultSuccessCallback, void (*)(CHIPDefaultSuccessCallback *)> onSuccess(Platform::New<CHIPDefaultSuccessCallback>(callback), Platform::Delete<CHIPDefaultSuccessCallback>); | |
| VerifyOrReturn(onSuccess.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native success callback", CHIP_ERROR_NO_MEMORY)); | |
| std::unique_ptr<CHIPDefaultFailureCallback, void (*)(CHIPDefaultFailureCallback *)> onFailure(Platform::New<CHIPDefaultFailureCallback>(callback), Platform::Delete<CHIPDefaultFailureCallback>); | |
| VerifyOrReturn(onFailure.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native failure callback", CHIP_ERROR_NO_MEMORY)); | |
| CHIP_ERROR err = CHIP_NO_ERROR; | |
| {{asCamelCased ../name false}}Cluster * cppCluster = reinterpret_cast<{{asCamelCased ../name false}}Cluster *>(clusterPtr); | |
| VerifyOrReturn(cppCluster != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Could not get native cluster", CHIP_ERROR_INCORRECT_STATE)); | |
| auto successFn = chip::Callback::Callback<CHIPDefaultWriteSuccessCallbackType>::FromCancelable(onSuccess->Cancel()); | |
| auto failureFn = chip::Callback::Callback<CHIPDefaultFailureCallbackType>::FromCancelable(onFailure->Cancel()); | |
| {{#if mustUseTimedWrite}} | |
| err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall, chip::JniReferences::GetInstance().IntegerToPrimitive(timedWriteTimeoutMs)); | |
| {{else}} | |
| if (timedWriteTimeoutMs == nullptr) { | |
| err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall); | |
| } else { | |
| err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall, chip::JniReferences::GetInstance().IntegerToPrimitive(timedWriteTimeoutMs)); | |
| } | |
| {{/if}} | |
| VerifyOrReturn(err == CHIP_NO_ERROR, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error writing attribute", err)); | |
| onSuccess.release(); | |
| onFailure.release(); | |
| } | |
| {{/if}} | |
| {{/unless}} | |
| {{/chip_server_cluster_attributes}} | |
| {{/chip_client_clusters}} | |
| {{/if}} | |
| #pragma clang diagnostic pop |