From 2d5a29f1e44e35b41d687efe1d8de62546ba4ebf Mon Sep 17 00:00:00 2001 From: Austin Hsieh Date: Thu, 17 Jun 2021 17:30:31 -0700 Subject: [PATCH 1/4] Create StackLock.h, containing StackLockGuard (formerly ScopedPthread) and StackUnlockGuard --- .../java/AndroidDeviceControllerWrapper.cpp | 7 +- .../java/AndroidDeviceControllerWrapper.h | 12 -- .../java/AndroidKeyValueStoreManagerImpl.cpp | 6 +- src/controller/java/BUILD.gn | 1 + .../java/CHIPDeviceController-JNI.cpp | 106 ++++++++---------- src/controller/java/JniReferences.cpp | 15 ++- src/controller/java/JniReferences.h | 21 +++- src/controller/java/StackLock.h | 43 +++++++ 8 files changed, 125 insertions(+), 86 deletions(-) create mode 100644 src/controller/java/StackLock.h diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 9013fb47ec0f0f..5128d05456dde6 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -17,6 +17,7 @@ */ #include "AndroidDeviceControllerWrapper.h" #include "CHIPJNIError.h" +#include "StackLock.h" #include #include @@ -32,7 +33,7 @@ AndroidDeviceControllerWrapper::~AndroidDeviceControllerWrapper() { if ((mJavaVM != nullptr) && (mJavaObjectRef != nullptr)) { - GetEnvForCurrentThread()->DeleteGlobalRef(mJavaObjectRef); + JniReferences::GetEnvForCurrentThread()->DeleteGlobalRef(mJavaObjectRef); } mController->Shutdown(); } @@ -40,12 +41,12 @@ AndroidDeviceControllerWrapper::~AndroidDeviceControllerWrapper() void AndroidDeviceControllerWrapper::SetJavaObjectRef(JavaVM * vm, jobject obj) { mJavaVM = vm; - mJavaObjectRef = GetEnvForCurrentThread()->NewGlobalRef(obj); + mJavaObjectRef = JniReferences::GetEnvForCurrentThread()->NewGlobalRef(obj); } void AndroidDeviceControllerWrapper::CallJavaMethod(const char * methodName, jint argument) { - CallVoidInt(GetEnvForCurrentThread(), mJavaObjectRef, methodName, argument); + CallVoidInt(JniReferences::GetEnvForCurrentThread(), mJavaObjectRef, methodName, argument); } AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(JavaVM * vm, jobject deviceControllerObj, diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index c954e48478b636..12517b19885f01 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -40,18 +40,6 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel public: ~AndroidDeviceControllerWrapper(); - // Use StackUnlockGuard to temporarily unlock the CHIP BLE stack, e.g. when calling application - // or Android BLE code as a result of a BLE event. - struct StackUnlockGuard - { - public: - StackUnlockGuard(pthread_mutex_t * mutex) : mMutex(mutex) { pthread_mutex_unlock(mMutex); } - ~StackUnlockGuard() { pthread_mutex_lock(mMutex); } - - private: - pthread_mutex_t * mMutex; - }; - chip::Controller::DeviceCommissioner * Controller() { return mController.get(); } chip::Controller::ExampleOperationalCredentialsIssuer & OpCredsIssuer() { return mOpCredsIssuer; } void SetJavaObjectRef(JavaVM * vm, jobject obj); diff --git a/src/controller/java/AndroidKeyValueStoreManagerImpl.cpp b/src/controller/java/AndroidKeyValueStoreManagerImpl.cpp index 18d1df19690026..253834dd9994d1 100644 --- a/src/controller/java/AndroidKeyValueStoreManagerImpl.cpp +++ b/src/controller/java/AndroidKeyValueStoreManagerImpl.cpp @@ -47,7 +47,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t ReturnErrorCodeIf(mGetMethod == nullptr, CHIP_ERROR_INCORRECT_STATE); ReturnErrorCodeIf(offset != 0, CHIP_ERROR_INVALID_ARGUMENT); - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); ReturnErrorCodeIf(env == nullptr, CHIP_ERROR_INTERNAL); UtfString javaKey(env, key); @@ -100,7 +100,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) ReturnErrorCodeIf(mKeyValueStoreManagerClass == nullptr, CHIP_ERROR_INCORRECT_STATE); ReturnErrorCodeIf(mDeleteMethod == nullptr, CHIP_ERROR_INCORRECT_STATE); - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); ReturnErrorCodeIf(env == nullptr, CHIP_ERROR_INTERNAL); UtfString javaKey(env, key); @@ -124,7 +124,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, ReturnErrorCodeIf(mSetMethod == nullptr, CHIP_ERROR_INCORRECT_STATE); ReturnErrorCodeIf(value_size > kMaxKvsValueBytes, CHIP_ERROR_INVALID_ARGUMENT); - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); ReturnErrorCodeIf(env == nullptr, CHIP_ERROR_INTERNAL); std::unique_ptr buffer(new char[BASE64_ENCODED_LEN(value_size) + 1]); diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 0aef043f121e3d..096f87c5a06289 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -37,6 +37,7 @@ shared_library("jni") { "JniReferences.cpp", "JniReferences.h", "JniTypeWrappers.h", + "StackLock.h", ] deps = [ diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index e0308cdac3f154..adaf01532a887c 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -29,6 +29,7 @@ #include "CHIPJNIError.h" #include "JniReferences.h" #include "JniTypeWrappers.h" +#include "StackLock.h" #include #include @@ -99,24 +100,12 @@ AndroidBlePlatformDelegate sBlePlatformDelegate; AndroidBleConnectionDelegate sBleConnectionDelegate; #endif -pthread_mutex_t sStackLock = PTHREAD_MUTEX_INITIALIZER; -pthread_t sIOThread = PTHREAD_NULL; -bool sShutdown = false; +pthread_t sIOThread = PTHREAD_NULL; +bool sShutdown = false; jclass sAndroidChipStackCls = NULL; jclass sChipDeviceControllerExceptionCls = NULL; -/** A scoped lock/unlock around a mutex. */ -class ScopedPthreadLock -{ -public: - ScopedPthreadLock(pthread_mutex_t * mutex) : mMutex(mutex) { pthread_mutex_lock(mMutex); } - ~ScopedPthreadLock() { pthread_mutex_unlock(mMutex); } - -private: - pthread_mutex_t * mMutex; -}; - } // namespace // NOTE: Remote device ID is in sync with the echo server device id @@ -145,11 +134,11 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved) chip::Platform::MemoryInit(); // Save a reference to the JVM. Will need this to call back into Java. - SetJavaVm(jvm); + JniReferences::SetJavaVm(jvm); sJVM = jvm; // Get a JNI environment object. - env = GetEnvForCurrentThread(); + env = JniReferences::GetEnvForCurrentThread(); VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().InitializeMethodForward(sJVM, env); @@ -203,7 +192,7 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved) if (err != CHIP_NO_ERROR) { ThrowError(env, err); - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); JNI_OnUnload(jvm, reserved); } @@ -212,7 +201,7 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved) void JNI_OnUnload(JavaVM * jvm, void * reserved) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); ChipLogProgress(Controller, "JNI_OnUnload() called"); // If the IO thread has been started, shut it down and wait for it to exit. @@ -221,7 +210,7 @@ void JNI_OnUnload(JavaVM * jvm, void * reserved) sShutdown = true; sSystemLayer.WakeSelect(); - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); pthread_join(sIOThread, NULL); } @@ -238,15 +227,15 @@ void JNI_OnUnload(JavaVM * jvm, void * reserved) JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); CHIP_ERROR err = CHIP_NO_ERROR; AndroidDeviceControllerWrapper * wrapper = NULL; long result = 0; ChipLogProgress(Controller, "newDeviceController() called"); - wrapper = - AndroidDeviceControllerWrapper::AllocateNew(sJVM, self, &sStackLock, kLocalDeviceId, &sSystemLayer, &sInetLayer, &err); + wrapper = AndroidDeviceControllerWrapper::AllocateNew(sJVM, self, JniReferences::GetStackLock(), kLocalDeviceId, &sSystemLayer, + &sInetLayer, &err); SuccessOrExit(err); result = wrapper->ToJNIHandle(); @@ -270,7 +259,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self) JNI_METHOD(void, pairDevice)(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jint connObj, jlong pinCode) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); CHIP_ERROR err = CHIP_NO_ERROR; AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); @@ -293,7 +282,7 @@ JNI_METHOD(void, pairDevice)(JNIEnv * env, jobject self, jlong handle, jlong dev JNI_METHOD(void, unpairDevice)(JNIEnv * env, jobject self, jlong handle, jlong deviceId) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); CHIP_ERROR err = CHIP_NO_ERROR; AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); @@ -310,7 +299,7 @@ JNI_METHOD(void, unpairDevice)(JNIEnv * env, jobject self, jlong handle, jlong d JNI_METHOD(void, stopDevicePairing)(JNIEnv * env, jobject self, jlong handle, jlong deviceId) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); CHIP_ERROR err = CHIP_NO_ERROR; AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); @@ -327,7 +316,7 @@ JNI_METHOD(void, stopDevicePairing)(JNIEnv * env, jobject self, jlong handle, jl JNI_METHOD(void, pairTestDeviceWithoutSecurity)(JNIEnv * env, jobject self, jlong handle, jstring deviceAddr) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); CHIP_ERROR err = CHIP_NO_ERROR; AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); chip::Inet::IPAddress deviceIPAddr; @@ -351,7 +340,7 @@ JNI_METHOD(void, pairTestDeviceWithoutSecurity)(JNIEnv * env, jobject self, jlon JNI_METHOD(void, disconnectDevice)(JNIEnv * env, jobject self, jlong handle, jlong deviceId) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); CHIP_ERROR err = CHIP_NO_ERROR; Device * chipDevice = nullptr; @@ -371,7 +360,7 @@ JNI_METHOD(void, disconnectDevice)(JNIEnv * env, jobject self, jlong handle, jlo JNI_METHOD(jboolean, isActive)(JNIEnv * env, jobject self, jlong handle) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); Device * chipDevice = reinterpret_cast(handle); return chipDevice->IsActive(); @@ -393,7 +382,7 @@ void GetCHIPDevice(JNIEnv * env, long wrapperHandle, uint64_t deviceId, Device * JNI_METHOD(jstring, getIpAddress)(JNIEnv * env, jobject self, jlong handle, jlong deviceId) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); Device * chipDevice = nullptr; GetCHIPDevice(env, handle, deviceId, &chipDevice); @@ -411,7 +400,7 @@ JNI_METHOD(jstring, getIpAddress)(JNIEnv * env, jobject self, jlong handle, jlon JNI_METHOD(void, updateAddress)(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jstring address, jint port) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); Device * chipDevice = nullptr; CHIP_ERROR err = CHIP_NO_ERROR; @@ -434,7 +423,7 @@ JNI_METHOD(void, updateAddress)(JNIEnv * env, jobject self, jlong handle, jlong JNI_METHOD(void, sendMessage)(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jstring messageObj) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); CHIP_ERROR err = CHIP_NO_ERROR; Device * chipDevice = nullptr; @@ -470,7 +459,7 @@ JNI_METHOD(void, sendMessage)(JNIEnv * env, jobject self, jlong handle, jlong de JNI_METHOD(void, sendCommand)(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jobject commandObj, jint aValue) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); CHIP_ERROR err = CHIP_NO_ERROR; Device * chipDevice = nullptr; @@ -589,7 +578,7 @@ JNI_METHOD(void, enableThreadNetwork) { auto ctx = std::make_unique(env, handle, deviceId, ByteSpan(extPanId, sizeof(extPanId))); - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); NetworkCommissioningCluster cluster; cluster.Associate(chipDevice, kNodeEndpoint); SuccessOrExit(err = cluster.AddThreadNetwork(ctx->mOnAddNetwork.Cancel(), ctx->mOnCommissioningFailed.Cancel(), @@ -607,7 +596,7 @@ JNI_METHOD(void, enableThreadNetwork) JNI_METHOD(jboolean, openPairingWindow)(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jint duration) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); CHIP_ERROR err = CHIP_NO_ERROR; Device * chipDevice = nullptr; chip::SetupPayload setupPayload; @@ -642,7 +631,7 @@ static bool JavaBytesToUUID(JNIEnv * env, jbyteArray value, chip::Ble::ChipBleUU JNI_ANDROID_CHIP_STACK_METHOD(void, handleIndicationReceived) (JNIEnv * env, jobject self, jint conn, jbyteArray svcId, jbyteArray charId, jbyteArray value) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); BLE_CONNECTION_OBJECT const connObj = reinterpret_cast(conn); const auto valueBegin = env->GetByteArrayElements(value, nullptr); const auto valueLength = env->GetArrayLength(value); @@ -667,7 +656,7 @@ JNI_ANDROID_CHIP_STACK_METHOD(void, handleIndicationReceived) JNI_ANDROID_CHIP_STACK_METHOD(void, handleWriteConfirmation) (JNIEnv * env, jobject self, jint conn, jbyteArray svcId, jbyteArray charId) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); BLE_CONNECTION_OBJECT const connObj = reinterpret_cast(conn); chip::Ble::ChipBleUUID svcUUID; @@ -685,7 +674,7 @@ JNI_ANDROID_CHIP_STACK_METHOD(void, handleWriteConfirmation) JNI_ANDROID_CHIP_STACK_METHOD(void, handleSubscribeComplete) (JNIEnv * env, jobject self, jint conn, jbyteArray svcId, jbyteArray charId) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); BLE_CONNECTION_OBJECT const connObj = reinterpret_cast(conn); chip::Ble::ChipBleUUID svcUUID; @@ -703,7 +692,7 @@ JNI_ANDROID_CHIP_STACK_METHOD(void, handleSubscribeComplete) JNI_ANDROID_CHIP_STACK_METHOD(void, handleUnsubscribeComplete) (JNIEnv * env, jobject self, jint conn, jbyteArray svcId, jbyteArray charId) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); BLE_CONNECTION_OBJECT const connObj = reinterpret_cast(conn); chip::Ble::ChipBleUUID svcUUID; @@ -720,7 +709,7 @@ JNI_ANDROID_CHIP_STACK_METHOD(void, handleUnsubscribeComplete) JNI_ANDROID_CHIP_STACK_METHOD(void, handleConnectionError)(JNIEnv * env, jobject self, jint conn) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); BLE_CONNECTION_OBJECT const connObj = reinterpret_cast(conn); sBleLayer.HandleConnectionError(connObj, BLE_ERROR_APP_CLOSED_CONNECTION); @@ -728,7 +717,7 @@ JNI_ANDROID_CHIP_STACK_METHOD(void, handleConnectionError)(JNIEnv * env, jobject JNI_METHOD(void, deleteDeviceController)(JNIEnv * env, jobject self, jlong handle) { - ScopedPthreadLock lock(&sStackLock); + StackLockGuard lock(JniReferences::GetStackLock()); AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); ChipLogProgress(Controller, "deleteDeviceController() called"); @@ -742,7 +731,7 @@ JNI_METHOD(void, deleteDeviceController)(JNIEnv * env, jobject self, jlong handl void HandleNotifyChipConnectionClosed(BLE_CONNECTION_OBJECT connObj) { CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); jmethodID method; intptr_t tmpConnObj; @@ -757,7 +746,7 @@ void HandleNotifyChipConnectionClosed(BLE_CONNECTION_OBJECT connObj) env->ExceptionClear(); tmpConnObj = reinterpret_cast(connObj); { - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); env->CallStaticVoidMethod(sAndroidChipStackCls, method, static_cast(tmpConnObj)); } VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); @@ -774,7 +763,7 @@ bool HandleSendCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_t * svc const uint8_t * characteristicData, uint32_t characteristicDataLen) { CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); jbyteArray svcIdObj; jbyteArray charIdObj; jbyteArray characteristicDataObj; @@ -802,7 +791,7 @@ bool HandleSendCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_t * svc env->ExceptionClear(); tmpConnObj = reinterpret_cast(connObj); { - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); rc = (bool) env->CallStaticBooleanMethod(sAndroidChipStackCls, method, static_cast(tmpConnObj), svcIdObj, charIdObj, characteristicDataObj); } @@ -822,7 +811,7 @@ bool HandleSendCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_t * svc bool HandleSubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_t * svcId, const uint8_t * charId) { CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); jbyteArray svcIdObj; jbyteArray charIdObj; jmethodID method; @@ -839,7 +828,7 @@ bool HandleSubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_t SuccessOrExit(err); { - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); method = env->GetStaticMethodID(sAndroidChipStackCls, "onSubscribeCharacteristic", "(I[B[B)Z"); } VerifyOrExit(method != NULL, err = CHIP_JNI_ERROR_METHOD_NOT_FOUND); @@ -865,7 +854,7 @@ bool HandleSubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_t bool HandleUnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_t * svcId, const uint8_t * charId) { CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); jbyteArray svcIdObj; jbyteArray charIdObj; jmethodID method; @@ -889,7 +878,7 @@ bool HandleUnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_ env->ExceptionClear(); tmpConnObj = reinterpret_cast(connObj); { - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); rc = (bool) env->CallStaticBooleanMethod(sAndroidChipStackCls, method, static_cast(tmpConnObj), svcIdObj, charIdObj); } VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); @@ -908,7 +897,7 @@ bool HandleUnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const uint8_ bool HandleCloseConnection(BLE_CONNECTION_OBJECT connObj) { CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); jmethodID method; intptr_t tmpConnObj; bool rc = false; @@ -924,7 +913,7 @@ bool HandleCloseConnection(BLE_CONNECTION_OBJECT connObj) env->ExceptionClear(); tmpConnObj = reinterpret_cast(connObj); { - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); rc = (bool) env->CallStaticBooleanMethod(sAndroidChipStackCls, method, static_cast(tmpConnObj)); } VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); @@ -942,7 +931,7 @@ bool HandleCloseConnection(BLE_CONNECTION_OBJECT connObj) uint16_t HandleGetMTU(BLE_CONNECTION_OBJECT connObj) { CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); jmethodID method; intptr_t tmpConnObj; uint16_t mtu = 0; @@ -951,7 +940,7 @@ uint16_t HandleGetMTU(BLE_CONNECTION_OBJECT connObj) VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); { - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); method = env->GetStaticMethodID(sAndroidChipStackCls, "onGetMTU", "(I)I"); } VerifyOrExit(method != NULL, err = CHIP_JNI_ERROR_METHOD_NOT_FOUND); @@ -977,7 +966,7 @@ uint16_t HandleGetMTU(BLE_CONNECTION_OBJECT connObj) void HandleNewConnection(void * appState, const uint16_t discriminator) { CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = GetEnvForCurrentThread(); + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); jmethodID method; jclass deviceControllerCls; AndroidDeviceControllerWrapper * wrapper = reinterpret_cast(appState); @@ -996,7 +985,7 @@ void HandleNewConnection(void * appState, const uint16_t discriminator) env->ExceptionClear(); { - AndroidDeviceControllerWrapper::StackUnlockGuard unlockGuard(&sStackLock); + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); env->CallVoidMethod(self, method); } VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); @@ -1034,7 +1023,7 @@ void * IOThreadMain(void * arg) ChipLogProgress(Controller, "IO thread starting"); // Lock the stack to prevent collisions with Java threads. - pthread_mutex_lock(&sStackLock); + pthread_mutex_lock(JniReferences::GetStackLock()); // Loop until we are told to exit. while (!quit.load(std::memory_order_relaxed)) @@ -1052,7 +1041,7 @@ void * IOThreadMain(void * arg) sInetLayer.PrepareSelect(numFDs, &readFDs, &writeFDs, &exceptFDs, sleepTime); // Unlock the stack so that Java threads can make API calls. - pthread_mutex_unlock(&sStackLock); + pthread_mutex_unlock(JniReferences::GetStackLock()); // Wait for for I/O or for the next timer to expire. int selectRes = select(numFDs, &readFDs, &writeFDs, &exceptFDs, &sleepTime); @@ -1062,7 +1051,7 @@ void * IOThreadMain(void * arg) // break; // Re-lock the stack. - pthread_mutex_lock(&sStackLock); + pthread_mutex_lock(JniReferences::GetStackLock()); // Perform I/O and/or dispatch timers. sSystemLayer.HandleSelectResult(selectRes, &readFDs, &writeFDs, &exceptFDs); @@ -1153,6 +1142,9 @@ CHIP_ERROR N2J_Error(JNIEnv * env, CHIP_ERROR inErr, jthrowable & outEx) case CHIP_JNI_ERROR_FIELD_NOT_FOUND: errStr = "CHIP Device Controller Error: JNI field not found"; break; + case CHIP_JNI_ERROR_DEVICE_NOT_FOUND: + errStr = "CHIP Device Controller Error: Device not found"; + break; default: errStr = ErrorStr(inErr); break; diff --git a/src/controller/java/JniReferences.cpp b/src/controller/java/JniReferences.cpp index a8db89755d0f63..7e1cad01e473ef 100644 --- a/src/controller/java/JniReferences.cpp +++ b/src/controller/java/JniReferences.cpp @@ -21,12 +21,19 @@ #include -void SetJavaVm(JavaVM * jvm) +pthread_mutex_t JniReferences::sStackLock = PTHREAD_MUTEX_INITIALIZER; +JavaVM * JniReferences::sJvm = nullptr; + +void JniReferences::SetJavaVm(JavaVM * jvm) { - sJvm = jvm; + CHIP_ERROR err = CHIP_NO_ERROR; + sJvm = jvm; + JNIEnv * env = GetEnvForCurrentThread(); + + VerifyOrReturn(env != NULL, ChipLogError(Controller, "Could not get JNI env for current thread")); } -JNIEnv * GetEnvForCurrentThread() +JNIEnv * JniReferences::GetEnvForCurrentThread() { JNIEnv * env; if (sJvm == NULL) @@ -75,14 +82,12 @@ CHIP_ERROR FindMethod(JNIEnv * env, jobject object, const char * methodName, con VerifyOrExit(env != nullptr && object != nullptr, err = CHIP_JNI_ERROR_NULL_OBJECT); javaClass = env->GetObjectClass(object); - ChipLogProgress(Controller, "FindMethod:: javaClass exists? %d", javaClass != NULL); VerifyOrExit(javaClass != NULL, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); *methodId = env->GetMethodID(javaClass, methodName, methodSignature); VerifyOrExit(*methodId != NULL, err = CHIP_JNI_ERROR_METHOD_NOT_FOUND); exit: - ChipLogProgress(Controller, "FindMethod Returning %d", err); return err; } diff --git a/src/controller/java/JniReferences.h b/src/controller/java/JniReferences.h index 4fa9ae45dd7689..cd3eef8ff5f188 100644 --- a/src/controller/java/JniReferences.h +++ b/src/controller/java/JniReferences.h @@ -17,16 +17,25 @@ #pragma once +#include #include +#include +#include -#include +class JniReferences +{ +public: + static pthread_mutex_t * GetStackLock() { return &sStackLock; } + + static void SetJavaVm(JavaVM * jvm); + + static JNIEnv * GetEnvForCurrentThread(); -namespace { -JavaVM * sJvm = nullptr; -} // namespace -void SetJavaVm(JavaVM * jvm); -JNIEnv * GetEnvForCurrentThread(); +private: + static pthread_mutex_t sStackLock; + static JavaVM * sJvm; +}; CHIP_ERROR GetClassRef(JNIEnv * env, const char * clsType, jclass & outCls); CHIP_ERROR FindMethod(JNIEnv * env, jobject object, const char * methodName, const char * methodSignature, jmethodID * methodId); diff --git a/src/controller/java/StackLock.h b/src/controller/java/StackLock.h new file mode 100644 index 00000000000000..0d8a1eff2c3360 --- /dev/null +++ b/src/controller/java/StackLock.h @@ -0,0 +1,43 @@ +/* + * + * 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. + */ + +#include + +/** A scoped lock/unlock around a mutex. */ +struct StackLockGuard +{ +public: + StackLockGuard(pthread_mutex_t * mutex) : mMutex(mutex) { pthread_mutex_lock(mMutex); } + ~StackLockGuard() { pthread_mutex_unlock(mMutex); } + +private: + pthread_mutex_t * mMutex; +}; + +/** + * Use StackUnlockGuard to temporarily unlock the CHIP BLE stack, e.g. when calling application + * or Android BLE code as a result of a BLE event. + */ +struct StackUnlockGuard +{ +public: + StackUnlockGuard(pthread_mutex_t * mutex) : mMutex(mutex) { pthread_mutex_unlock(mMutex); } + ~StackUnlockGuard() { pthread_mutex_lock(mMutex); } + +private: + pthread_mutex_t * mMutex; +}; From 99f5b18f3ba933b32bca9fb97ecd12cde9a17514 Mon Sep 17 00:00:00 2001 From: Austin Hsieh Date: Thu, 17 Jun 2021 17:34:10 -0700 Subject: [PATCH 2/4] Add ZAP templates for accessing clusters through JNI --- scripts/tools/zap_regen_all.py | 1 + src/controller/java/BUILD.gn | 1 + src/controller/java/CHIPJNIError.h | 1 + src/controller/java/JniReferences.cpp | 3 + src/controller/java/JniReferences.h | 3 + .../ChipClusterException.java | 32 ++ .../java/templates/CHIPClusters-JNI.zapt | 395 ++++++++++++++++++ .../java/templates/ChipClusters-java.zapt | 103 +++++ src/controller/java/templates/helper.js | 157 +++++++ src/controller/java/templates/templates.json | 39 ++ 10 files changed, 735 insertions(+) create mode 100644 src/controller/java/src/chip/devicecontroller/ChipClusterException.java create mode 100644 src/controller/java/templates/CHIPClusters-JNI.zapt create mode 100644 src/controller/java/templates/ChipClusters-java.zapt create mode 100644 src/controller/java/templates/helper.js create mode 100644 src/controller/java/templates/templates.json diff --git a/scripts/tools/zap_regen_all.py b/scripts/tools/zap_regen_all.py index 4871ae59c24c06..4bdaca6afe55d4 100755 --- a/scripts/tools/zap_regen_all.py +++ b/scripts/tools/zap_regen_all.py @@ -40,6 +40,7 @@ def getSpecificTemplatesTargets(): targets.append(['src/controller/data_model/controller-clusters.zap', '-t', 'examples/chip-tool/templates/templates.json']) targets.append(['src/controller/data_model/controller-clusters.zap', '-t', 'src/controller/python/templates/templates.json']) targets.append(['src/controller/data_model/controller-clusters.zap', '-t', 'src/darwin/Framework/CHIP/templates/templates.json']) + targets.append(['src/controller/data_model/controller-clusters.zap', '-t', 'src/controller/java/templates/templates.json']) return targets def getTargets(): diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 096f87c5a06289..346cc3552b0739 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -58,6 +58,7 @@ android_library("java") { sources = [ "src/chip/devicecontroller/AndroidChipStack.java", + "src/chip/devicecontroller/ChipClusterException.java", "src/chip/devicecontroller/ChipCommandType.java", "src/chip/devicecontroller/ChipDeviceController.java", "src/chip/devicecontroller/ChipDeviceControllerException.java", diff --git a/src/controller/java/CHIPJNIError.h b/src/controller/java/CHIPJNIError.h index d31f613a3953f5..9f6faf1f26d39a 100644 --- a/src/controller/java/CHIPJNIError.h +++ b/src/controller/java/CHIPJNIError.h @@ -28,3 +28,4 @@ #define CHIP_JNI_ERROR_FIELD_NOT_FOUND _CHIP_JNI_ERROR(3) #define CHIP_JNI_ERROR_NO_ENV _CHIP_JNI_ERROR(4) #define CHIP_JNI_ERROR_NULL_OBJECT _CHIP_JNI_ERROR(5) +#define CHIP_JNI_ERROR_DEVICE_NOT_FOUND _CHIP_JNI_ERROR(6) diff --git a/src/controller/java/JniReferences.cpp b/src/controller/java/JniReferences.cpp index 7e1cad01e473ef..ab4b62f77fb1f1 100644 --- a/src/controller/java/JniReferences.cpp +++ b/src/controller/java/JniReferences.cpp @@ -23,6 +23,7 @@ pthread_mutex_t JniReferences::sStackLock = PTHREAD_MUTEX_INITIALIZER; JavaVM * JniReferences::sJvm = nullptr; +jclass JniReferences::sClusterExceptionCls = nullptr; void JniReferences::SetJavaVm(JavaVM * jvm) { @@ -31,6 +32,8 @@ void JniReferences::SetJavaVm(JavaVM * jvm) JNIEnv * env = GetEnvForCurrentThread(); VerifyOrReturn(env != NULL, ChipLogError(Controller, "Could not get JNI env for current thread")); + err = GetClassRef(env, "chip/devicecontroller/ChipClusterException", sClusterExceptionCls); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find ChipClusterException class")); } JNIEnv * JniReferences::GetEnvForCurrentThread() diff --git a/src/controller/java/JniReferences.h b/src/controller/java/JniReferences.h index cd3eef8ff5f188..bc9fd06295b547 100644 --- a/src/controller/java/JniReferences.h +++ b/src/controller/java/JniReferences.h @@ -31,12 +31,15 @@ class JniReferences static JNIEnv * GetEnvForCurrentThread(); + static jclass GetClusterExceptionCls() { return sClusterExceptionCls; } private: static pthread_mutex_t sStackLock; static JavaVM * sJvm; + static jclass sClusterExceptionCls; }; +jclass GetClusterExceptionCls(); CHIP_ERROR GetClassRef(JNIEnv * env, const char * clsType, jclass & outCls); CHIP_ERROR FindMethod(JNIEnv * env, jobject object, const char * methodName, const char * methodSignature, jmethodID * methodId); void CallVoidInt(JNIEnv * env, jobject object, const char * methodName, jint argument); diff --git a/src/controller/java/src/chip/devicecontroller/ChipClusterException.java b/src/controller/java/src/chip/devicecontroller/ChipClusterException.java new file mode 100644 index 00000000000000..d72008876b5b36 --- /dev/null +++ b/src/controller/java/src/chip/devicecontroller/ChipClusterException.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * 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. + * + */ +package chip.devicecontroller; + +/** Exception class holding error codes defined by clusters. */ +public class ChipClusterException extends Exception { + private static final long serialVersionUID = 1L; + + public int errorCode; + + public ChipClusterException() {} + + public ChipClusterException(int errorCode) { + super(String.format("CHIP cluster error: %d", errorCode)); + this.errorCode = errorCode; + } +} diff --git a/src/controller/java/templates/CHIPClusters-JNI.zapt b/src/controller/java/templates/CHIPClusters-JNI.zapt new file mode 100644 index 00000000000000..a53d091a7194cc --- /dev/null +++ b/src/controller/java/templates/CHIPClusters-JNI.zapt @@ -0,0 +1,395 @@ +{{> header}} +{{#if (chip_has_client_clusters)}} + +#include "CHIPJNIError.h" +#include "gen/CHIPClusters.h" +#include "gen/CHIPClientCallbacks.h" +#include "JniReferences.h" +#include "JniTypeWrappers.h" +#include "StackLock.h" + +#include +#include +#include +#include + +#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; + +static CHIP_ERROR CreateChipClusterException(JNIEnv * env, jint errorCode, jthrowable & outEx); +static CHIP_ERROR CreateIllegalStateException(JNIEnv * env, const char message[], jint errorCode, jthrowable & outEx); + +CHIP_ERROR CreateChipClusterException(JNIEnv * env, jint errorCode, jthrowable & outEx) { + CHIP_ERROR err = CHIP_NO_ERROR; + jmethodID exceptionConstructor; + + exceptionConstructor = env->GetMethodID(JniReferences::GetClusterExceptionCls(), "", "(I)V"); + VerifyOrExit(exceptionConstructor != nullptr, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); + + outEx = (jthrowable) env->NewObject(JniReferences::GetClusterExceptionCls(), exceptionConstructor, errorCode); + VerifyOrExit(outEx != nullptr, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); + +exit: + return err; +} + +CHIP_ERROR CreateIllegalStateException(JNIEnv * env, const char message[], jint errorCode, jthrowable & outEx) { + CHIP_ERROR err = CHIP_NO_ERROR; + jmethodID exceptionConstructor; + jclass exceptionClass; + jstring errStr; + + err = GetClassRef(env, "java/lang/IllegalStateException", exceptionClass); + SuccessOrExit(err); + + exceptionConstructor = env->GetMethodID(exceptionClass, "", "(Ljava/lang/String;)V"); + VerifyOrExit(exceptionConstructor != nullptr, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); + + char buf[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE]; + snprintf(buf, sizeof(buf), "%s: %d", message, errorCode); + errStr = env->NewStringUTF(buf); + + outEx = (jthrowable) env->NewObject(exceptionClass, exceptionConstructor, errStr); + VerifyOrExit(outEx != nullptr, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); +exit: + env->DeleteGlobalRef(exceptionClass); + return err; +} + +class CHIPDefaultSuccessCallback : public Callback::Callback { + public: + CHIPDefaultSuccessCallback(jobject javaCallback): Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + + ~CHIPDefaultSuccessCallback() + { + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + if (env == nullptr) { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + jmethodID javaMethod; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + CHIPDefaultSuccessCallback * cppCallback = nullptr; + + VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); + + cppCallback = reinterpret_cast(context); + VerifyOrExit(cppCallback != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + // It's valid for javaCallbackRef to be nullptr if the Java code passed in a null callback. + javaCallbackRef = cppCallback->javaCallbackRef; + VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); + + err = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->ExceptionClear(); + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + if (cppCallback != nullptr) { + cppCallback->Cancel(); + delete cppCallback; + } + } + + private: + jobject javaCallbackRef; +}; + +class CHIPDefaultFailureCallback : public Callback::Callback { + public: + CHIPDefaultFailureCallback(jobject javaCallback): Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + + ~CHIPDefaultFailureCallback() + { + JNIEnv * env = JniReferences::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + jmethodID javaMethod; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jthrowable exception; + CHIPDefaultFailureCallback * cppCallback = nullptr; + + VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); + + cppCallback = reinterpret_cast(context); + VerifyOrExit(cppCallback != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + // It's valid for javaCallbackRef to be nullptr if the Java code passed in a null callback. + javaCallbackRef = cppCallback->javaCallbackRef; + VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); + + err = FindMethod(env, javaCallbackRef, "onError", "(Ljava/lang/Exception;)V", &javaMethod); + SuccessOrExit(err); + + err = CreateChipClusterException(env, status, exception); + SuccessOrExit(err); + + env->ExceptionClear(); + env->CallVoidMethod(javaCallbackRef, javaMethod, exception); + exit: + if (err != CHIP_NO_ERROR) { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + if (cppCallback != nullptr) { + cppCallback->Cancel(); + delete cppCallback; + } + } + + private: + jobject javaCallbackRef; +}; + +// TODO(#7376): add attribute callbacks. + +{{#all_user_clusters}} +{{#if (isClient side) }} +{{#if (user_cluster_has_enabled_command name side)}} +{{#all_user_cluster_commands}} +{{#if (isStrEqual clusterName parent.name)}} +{{#if (isCommandAvailable parent.side incoming outgoing commandSource name)}} +class CHIP{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback : public Callback::Callback<{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback> +{ + public: + CHIP{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback(jobject javaCallback): Callback::Callback<{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback>(CallbackFn, this) + { + JNIEnv * env = JniReferences::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{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback() + { + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + if (env == nullptr) { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context{{#zcl_command_arguments}}{{#unless (isStrEqual label "status")}}, {{#if (isOctetString type)}}chip::ByteSpan{{else}}{{asUnderlyingZclType type}}{{/if}} {{asSymbol label}}{{/unless}}{{/zcl_command_arguments}}) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIP{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback * cppCallback = nullptr; + {{#zcl_command_arguments}} + {{#unless (isStrEqual label "status")}} + {{#if (isOctetString type)}} + jbyteArray {{asSymbol label}}Arr; + {{else if (isShortString type)}} + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString {{asSymbol label}}Str(env, ""); + {{/if}} + {{/unless}} + {{/zcl_command_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 = FindMethod(env, javaCallbackRef, "onSuccess", "({{#zcl_command_arguments}}{{#unless (isStrEqual label "status")}}{{#if isArray}}{{else if (isOctetString type)}}[B{{else if (isShortString type)}}Ljava/lang/String;{{else}}{{asJniSignature label type}}{{/if}}{{/unless}}{{/zcl_command_arguments}})V", &javaMethod); + SuccessOrExit(err); + + {{#zcl_command_arguments}} + {{#unless (isStrEqual label "status")}} + {{#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}} + {{/unless}} + {{/zcl_command_arguments}} + + env->CallVoidMethod(javaCallbackRef, javaMethod + {{#zcl_command_arguments}} + {{#unless (isStrEqual label "status")}} + {{#if isArray}} + // {{asSymbol label}}: {{#if (isOctetString type)}}chip::ByteSpan{{else}}{{asUnderlyingZclType type}}{{/if}} + // 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}} + {{/unless}} + {{/zcl_command_arguments}} + ); + + {{#zcl_command_arguments}} + {{#unless (isStrEqual label "status")}} + {{#if (isOctetString type)}} + env->DeleteLocalRef({{asSymbol label}}Arr); + {{/if}} + {{/unless}} + {{/zcl_command_arguments}} + + exit: + if (err != CHIP_NO_ERROR) { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + if (cppCallback != nullptr) { + cppCallback->Cancel(); + delete cppCallback; + } + } + + private: + jobject javaCallbackRef; +}; + +{{/if}} +{{/if}} +{{/all_user_cluster_commands}} +{{/if}} +{{/if}} +{{/all_user_clusters}} +JNI_METHOD(void, BaseChipCluster, deleteCluster)(JNIEnv * env, jobject self, jlong clusterPtr) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ClusterBase * cluster = reinterpret_cast(clusterPtr); + if (cluster != nullptr) { + delete cluster; + } +} + +{{#chip_client_clusters}} +JNI_METHOD(jlong, {{asCamelCased name false}}Cluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + {{asCamelCased name false}}Cluster * cppCluster = new {{asCamelCased name false}}Cluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +{{#chip_server_cluster_commands}} +{{#if (zcl_command_arguments_count this.id)}} +JNI_METHOD(void, {{asCamelCased ../name false}}Cluster, {{asCamelCased name}})(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, {{#chip_server_cluster_command_arguments}}{{asJniBasicType type}} {{asCamelCased label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/chip_server_cluster_command_arguments}}) +{{else}} +JNI_METHOD(void, {{asCamelCased ../name false}}Cluster, {{asCamelCased name}})(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{{/if}} +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + {{asCamelCased ../name false}}Cluster * cppCluster; + + {{#chip_server_cluster_command_arguments}} + {{#if (isOctetString type)}} + JniByteArray {{asCamelCased label}}Arr(env, {{asCamelCased label}}); + {{else if (isCharString type)}} + JniUtfString {{asCamelCased label}}Str(env, {{asCamelCased label}}); + {{/if}} + {{/chip_server_cluster_command_arguments}} + {{#if hasSpecificResponse}} + CHIP{{asCamelCased parent.name false}}Cluster{{asCamelCased responseName false}}Callback * onSuccess; + {{else}} + CHIPDefaultSuccessCallback * onSuccess; + {{/if}} + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast<{{asCamelCased ../name false}}Cluster *>(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + {{#if hasSpecificResponse}} + onSuccess = new CHIP{{asCamelCased parent.name false}}Cluster{{asCamelCased responseName false}}Callback(callback); + {{else}} + onSuccess = new CHIPDefaultSuccessCallback(callback); + {{/if}} + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->{{asCamelCased name false}}(onSuccess->Cancel(), onFailure->Cancel(){{#chip_server_cluster_command_arguments}}, {{#if (isOctetString type)}}chip::ByteSpan((const uint8_t*) {{asCamelCased label}}Arr.data(), {{asCamelCased label}}Arr.size()){{else if (isCharString type)}}chip::ByteSpan((const uint8_t*) {{asCamelCased label}}, strlen({{asCamelCased label}}Str.c_str())){{else}}{{asCamelCased label}}{{/if}}{{/chip_server_cluster_command_arguments}}); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +{{/chip_server_cluster_commands}} +{{/chip_client_clusters}} +{{/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 new file mode 100644 index 00000000000000..8f8b2c614898fd --- /dev/null +++ b/src/controller/java/templates/ChipClusters-java.zapt @@ -0,0 +1,103 @@ +{{> header}} +{{#if (chip_has_client_clusters)}} + +package chip.devicecontroller; + +public class ChipClusters { + + public interface DefaultClusterCallback { + void onSuccess(); + void onError(Exception error); + } + + // TODO(#7376): add attribute callbacks. + + public static abstract class BaseChipCluster { + protected long chipClusterPtr; + + public BaseChipCluster(long devicePtr, int endpointId) { + chipClusterPtr = initWithDevice(devicePtr, endpointId); + } + + public abstract long initWithDevice(long devicePtr, int endpointId); + + public native void deleteCluster(long chipClusterPtr); + + @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + + if (chipClusterPtr != 0) { + deleteCluster(chipClusterPtr); + chipClusterPtr = 0; + } + } + } + + {{#chip_client_clusters}} + public static class {{asCamelCased name false}}Cluster extends BaseChipCluster { + public {{asCamelCased name false}}Cluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + {{#chip_server_cluster_commands}} + + {{#if (zcl_command_arguments_count this.id)}} + public void {{asCamelCased name}}({{#if hasSpecificResponse}}{{asCamelCased responseName false}}Callback{{else}}DefaultClusterCallback{{/if}} callback, {{#chip_server_cluster_command_arguments}}{{asJavaBasicType type}} {{asCamelCased label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/chip_server_cluster_command_arguments}}) { + {{else}} + public void {{asCamelCased name}}({{#if hasSpecificResponse}}{{asCamelCased responseName false}}Callback{{else}}DefaultClusterCallback{{/if}} callback) { + {{/if}} + {{#if (zcl_command_arguments_count this.id)}} + {{asCamelCased name}}(chipClusterPtr, callback, {{#chip_server_cluster_command_arguments}}{{asCamelCased label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/chip_server_cluster_command_arguments}}); + {{else}} + {{asCamelCased name}}(chipClusterPtr, callback); + {{/if}} + } + + {{/chip_server_cluster_commands}} + {{#chip_server_cluster_commands}} + {{#if (zcl_command_arguments_count this.id)}} + private native void {{asCamelCased name}}(long chipClusterPtr, {{#if hasSpecificResponse}}{{asCamelCased responseName false}}Callback{{else}}DefaultClusterCallback{{/if}} callback, {{#chip_server_cluster_command_arguments}}{{asJavaBasicType type}} {{asCamelCased label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/chip_server_cluster_command_arguments}}); + {{else}} + private native void {{asCamelCased name}}(long chipClusterPtr, {{#if hasSpecificResponse}}{{asCamelCased responseName false}}Callback{{else}}DefaultClusterCallback{{/if}} callback); + {{/if}} + + {{/chip_server_cluster_commands}} + {{#if (user_cluster_has_enabled_command name side)}} + {{#all_user_cluster_commands}} + {{#if (isStrEqual clusterName parent.name)}} + {{#if (isCommandAvailable parent.side incoming outgoing commandSource name)}} + public interface {{asCamelCased name false}}Callback { + void onSuccess( +{{#zcl_command_arguments}} +{{#unless (isStrEqual label "status")}} +{{#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}} {{asSymbol label}} +{{/if}} +{{/unless}} +{{/zcl_command_arguments}} + ); + + void onError(Exception error); + } + + {{/if}} + {{/if}} + {{/all_user_cluster_commands}} + {{/if}} + } + {{#unless (isLastElement index count)}} + + {{/unless}} + {{/chip_client_clusters}} +} +{{/if}} \ No newline at end of file diff --git a/src/controller/java/templates/helper.js b/src/controller/java/templates/helper.js new file mode 100644 index 00000000000000..d09afe9aa6cd8b --- /dev/null +++ b/src/controller/java/templates/helper.js @@ -0,0 +1,157 @@ +/* + * + * 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. + */ + +// Import helpers from zap core +const zapPath = '../../../../third_party/zap/repo/src-electron/'; +const templateUtil = require(zapPath + 'generator/template-util.js') +const zclHelper = require(zapPath + 'generator/helper-zcl.js') +const queryZcl = require(zapPath + 'db/query-zcl.js') + +const ChipTypesHelper = require('../../../../src/app/zap-templates/common/ChipTypesHelper.js'); +const StringHelper = require('../../../../src/app/zap-templates/common/StringHelper.js'); + +function convertBasicCTypeToJavaType(cType) +{ + switch (cType) { + case 'uint8_t': + case 'int8_t': + case 'uint16_t': + case 'int16_t': + return 'int'; + case 'uint32_t': + case 'int32_t': + case 'uint64_t': + case 'int64_t': + return 'long'; + default: + error = ': Unhandled type ' + cType; + throw error; + } +} + +function convertBasicCTypeToJniType(cType) +{ + switch (convertBasicCTypeToJavaType(cType)) { + case 'int': + return 'jint'; + case 'long': + return 'jlong'; + default: + error = ': Unhandled type ' + cType; + throw error; + } +} + +function asJavaBasicType(type) +{ + if (StringHelper.isOctetString(type)) { + return 'byte[]'; + } else if (StringHelper.isCharString(type)) { + return 'String'; + } else { + return convertBasicCTypeToJavaType(ChipTypesHelper.asBasicType(this.chipType)); + } +} + +function asJniBasicType(type) +{ + if (StringHelper.isOctetString(type)) { + return 'jbyteArray'; + } else if (StringHelper.isCharString(type)) { + return 'jstring'; + } else { + return convertBasicCTypeToJniType(ChipTypesHelper.asBasicType(this.chipType)); + } +} + +function asJavaBasicTypeForZclType(type) +{ + function fn(pkgId) + { + const options = { 'hash' : {} }; + return zclHelper.asUnderlyingZclType.call(this, type, options).then(zclType => { + return convertBasicCTypeToJavaType(ChipTypesHelper.asBasicType(zclType)); + }) + } + + const promise = templateUtil.ensureZclPackageId(this).then(fn.bind(this)).catch(err => console.log(err)); + return templateUtil.templatePromise(this.global, promise) +} + +function asJniBasicTypeForZclType(type) +{ + function fn(pkgId) + { + const options = { 'hash' : {} }; + return zclHelper.asUnderlyingZclType.call(this, type, options).then(zclType => { + return convertBasicCTypeToJniType(ChipTypesHelper.asBasicType(zclType)); + }) + } + + const promise = templateUtil.ensureZclPackageId(this).then(fn.bind(this)).catch(err => console.log(err)); + return templateUtil.templatePromise(this.global, promise) +} + +function asJniSignature(label, type) +{ + function fn(pkgId) + { + const options = { 'hash' : {} }; + return zclHelper.asUnderlyingZclType.call(this, type, options).then(zclType => { + switch (convertBasicCTypeToJavaType(ChipTypesHelper.asBasicType(zclType))) { + case 'int': + return 'I'; + case 'long': + return 'J'; + default: + error = label + ': Unhandled underlying type ' + zclType + ' for original type ' + type; + throw error; + } + }) + } + + const promise = templateUtil.ensureZclPackageId(this).then(fn.bind(this)).catch(err => console.log(err)); + return templateUtil.templatePromise(this.global, promise) +} + +function omitCommaForFirstNonStatusCommand(id, index) +{ + let promise = templateUtil.ensureZclPackageId(this) + .then((pkgId) => { return queryZcl.selectCommandArgumentsByCommandId(this.global.db, id, pkgId) }) + .catch(err => console.log(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.label != "status" && !command.isArray); + if (firstNonStatusCommandIndex == -1 || firstNonStatusCommandIndex != index) { + return ", "; + } + return ""; + }) + .catch(err => console.log(err)); + + return templateUtil.templatePromise(this.global, promise); +} + +// +// Module exports +// +exports.asJavaBasicType = asJavaBasicType; +exports.asJniBasicType = asJniBasicType; +exports.asJniBasicTypeForZclType = asJniBasicTypeForZclType; +exports.asJniSignature = asJniSignature; +exports.asJavaBasicTypeForZclType = asJavaBasicTypeForZclType; +exports.omitCommaForFirstNonStatusCommand = omitCommaForFirstNonStatusCommand; diff --git a/src/controller/java/templates/templates.json b/src/controller/java/templates/templates.json new file mode 100644 index 00000000000000..a4e32d5ee0a615 --- /dev/null +++ b/src/controller/java/templates/templates.json @@ -0,0 +1,39 @@ +{ + "name": "CHIP Android templates", + "version": "chip-v1", + "helpers": [ + "../../../app/zap-templates/common/ListHelper.js", + "../../../app/zap-templates/common/StringHelper.js", + "../../../app/zap-templates/partials/helper.js", + "../../../app/zap-templates/templates/app/helper.js", + "../../../app/zap-templates/templates/chip/helper.js", + "helper.js" + ], + "override": "../../../app/zap-templates/common/override.js", + "partials": [ + { + "name": "header", + "path": "../../../app/zap-templates/partials/header.zapt" + }, + { + "name": "clusters_header", + "path": "../../../app/zap-templates/partials/clusters_header.zapt" + }, + { + "name": "cluster_header", + "path": "../../../app/zap-templates/partials/cluster_header.zapt" + } + ], + "templates": [ + { + "path": "CHIPClusters-JNI.zapt", + "name": "CHIP ZCL API for Java (native code)", + "output": "src/controller/java/gen/CHIPClusters-JNI.cpp" + }, + { + "path": "ChipClusters-java.zapt", + "name": "CHIP ZCL API for Java", + "output": "src/controller/java/gen/ChipClusters.java" + } + ] +} From 6437ffcc80201ea7b8b6e99f97c4fdbe8258abc0 Mon Sep 17 00:00:00 2001 From: Austin Hsieh Date: Thu, 17 Jun 2021 17:34:56 -0700 Subject: [PATCH 3/4] Generated files and java/BUILD changes to include them --- src/controller/java/BUILD.gn | 12 + src/controller/java/gen/CHIPClusters-JNI.cpp | 11921 +++++++++++++++++ src/controller/java/gen/ChipClusters.java | 2356 ++++ 3 files changed, 14289 insertions(+) create mode 100644 src/controller/java/gen/CHIPClusters-JNI.cpp create mode 100644 src/controller/java/gen/ChipClusters.java diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 346cc3552b0739..70a5fdea8358f5 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -18,6 +18,13 @@ import("//build_overrides/chip.gni") import("${build_root}/config/android_abi.gni") import("${chip_root}/build/chip/java/rules.gni") +config("java_config") { + include_dirs = [ + ".", + "..", + ] +} + shared_library("jni") { output_name = "libCHIPController" @@ -38,13 +45,17 @@ shared_library("jni") { "JniReferences.h", "JniTypeWrappers.h", "StackLock.h", + "gen/CHIPClusters-JNI.cpp", ] deps = [ + "${chip_root}/src/app", "${chip_root}/src/controller/data_model", "${chip_root}/src/lib", ] + public_configs = [ ":java_config" ] + output_dir = "${root_out_dir}/lib/jni/${android_abi}" } @@ -57,6 +68,7 @@ android_library("java") { ] sources = [ + "gen/ChipClusters.java", "src/chip/devicecontroller/AndroidChipStack.java", "src/chip/devicecontroller/ChipClusterException.java", "src/chip/devicecontroller/ChipCommandType.java", diff --git a/src/controller/java/gen/CHIPClusters-JNI.cpp b/src/controller/java/gen/CHIPClusters-JNI.cpp new file mode 100644 index 00000000000000..78d595f330f360 --- /dev/null +++ b/src/controller/java/gen/CHIPClusters-JNI.cpp @@ -0,0 +1,11921 @@ +/* + * + * 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 "CHIPJNIError.h" +#include "JniReferences.h" +#include "JniTypeWrappers.h" +#include "StackLock.h" +#include "gen/CHIPClientCallbacks.h" +#include "gen/CHIPClusters.h" + +#include +#include +#include +#include + +#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; + +static CHIP_ERROR CreateChipClusterException(JNIEnv * env, jint errorCode, jthrowable & outEx); +static CHIP_ERROR CreateIllegalStateException(JNIEnv * env, const char message[], jint errorCode, jthrowable & outEx); + +CHIP_ERROR CreateChipClusterException(JNIEnv * env, jint errorCode, jthrowable & outEx) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + jmethodID exceptionConstructor; + + exceptionConstructor = env->GetMethodID(JniReferences::GetClusterExceptionCls(), "", "(I)V"); + VerifyOrExit(exceptionConstructor != nullptr, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); + + outEx = (jthrowable) env->NewObject(JniReferences::GetClusterExceptionCls(), exceptionConstructor, errorCode); + VerifyOrExit(outEx != nullptr, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); + +exit: + return err; +} + +CHIP_ERROR CreateIllegalStateException(JNIEnv * env, const char message[], jint errorCode, jthrowable & outEx) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + jmethodID exceptionConstructor; + jclass exceptionClass; + jstring errStr; + + err = GetClassRef(env, "java/lang/IllegalStateException", exceptionClass); + SuccessOrExit(err); + + exceptionConstructor = env->GetMethodID(exceptionClass, "", "(Ljava/lang/String;)V"); + VerifyOrExit(exceptionConstructor != nullptr, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); + + char buf[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE]; + snprintf(buf, sizeof(buf), "%s: %d", message, errorCode); + errStr = env->NewStringUTF(buf); + + outEx = (jthrowable) env->NewObject(exceptionClass, exceptionConstructor, errStr); + VerifyOrExit(outEx != nullptr, err = CHIP_JNI_ERROR_TYPE_NOT_FOUND); +exit: + env->DeleteGlobalRef(exceptionClass); + return err; +} + +class CHIPDefaultSuccessCallback : public Callback::Callback +{ +public: + CHIPDefaultSuccessCallback(jobject javaCallback) : Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + + ~CHIPDefaultSuccessCallback() + { + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + jmethodID javaMethod; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + CHIPDefaultSuccessCallback * cppCallback = nullptr; + + VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); + + cppCallback = reinterpret_cast(context); + VerifyOrExit(cppCallback != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + // It's valid for javaCallbackRef to be nullptr if the Java code passed in a null callback. + javaCallbackRef = cppCallback->javaCallbackRef; + VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); + + err = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->ExceptionClear(); + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +class CHIPDefaultFailureCallback : public Callback::Callback +{ +public: + CHIPDefaultFailureCallback(jobject javaCallback) : Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + + ~CHIPDefaultFailureCallback() + { + JNIEnv * env = JniReferences::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + jmethodID javaMethod; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jthrowable exception; + CHIPDefaultFailureCallback * cppCallback = nullptr; + + VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); + + cppCallback = reinterpret_cast(context); + VerifyOrExit(cppCallback != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + // It's valid for javaCallbackRef to be nullptr if the Java code passed in a null callback. + javaCallbackRef = cppCallback->javaCallbackRef; + VerifyOrExit(javaCallbackRef != nullptr, err = CHIP_NO_ERROR); + + err = FindMethod(env, javaCallbackRef, "onError", "(Ljava/lang/Exception;)V", &javaMethod); + SuccessOrExit(err); + + err = CreateChipClusterException(env, status, exception); + SuccessOrExit(err); + + env->ExceptionClear(); + env->CallVoidMethod(javaCallbackRef, javaMethod, exception); + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +// TODO(#7376): add attribute callbacks. + +class CHIPAccountLoginClusterGetSetupPINResponseCallback : public Callback::Callback +{ +public: + CHIPAccountLoginClusterGetSetupPINResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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::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 * setupPIN) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPAccountLoginClusterGetSetupPINResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString setupPINStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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 * data) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPApplicationLauncherClusterLaunchAppResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString dataStr(env, ""); + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, dataStr.jniValue()); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +class CHIPContentLaunchClusterLaunchContentResponseCallback + : public Callback::Callback +{ +public: + CHIPContentLaunchClusterLaunchContentResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + ~CHIPContentLaunchClusterLaunchContentResponseCallback() + { + JNIEnv * env = JniReferences::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 * data, uint8_t contentLaunchStatus) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPContentLaunchClusterLaunchContentResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString dataStr(env, ""); + + 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 = 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: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +class CHIPContentLaunchClusterLaunchURLResponseCallback : public Callback::Callback +{ +public: + CHIPContentLaunchClusterLaunchURLResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + ~CHIPContentLaunchClusterLaunchURLResponseCallback() + { + JNIEnv * env = JniReferences::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 * data, uint8_t contentLaunchStatus) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPContentLaunchClusterLaunchURLResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString dataStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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, uint32_t localStartTime, uint32_t localEndTime, + uint8_t operatingModeDuringHoliday) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(IJJI)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(scheduleId), static_cast(localStartTime), + static_cast(localEndTime), static_cast(operatingModeDuringHoliday)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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, uint8_t * pin) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPDoorLockClusterGetLogRecordResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString pinStr(env, ""); + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(IJIIIILjava/lang/String;)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(logEntryId), static_cast(timestamp), + static_cast(eventType), static_cast(source), static_cast(eventIdOrAlarmCode), + static_cast(userId), pinStr.jniValue()); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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, uint8_t * pin) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPDoorLockClusterGetPinResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString pinStr(env, ""); + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(IIILjava/lang/String;)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(userId), static_cast(userStatus), + static_cast(userType), pinStr.jniValue()); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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, uint8_t * rfid) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPDoorLockClusterGetRfidResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString rfidStr(env, ""); + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(IIILjava/lang/String;)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(userId), static_cast(userStatus), + static_cast(userType), rfidStr.jniValue()); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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 daysMask, uint8_t startHour, + uint8_t startMinute, uint8_t endHour, uint8_t endMinute) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(IIIIIII)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(scheduleId), static_cast(userId), + 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: %d", err); + } + 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::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::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, uint32_t localStartTime, uint32_t localEndTime) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(IIJJ)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(scheduleId), static_cast(userId), + static_cast(localStartTime), static_cast(localEndTime)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPGeneralCommissioningClusterArmFailSafeResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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 groupId) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(groupId)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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 groupId) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(groupId)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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 groupId, uint8_t * groupName) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPGroupsClusterViewGroupResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString groupNameStr(env, ""); + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(ILjava/lang/String;)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(groupId), groupNameStr.jniValue()); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "()V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +class CHIPMediaPlaybackClusterMediaSkipSeekResponseCallback + : public Callback::Callback +{ +public: + CHIPMediaPlaybackClusterMediaSkipSeekResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + ~CHIPMediaPlaybackClusterMediaSkipSeekResponseCallback() + { + JNIEnv * env = JniReferences::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPMediaPlaybackClusterMediaSkipSeekResponseCallback * 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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPNetworkCommissioningClusterDisableNetworkResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPNetworkCommissioningClusterEnableNetworkResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText, + /* TYPE WARNING: array array defaults to */ uint8_t * wifiScanResults, + /* TYPE WARNING: array array defaults to */ uint8_t * threadScanResults) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPNetworkCommissioningClusterScanNetworksResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + 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::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::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, uint8_t * debugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString debugTextStr(env, ""); + + 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 = 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: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +class CHIPOtaSoftwareUpdateServerClusterApplyUpdateRequestResponseCallback + : public Callback::Callback +{ +public: + CHIPOtaSoftwareUpdateServerClusterApplyUpdateRequestResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + ~CHIPOtaSoftwareUpdateServerClusterApplyUpdateRequestResponseCallback() + { + JNIEnv * env = JniReferences::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPOtaSoftwareUpdateServerClusterApplyUpdateRequestResponseCallback * 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 = 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: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +class CHIPOtaSoftwareUpdateServerClusterQueryImageResponseCallback + : public Callback::Callback +{ +public: + CHIPOtaSoftwareUpdateServerClusterQueryImageResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + ~CHIPOtaSoftwareUpdateServerClusterQueryImageResponseCallback() + { + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context, uint32_t delayedActionTime, uint8_t * imageURI, uint32_t softwareVersion, + chip::ByteSpan updateToken, uint8_t userConsentNeeded, chip::ByteSpan metadataForClient) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPOtaSoftwareUpdateServerClusterQueryImageResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString imageURIStr(env, ""); + jbyteArray updateTokenArr; + jbyteArray metadataForClientArr; + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(JLjava/lang/String;J[BI[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); + metadataForClientArr = env->NewByteArray(metadataForClient.size()); + VerifyOrExit(metadataForClientArr != nullptr, err = CHIP_ERROR_NO_MEMORY); + env->ExceptionClear(); + env->SetByteArrayRegion(metadataForClientArr, 0, metadataForClient.size(), + reinterpret_cast(metadataForClient.data())); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(delayedActionTime), imageURIStr.jniValue(), + static_cast(softwareVersion), updateTokenArr, static_cast(userConsentNeeded), + metadataForClientArr); + + env->DeleteLocalRef(updateTokenArr); + env->DeleteLocalRef(metadataForClientArr); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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 CSR, chip::ByteSpan CSRNonce, chip::ByteSpan VendorReserved1, + chip::ByteSpan VendorReserved2, chip::ByteSpan VendorReserved3, chip::ByteSpan Signature) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPOperationalCredentialsClusterOpCSRResponseCallback * cppCallback = nullptr; + jbyteArray CSRArr; + jbyteArray CSRNonceArr; + jbyteArray VendorReserved1Arr; + jbyteArray VendorReserved2Arr; + jbyteArray VendorReserved3Arr; + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "([B[B[B[B[B[B)V", &javaMethod); + SuccessOrExit(err); + + CSRArr = env->NewByteArray(CSR.size()); + VerifyOrExit(CSRArr != nullptr, err = CHIP_ERROR_NO_MEMORY); + env->ExceptionClear(); + env->SetByteArrayRegion(CSRArr, 0, CSR.size(), reinterpret_cast(CSR.data())); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + CSRNonceArr = env->NewByteArray(CSRNonce.size()); + VerifyOrExit(CSRNonceArr != nullptr, err = CHIP_ERROR_NO_MEMORY); + env->ExceptionClear(); + env->SetByteArrayRegion(CSRNonceArr, 0, CSRNonce.size(), reinterpret_cast(CSRNonce.data())); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + VendorReserved1Arr = env->NewByteArray(VendorReserved1.size()); + VerifyOrExit(VendorReserved1Arr != nullptr, err = CHIP_ERROR_NO_MEMORY); + env->ExceptionClear(); + env->SetByteArrayRegion(VendorReserved1Arr, 0, VendorReserved1.size(), + reinterpret_cast(VendorReserved1.data())); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + VendorReserved2Arr = env->NewByteArray(VendorReserved2.size()); + VerifyOrExit(VendorReserved2Arr != nullptr, err = CHIP_ERROR_NO_MEMORY); + env->ExceptionClear(); + env->SetByteArrayRegion(VendorReserved2Arr, 0, VendorReserved2.size(), + reinterpret_cast(VendorReserved2.data())); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + VendorReserved3Arr = env->NewByteArray(VendorReserved3.size()); + VerifyOrExit(VendorReserved3Arr != nullptr, err = CHIP_ERROR_NO_MEMORY); + env->ExceptionClear(); + env->SetByteArrayRegion(VendorReserved3Arr, 0, VendorReserved3.size(), + reinterpret_cast(VendorReserved3.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, CSRArr, CSRNonceArr, VendorReserved1Arr, VendorReserved2Arr, + VendorReserved3Arr, SignatureArr); + + env->DeleteLocalRef(CSRArr); + env->DeleteLocalRef(CSRNonceArr); + env->DeleteLocalRef(VendorReserved1Arr); + env->DeleteLocalRef(VendorReserved2Arr); + env->DeleteLocalRef(VendorReserved3Arr); + env->DeleteLocalRef(SignatureArr); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +class CHIPOperationalCredentialsClusterOpCertResponseCallback + : public Callback::Callback +{ +public: + CHIPOperationalCredentialsClusterOpCertResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + ~CHIPOperationalCredentialsClusterOpCertResponseCallback() + { + JNIEnv * env = JniReferences::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, uint64_t FabricIndex, uint8_t * DebugText) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPOperationalCredentialsClusterOpCertResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString DebugTextStr(env, ""); + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(IJLjava/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: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +class CHIPOperationalCredentialsClusterSetFabricResponseCallback + : public Callback::Callback +{ +public: + CHIPOperationalCredentialsClusterSetFabricResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) + { + JNIEnv * env = JniReferences::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"); + } + } + ~CHIPOperationalCredentialsClusterSetFabricResponseCallback() + { + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); + }; + + static void CallbackFn(void * context, chip::FabricId FabricId) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPOperationalCredentialsClusterSetFabricResponseCallback * 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(J)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(FabricId)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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 groupId, uint8_t sceneId) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(groupId), static_cast(sceneId)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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, uint16_t groupId, uint8_t sceneCount, + /* TYPE WARNING: array array defaults to */ uint8_t * sceneList) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(III)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, 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: %d", err); + } + 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::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::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 groupId) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(I)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(groupId)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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 groupId, uint8_t sceneId) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(groupId), static_cast(sceneId)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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 groupId, uint8_t sceneId) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = FindMethod(env, javaCallbackRef, "onSuccess", "(II)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast(groupId), static_cast(sceneId)); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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 groupId, uint8_t sceneId, uint16_t transitionTime, uint8_t * sceneName, + /* TYPE WARNING: array array defaults to */ uint8_t * extensionFieldSets) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPScenesClusterViewSceneResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString sceneNameStr(env, ""); + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(IIILjava/lang/String;)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, 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: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + 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::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::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 * data) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + CHIPTargetNavigatorClusterNavigateTargetResponseCallback * cppCallback = nullptr; + // ByteSpan is not properly returned yet, temporarily use empty string + UtfString dataStr(env, ""); + + 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 = FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;)V", &javaMethod); + SuccessOrExit(err); + + env->CallVoidMethod(javaCallbackRef, javaMethod, dataStr.jniValue()); + + exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error invoking Java callback: %d", err); + } + 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::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::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) + { + StackUnlockGuard unlockGuard(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::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 = 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: %d", err); + } + if (cppCallback != nullptr) + { + cppCallback->Cancel(); + delete cppCallback; + } + } + +private: + jobject javaCallbackRef; +}; + +JNI_METHOD(void, BaseChipCluster, deleteCluster)(JNIEnv * env, jobject self, jlong clusterPtr) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ClusterBase * cluster = reinterpret_cast(clusterPtr); + if (cluster != nullptr) + { + delete cluster; + } +} + +JNI_METHOD(jlong, AccountLoginCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + AccountLoginCluster * cppCluster = new AccountLoginCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, AccountLoginCluster, getSetupPIN) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring tempAccountIdentifier) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + AccountLoginCluster * cppCluster; + + JniUtfString tempAccountIdentifierStr(env, tempAccountIdentifier); + CHIPAccountLoginClusterGetSetupPINResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPAccountLoginClusterGetSetupPINResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = + cppCluster->GetSetupPIN(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) tempAccountIdentifier, strlen(tempAccountIdentifierStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, AccountLoginCluster, login) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring tempAccountIdentifier, jstring setupPIN) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + AccountLoginCluster * cppCluster; + + JniUtfString tempAccountIdentifierStr(env, tempAccountIdentifier); + JniUtfString setupPINStr(env, setupPIN); + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Login(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) tempAccountIdentifier, strlen(tempAccountIdentifierStr.c_str())), + chip::ByteSpan((const uint8_t *) setupPIN, strlen(setupPINStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, ApplicationBasicCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ApplicationBasicCluster * cppCluster = new ApplicationBasicCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, ApplicationLauncherCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ApplicationLauncherCluster * cppCluster = new ApplicationLauncherCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, ApplicationLauncherCluster, launchApp) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring data, jint catalogVendorId, jstring applicationId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ApplicationLauncherCluster * cppCluster; + + JniUtfString dataStr(env, data); + JniUtfString applicationIdStr(env, applicationId); + CHIPApplicationLauncherClusterLaunchAppResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPApplicationLauncherClusterLaunchAppResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->LaunchApp(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) data, strlen(dataStr.c_str())), catalogVendorId, + chip::ByteSpan((const uint8_t *) applicationId, strlen(applicationIdStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, AudioOutputCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + AudioOutputCluster * cppCluster = new AudioOutputCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, AudioOutputCluster, renameOutput) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint index, jstring name) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + AudioOutputCluster * cppCluster; + + JniUtfString nameStr(env, name); + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RenameOutput(onSuccess->Cancel(), onFailure->Cancel(), index, + chip::ByteSpan((const uint8_t *) name, strlen(nameStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, AudioOutputCluster, selectOutput)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint index) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + AudioOutputCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SelectOutput(onSuccess->Cancel(), onFailure->Cancel(), index); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, BarrierControlCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + BarrierControlCluster * cppCluster = new BarrierControlCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, BarrierControlCluster, barrierControlGoToPercent) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint percentOpen) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + BarrierControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->BarrierControlGoToPercent(onSuccess->Cancel(), onFailure->Cancel(), percentOpen); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, BarrierControlCluster, barrierControlStop)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + BarrierControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->BarrierControlStop(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, BasicCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + BasicCluster * cppCluster = new BasicCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, BasicCluster, mfgSpecificPing)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + BasicCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MfgSpecificPing(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, BinaryInputBasicCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + BinaryInputBasicCluster * cppCluster = new BinaryInputBasicCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, BindingCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + BindingCluster * cppCluster = new BindingCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, BindingCluster, bind) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong nodeId, jint groupId, jint endpointId, jint clusterId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + BindingCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Bind(onSuccess->Cancel(), onFailure->Cancel(), nodeId, groupId, endpointId, clusterId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, BindingCluster, unbind) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong nodeId, jint groupId, jint endpointId, jint clusterId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + BindingCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Unbind(onSuccess->Cancel(), onFailure->Cancel(), nodeId, groupId, endpointId, clusterId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, BridgedDeviceBasicCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + BridgedDeviceBasicCluster * cppCluster = new BridgedDeviceBasicCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, ColorControlCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ColorControlCluster * cppCluster = new ColorControlCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, ColorControlCluster, moveColor) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint rateX, jint rateY, jint optionsMask, jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveColor(onSuccess->Cancel(), onFailure->Cancel(), rateX, rateY, optionsMask, optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +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) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveColorTemperature(onSuccess->Cancel(), onFailure->Cancel(), moveMode, rate, colorTemperatureMinimum, + colorTemperatureMaximum, optionsMask, optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, moveHue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate, jint optionsMask, jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveHue(onSuccess->Cancel(), onFailure->Cancel(), moveMode, rate, optionsMask, optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, moveSaturation) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate, jint optionsMask, jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveSaturation(onSuccess->Cancel(), onFailure->Cancel(), moveMode, rate, optionsMask, optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, moveToColor) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint colorX, jint colorY, jint transitionTime, jint optionsMask, + jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveToColor(onSuccess->Cancel(), onFailure->Cancel(), colorX, colorY, transitionTime, optionsMask, + optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, moveToColorTemperature) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint colorTemperature, jint transitionTime, jint optionsMask, + jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveToColorTemperature(onSuccess->Cancel(), onFailure->Cancel(), colorTemperature, transitionTime, + optionsMask, optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, moveToHue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint hue, jint direction, jint transitionTime, jint optionsMask, + jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveToHue(onSuccess->Cancel(), onFailure->Cancel(), hue, direction, transitionTime, optionsMask, + optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, moveToHueAndSaturation) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint hue, jint saturation, jint transitionTime, jint optionsMask, + jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveToHueAndSaturation(onSuccess->Cancel(), onFailure->Cancel(), hue, saturation, transitionTime, optionsMask, + optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, moveToSaturation) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint saturation, jint transitionTime, jint optionsMask, + jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveToSaturation(onSuccess->Cancel(), onFailure->Cancel(), saturation, transitionTime, optionsMask, + optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, stepColor) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepX, jint stepY, jint transitionTime, jint optionsMask, + jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = + cppCluster->StepColor(onSuccess->Cancel(), onFailure->Cancel(), stepX, stepY, transitionTime, optionsMask, optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +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) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->StepColorTemperature(onSuccess->Cancel(), onFailure->Cancel(), stepMode, stepSize, transitionTime, + colorTemperatureMinimum, colorTemperatureMaximum, optionsMask, optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, stepHue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime, + jint optionsMask, jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->StepHue(onSuccess->Cancel(), onFailure->Cancel(), stepMode, stepSize, transitionTime, optionsMask, + optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, stepSaturation) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime, + jint optionsMask, jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->StepSaturation(onSuccess->Cancel(), onFailure->Cancel(), stepMode, stepSize, transitionTime, optionsMask, + optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ColorControlCluster, stopMoveStep) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint optionsMask, jint optionsOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ColorControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->StopMoveStep(onSuccess->Cancel(), onFailure->Cancel(), optionsMask, optionsOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, ContentLaunchCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ContentLaunchCluster * cppCluster = new ContentLaunchCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, ContentLaunchCluster, launchContent) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint autoPlay, jstring data) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ContentLaunchCluster * cppCluster; + + JniUtfString dataStr(env, data); + CHIPContentLaunchClusterLaunchContentResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPContentLaunchClusterLaunchContentResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->LaunchContent(onSuccess->Cancel(), onFailure->Cancel(), autoPlay, + chip::ByteSpan((const uint8_t *) data, strlen(dataStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ContentLaunchCluster, launchURL) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring contentURL, jstring displayString) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ContentLaunchCluster * cppCluster; + + JniUtfString contentURLStr(env, contentURL); + JniUtfString displayStringStr(env, displayString); + CHIPContentLaunchClusterLaunchURLResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPContentLaunchClusterLaunchURLResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->LaunchURL(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) contentURL, strlen(contentURLStr.c_str())), + chip::ByteSpan((const uint8_t *) displayString, strlen(displayStringStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, DescriptorCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + DescriptorCluster * cppCluster = new DescriptorCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, DoorLockCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + DoorLockCluster * cppCluster = new DoorLockCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, DoorLockCluster, clearAllPins)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterClearAllPinsResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterClearAllPinsResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ClearAllPins(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, clearAllRfids)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterClearAllRfidsResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterClearAllRfidsResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ClearAllRfids(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, clearHolidaySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterClearHolidayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterClearHolidayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ClearHolidaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, clearPin)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterClearPinResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterClearPinResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ClearPin(onSuccess->Cancel(), onFailure->Cancel(), userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, clearRfid)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterClearRfidResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterClearRfidResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ClearRfid(onSuccess->Cancel(), onFailure->Cancel(), userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, clearWeekdaySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterClearWeekdayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterClearWeekdayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ClearWeekdaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, clearYeardaySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterClearYeardayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterClearYeardayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ClearYeardaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, getHolidaySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterGetHolidayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterGetHolidayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetHolidaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, getLogRecord)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint logIndex) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterGetLogRecordResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterGetLogRecordResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetLogRecord(onSuccess->Cancel(), onFailure->Cancel(), logIndex); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, getPin)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterGetPinResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterGetPinResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetPin(onSuccess->Cancel(), onFailure->Cancel(), userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, getRfid)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterGetRfidResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterGetRfidResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetRfid(onSuccess->Cancel(), onFailure->Cancel(), userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, getUserType)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterGetUserTypeResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterGetUserTypeResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetUserType(onSuccess->Cancel(), onFailure->Cancel(), userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, getWeekdaySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterGetWeekdayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterGetWeekdayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetWeekdaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, getYeardaySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterGetYeardayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterGetYeardayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetYeardaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, lockDoor)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring pin) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + JniUtfString pinStr(env, pin); + CHIPDoorLockClusterLockDoorResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterLockDoorResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->LockDoor(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) pin, strlen(pinStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, setHolidaySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jlong localStartTime, jlong localEndTime, + jint operatingModeDuringHoliday) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterSetHolidayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterSetHolidayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetHolidaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, localStartTime, localEndTime, + operatingModeDuringHoliday); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, setPin) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId, jint userStatus, jint userType, jstring pin) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + JniUtfString pinStr(env, pin); + CHIPDoorLockClusterSetPinResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterSetPinResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetPin(onSuccess->Cancel(), onFailure->Cancel(), userId, userStatus, userType, + chip::ByteSpan((const uint8_t *) pin, strlen(pinStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, setRfid) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId, jint userStatus, jint userType, jstring id) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + JniUtfString idStr(env, id); + CHIPDoorLockClusterSetRfidResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterSetRfidResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetRfid(onSuccess->Cancel(), onFailure->Cancel(), userId, userStatus, userType, + chip::ByteSpan((const uint8_t *) id, strlen(idStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, setUserType) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint userId, jint userType) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterSetUserTypeResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterSetUserTypeResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetUserType(onSuccess->Cancel(), onFailure->Cancel(), userId, userType); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +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) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterSetWeekdayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterSetWeekdayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetWeekdaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId, daysMask, startHour, + startMinute, endHour, endMinute); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, setYeardaySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint scheduleId, jint userId, jlong localStartTime, + jlong localEndTime) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + CHIPDoorLockClusterSetYeardayScheduleResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterSetYeardayScheduleResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = + cppCluster->SetYeardaySchedule(onSuccess->Cancel(), onFailure->Cancel(), scheduleId, userId, localStartTime, localEndTime); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, unlockDoor)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring pin) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + JniUtfString pinStr(env, pin); + CHIPDoorLockClusterUnlockDoorResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterUnlockDoorResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->UnlockDoor(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) pin, strlen(pinStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, DoorLockCluster, unlockWithTimeout) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint timeoutInSeconds, jstring pin) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + DoorLockCluster * cppCluster; + + JniUtfString pinStr(env, pin); + CHIPDoorLockClusterUnlockWithTimeoutResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDoorLockClusterUnlockWithTimeoutResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->UnlockWithTimeout(onSuccess->Cancel(), onFailure->Cancel(), timeoutInSeconds, + chip::ByteSpan((const uint8_t *) pin, strlen(pinStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, EthernetNetworkDiagnosticsCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + EthernetNetworkDiagnosticsCluster * cppCluster = new EthernetNetworkDiagnosticsCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, EthernetNetworkDiagnosticsCluster, resetCounts)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + EthernetNetworkDiagnosticsCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ResetCounts(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, FixedLabelCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + FixedLabelCluster * cppCluster = new FixedLabelCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, GeneralCommissioningCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + GeneralCommissioningCluster * cppCluster = new GeneralCommissioningCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, GeneralCommissioningCluster, armFailSafe) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint expiryLengthSeconds, jlong breadcrumb, jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GeneralCommissioningCluster * cppCluster; + + CHIPGeneralCommissioningClusterArmFailSafeResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPGeneralCommissioningClusterArmFailSafeResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ArmFailSafe(onSuccess->Cancel(), onFailure->Cancel(), expiryLengthSeconds, breadcrumb, timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, GeneralCommissioningCluster, commissioningComplete)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GeneralCommissioningCluster * cppCluster; + + CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->CommissioningComplete(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, GeneralCommissioningCluster, setRegulatoryConfig) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint location, jstring countryCode, jlong breadcrumb, + jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GeneralCommissioningCluster * cppCluster; + + JniUtfString countryCodeStr(env, countryCode); + CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetRegulatoryConfig(onSuccess->Cancel(), onFailure->Cancel(), location, + chip::ByteSpan((const uint8_t *) countryCode, strlen(countryCodeStr.c_str())), breadcrumb, + timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, GeneralDiagnosticsCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + GeneralDiagnosticsCluster * cppCluster = new GeneralDiagnosticsCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, GroupKeyManagementCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + GroupKeyManagementCluster * cppCluster = new GroupKeyManagementCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, GroupsCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + GroupsCluster * cppCluster = new GroupsCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, GroupsCluster, addGroup) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jstring groupName) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GroupsCluster * cppCluster; + + JniUtfString groupNameStr(env, groupName); + CHIPGroupsClusterAddGroupResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPGroupsClusterAddGroupResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->AddGroup(onSuccess->Cancel(), onFailure->Cancel(), groupId, + chip::ByteSpan((const uint8_t *) groupName, strlen(groupNameStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, GroupsCluster, addGroupIfIdentifying) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jstring groupName) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GroupsCluster * cppCluster; + + JniUtfString groupNameStr(env, groupName); + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->AddGroupIfIdentifying(onSuccess->Cancel(), onFailure->Cancel(), groupId, + chip::ByteSpan((const uint8_t *) groupName, strlen(groupNameStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, GroupsCluster, getGroupMembership) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupCount, jint groupList) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GroupsCluster * cppCluster; + + CHIPGroupsClusterGetGroupMembershipResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPGroupsClusterGetGroupMembershipResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetGroupMembership(onSuccess->Cancel(), onFailure->Cancel(), groupCount, groupList); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, GroupsCluster, removeAllGroups)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GroupsCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RemoveAllGroups(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, GroupsCluster, removeGroup)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GroupsCluster * cppCluster; + + CHIPGroupsClusterRemoveGroupResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPGroupsClusterRemoveGroupResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RemoveGroup(onSuccess->Cancel(), onFailure->Cancel(), groupId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, GroupsCluster, viewGroup)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + GroupsCluster * cppCluster; + + CHIPGroupsClusterViewGroupResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPGroupsClusterViewGroupResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ViewGroup(onSuccess->Cancel(), onFailure->Cancel(), groupId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, IdentifyCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + IdentifyCluster * cppCluster = new IdentifyCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, IdentifyCluster, identify)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint identifyTime) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + IdentifyCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Identify(onSuccess->Cancel(), onFailure->Cancel(), identifyTime); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, IdentifyCluster, identifyQuery)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + IdentifyCluster * cppCluster; + + CHIPIdentifyClusterIdentifyQueryResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPIdentifyClusterIdentifyQueryResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->IdentifyQuery(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, KeypadInputCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + KeypadInputCluster * cppCluster = new KeypadInputCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, KeypadInputCluster, sendKey)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint keyCode) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + KeypadInputCluster * cppCluster; + + CHIPKeypadInputClusterSendKeyResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPKeypadInputClusterSendKeyResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SendKey(onSuccess->Cancel(), onFailure->Cancel(), keyCode); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, LevelControlCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + LevelControlCluster * cppCluster = new LevelControlCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, LevelControlCluster, move) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate, jint optionMask, jint optionOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LevelControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Move(onSuccess->Cancel(), onFailure->Cancel(), moveMode, rate, optionMask, optionOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, LevelControlCluster, moveToLevel) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint level, jint transitionTime, jint optionMask, + jint optionOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LevelControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveToLevel(onSuccess->Cancel(), onFailure->Cancel(), level, transitionTime, optionMask, optionOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, LevelControlCluster, moveToLevelWithOnOff) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint level, jint transitionTime) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LevelControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveToLevelWithOnOff(onSuccess->Cancel(), onFailure->Cancel(), level, transitionTime); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, LevelControlCluster, moveWithOnOff) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint moveMode, jint rate) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LevelControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MoveWithOnOff(onSuccess->Cancel(), onFailure->Cancel(), moveMode, rate); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, LevelControlCluster, step) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime, jint optionMask, + jint optionOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LevelControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = + cppCluster->Step(onSuccess->Cancel(), onFailure->Cancel(), stepMode, stepSize, transitionTime, optionMask, optionOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, LevelControlCluster, stepWithOnOff) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint stepMode, jint stepSize, jint transitionTime) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LevelControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->StepWithOnOff(onSuccess->Cancel(), onFailure->Cancel(), stepMode, stepSize, transitionTime); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, LevelControlCluster, stop) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint optionMask, jint optionOverride) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LevelControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Stop(onSuccess->Cancel(), onFailure->Cancel(), optionMask, optionOverride); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, LevelControlCluster, stopWithOnOff)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LevelControlCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->StopWithOnOff(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, LowPowerCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + LowPowerCluster * cppCluster = new LowPowerCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, LowPowerCluster, sleep)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + LowPowerCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Sleep(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, MediaInputCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + MediaInputCluster * cppCluster = new MediaInputCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, MediaInputCluster, hideInputStatus)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaInputCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->HideInputStatus(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaInputCluster, renameInput) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint index, jstring name) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaInputCluster * cppCluster; + + JniUtfString nameStr(env, name); + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RenameInput(onSuccess->Cancel(), onFailure->Cancel(), index, + chip::ByteSpan((const uint8_t *) name, strlen(nameStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaInputCluster, selectInput)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint index) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaInputCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SelectInput(onSuccess->Cancel(), onFailure->Cancel(), index); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaInputCluster, showInputStatus)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaInputCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ShowInputStatus(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, MediaPlaybackCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + MediaPlaybackCluster * cppCluster = new MediaPlaybackCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, MediaPlaybackCluster, mediaFastForward)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaFastForwardResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaFastForwardResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaFastForward(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaNext)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaNextResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaNextResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaNext(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaPause)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaPauseResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaPauseResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaPause(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaPlay)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaPlayResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaPlayResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaPlay(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaPrevious)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaPreviousResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaPreviousResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaPrevious(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaRewind)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaRewindResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaRewindResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaRewind(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaSkipBackward) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong deltaPositionMilliseconds) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaSkipBackwardResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaSkipBackward(onSuccess->Cancel(), onFailure->Cancel(), deltaPositionMilliseconds); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaSkipForward) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong deltaPositionMilliseconds) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaSkipForwardResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaSkipForward(onSuccess->Cancel(), onFailure->Cancel(), deltaPositionMilliseconds); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaSkipSeek) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong position) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaSkipSeekResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaSkipSeekResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaSkipSeek(onSuccess->Cancel(), onFailure->Cancel(), position); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaStartOver)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaStartOverResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaStartOverResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaStartOver(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, MediaPlaybackCluster, mediaStop)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + MediaPlaybackCluster * cppCluster; + + CHIPMediaPlaybackClusterMediaStopResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPMediaPlaybackClusterMediaStopResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->MediaStop(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, NetworkCommissioningCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + NetworkCommissioningCluster * cppCluster = new NetworkCommissioningCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, NetworkCommissioningCluster, addThreadNetwork) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray operationalDataset, jlong breadcrumb, jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + JniByteArray operationalDatasetArr(env, operationalDataset); + CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPNetworkCommissioningClusterAddThreadNetworkResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->AddThreadNetwork(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) operationalDatasetArr.data(), operationalDatasetArr.size()), + breadcrumb, timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, NetworkCommissioningCluster, addWiFiNetwork) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jbyteArray credentials, jlong breadcrumb, + jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + JniByteArray ssidArr(env, ssid); + JniByteArray credentialsArr(env, credentials); + CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPNetworkCommissioningClusterAddWiFiNetworkResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = 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); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, NetworkCommissioningCluster, disableNetwork) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jlong breadcrumb, jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + JniByteArray networkIDArr(env, networkID); + CHIPNetworkCommissioningClusterDisableNetworkResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPNetworkCommissioningClusterDisableNetworkResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->DisableNetwork(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) networkIDArr.data(), networkIDArr.size()), breadcrumb, + timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, NetworkCommissioningCluster, enableNetwork) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jlong breadcrumb, jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + JniByteArray networkIDArr(env, networkID); + CHIPNetworkCommissioningClusterEnableNetworkResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPNetworkCommissioningClusterEnableNetworkResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->EnableNetwork(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) networkIDArr.data(), networkIDArr.size()), breadcrumb, + timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, NetworkCommissioningCluster, getLastNetworkCommissioningResult) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetLastNetworkCommissioningResult(onSuccess->Cancel(), onFailure->Cancel(), timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, NetworkCommissioningCluster, removeNetwork) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray networkID, jlong breadcrumb, jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + JniByteArray networkIDArr(env, networkID); + CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPNetworkCommissioningClusterRemoveNetworkResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RemoveNetwork(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) networkIDArr.data(), networkIDArr.size()), breadcrumb, + timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, NetworkCommissioningCluster, scanNetworks) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jlong breadcrumb, jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + JniByteArray ssidArr(env, ssid); + CHIPNetworkCommissioningClusterScanNetworksResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPNetworkCommissioningClusterScanNetworksResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ScanNetworks(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) ssidArr.data(), ssidArr.size()), breadcrumb, timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, NetworkCommissioningCluster, updateThreadNetwork) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray operationalDataset, jlong breadcrumb, jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + JniByteArray operationalDatasetArr(env, operationalDataset); + CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPNetworkCommissioningClusterUpdateThreadNetworkResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->UpdateThreadNetwork( + onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) operationalDatasetArr.data(), operationalDatasetArr.size()), breadcrumb, timeoutMs); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, NetworkCommissioningCluster, updateWiFiNetwork) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray ssid, jbyteArray credentials, jlong breadcrumb, + jlong timeoutMs) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + NetworkCommissioningCluster * cppCluster; + + JniByteArray ssidArr(env, ssid); + JniByteArray credentialsArr(env, credentials); + CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = 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); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, OtaSoftwareUpdateServerCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + OtaSoftwareUpdateServerCluster * cppCluster = new OtaSoftwareUpdateServerCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, OtaSoftwareUpdateServerCluster, applyUpdateRequest) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray updateToken, jlong newVersion) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OtaSoftwareUpdateServerCluster * cppCluster; + + JniByteArray updateTokenArr(env, updateToken); + CHIPOtaSoftwareUpdateServerClusterApplyUpdateRequestResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPOtaSoftwareUpdateServerClusterApplyUpdateRequestResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = + cppCluster->ApplyUpdateRequest(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) updateTokenArr.data(), updateTokenArr.size()), newVersion); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OtaSoftwareUpdateServerCluster, notifyUpdateApplied) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray updateToken, jlong currentVersion) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OtaSoftwareUpdateServerCluster * cppCluster; + + JniByteArray updateTokenArr(env, updateToken); + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->NotifyUpdateApplied(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) updateTokenArr.data(), updateTokenArr.size()), + currentVersion); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OtaSoftwareUpdateServerCluster, queryImage) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint vendorId, jint productId, jint imageType, + jint hardwareVersion, jlong currentVersion, jint protocolsSupported, jstring location, jint clientCanConsent, + jbyteArray metadataForServer) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OtaSoftwareUpdateServerCluster * cppCluster; + + JniUtfString locationStr(env, location); + JniByteArray metadataForServerArr(env, metadataForServer); + CHIPOtaSoftwareUpdateServerClusterQueryImageResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPOtaSoftwareUpdateServerClusterQueryImageResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->QueryImage(onSuccess->Cancel(), onFailure->Cancel(), vendorId, productId, imageType, hardwareVersion, + currentVersion, protocolsSupported, + chip::ByteSpan((const uint8_t *) location, strlen(locationStr.c_str())), clientCanConsent, + chip::ByteSpan((const uint8_t *) metadataForServerArr.data(), metadataForServerArr.size())); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, OnOffCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + OnOffCluster * cppCluster = new OnOffCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, OnOffCluster, off)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OnOffCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Off(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OnOffCluster, on)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OnOffCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->On(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OnOffCluster, toggle)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OnOffCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Toggle(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, OperationalCredentialsCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + OperationalCredentialsCluster * cppCluster = new OperationalCredentialsCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, OperationalCredentialsCluster, addOpCert) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray operationalCert, jbyteArray iPKValue, + jlong caseAdminNode, jint adminVendorId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OperationalCredentialsCluster * cppCluster; + + JniByteArray operationalCertArr(env, operationalCert); + JniByteArray iPKValueArr(env, iPKValue); + CHIPOperationalCredentialsClusterOpCertResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPOperationalCredentialsClusterOpCertResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->AddOpCert(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) operationalCertArr.data(), operationalCertArr.size()), + chip::ByteSpan((const uint8_t *) iPKValueArr.data(), iPKValueArr.size()), caseAdminNode, + adminVendorId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OperationalCredentialsCluster, addTrustedRootCertificate) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray rootCertificate) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OperationalCredentialsCluster * cppCluster; + + JniByteArray rootCertificateArr(env, rootCertificate); + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->AddTrustedRootCertificate( + onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) rootCertificateArr.data(), rootCertificateArr.size())); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OperationalCredentialsCluster, opCSRRequest) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray cSRNonce) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OperationalCredentialsCluster * cppCluster; + + JniByteArray cSRNonceArr(env, cSRNonce); + CHIPOperationalCredentialsClusterOpCSRResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPOperationalCredentialsClusterOpCSRResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->OpCSRRequest(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) cSRNonceArr.data(), cSRNonceArr.size())); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OperationalCredentialsCluster, removeAllFabrics)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OperationalCredentialsCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RemoveAllFabrics(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OperationalCredentialsCluster, removeFabric) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jlong fabricId, jlong nodeId, jint vendorId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OperationalCredentialsCluster * cppCluster; + + CHIPOperationalCredentialsClusterOpCertResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPOperationalCredentialsClusterOpCertResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RemoveFabric(onSuccess->Cancel(), onFailure->Cancel(), fabricId, nodeId, vendorId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OperationalCredentialsCluster, removeTrustedRootCertificate) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jbyteArray trustedRootIdentifier) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OperationalCredentialsCluster * cppCluster; + + JniByteArray trustedRootIdentifierArr(env, trustedRootIdentifier); + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RemoveTrustedRootCertificate( + onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) trustedRootIdentifierArr.data(), trustedRootIdentifierArr.size())); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OperationalCredentialsCluster, setFabric) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint vendorId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OperationalCredentialsCluster * cppCluster; + + CHIPOperationalCredentialsClusterSetFabricResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPOperationalCredentialsClusterSetFabricResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetFabric(onSuccess->Cancel(), onFailure->Cancel(), vendorId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, OperationalCredentialsCluster, updateFabricLabel) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring label) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + OperationalCredentialsCluster * cppCluster; + + JniUtfString labelStr(env, label); + CHIPOperationalCredentialsClusterOpCertResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPOperationalCredentialsClusterOpCertResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->UpdateFabricLabel(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) label, strlen(labelStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, PumpConfigurationAndControlCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + PumpConfigurationAndControlCluster * cppCluster = new PumpConfigurationAndControlCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, RelativeHumidityMeasurementCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + RelativeHumidityMeasurementCluster * cppCluster = new RelativeHumidityMeasurementCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, ScenesCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ScenesCluster * cppCluster = new ScenesCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, ScenesCluster, addScene) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId, jint transitionTime, jstring sceneName, + jint clusterId, jint length, jint value) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ScenesCluster * cppCluster; + + JniUtfString sceneNameStr(env, sceneName); + CHIPScenesClusterAddSceneResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPScenesClusterAddSceneResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->AddScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId, transitionTime, + chip::ByteSpan((const uint8_t *) sceneName, strlen(sceneNameStr.c_str())), clusterId, length, value); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ScenesCluster, getSceneMembership)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ScenesCluster * cppCluster; + + CHIPScenesClusterGetSceneMembershipResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPScenesClusterGetSceneMembershipResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetSceneMembership(onSuccess->Cancel(), onFailure->Cancel(), groupId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ScenesCluster, recallScene) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId, jint transitionTime) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ScenesCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RecallScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId, transitionTime); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ScenesCluster, removeAllScenes)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ScenesCluster * cppCluster; + + CHIPScenesClusterRemoveAllScenesResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPScenesClusterRemoveAllScenesResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RemoveAllScenes(onSuccess->Cancel(), onFailure->Cancel(), groupId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ScenesCluster, removeScene) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ScenesCluster * cppCluster; + + CHIPScenesClusterRemoveSceneResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPScenesClusterRemoveSceneResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->RemoveScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ScenesCluster, storeScene) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ScenesCluster * cppCluster; + + CHIPScenesClusterStoreSceneResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPScenesClusterStoreSceneResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->StoreScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ScenesCluster, viewScene) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint groupId, jint sceneId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ScenesCluster * cppCluster; + + CHIPScenesClusterViewSceneResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPScenesClusterViewSceneResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ViewScene(onSuccess->Cancel(), onFailure->Cancel(), groupId, sceneId); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, SoftwareDiagnosticsCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + SoftwareDiagnosticsCluster * cppCluster = new SoftwareDiagnosticsCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, SoftwareDiagnosticsCluster, resetWatermarks)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + SoftwareDiagnosticsCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ResetWatermarks(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, SwitchCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + SwitchCluster * cppCluster = new SwitchCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, TvChannelCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + TvChannelCluster * cppCluster = new TvChannelCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, TvChannelCluster, changeChannel)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jstring match) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + TvChannelCluster * cppCluster; + + JniUtfString matchStr(env, match); + CHIPTvChannelClusterChangeChannelResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPTvChannelClusterChangeChannelResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ChangeChannel(onSuccess->Cancel(), onFailure->Cancel(), + chip::ByteSpan((const uint8_t *) match, strlen(matchStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, TvChannelCluster, changeChannelByNumber) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint majorNumber, jint minorNumber) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + TvChannelCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ChangeChannelByNumber(onSuccess->Cancel(), onFailure->Cancel(), majorNumber, minorNumber); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, TvChannelCluster, skipChannel)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint count) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + TvChannelCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SkipChannel(onSuccess->Cancel(), onFailure->Cancel(), count); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, TargetNavigatorCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + TargetNavigatorCluster * cppCluster = new TargetNavigatorCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, TargetNavigatorCluster, navigateTarget) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint target, jstring data) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + TargetNavigatorCluster * cppCluster; + + JniUtfString dataStr(env, data); + CHIPTargetNavigatorClusterNavigateTargetResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPTargetNavigatorClusterNavigateTargetResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->NavigateTarget(onSuccess->Cancel(), onFailure->Cancel(), target, + chip::ByteSpan((const uint8_t *) data, strlen(dataStr.c_str()))); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, TemperatureMeasurementCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + TemperatureMeasurementCluster * cppCluster = new TemperatureMeasurementCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, TestClusterCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + TestClusterCluster * cppCluster = new TestClusterCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, TestClusterCluster, test)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + TestClusterCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->Test(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, TestClusterCluster, testNotHandled)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + TestClusterCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->TestNotHandled(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, TestClusterCluster, testSpecific)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + TestClusterCluster * cppCluster; + + CHIPTestClusterClusterTestSpecificResponseCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPTestClusterClusterTestSpecificResponseCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->TestSpecific(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, TestClusterCluster, testUnknownCommand)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + TestClusterCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->TestUnknownCommand(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, ThermostatCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ThermostatCluster * cppCluster = new ThermostatCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, ThermostatCluster, clearWeeklySchedule)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ThermostatCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ClearWeeklySchedule(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ThermostatCluster, getRelayStatusLog)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ThermostatCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetRelayStatusLog(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ThermostatCluster, getWeeklySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint daysToReturn, jint modeToReturn) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ThermostatCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->GetWeeklySchedule(onSuccess->Cancel(), onFailure->Cancel(), daysToReturn, modeToReturn); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ThermostatCluster, setWeeklySchedule) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint numberOfTransitionsForSequence, jint dayOfWeekForSequence, + jint modeForSequence, jint payload) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ThermostatCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetWeeklySchedule(onSuccess->Cancel(), onFailure->Cancel(), numberOfTransitionsForSequence, + dayOfWeekForSequence, modeForSequence, payload); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, ThermostatCluster, setpointRaiseLower) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint mode, jint amount) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ThermostatCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->SetpointRaiseLower(onSuccess->Cancel(), onFailure->Cancel(), mode, amount); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, ThreadNetworkDiagnosticsCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + ThreadNetworkDiagnosticsCluster * cppCluster = new ThreadNetworkDiagnosticsCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, ThreadNetworkDiagnosticsCluster, resetCounts)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + ThreadNetworkDiagnosticsCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->ResetCounts(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(jlong, WakeOnLanCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + WakeOnLanCluster * cppCluster = new WakeOnLanCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(jlong, WindowCoveringCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + WindowCoveringCluster * cppCluster = new WindowCoveringCluster(); + + cppCluster->Associate(reinterpret_cast(devicePtr), endpointId); + return reinterpret_cast(cppCluster); +} + +JNI_METHOD(void, WindowCoveringCluster, windowCoveringDownClose)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + WindowCoveringCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->WindowCoveringDownClose(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, WindowCoveringCluster, windowCoveringGoToLiftPercentage) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint percentageLiftValue) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + WindowCoveringCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->WindowCoveringGoToLiftPercentage(onSuccess->Cancel(), onFailure->Cancel(), percentageLiftValue); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, WindowCoveringCluster, windowCoveringGoToLiftValue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint liftValue) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + WindowCoveringCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->WindowCoveringGoToLiftValue(onSuccess->Cancel(), onFailure->Cancel(), liftValue); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, WindowCoveringCluster, windowCoveringGoToTiltPercentage) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint percentageTiltValue) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + WindowCoveringCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->WindowCoveringGoToTiltPercentage(onSuccess->Cancel(), onFailure->Cancel(), percentageTiltValue); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, WindowCoveringCluster, windowCoveringGoToTiltValue) +(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint tiltValue) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + WindowCoveringCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->WindowCoveringGoToTiltValue(onSuccess->Cancel(), onFailure->Cancel(), tiltValue); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, WindowCoveringCluster, windowCoveringStop)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + WindowCoveringCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->WindowCoveringStop(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} +JNI_METHOD(void, WindowCoveringCluster, windowCoveringUpOpen)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + CHIP_ERROR err = CHIP_NO_ERROR; + WindowCoveringCluster * cppCluster; + + CHIPDefaultSuccessCallback * onSuccess; + CHIPDefaultFailureCallback * onFailure; + + cppCluster = reinterpret_cast(clusterPtr); + VerifyOrExit(cppCluster != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + onSuccess = new CHIPDefaultSuccessCallback(callback); + VerifyOrExit(onSuccess != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + onFailure = new CHIPDefaultFailureCallback(callback); + VerifyOrExit(onFailure != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + + err = cppCluster->WindowCoveringUpOpen(onSuccess->Cancel(), onFailure->Cancel()); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + delete onSuccess; + delete onFailure; + + jthrowable exception; + jmethodID method; + + err = FindMethod(env, callback, "onError", "(Ljava/lang/Exception;)V", &method); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + + err = CreateIllegalStateException(env, "Error invoking cluster", err, exception); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Error throwing IllegalStateException %d", err); + return; + } + env->CallVoidMethod(callback, method, exception); + } +} diff --git a/src/controller/java/gen/ChipClusters.java b/src/controller/java/gen/ChipClusters.java new file mode 100644 index 00000000000000..5357c1697eb414 --- /dev/null +++ b/src/controller/java/gen/ChipClusters.java @@ -0,0 +1,2356 @@ +/* + * + * 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 + +package chip.devicecontroller; + +public class ChipClusters { + + public interface DefaultClusterCallback { + void onSuccess(); + + void onError(Exception error); + } + + // TODO(#7376): add attribute callbacks. + + public abstract static class BaseChipCluster { + protected long chipClusterPtr; + + public BaseChipCluster(long devicePtr, int endpointId) { + chipClusterPtr = initWithDevice(devicePtr, endpointId); + } + + public abstract long initWithDevice(long devicePtr, int endpointId); + + public native void deleteCluster(long chipClusterPtr); + + @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + + if (chipClusterPtr != 0) { + deleteCluster(chipClusterPtr); + chipClusterPtr = 0; + } + } + } + + public static class AccountLoginCluster extends BaseChipCluster { + public AccountLoginCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void getSetupPIN(GetSetupPINResponseCallback callback, String tempAccountIdentifier) { + getSetupPIN(chipClusterPtr, callback, tempAccountIdentifier); + } + + public void login( + DefaultClusterCallback callback, String tempAccountIdentifier, String setupPIN) { + login(chipClusterPtr, callback, tempAccountIdentifier, setupPIN); + } + + private native void getSetupPIN( + long chipClusterPtr, GetSetupPINResponseCallback callback, String tempAccountIdentifier); + + private native void login( + long chipClusterPtr, + DefaultClusterCallback callback, + String tempAccountIdentifier, + String setupPIN); + + public interface GetSetupPINResponseCallback { + void onSuccess(String setupPIN); + + void onError(Exception error); + } + } + + public static class ApplicationBasicCluster extends BaseChipCluster { + public ApplicationBasicCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class ApplicationLauncherCluster extends BaseChipCluster { + public ApplicationLauncherCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void launchApp( + LaunchAppResponseCallback callback, + String data, + int catalogVendorId, + String applicationId) { + launchApp(chipClusterPtr, callback, data, catalogVendorId, applicationId); + } + + private native void launchApp( + long chipClusterPtr, + LaunchAppResponseCallback callback, + String data, + int catalogVendorId, + String applicationId); + + public interface LaunchAppResponseCallback { + void onSuccess(String data); + + void onError(Exception error); + } + } + + public static class AudioOutputCluster extends BaseChipCluster { + public AudioOutputCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void renameOutput(DefaultClusterCallback callback, int index, String name) { + renameOutput(chipClusterPtr, callback, index, name); + } + + public void selectOutput(DefaultClusterCallback callback, int index) { + selectOutput(chipClusterPtr, callback, index); + } + + private native void renameOutput( + long chipClusterPtr, DefaultClusterCallback callback, int index, String name); + + private native void selectOutput( + long chipClusterPtr, DefaultClusterCallback callback, int index); + } + + public static class BarrierControlCluster extends BaseChipCluster { + public BarrierControlCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void barrierControlGoToPercent(DefaultClusterCallback callback, int percentOpen) { + barrierControlGoToPercent(chipClusterPtr, callback, percentOpen); + } + + public void barrierControlStop(DefaultClusterCallback callback) { + barrierControlStop(chipClusterPtr, callback); + } + + private native void barrierControlGoToPercent( + long chipClusterPtr, DefaultClusterCallback callback, int percentOpen); + + private native void barrierControlStop(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class BasicCluster extends BaseChipCluster { + public BasicCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void mfgSpecificPing(DefaultClusterCallback callback) { + mfgSpecificPing(chipClusterPtr, callback); + } + + private native void mfgSpecificPing(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class BinaryInputBasicCluster extends BaseChipCluster { + public BinaryInputBasicCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class BindingCluster extends BaseChipCluster { + public BindingCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void bind( + DefaultClusterCallback callback, long nodeId, int groupId, int endpointId, int clusterId) { + bind(chipClusterPtr, callback, nodeId, groupId, endpointId, clusterId); + } + + public void unbind( + DefaultClusterCallback callback, long nodeId, int groupId, int endpointId, int clusterId) { + unbind(chipClusterPtr, callback, nodeId, groupId, endpointId, clusterId); + } + + private native void bind( + long chipClusterPtr, + DefaultClusterCallback callback, + long nodeId, + int groupId, + int endpointId, + int clusterId); + + private native void unbind( + long chipClusterPtr, + DefaultClusterCallback callback, + long nodeId, + int groupId, + int endpointId, + int clusterId); + } + + public static class BridgedDeviceBasicCluster extends BaseChipCluster { + public BridgedDeviceBasicCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class ColorControlCluster extends BaseChipCluster { + public ColorControlCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void moveColor( + DefaultClusterCallback callback, + int rateX, + int rateY, + int optionsMask, + int 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) { + moveColorTemperature( + chipClusterPtr, + callback, + moveMode, + rate, + colorTemperatureMinimum, + colorTemperatureMaximum, + optionsMask, + optionsOverride); + } + + public void moveHue( + DefaultClusterCallback callback, + int moveMode, + int rate, + int optionsMask, + int optionsOverride) { + moveHue(chipClusterPtr, callback, moveMode, rate, optionsMask, optionsOverride); + } + + public void moveSaturation( + DefaultClusterCallback callback, + int moveMode, + int rate, + int optionsMask, + int optionsOverride) { + moveSaturation(chipClusterPtr, callback, moveMode, rate, optionsMask, optionsOverride); + } + + public void moveToColor( + DefaultClusterCallback callback, + int colorX, + int colorY, + int transitionTime, + int optionsMask, + int optionsOverride) { + moveToColor( + chipClusterPtr, callback, colorX, colorY, transitionTime, optionsMask, optionsOverride); + } + + public void moveToColorTemperature( + DefaultClusterCallback callback, + int colorTemperature, + int transitionTime, + int optionsMask, + int optionsOverride) { + moveToColorTemperature( + chipClusterPtr, callback, colorTemperature, transitionTime, optionsMask, optionsOverride); + } + + public void moveToHue( + DefaultClusterCallback callback, + int hue, + int direction, + int transitionTime, + int optionsMask, + int optionsOverride) { + moveToHue( + chipClusterPtr, callback, hue, direction, transitionTime, optionsMask, optionsOverride); + } + + public void moveToHueAndSaturation( + DefaultClusterCallback callback, + int hue, + int saturation, + int transitionTime, + int optionsMask, + int optionsOverride) { + moveToHueAndSaturation( + chipClusterPtr, callback, hue, saturation, transitionTime, optionsMask, optionsOverride); + } + + public void moveToSaturation( + DefaultClusterCallback callback, + int saturation, + int transitionTime, + int optionsMask, + int optionsOverride) { + moveToSaturation( + chipClusterPtr, callback, saturation, transitionTime, optionsMask, optionsOverride); + } + + public void stepColor( + DefaultClusterCallback callback, + int stepX, + int stepY, + int transitionTime, + int optionsMask, + int 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) { + stepColorTemperature( + chipClusterPtr, + callback, + stepMode, + stepSize, + transitionTime, + colorTemperatureMinimum, + colorTemperatureMaximum, + optionsMask, + optionsOverride); + } + + public void stepHue( + DefaultClusterCallback callback, + int stepMode, + int stepSize, + int transitionTime, + int optionsMask, + int optionsOverride) { + stepHue( + chipClusterPtr, + callback, + stepMode, + stepSize, + transitionTime, + optionsMask, + optionsOverride); + } + + public void stepSaturation( + DefaultClusterCallback callback, + int stepMode, + int stepSize, + int transitionTime, + int optionsMask, + int optionsOverride) { + stepSaturation( + chipClusterPtr, + callback, + stepMode, + stepSize, + transitionTime, + optionsMask, + optionsOverride); + } + + public void stopMoveStep( + DefaultClusterCallback callback, int optionsMask, int optionsOverride) { + stopMoveStep(chipClusterPtr, callback, optionsMask, optionsOverride); + } + + private native void moveColor( + long chipClusterPtr, + DefaultClusterCallback callback, + int rateX, + int rateY, + int optionsMask, + int optionsOverride); + + private native void moveColorTemperature( + long chipClusterPtr, + DefaultClusterCallback callback, + int moveMode, + int rate, + int colorTemperatureMinimum, + int colorTemperatureMaximum, + int optionsMask, + int optionsOverride); + + private native void moveHue( + long chipClusterPtr, + DefaultClusterCallback callback, + int moveMode, + int rate, + int optionsMask, + int optionsOverride); + + private native void moveSaturation( + long chipClusterPtr, + DefaultClusterCallback callback, + int moveMode, + int rate, + int optionsMask, + int optionsOverride); + + private native void moveToColor( + long chipClusterPtr, + DefaultClusterCallback callback, + int colorX, + int colorY, + int transitionTime, + int optionsMask, + int optionsOverride); + + private native void moveToColorTemperature( + long chipClusterPtr, + DefaultClusterCallback callback, + int colorTemperature, + int transitionTime, + int optionsMask, + int optionsOverride); + + private native void moveToHue( + long chipClusterPtr, + DefaultClusterCallback callback, + int hue, + int direction, + int transitionTime, + int optionsMask, + int optionsOverride); + + private native void moveToHueAndSaturation( + long chipClusterPtr, + DefaultClusterCallback callback, + int hue, + int saturation, + int transitionTime, + int optionsMask, + int optionsOverride); + + private native void moveToSaturation( + long chipClusterPtr, + DefaultClusterCallback callback, + int saturation, + int transitionTime, + int optionsMask, + int optionsOverride); + + private native void stepColor( + long chipClusterPtr, + DefaultClusterCallback callback, + int stepX, + int stepY, + int transitionTime, + int optionsMask, + int optionsOverride); + + private native void stepColorTemperature( + long chipClusterPtr, + DefaultClusterCallback callback, + int stepMode, + int stepSize, + int transitionTime, + int colorTemperatureMinimum, + int colorTemperatureMaximum, + int optionsMask, + int optionsOverride); + + private native void stepHue( + long chipClusterPtr, + DefaultClusterCallback callback, + int stepMode, + int stepSize, + int transitionTime, + int optionsMask, + int optionsOverride); + + private native void stepSaturation( + long chipClusterPtr, + DefaultClusterCallback callback, + int stepMode, + int stepSize, + int transitionTime, + int optionsMask, + int optionsOverride); + + private native void stopMoveStep( + long chipClusterPtr, DefaultClusterCallback callback, int optionsMask, int optionsOverride); + } + + public static class ContentLaunchCluster extends BaseChipCluster { + public ContentLaunchCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void launchContent(LaunchContentResponseCallback callback, int autoPlay, String data) { + launchContent(chipClusterPtr, callback, autoPlay, data); + } + + public void launchURL( + LaunchURLResponseCallback callback, String contentURL, String displayString) { + launchURL(chipClusterPtr, callback, contentURL, displayString); + } + + private native void launchContent( + long chipClusterPtr, LaunchContentResponseCallback callback, int autoPlay, String data); + + private native void launchURL( + long chipClusterPtr, + LaunchURLResponseCallback callback, + String contentURL, + String displayString); + + public interface LaunchContentResponseCallback { + void onSuccess(String data, int contentLaunchStatus); + + void onError(Exception error); + } + + public interface LaunchURLResponseCallback { + void onSuccess(String data, int contentLaunchStatus); + + void onError(Exception error); + } + } + + public static class DescriptorCluster extends BaseChipCluster { + public DescriptorCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class DoorLockCluster extends BaseChipCluster { + public DoorLockCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void clearAllPins(ClearAllPinsResponseCallback callback) { + clearAllPins(chipClusterPtr, callback); + } + + public void clearAllRfids(ClearAllRfidsResponseCallback callback) { + clearAllRfids(chipClusterPtr, callback); + } + + public void clearHolidaySchedule( + ClearHolidayScheduleResponseCallback callback, int scheduleId) { + clearHolidaySchedule(chipClusterPtr, callback, scheduleId); + } + + public void clearPin(ClearPinResponseCallback callback, int userId) { + clearPin(chipClusterPtr, callback, userId); + } + + public void clearRfid(ClearRfidResponseCallback callback, int userId) { + clearRfid(chipClusterPtr, callback, userId); + } + + public void clearWeekdaySchedule( + ClearWeekdayScheduleResponseCallback callback, int scheduleId, int userId) { + clearWeekdaySchedule(chipClusterPtr, callback, scheduleId, userId); + } + + public void clearYeardaySchedule( + ClearYeardayScheduleResponseCallback callback, int scheduleId, int userId) { + clearYeardaySchedule(chipClusterPtr, callback, scheduleId, userId); + } + + public void getHolidaySchedule(GetHolidayScheduleResponseCallback callback, int scheduleId) { + getHolidaySchedule(chipClusterPtr, callback, scheduleId); + } + + public void getLogRecord(GetLogRecordResponseCallback callback, int logIndex) { + getLogRecord(chipClusterPtr, callback, logIndex); + } + + public void getPin(GetPinResponseCallback callback, int userId) { + getPin(chipClusterPtr, callback, userId); + } + + public void getRfid(GetRfidResponseCallback callback, int userId) { + getRfid(chipClusterPtr, callback, userId); + } + + public void getUserType(GetUserTypeResponseCallback callback, int userId) { + getUserType(chipClusterPtr, callback, userId); + } + + public void getWeekdaySchedule( + GetWeekdayScheduleResponseCallback callback, int scheduleId, int userId) { + getWeekdaySchedule(chipClusterPtr, callback, scheduleId, userId); + } + + public void getYeardaySchedule( + GetYeardayScheduleResponseCallback callback, int scheduleId, int userId) { + getYeardaySchedule(chipClusterPtr, callback, scheduleId, userId); + } + + public void lockDoor(LockDoorResponseCallback callback, String pin) { + lockDoor(chipClusterPtr, callback, pin); + } + + public void setHolidaySchedule( + SetHolidayScheduleResponseCallback callback, + int scheduleId, + long localStartTime, + long localEndTime, + int operatingModeDuringHoliday) { + setHolidaySchedule( + chipClusterPtr, + callback, + scheduleId, + localStartTime, + localEndTime, + operatingModeDuringHoliday); + } + + public void setPin( + SetPinResponseCallback callback, int userId, int userStatus, int userType, String pin) { + setPin(chipClusterPtr, callback, userId, userStatus, userType, pin); + } + + public void setRfid( + SetRfidResponseCallback callback, int userId, int userStatus, int userType, String id) { + setRfid(chipClusterPtr, callback, userId, userStatus, userType, id); + } + + public void setUserType(SetUserTypeResponseCallback callback, int userId, int 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) { + setWeekdaySchedule( + chipClusterPtr, + callback, + scheduleId, + userId, + daysMask, + startHour, + startMinute, + endHour, + endMinute); + } + + public void setYeardaySchedule( + SetYeardayScheduleResponseCallback callback, + int scheduleId, + int userId, + long localStartTime, + long localEndTime) { + setYeardaySchedule( + chipClusterPtr, callback, scheduleId, userId, localStartTime, localEndTime); + } + + public void unlockDoor(UnlockDoorResponseCallback callback, String pin) { + unlockDoor(chipClusterPtr, callback, pin); + } + + public void unlockWithTimeout( + UnlockWithTimeoutResponseCallback callback, int timeoutInSeconds, String pin) { + unlockWithTimeout(chipClusterPtr, callback, timeoutInSeconds, pin); + } + + private native void clearAllPins(long chipClusterPtr, ClearAllPinsResponseCallback callback); + + private native void clearAllRfids(long chipClusterPtr, ClearAllRfidsResponseCallback callback); + + private native void clearHolidaySchedule( + long chipClusterPtr, ClearHolidayScheduleResponseCallback callback, int scheduleId); + + private native void clearPin( + long chipClusterPtr, ClearPinResponseCallback callback, int userId); + + private native void clearRfid( + long chipClusterPtr, ClearRfidResponseCallback callback, int userId); + + private native void clearWeekdaySchedule( + long chipClusterPtr, + ClearWeekdayScheduleResponseCallback callback, + int scheduleId, + int userId); + + private native void clearYeardaySchedule( + long chipClusterPtr, + ClearYeardayScheduleResponseCallback callback, + int scheduleId, + int userId); + + private native void getHolidaySchedule( + long chipClusterPtr, GetHolidayScheduleResponseCallback callback, int scheduleId); + + private native void getLogRecord( + long chipClusterPtr, GetLogRecordResponseCallback callback, int logIndex); + + private native void getPin(long chipClusterPtr, GetPinResponseCallback callback, int userId); + + private native void getRfid(long chipClusterPtr, GetRfidResponseCallback callback, int userId); + + private native void getUserType( + long chipClusterPtr, GetUserTypeResponseCallback callback, int userId); + + private native void getWeekdaySchedule( + long chipClusterPtr, + GetWeekdayScheduleResponseCallback callback, + int scheduleId, + int userId); + + private native void getYeardaySchedule( + long chipClusterPtr, + GetYeardayScheduleResponseCallback callback, + int scheduleId, + int userId); + + private native void lockDoor( + long chipClusterPtr, LockDoorResponseCallback callback, String pin); + + private native void setHolidaySchedule( + long chipClusterPtr, + SetHolidayScheduleResponseCallback callback, + int scheduleId, + long localStartTime, + long localEndTime, + int operatingModeDuringHoliday); + + private native void setPin( + long chipClusterPtr, + SetPinResponseCallback callback, + int userId, + int userStatus, + int userType, + String pin); + + private native void setRfid( + long chipClusterPtr, + SetRfidResponseCallback callback, + int userId, + int userStatus, + int userType, + String id); + + private native void setUserType( + long chipClusterPtr, SetUserTypeResponseCallback callback, int userId, int userType); + + private native void setWeekdaySchedule( + long chipClusterPtr, + SetWeekdayScheduleResponseCallback callback, + int scheduleId, + int userId, + int daysMask, + int startHour, + int startMinute, + int endHour, + int endMinute); + + private native void setYeardaySchedule( + long chipClusterPtr, + SetYeardayScheduleResponseCallback callback, + int scheduleId, + int userId, + long localStartTime, + long localEndTime); + + private native void unlockDoor( + long chipClusterPtr, UnlockDoorResponseCallback callback, String pin); + + private native void unlockWithTimeout( + long chipClusterPtr, + UnlockWithTimeoutResponseCallback callback, + int timeoutInSeconds, + String pin); + + public interface ClearAllPinsResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface ClearAllRfidsResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface ClearHolidayScheduleResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface ClearPinResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface ClearRfidResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface ClearWeekdayScheduleResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface ClearYeardayScheduleResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface GetHolidayScheduleResponseCallback { + void onSuccess( + int scheduleId, long localStartTime, long localEndTime, int operatingModeDuringHoliday); + + void onError(Exception error); + } + + public interface GetLogRecordResponseCallback { + void onSuccess( + int logEntryId, + long timestamp, + int eventType, + int source, + int eventIdOrAlarmCode, + int userId, + String pin); + + void onError(Exception error); + } + + public interface GetPinResponseCallback { + void onSuccess(int userId, int userStatus, int userType, String pin); + + void onError(Exception error); + } + + public interface GetRfidResponseCallback { + void onSuccess(int userId, int userStatus, int userType, String rfid); + + void onError(Exception error); + } + + public interface GetUserTypeResponseCallback { + void onSuccess(int userId, int userType); + + void onError(Exception error); + } + + public interface GetWeekdayScheduleResponseCallback { + void onSuccess( + int scheduleId, + int userId, + int daysMask, + int startHour, + int startMinute, + int endHour, + int endMinute); + + void onError(Exception error); + } + + public interface GetYeardayScheduleResponseCallback { + void onSuccess(int scheduleId, int userId, long localStartTime, long localEndTime); + + void onError(Exception error); + } + + public interface LockDoorResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface SetHolidayScheduleResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface SetPinResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface SetRfidResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface SetUserTypeResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface SetWeekdayScheduleResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface SetYeardayScheduleResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface UnlockDoorResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + + public interface UnlockWithTimeoutResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + } + + public static class EthernetNetworkDiagnosticsCluster extends BaseChipCluster { + public EthernetNetworkDiagnosticsCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void resetCounts(DefaultClusterCallback callback) { + resetCounts(chipClusterPtr, callback); + } + + private native void resetCounts(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class FixedLabelCluster extends BaseChipCluster { + public FixedLabelCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class GeneralCommissioningCluster extends BaseChipCluster { + public GeneralCommissioningCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void armFailSafe( + ArmFailSafeResponseCallback callback, + int expiryLengthSeconds, + long breadcrumb, + long timeoutMs) { + armFailSafe(chipClusterPtr, callback, expiryLengthSeconds, breadcrumb, timeoutMs); + } + + public void commissioningComplete(CommissioningCompleteResponseCallback callback) { + commissioningComplete(chipClusterPtr, callback); + } + + public void setRegulatoryConfig( + SetRegulatoryConfigResponseCallback callback, + int location, + String countryCode, + 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); + + private native void commissioningComplete( + long chipClusterPtr, CommissioningCompleteResponseCallback callback); + + private native void setRegulatoryConfig( + long chipClusterPtr, + SetRegulatoryConfigResponseCallback callback, + int location, + String countryCode, + long breadcrumb, + long timeoutMs); + + public interface ArmFailSafeResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + + public interface CommissioningCompleteResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + + public interface SetRegulatoryConfigResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + } + + public static class GeneralDiagnosticsCluster extends BaseChipCluster { + public GeneralDiagnosticsCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class GroupKeyManagementCluster extends BaseChipCluster { + public GroupKeyManagementCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class GroupsCluster extends BaseChipCluster { + public GroupsCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void addGroup(AddGroupResponseCallback callback, int groupId, String groupName) { + addGroup(chipClusterPtr, callback, groupId, groupName); + } + + public void addGroupIfIdentifying( + DefaultClusterCallback callback, int groupId, String groupName) { + addGroupIfIdentifying(chipClusterPtr, callback, groupId, groupName); + } + + public void getGroupMembership( + GetGroupMembershipResponseCallback callback, int groupCount, int groupList) { + getGroupMembership(chipClusterPtr, callback, groupCount, groupList); + } + + public void removeAllGroups(DefaultClusterCallback callback) { + removeAllGroups(chipClusterPtr, callback); + } + + public void removeGroup(RemoveGroupResponseCallback callback, int groupId) { + removeGroup(chipClusterPtr, callback, groupId); + } + + public void viewGroup(ViewGroupResponseCallback callback, int groupId) { + viewGroup(chipClusterPtr, callback, groupId); + } + + private native void addGroup( + long chipClusterPtr, AddGroupResponseCallback callback, int groupId, String groupName); + + private native void addGroupIfIdentifying( + long chipClusterPtr, DefaultClusterCallback callback, int groupId, String groupName); + + private native void getGroupMembership( + long chipClusterPtr, + GetGroupMembershipResponseCallback callback, + int groupCount, + int groupList); + + private native void removeAllGroups(long chipClusterPtr, DefaultClusterCallback callback); + + private native void removeGroup( + long chipClusterPtr, RemoveGroupResponseCallback callback, int groupId); + + private native void viewGroup( + long chipClusterPtr, ViewGroupResponseCallback callback, int groupId); + + public interface AddGroupResponseCallback { + void onSuccess(int groupId); + + void onError(Exception error); + } + + public interface GetGroupMembershipResponseCallback { + void onSuccess(int capacity, int groupCount + // groupList: /* TYPE WARNING: array array defaults to */ uint8_t * + // Conversion from this type to Java is not properly implemented yet + ); + + void onError(Exception error); + } + + public interface RemoveGroupResponseCallback { + void onSuccess(int groupId); + + void onError(Exception error); + } + + public interface ViewGroupResponseCallback { + void onSuccess(int groupId, String groupName); + + void onError(Exception error); + } + } + + public static class IdentifyCluster extends BaseChipCluster { + public IdentifyCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void identify(DefaultClusterCallback callback, int identifyTime) { + identify(chipClusterPtr, callback, identifyTime); + } + + public void identifyQuery(IdentifyQueryResponseCallback callback) { + identifyQuery(chipClusterPtr, callback); + } + + private native void identify( + long chipClusterPtr, DefaultClusterCallback callback, int identifyTime); + + private native void identifyQuery(long chipClusterPtr, IdentifyQueryResponseCallback callback); + + public interface IdentifyQueryResponseCallback { + void onSuccess(int timeout); + + void onError(Exception error); + } + } + + public static class KeypadInputCluster extends BaseChipCluster { + public KeypadInputCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void sendKey(SendKeyResponseCallback callback, int keyCode) { + sendKey(chipClusterPtr, callback, keyCode); + } + + private native void sendKey(long chipClusterPtr, SendKeyResponseCallback callback, int keyCode); + + public interface SendKeyResponseCallback { + void onSuccess(); + + void onError(Exception error); + } + } + + public static class LevelControlCluster extends BaseChipCluster { + public LevelControlCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void move( + DefaultClusterCallback callback, + int moveMode, + int rate, + int optionMask, + int optionOverride) { + move(chipClusterPtr, callback, moveMode, rate, optionMask, optionOverride); + } + + public void moveToLevel( + DefaultClusterCallback callback, + int level, + int transitionTime, + int optionMask, + int optionOverride) { + moveToLevel(chipClusterPtr, callback, level, transitionTime, optionMask, optionOverride); + } + + public void moveToLevelWithOnOff( + DefaultClusterCallback callback, int level, int transitionTime) { + moveToLevelWithOnOff(chipClusterPtr, callback, level, transitionTime); + } + + public void moveWithOnOff(DefaultClusterCallback callback, int moveMode, int rate) { + moveWithOnOff(chipClusterPtr, callback, moveMode, rate); + } + + public void step( + DefaultClusterCallback callback, + int stepMode, + int stepSize, + int transitionTime, + int optionMask, + int optionOverride) { + step( + chipClusterPtr, callback, stepMode, stepSize, transitionTime, optionMask, optionOverride); + } + + public void stepWithOnOff( + DefaultClusterCallback callback, int stepMode, int stepSize, int transitionTime) { + stepWithOnOff(chipClusterPtr, callback, stepMode, stepSize, transitionTime); + } + + public void stop(DefaultClusterCallback callback, int optionMask, int optionOverride) { + stop(chipClusterPtr, callback, optionMask, optionOverride); + } + + public void stopWithOnOff(DefaultClusterCallback callback) { + stopWithOnOff(chipClusterPtr, callback); + } + + private native void move( + long chipClusterPtr, + DefaultClusterCallback callback, + int moveMode, + int rate, + int optionMask, + int optionOverride); + + private native void moveToLevel( + long chipClusterPtr, + DefaultClusterCallback callback, + int level, + int transitionTime, + int optionMask, + int optionOverride); + + private native void moveToLevelWithOnOff( + long chipClusterPtr, DefaultClusterCallback callback, int level, int transitionTime); + + private native void moveWithOnOff( + long chipClusterPtr, DefaultClusterCallback callback, int moveMode, int rate); + + private native void step( + long chipClusterPtr, + DefaultClusterCallback callback, + int stepMode, + int stepSize, + int transitionTime, + int optionMask, + int optionOverride); + + private native void stepWithOnOff( + long chipClusterPtr, + DefaultClusterCallback callback, + int stepMode, + int stepSize, + int transitionTime); + + private native void stop( + long chipClusterPtr, DefaultClusterCallback callback, int optionMask, int optionOverride); + + private native void stopWithOnOff(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class LowPowerCluster extends BaseChipCluster { + public LowPowerCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void sleep(DefaultClusterCallback callback) { + sleep(chipClusterPtr, callback); + } + + private native void sleep(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class MediaInputCluster extends BaseChipCluster { + public MediaInputCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void hideInputStatus(DefaultClusterCallback callback) { + hideInputStatus(chipClusterPtr, callback); + } + + public void renameInput(DefaultClusterCallback callback, int index, String name) { + renameInput(chipClusterPtr, callback, index, name); + } + + public void selectInput(DefaultClusterCallback callback, int index) { + selectInput(chipClusterPtr, callback, index); + } + + public void showInputStatus(DefaultClusterCallback callback) { + showInputStatus(chipClusterPtr, callback); + } + + private native void hideInputStatus(long chipClusterPtr, DefaultClusterCallback callback); + + private native void renameInput( + long chipClusterPtr, DefaultClusterCallback callback, int index, String name); + + private native void selectInput( + long chipClusterPtr, DefaultClusterCallback callback, int index); + + private native void showInputStatus(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class MediaPlaybackCluster extends BaseChipCluster { + public MediaPlaybackCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void mediaFastForward(MediaFastForwardResponseCallback callback) { + mediaFastForward(chipClusterPtr, callback); + } + + public void mediaNext(MediaNextResponseCallback callback) { + mediaNext(chipClusterPtr, callback); + } + + public void mediaPause(MediaPauseResponseCallback callback) { + mediaPause(chipClusterPtr, callback); + } + + public void mediaPlay(MediaPlayResponseCallback callback) { + mediaPlay(chipClusterPtr, callback); + } + + public void mediaPrevious(MediaPreviousResponseCallback callback) { + mediaPrevious(chipClusterPtr, callback); + } + + public void mediaRewind(MediaRewindResponseCallback callback) { + mediaRewind(chipClusterPtr, callback); + } + + public void mediaSkipBackward( + MediaSkipBackwardResponseCallback callback, long deltaPositionMilliseconds) { + mediaSkipBackward(chipClusterPtr, callback, deltaPositionMilliseconds); + } + + public void mediaSkipForward( + MediaSkipForwardResponseCallback callback, long deltaPositionMilliseconds) { + mediaSkipForward(chipClusterPtr, callback, deltaPositionMilliseconds); + } + + public void mediaSkipSeek(MediaSkipSeekResponseCallback callback, long position) { + mediaSkipSeek(chipClusterPtr, callback, position); + } + + public void mediaStartOver(MediaStartOverResponseCallback callback) { + mediaStartOver(chipClusterPtr, callback); + } + + public void mediaStop(MediaStopResponseCallback callback) { + mediaStop(chipClusterPtr, callback); + } + + private native void mediaFastForward( + long chipClusterPtr, MediaFastForwardResponseCallback callback); + + private native void mediaNext(long chipClusterPtr, MediaNextResponseCallback callback); + + private native void mediaPause(long chipClusterPtr, MediaPauseResponseCallback callback); + + private native void mediaPlay(long chipClusterPtr, MediaPlayResponseCallback callback); + + private native void mediaPrevious(long chipClusterPtr, MediaPreviousResponseCallback callback); + + private native void mediaRewind(long chipClusterPtr, MediaRewindResponseCallback callback); + + private native void mediaSkipBackward( + long chipClusterPtr, + MediaSkipBackwardResponseCallback callback, + long deltaPositionMilliseconds); + + private native void mediaSkipForward( + long chipClusterPtr, + MediaSkipForwardResponseCallback callback, + long deltaPositionMilliseconds); + + private native void mediaSkipSeek( + long chipClusterPtr, MediaSkipSeekResponseCallback callback, long position); + + private native void mediaStartOver( + long chipClusterPtr, MediaStartOverResponseCallback callback); + + private native void mediaStop(long chipClusterPtr, MediaStopResponseCallback callback); + + public interface MediaFastForwardResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaNextResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaPauseResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaPlayResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaPreviousResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaRewindResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaSkipBackwardResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaSkipForwardResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaSkipSeekResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaStartOverResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + + public interface MediaStopResponseCallback { + void onSuccess(int mediaPlaybackStatus); + + void onError(Exception error); + } + } + + public static class NetworkCommissioningCluster extends BaseChipCluster { + public NetworkCommissioningCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void addThreadNetwork( + AddThreadNetworkResponseCallback callback, + byte[] operationalDataset, + long breadcrumb, + long timeoutMs) { + addThreadNetwork(chipClusterPtr, callback, operationalDataset, breadcrumb, timeoutMs); + } + + public void addWiFiNetwork( + AddWiFiNetworkResponseCallback callback, + byte[] ssid, + byte[] credentials, + long breadcrumb, + long timeoutMs) { + addWiFiNetwork(chipClusterPtr, callback, ssid, credentials, breadcrumb, timeoutMs); + } + + public void disableNetwork( + DisableNetworkResponseCallback callback, + byte[] networkID, + long breadcrumb, + long timeoutMs) { + disableNetwork(chipClusterPtr, callback, networkID, breadcrumb, timeoutMs); + } + + public void enableNetwork( + EnableNetworkResponseCallback callback, byte[] networkID, long breadcrumb, long timeoutMs) { + enableNetwork(chipClusterPtr, callback, networkID, breadcrumb, timeoutMs); + } + + public void getLastNetworkCommissioningResult(DefaultClusterCallback callback, long timeoutMs) { + getLastNetworkCommissioningResult(chipClusterPtr, callback, timeoutMs); + } + + public void removeNetwork( + 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) { + scanNetworks(chipClusterPtr, callback, ssid, breadcrumb, timeoutMs); + } + + public void updateThreadNetwork( + UpdateThreadNetworkResponseCallback callback, + byte[] operationalDataset, + long breadcrumb, + long timeoutMs) { + updateThreadNetwork(chipClusterPtr, callback, operationalDataset, breadcrumb, timeoutMs); + } + + public void updateWiFiNetwork( + UpdateWiFiNetworkResponseCallback callback, + byte[] ssid, + byte[] credentials, + long breadcrumb, + long timeoutMs) { + updateWiFiNetwork(chipClusterPtr, callback, ssid, credentials, breadcrumb, timeoutMs); + } + + private native void addThreadNetwork( + long chipClusterPtr, + AddThreadNetworkResponseCallback callback, + byte[] operationalDataset, + long breadcrumb, + long timeoutMs); + + private native void addWiFiNetwork( + long chipClusterPtr, + AddWiFiNetworkResponseCallback callback, + byte[] ssid, + byte[] credentials, + long breadcrumb, + long timeoutMs); + + private native void disableNetwork( + long chipClusterPtr, + DisableNetworkResponseCallback callback, + byte[] networkID, + long breadcrumb, + long timeoutMs); + + private native void enableNetwork( + long chipClusterPtr, + EnableNetworkResponseCallback callback, + byte[] networkID, + long breadcrumb, + long timeoutMs); + + private native void getLastNetworkCommissioningResult( + long chipClusterPtr, DefaultClusterCallback callback, long timeoutMs); + + private native void removeNetwork( + long chipClusterPtr, + RemoveNetworkResponseCallback callback, + byte[] networkID, + long breadcrumb, + long timeoutMs); + + private native void scanNetworks( + long chipClusterPtr, + ScanNetworksResponseCallback callback, + byte[] ssid, + long breadcrumb, + long timeoutMs); + + private native void updateThreadNetwork( + long chipClusterPtr, + UpdateThreadNetworkResponseCallback callback, + byte[] operationalDataset, + long breadcrumb, + long timeoutMs); + + private native void updateWiFiNetwork( + long chipClusterPtr, + UpdateWiFiNetworkResponseCallback callback, + byte[] ssid, + byte[] credentials, + long breadcrumb, + long timeoutMs); + + public interface AddThreadNetworkResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + + public interface AddWiFiNetworkResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + + public interface DisableNetworkResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + + public interface EnableNetworkResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + + public interface RemoveNetworkResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + + public interface ScanNetworksResponseCallback { + void onSuccess(int 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 * + // Conversion from this type to Java is not properly implemented yet + ); + + void onError(Exception error); + } + + public interface UpdateThreadNetworkResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + + public interface UpdateWiFiNetworkResponseCallback { + void onSuccess(int errorCode, String debugText); + + void onError(Exception error); + } + } + + public static class OtaSoftwareUpdateServerCluster extends BaseChipCluster { + public OtaSoftwareUpdateServerCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void applyUpdateRequest( + ApplyUpdateRequestResponseCallback callback, byte[] updateToken, long newVersion) { + applyUpdateRequest(chipClusterPtr, callback, updateToken, newVersion); + } + + public void notifyUpdateApplied( + DefaultClusterCallback callback, byte[] updateToken, long currentVersion) { + notifyUpdateApplied(chipClusterPtr, callback, updateToken, currentVersion); + } + + public void queryImage( + QueryImageResponseCallback callback, + int vendorId, + int productId, + int imageType, + int hardwareVersion, + long currentVersion, + int protocolsSupported, + String location, + int clientCanConsent, + byte[] metadataForServer) { + queryImage( + chipClusterPtr, + callback, + vendorId, + productId, + imageType, + hardwareVersion, + currentVersion, + protocolsSupported, + location, + clientCanConsent, + metadataForServer); + } + + private native void applyUpdateRequest( + long chipClusterPtr, + ApplyUpdateRequestResponseCallback callback, + byte[] updateToken, + long newVersion); + + private native void notifyUpdateApplied( + long chipClusterPtr, + DefaultClusterCallback callback, + byte[] updateToken, + long currentVersion); + + private native void queryImage( + long chipClusterPtr, + QueryImageResponseCallback callback, + int vendorId, + int productId, + int imageType, + int hardwareVersion, + long currentVersion, + int protocolsSupported, + String location, + int clientCanConsent, + byte[] metadataForServer); + + public interface ApplyUpdateRequestResponseCallback { + void onSuccess(int action, long delayedActionTime); + + void onError(Exception error); + } + + public interface QueryImageResponseCallback { + void onSuccess( + long delayedActionTime, + String imageURI, + long softwareVersion, + byte[] updateToken, + int userConsentNeeded, + byte[] metadataForClient); + + void onError(Exception error); + } + } + + public static class OnOffCluster extends BaseChipCluster { + public OnOffCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void off(DefaultClusterCallback callback) { + off(chipClusterPtr, callback); + } + + public void on(DefaultClusterCallback callback) { + on(chipClusterPtr, callback); + } + + public void toggle(DefaultClusterCallback callback) { + toggle(chipClusterPtr, callback); + } + + private native void off(long chipClusterPtr, DefaultClusterCallback callback); + + private native void on(long chipClusterPtr, DefaultClusterCallback callback); + + private native void toggle(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class OperationalCredentialsCluster extends BaseChipCluster { + public OperationalCredentialsCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void addOpCert( + OpCertResponseCallback callback, + byte[] operationalCert, + byte[] iPKValue, + long caseAdminNode, + int adminVendorId) { + addOpCert(chipClusterPtr, callback, operationalCert, iPKValue, caseAdminNode, adminVendorId); + } + + public void addTrustedRootCertificate(DefaultClusterCallback callback, byte[] rootCertificate) { + addTrustedRootCertificate(chipClusterPtr, callback, rootCertificate); + } + + public void opCSRRequest(OpCSRResponseCallback callback, byte[] cSRNonce) { + opCSRRequest(chipClusterPtr, callback, cSRNonce); + } + + public void removeAllFabrics(DefaultClusterCallback callback) { + removeAllFabrics(chipClusterPtr, callback); + } + + public void removeFabric( + OpCertResponseCallback callback, long fabricId, long nodeId, int vendorId) { + removeFabric(chipClusterPtr, callback, fabricId, nodeId, vendorId); + } + + public void removeTrustedRootCertificate( + DefaultClusterCallback callback, byte[] trustedRootIdentifier) { + removeTrustedRootCertificate(chipClusterPtr, callback, trustedRootIdentifier); + } + + public void setFabric(SetFabricResponseCallback callback, int vendorId) { + setFabric(chipClusterPtr, callback, vendorId); + } + + public void updateFabricLabel(OpCertResponseCallback callback, String label) { + updateFabricLabel(chipClusterPtr, callback, label); + } + + private native void addOpCert( + long chipClusterPtr, + OpCertResponseCallback callback, + byte[] operationalCert, + byte[] iPKValue, + long caseAdminNode, + int adminVendorId); + + private native void addTrustedRootCertificate( + long chipClusterPtr, DefaultClusterCallback callback, byte[] rootCertificate); + + private native void opCSRRequest( + long chipClusterPtr, OpCSRResponseCallback callback, byte[] cSRNonce); + + private native void removeAllFabrics(long chipClusterPtr, DefaultClusterCallback callback); + + private native void removeFabric( + long chipClusterPtr, + OpCertResponseCallback callback, + long fabricId, + long nodeId, + int vendorId); + + private native void removeTrustedRootCertificate( + long chipClusterPtr, DefaultClusterCallback callback, byte[] trustedRootIdentifier); + + private native void setFabric( + long chipClusterPtr, SetFabricResponseCallback callback, int vendorId); + + private native void updateFabricLabel( + long chipClusterPtr, OpCertResponseCallback callback, String label); + + public interface OpCSRResponseCallback { + void onSuccess( + byte[] CSR, + byte[] CSRNonce, + byte[] VendorReserved1, + byte[] VendorReserved2, + byte[] VendorReserved3, + byte[] Signature); + + void onError(Exception error); + } + + public interface OpCertResponseCallback { + void onSuccess(int StatusCode, long FabricIndex, String DebugText); + + void onError(Exception error); + } + + public interface SetFabricResponseCallback { + void onSuccess(long FabricId); + + void onError(Exception error); + } + } + + public static class PumpConfigurationAndControlCluster extends BaseChipCluster { + public PumpConfigurationAndControlCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class RelativeHumidityMeasurementCluster extends BaseChipCluster { + public RelativeHumidityMeasurementCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class ScenesCluster extends BaseChipCluster { + public ScenesCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void addScene( + AddSceneResponseCallback callback, + int groupId, + int sceneId, + int transitionTime, + String sceneName, + int clusterId, + int length, + int value) { + addScene( + chipClusterPtr, + callback, + groupId, + sceneId, + transitionTime, + sceneName, + clusterId, + length, + value); + } + + public void getSceneMembership(GetSceneMembershipResponseCallback callback, int groupId) { + getSceneMembership(chipClusterPtr, callback, groupId); + } + + public void recallScene( + DefaultClusterCallback callback, int groupId, int sceneId, int transitionTime) { + recallScene(chipClusterPtr, callback, groupId, sceneId, transitionTime); + } + + public void removeAllScenes(RemoveAllScenesResponseCallback callback, int groupId) { + removeAllScenes(chipClusterPtr, callback, groupId); + } + + public void removeScene(RemoveSceneResponseCallback callback, int groupId, int sceneId) { + removeScene(chipClusterPtr, callback, groupId, sceneId); + } + + public void storeScene(StoreSceneResponseCallback callback, int groupId, int sceneId) { + storeScene(chipClusterPtr, callback, groupId, sceneId); + } + + public void viewScene(ViewSceneResponseCallback callback, int groupId, int sceneId) { + viewScene(chipClusterPtr, callback, groupId, sceneId); + } + + private native void addScene( + long chipClusterPtr, + AddSceneResponseCallback callback, + int groupId, + int sceneId, + int transitionTime, + String sceneName, + int clusterId, + int length, + int value); + + private native void getSceneMembership( + long chipClusterPtr, GetSceneMembershipResponseCallback callback, int groupId); + + private native void recallScene( + long chipClusterPtr, + DefaultClusterCallback callback, + int groupId, + int sceneId, + int transitionTime); + + private native void removeAllScenes( + long chipClusterPtr, RemoveAllScenesResponseCallback callback, int groupId); + + private native void removeScene( + long chipClusterPtr, RemoveSceneResponseCallback callback, int groupId, int sceneId); + + private native void storeScene( + long chipClusterPtr, StoreSceneResponseCallback callback, int groupId, int sceneId); + + private native void viewScene( + long chipClusterPtr, ViewSceneResponseCallback callback, int groupId, int sceneId); + + public interface AddSceneResponseCallback { + void onSuccess(int groupId, int sceneId); + + void onError(Exception error); + } + + public interface GetSceneMembershipResponseCallback { + void onSuccess(int capacity, int groupId, int sceneCount + // sceneList: /* TYPE WARNING: array array defaults to */ uint8_t * + // Conversion from this type to Java is not properly implemented yet + ); + + void onError(Exception error); + } + + public interface RemoveAllScenesResponseCallback { + void onSuccess(int groupId); + + void onError(Exception error); + } + + public interface RemoveSceneResponseCallback { + void onSuccess(int groupId, int sceneId); + + void onError(Exception error); + } + + public interface StoreSceneResponseCallback { + void onSuccess(int groupId, int sceneId); + + void onError(Exception error); + } + + public interface ViewSceneResponseCallback { + void onSuccess(int groupId, int sceneId, int transitionTime, String sceneName + // extensionFieldSets: /* TYPE WARNING: array array defaults to */ uint8_t * + // Conversion from this type to Java is not properly implemented yet + ); + + void onError(Exception error); + } + } + + public static class SoftwareDiagnosticsCluster extends BaseChipCluster { + public SoftwareDiagnosticsCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void resetWatermarks(DefaultClusterCallback callback) { + resetWatermarks(chipClusterPtr, callback); + } + + private native void resetWatermarks(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class SwitchCluster extends BaseChipCluster { + public SwitchCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class TvChannelCluster extends BaseChipCluster { + public TvChannelCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void changeChannel(ChangeChannelResponseCallback callback, String match) { + changeChannel(chipClusterPtr, callback, match); + } + + public void changeChannelByNumber( + DefaultClusterCallback callback, int majorNumber, int minorNumber) { + changeChannelByNumber(chipClusterPtr, callback, majorNumber, minorNumber); + } + + public void skipChannel(DefaultClusterCallback callback, int count) { + skipChannel(chipClusterPtr, callback, count); + } + + private native void changeChannel( + long chipClusterPtr, ChangeChannelResponseCallback callback, String match); + + private native void changeChannelByNumber( + long chipClusterPtr, DefaultClusterCallback callback, int majorNumber, int minorNumber); + + private native void skipChannel( + long chipClusterPtr, DefaultClusterCallback callback, int count); + + public interface ChangeChannelResponseCallback { + void onSuccess( + // ChannelMatch: /* TYPE WARNING: array array defaults to */ uint8_t * + // Conversion from this type to Java is not properly implemented yet + int ErrorType); + + void onError(Exception error); + } + } + + public static class TargetNavigatorCluster extends BaseChipCluster { + public TargetNavigatorCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void navigateTarget(NavigateTargetResponseCallback callback, int target, String data) { + navigateTarget(chipClusterPtr, callback, target, data); + } + + private native void navigateTarget( + long chipClusterPtr, NavigateTargetResponseCallback callback, int target, String data); + + public interface NavigateTargetResponseCallback { + void onSuccess(String data); + + void onError(Exception error); + } + } + + public static class TemperatureMeasurementCluster extends BaseChipCluster { + public TemperatureMeasurementCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class TestClusterCluster extends BaseChipCluster { + public TestClusterCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void test(DefaultClusterCallback callback) { + test(chipClusterPtr, callback); + } + + public void testNotHandled(DefaultClusterCallback callback) { + testNotHandled(chipClusterPtr, callback); + } + + public void testSpecific(TestSpecificResponseCallback callback) { + testSpecific(chipClusterPtr, callback); + } + + public void testUnknownCommand(DefaultClusterCallback callback) { + testUnknownCommand(chipClusterPtr, callback); + } + + private native void test(long chipClusterPtr, DefaultClusterCallback callback); + + private native void testNotHandled(long chipClusterPtr, DefaultClusterCallback callback); + + private native void testSpecific(long chipClusterPtr, TestSpecificResponseCallback callback); + + private native void testUnknownCommand(long chipClusterPtr, DefaultClusterCallback callback); + + public interface TestSpecificResponseCallback { + void onSuccess(int returnValue); + + void onError(Exception error); + } + } + + public static class ThermostatCluster extends BaseChipCluster { + public ThermostatCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void clearWeeklySchedule(DefaultClusterCallback callback) { + clearWeeklySchedule(chipClusterPtr, callback); + } + + public void getRelayStatusLog(DefaultClusterCallback callback) { + getRelayStatusLog(chipClusterPtr, callback); + } + + public void getWeeklySchedule( + DefaultClusterCallback callback, int daysToReturn, int modeToReturn) { + getWeeklySchedule(chipClusterPtr, callback, daysToReturn, modeToReturn); + } + + public void setWeeklySchedule( + DefaultClusterCallback callback, + int numberOfTransitionsForSequence, + int dayOfWeekForSequence, + int modeForSequence, + int payload) { + setWeeklySchedule( + chipClusterPtr, + callback, + numberOfTransitionsForSequence, + dayOfWeekForSequence, + modeForSequence, + payload); + } + + public void setpointRaiseLower(DefaultClusterCallback callback, int mode, int amount) { + setpointRaiseLower(chipClusterPtr, callback, mode, amount); + } + + private native void clearWeeklySchedule(long chipClusterPtr, DefaultClusterCallback callback); + + private native void getRelayStatusLog(long chipClusterPtr, DefaultClusterCallback callback); + + private native void getWeeklySchedule( + long chipClusterPtr, DefaultClusterCallback callback, int daysToReturn, int modeToReturn); + + private native void setWeeklySchedule( + long chipClusterPtr, + DefaultClusterCallback callback, + int numberOfTransitionsForSequence, + int dayOfWeekForSequence, + int modeForSequence, + int payload); + + private native void setpointRaiseLower( + long chipClusterPtr, DefaultClusterCallback callback, int mode, int amount); + } + + public static class ThreadNetworkDiagnosticsCluster extends BaseChipCluster { + public ThreadNetworkDiagnosticsCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void resetCounts(DefaultClusterCallback callback) { + resetCounts(chipClusterPtr, callback); + } + + private native void resetCounts(long chipClusterPtr, DefaultClusterCallback callback); + } + + public static class WakeOnLanCluster extends BaseChipCluster { + public WakeOnLanCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + } + + public static class WindowCoveringCluster extends BaseChipCluster { + public WindowCoveringCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId); + } + + @Override + public native long initWithDevice(long devicePtr, int endpointId); + + public void windowCoveringDownClose(DefaultClusterCallback callback) { + windowCoveringDownClose(chipClusterPtr, callback); + } + + public void windowCoveringGoToLiftPercentage( + DefaultClusterCallback callback, int percentageLiftValue) { + windowCoveringGoToLiftPercentage(chipClusterPtr, callback, percentageLiftValue); + } + + public void windowCoveringGoToLiftValue(DefaultClusterCallback callback, int liftValue) { + windowCoveringGoToLiftValue(chipClusterPtr, callback, liftValue); + } + + public void windowCoveringGoToTiltPercentage( + DefaultClusterCallback callback, int percentageTiltValue) { + windowCoveringGoToTiltPercentage(chipClusterPtr, callback, percentageTiltValue); + } + + public void windowCoveringGoToTiltValue(DefaultClusterCallback callback, int tiltValue) { + windowCoveringGoToTiltValue(chipClusterPtr, callback, tiltValue); + } + + public void windowCoveringStop(DefaultClusterCallback callback) { + windowCoveringStop(chipClusterPtr, callback); + } + + public void windowCoveringUpOpen(DefaultClusterCallback callback) { + windowCoveringUpOpen(chipClusterPtr, callback); + } + + private native void windowCoveringDownClose( + long chipClusterPtr, DefaultClusterCallback callback); + + private native void windowCoveringGoToLiftPercentage( + long chipClusterPtr, DefaultClusterCallback callback, int percentageLiftValue); + + private native void windowCoveringGoToLiftValue( + long chipClusterPtr, DefaultClusterCallback callback, int liftValue); + + private native void windowCoveringGoToTiltPercentage( + long chipClusterPtr, DefaultClusterCallback callback, int percentageTiltValue); + + private native void windowCoveringGoToTiltValue( + long chipClusterPtr, DefaultClusterCallback callback, int tiltValue); + + private native void windowCoveringStop(long chipClusterPtr, DefaultClusterCallback callback); + + private native void windowCoveringUpOpen(long chipClusterPtr, DefaultClusterCallback callback); + } +} From eb8809fecda4ffe793c04c1de84a8568c34998cf Mon Sep 17 00:00:00 2001 From: Austin Hsieh Date: Thu, 17 Jun 2021 17:35:36 -0700 Subject: [PATCH 4/4] Update Android CHIPTool to use cluster commands. --- .../clusterclient/OnOffClientFragment.kt | 128 ++++++++++------ .../DeviceProvisioningFragment.kt | 28 ++-- .../provisioning/EnterNetworkFragment.kt | 139 ++++++++++++++---- .../java/CHIPDeviceController-JNI.cpp | 13 ++ .../ChipDeviceController.java | 6 + 5 files changed, 225 insertions(+), 89 deletions(-) diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/OnOffClientFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/OnOffClientFragment.kt index 868973312edd81..b3a7552d21beac 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/OnOffClientFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/OnOffClientFragment.kt @@ -11,32 +11,37 @@ import android.view.ViewGroup import android.widget.SeekBar import android.widget.Toast import androidx.fragment.app.Fragment -import chip.devicecontroller.ChipCommandType +import chip.devicecontroller.ChipClusters +import chip.devicecontroller.ChipClusters.OnOffCluster import chip.devicecontroller.ChipDeviceController import chip.devicecontroller.ChipDeviceControllerException import com.google.chip.chiptool.ChipClient import com.google.chip.chiptool.GenericChipDeviceListener import com.google.chip.chiptool.R import com.google.chip.chiptool.util.DeviceIdUtil -import kotlinx.android.synthetic.main.on_off_client_fragment.* -import kotlinx.android.synthetic.main.on_off_client_fragment.view.* +import kotlinx.android.synthetic.main.on_off_client_fragment.commandStatusTv +import kotlinx.android.synthetic.main.on_off_client_fragment.deviceIdEd +import kotlinx.android.synthetic.main.on_off_client_fragment.fabricIdEd +import kotlinx.android.synthetic.main.on_off_client_fragment.levelBar +import kotlinx.android.synthetic.main.on_off_client_fragment.view.levelBar +import kotlinx.android.synthetic.main.on_off_client_fragment.view.offBtn +import kotlinx.android.synthetic.main.on_off_client_fragment.view.onBtn +import kotlinx.android.synthetic.main.on_off_client_fragment.view.toggleBtn +import kotlinx.android.synthetic.main.on_off_client_fragment.view.updateAddressBtn class OnOffClientFragment : Fragment() { private val deviceController: ChipDeviceController get() = ChipClient.getDeviceController() - private var commandType: ChipCommandType? = null - private var levelValue: Int? = null - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? ): View { return inflater.inflate(R.layout.on_off_client_fragment, container, false).apply { deviceController.setCompletionListener(ChipControllerCallback()) - updateAddressBtn.setOnClickListener{ updateAddressClick() } + updateAddressBtn.setOnClickListener { updateAddressClick() } onBtn.setOnClickListener { sendOnCommandClick() } offBtn.setOnClickListener { sendOffCommandClick() } toggleBtn.setOnClickListener { sendToggleCommandClick() } @@ -50,12 +55,12 @@ class OnOffClientFragment : Fragment() { } override fun onStopTrackingTouch(seekBar: SeekBar?) { - Toast.makeText(requireContext(), - "Level is: " + levelBar.progress, - Toast.LENGTH_SHORT).show() - commandType = ChipCommandType.LEVEL - levelValue = levelBar.progress - sendCommand() + Toast.makeText( + requireContext(), + "Level is: " + levelBar.progress, + Toast.LENGTH_SHORT + ).show() + sendLevelCommandClick() } }) } @@ -70,9 +75,7 @@ class OnOffClientFragment : Fragment() { } inner class ChipControllerCallback : GenericChipDeviceListener() { - override fun onConnectDeviceComplete() { - sendCommand() - } + override fun onConnectDeviceComplete() {} override fun onSendMessageComplete(message: String?) { commandStatusTv.text = requireContext().getString(R.string.echo_status_response, message) @@ -93,7 +96,10 @@ class OnOffClientFragment : Fragment() { private fun updateAddressClick() { val serviceInfo = NsdServiceInfo().apply { - serviceName = "%016X-%016X".format(fabricIdEd.text.toString().toLong(), deviceIdEd.text.toString().toLong()) + serviceName = "%016X-%016X".format( + fabricIdEd.text.toString().toLong(), + deviceIdEd.text.toString().toLong() + ) serviceType = "_chip._tcp" } @@ -125,43 +131,69 @@ class OnOffClientFragment : Fragment() { } } + private fun sendLevelCommandClick() { + val cluster = ChipClusters.LevelControlCluster( + ChipClient.getDeviceController() + .getDevicePointer(deviceIdEd.text.toString().toLong()), 1 + ) + cluster.moveToLevel(object : ChipClusters.DefaultClusterCallback { + override fun onSuccess() { + showMessage("MoveToLevel command success") + } + + override fun onError(ex: Exception) { + showMessage("MoveToLevel command failure $ex") + Log.e(TAG, "MoveToLevel command failure", ex) + } + + }, levelBar.progress, 0, 0, 0) + } + private fun sendOnCommandClick() { - commandType = ChipCommandType.ON - levelValue = 0 - sendCommand() + getOnOffClusterForDevice().on(object : ChipClusters.DefaultClusterCallback { + override fun onSuccess() { + showMessage("ON command success") + } + + override fun onError(ex: Exception) { + showMessage("ON command failure $ex") + Log.e(TAG, "ON command failure", ex) + } + + }) } private fun sendOffCommandClick() { - commandType = ChipCommandType.OFF - levelValue = 0 - sendCommand() - } + getOnOffClusterForDevice().off(object : ChipClusters.DefaultClusterCallback { + override fun onSuccess() { + showMessage("OFF command success") + } - private fun sendToggleCommandClick() { - commandType = ChipCommandType.TOGGLE - levelValue = 0 - sendCommand() + override fun onError(ex: Exception) { + showMessage("OFF command failure $ex") + Log.e(TAG, "OFF command failure", ex) + } + }) } - private fun sendCommand() { - val chipCommandType = commandType ?: run { - Log.e(TAG, "No ChipCommandType specified.") - return - } + private fun sendToggleCommandClick() { + getOnOffClusterForDevice().toggle(object : ChipClusters.DefaultClusterCallback { + override fun onSuccess() { + showMessage("TOGGLE command success") + } - commandStatusTv.text = requireContext() - .getString(R.string.send_command_type_label_text, chipCommandType.name, levelValue) + override fun onError(ex: Exception) { + showMessage("TOGGLE command failure $ex") + Log.e(TAG, "TOGGLE command failure", ex) + } + }) + } - try { - // mask levelValue from integer to uint8_t and if null use 0 - deviceController.sendCommand( - DeviceIdUtil.getLastDeviceId(requireContext()), - commandType, - ( 0xff and (levelValue ?: 0)) - ) - } catch (e: ChipDeviceControllerException) { - showMessage(e.toString()) - } + private fun getOnOffClusterForDevice(): OnOffCluster { + return OnOffCluster( + ChipClient.getDeviceController() + .getDevicePointer(deviceIdEd.text.toString().toLong()), 1 + ) } private fun showMessage(msg: String) { diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt index 7c0ba6c568f03b..7c120e38cf37df 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt @@ -49,15 +49,15 @@ class DeviceProvisioningFragment : Fragment() { private val networkType: ProvisionNetworkType get() = requireNotNull( - ProvisionNetworkType.fromName(arguments?.getString(ARG_PROVISION_NETWORK_TYPE)) + ProvisionNetworkType.fromName(arguments?.getString(ARG_PROVISION_NETWORK_TYPE)) ) private val scope = CoroutineScope(Dispatchers.Main + Job()) override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? ): View { deviceInfo = checkNotNull(requireArguments().getParcelable(ARG_DEVICE_INFO)) return inflater.inflate(R.layout.single_fragment_container, container, false).apply { @@ -83,8 +83,8 @@ class DeviceProvisioningFragment : Fragment() { val bluetoothManager = BluetoothManager() showMessage( - R.string.rendezvous_over_ble_scanning_text, - deviceInfo.discriminator.toString() + R.string.rendezvous_over_ble_scanning_text, + deviceInfo.discriminator.toString() ) val device = bluetoothManager.getBluetoothDevice(deviceInfo.discriminator) ?: run { showMessage(R.string.rendezvous_over_ble_scanning_failed_text) @@ -92,8 +92,8 @@ class DeviceProvisioningFragment : Fragment() { } showMessage( - R.string.rendezvous_over_ble_connecting_text, - device.name ?: device.address.toString() + R.string.rendezvous_over_ble_connecting_text, + device.name ?: device.address.toString() ) gatt = bluetoothManager.connect(requireContext(), device) @@ -110,7 +110,7 @@ class DeviceProvisioningFragment : Fragment() { requireActivity().runOnUiThread { val context = requireContext() Toast.makeText(context, context.getString(msgResId, stringArgs), Toast.LENGTH_SHORT) - .show() + .show() } } @@ -120,13 +120,13 @@ class DeviceProvisioningFragment : Fragment() { } override fun onStatusUpdate(status: Int) { - Log.d(TAG, "Pairing status update: $status"); + Log.d(TAG, "Pairing status update: $status") } override fun onPairingComplete(code: Int) { Log.d(TAG, "onPairingComplete: $code") - if (code == 0) { + if (code == STATUS_PAIRING_SUCCESS) { childFragmentManager.beginTransaction() .add(R.id.fragment_container, EnterNetworkFragment.newInstance(networkType)) .commit() @@ -171,11 +171,11 @@ class DeviceProvisioningFragment : Fragment() { private const val TAG = "DeviceProvisioningFragment" private const val ARG_DEVICE_INFO = "device_info" private const val ARG_PROVISION_NETWORK_TYPE = "provision_network_type" - private const val STATUS_NETWORK_PROVISIONING_SUCCESS = 2 + private const val STATUS_PAIRING_SUCCESS = 0 fun newInstance( - deviceInfo: CHIPDeviceInfo, - networkType: ProvisionNetworkType + deviceInfo: CHIPDeviceInfo, + networkType: ProvisionNetworkType ): DeviceProvisioningFragment { return DeviceProvisioningFragment().apply { arguments = Bundle(2).apply { diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt index d966faa5578abb..49af7e8d743302 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt @@ -18,11 +18,13 @@ package com.google.chip.chiptool.provisioning import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.fragment.app.Fragment +import chip.devicecontroller.ChipClusters.NetworkCommissioningCluster import chip.devicecontroller.ChipDeviceControllerException import com.google.chip.chiptool.ChipClient import com.google.chip.chiptool.R @@ -32,8 +34,9 @@ import kotlinx.android.synthetic.main.enter_thread_network_fragment.channelEd import kotlinx.android.synthetic.main.enter_thread_network_fragment.masterKeyEd import kotlinx.android.synthetic.main.enter_thread_network_fragment.panIdEd import kotlinx.android.synthetic.main.enter_thread_network_fragment.xpanIdEd -import kotlinx.android.synthetic.main.enter_wifi_network_fragment.* -import kotlinx.android.synthetic.main.enter_wifi_network_fragment.view.* +import kotlinx.android.synthetic.main.enter_wifi_network_fragment.pwdEd +import kotlinx.android.synthetic.main.enter_wifi_network_fragment.ssidEd +import kotlinx.android.synthetic.main.enter_wifi_network_fragment.view.saveNetworkBtn /** * Fragment to collect Wi-Fi network information from user and send it to device being provisioned. @@ -42,19 +45,23 @@ class EnterNetworkFragment : Fragment() { private val networkType: ProvisionNetworkType get() = requireNotNull( - ProvisionNetworkType.fromName(arguments?.getString(ARG_PROVISION_NETWORK_TYPE)) + ProvisionNetworkType.fromName(arguments?.getString(ARG_PROVISION_NETWORK_TYPE)) ) override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? ): View? { val layoutRes = when (networkType) { ProvisionNetworkType.WIFI -> R.layout.enter_wifi_network_fragment ProvisionNetworkType.THREAD -> R.layout.enter_thread_network_fragment } + if (USE_HARDCODED_WIFI) { + saveHardcodedWifiNetwork() + } + return inflater.inflate(layoutRes, container, false).apply { saveNetworkBtn.setOnClickListener { onSaveNetworkClicked() } } @@ -68,16 +75,80 @@ class EnterNetworkFragment : Fragment() { } } + private fun saveHardcodedWifiNetwork() { + addAndEnableWifiNetwork(HARDCODED_WIFI_SSID, HARDCODED_WIFI_PASSWORD) + } + private fun saveWifiNetwork() { - val ssid = ssidEd.text - val pwd = pwdEd.text + val ssid = ssidEd?.text + val pwd = pwdEd?.text if (ssid.isNullOrBlank() || pwd.isNullOrBlank()) { Toast.makeText(requireContext(), "Ssid and password required.", Toast.LENGTH_SHORT).show() return } - // Do something with the credentials + addAndEnableWifiNetwork(ssid.toString(), pwd.toString()) + } + + private fun addAndEnableWifiNetwork(ssid: String, password: String) { + // Uses UTF-8 as default + val ssidBytes = ssid.toByteArray() + val pwdBytes = password.toByteArray() + + val devicePtr = ChipClient.getDeviceController() + .getDevicePointer(DeviceIdUtil.getLastDeviceId(requireContext())) + val cluster = NetworkCommissioningCluster(devicePtr, /* endpointId = */ 0) + + val enableNetworkCallback = object : + NetworkCommissioningCluster.EnableNetworkResponseCallback { + override fun onSuccess(errorCode: Int, debugText: String) { + Log.v(TAG, "EnableNetwork for $ssid succeeded, proceeding to OnOff") + + requireActivity().runOnUiThread { + Toast.makeText( + requireContext(), + R.string.rendezvous_over_ble_commissioning_success_text, + Toast.LENGTH_SHORT + ).show() + } + + FragmentUtil.getHost( + this@EnterNetworkFragment, + DeviceProvisioningFragment.Callback::class.java + )?.onCommissioningComplete(0) + } + + override fun onError(ex: Exception) { + Log.e(TAG, "EnableNetwork for $ssid failed", ex) + // TODO: consolidate error codes + FragmentUtil.getHost( + this@EnterNetworkFragment, + DeviceProvisioningFragment.Callback::class.java + )?.onCommissioningComplete(-1) + } + } + + cluster.addWiFiNetwork(object : + NetworkCommissioningCluster.AddWiFiNetworkResponseCallback { + override fun onSuccess(errorCode: Int, debugText: String) { + Log.v(TAG, "AddWifiNetwork for $ssid succeeded") + cluster.enableNetwork( + enableNetworkCallback, + ssidBytes, + /* breadcrumb = */ 0L, + ENABLE_NETWORK_TIMEOUT + ) + } + + override fun onError(ex: Exception) { + Log.e(TAG, "AddWifiNetwork for $ssid failed", ex) + FragmentUtil.getHost( + this@EnterNetworkFragment, + DeviceProvisioningFragment.Callback::class.java + )?.onCommissioningComplete(-1) + } + }, ssidBytes, pwdBytes, /* breadcrumb = */ 0L, ADD_WIFI_NETWORK_TIMEOUT) } private fun saveThreadNetwork() { @@ -118,25 +189,31 @@ class EnterNetworkFragment : Fragment() { try { ChipClient.getDeviceController().enableThreadNetwork( - DeviceIdUtil.getLastDeviceId(requireContext()), - MakeThreadOperationalDataset( - channelStr.toString().toInt(), - panIdStr.toString().toInt(16), - xpanIdStr.hexToByteArray(), - masterKeyStr.hexToByteArray() - )) + DeviceIdUtil.getLastDeviceId(requireContext()), + MakeThreadOperationalDataset( + channelStr.toString().toInt(), + panIdStr.toString().toInt(16), + xpanIdStr.hexToByteArray(), + masterKeyStr.hexToByteArray() + ) + ) } catch (e: ChipDeviceControllerException) { - Toast.makeText(requireContext(), R.string.rendezvous_over_ble_commissioning_failure_text, Toast.LENGTH_SHORT).show() + Toast.makeText( + requireContext(), + R.string.rendezvous_over_ble_commissioning_failure_text, + Toast.LENGTH_SHORT + ).show() FragmentUtil.getHost(this, DeviceProvisioningFragment.Callback::class.java) - ?.onCommissioningComplete(e.errorCode) + ?.onCommissioningComplete(e.errorCode) } } private fun MakeThreadOperationalDataset( - channel: Int, - panId: Int, - xpanId: ByteArray, - masterKey: ByteArray): ByteArray { + channel: Int, + panId: Int, + xpanId: ByteArray, + masterKey: ByteArray + ): ByteArray { // channel var dataset = byteArrayOf(TYPE_CHANNEL.toByte(), NUM_CHANNEL_BYTES.toByte()) dataset += 0x00.toByte() // Channel Page 0. @@ -163,20 +240,28 @@ class EnterNetworkFragment : Fragment() { } private fun String.hexToByteArray(): ByteArray { - return chunked(2).map{ byteStr -> byteStr.toUByte(16).toByte()}.toByteArray() + return chunked(2).map { byteStr -> byteStr.toUByte(16).toByte() }.toByteArray() } companion object { private const val TAG = "EnterNetworkFragment" private const val ARG_PROVISION_NETWORK_TYPE = "provision_network_type" + + // TODO(#5035): remove hardcoded option when delayed commands work. + private const val USE_HARDCODED_WIFI = false + private const val HARDCODED_WIFI_SSID = "" + private const val HARDCODED_WIFI_PASSWORD = "" + private const val ADD_WIFI_NETWORK_TIMEOUT = 10000L + private const val ENABLE_NETWORK_TIMEOUT = 10000L + private const val NUM_CHANNEL_BYTES = 3 private const val NUM_PANID_BYTES = 2 private const val NUM_XPANID_BYTES = 8 private const val NUM_MASTER_KEY_BYTES = 16 - private const val TYPE_CHANNEL = 0; // Type of Thread Channel TLV. - private const val TYPE_PANID = 1; // Type of Thread PAN ID TLV. - private const val TYPE_XPANID = 2; // Type of Thread Extended PAN ID TLV. - private const val TYPE_MASTER_KEY = 5; // Type of Thread Network Master Key TLV. + private const val TYPE_CHANNEL = 0 // Type of Thread Channel TLV. + private const val TYPE_PANID = 1 // Type of Thread PAN ID TLV. + private const val TYPE_XPANID = 2 // Type of Thread Extended PAN ID TLV. + private const val TYPE_MASTER_KEY = 5 // Type of Thread Network Master Key TLV. fun newInstance(provisionNetworkType: ProvisionNetworkType): EnterNetworkFragment { return EnterNetworkFragment().apply { diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index adaf01532a887c..34aa01bb54ceb5 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -314,6 +314,19 @@ JNI_METHOD(void, stopDevicePairing)(JNIEnv * env, jobject self, jlong handle, jl } } +JNI_METHOD(jlong, getDevicePointer)(JNIEnv * env, jobject self, jlong handle, jlong deviceId) +{ + StackLockGuard lock(JniReferences::GetStackLock()); + Device * chipDevice = nullptr; + + ChipLogProgress(Controller, "getDevicePointer() called with device ID"); + + GetCHIPDevice(env, handle, deviceId, &chipDevice); + + static_assert(sizeof(jlong) >= sizeof(void *), "Need to store a pointer in a java handle"); + return reinterpret_cast(chipDevice); +} + JNI_METHOD(void, pairTestDeviceWithoutSecurity)(JNIEnv * env, jobject self, jlong handle, jstring deviceAddr) { StackLockGuard lock(JniReferences::GetStackLock()); diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 5f97ea6f742d3b..28e423f3984a2c 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -78,6 +78,10 @@ public void pairDevice(long deviceId, int connectionId, long pinCode) { pairDevice(deviceControllerPtr, deviceId, connectionId, pinCode); } + public long getDevicePointer(long deviceId) { + return getDevicePointer(deviceControllerPtr, deviceId); + } + public boolean disconnectDevice(long deviceId) { return disconnectDevice(deviceControllerPtr, deviceId); } @@ -193,6 +197,8 @@ private native void pairDevice( private native void unpairDevice(long deviceControllerPtr, long deviceId); + private native long getDevicePointer(long deviceControllerPtr, long deviceId); + private native void pairTestDeviceWithoutSecurity(long deviceControllerPtr, String ipAddress); private native boolean disconnectDevice(long deviceControllerPtr, long deviceId);