diff --git a/scripts/idl/generators/bridge/__init__.py b/scripts/idl/generators/bridge/__init__.py index 7e993dd965b66e..7a43c9e802b88a 100644 --- a/scripts/idl/generators/bridge/__init__.py +++ b/scripts/idl/generators/bridge/__init__.py @@ -44,22 +44,15 @@ def get_field_info(definition: Field, cluster: Cluster, idl: Idl): context = create_lookup_context(idl, cluster) actual = ParseDataType(definition.data_type, context) - orig = actual - is_enum = type(actual) == IdlEnumType - - if type(actual) == IdlEnumType: - actual = actual.base_type - elif type(actual) == IdlBitmapType: + if type(actual) == IdlEnumType or type(actual) == IdlBitmapType: actual = actual.base_type if type(actual) == BasicString: return 'OctetString', 'char', actual.max_length, \ - 'ZCL_%s_ATTRIBUTE_TYPE' % orig.idl_name.upper() + 'ZCL_%s_ATTRIBUTE_TYPE' % actual.idl_name.upper() if type(actual) == BasicInteger: - name = orig.idl_name.upper() - if is_enum: - name = actual.idl_name.upper() + name = actual.idl_name.upper() ty = "int%d_t" % actual.power_of_two_bits if not actual.is_signed: ty = "u" + ty diff --git a/scripts/idl/tests/inputs/several_clusters.matter b/scripts/idl/tests/inputs/several_clusters.matter index a9963a3e3bcee0..48832dd150a945 100644 --- a/scripts/idl/tests/inputs/several_clusters.matter +++ b/scripts/idl/tests/inputs/several_clusters.matter @@ -12,7 +12,13 @@ client cluster Third = 3 { kKnown = 100; } + bitmap LevelControlOptions : BITMAP8 { + kExecuteIfOff = 0x1; + kCoupleColorTempToLevel = 0x2; + } + attribute MyEnum someEnum = 10; + attribute LevelControlOptions options = 20; } server cluster Third = 3 { diff --git a/scripts/idl/tests/outputs/several_clusters/bridge/ThirdServer.h b/scripts/idl/tests/outputs/several_clusters/bridge/ThirdServer.h index 3779b80fa8a264..6f52806e477a89 100644 --- a/scripts/idl/tests/outputs/several_clusters/bridge/ThirdServer.h +++ b/scripts/idl/tests/outputs/several_clusters/bridge/ThirdServer.h @@ -8,7 +8,8 @@ struct ThirdCluster : public GeneratedCluster { ThirdCluster() : - mSomeEnum(chip::CharSpan("someEnum"), 10, ATTRIBUTE_MASK_WRITABLE, ZCL_ENUM8_ATTRIBUTE_TYPE, 1) + mSomeEnum(chip::CharSpan("someEnum"), 10, ATTRIBUTE_MASK_WRITABLE, ZCL_ENUM8_ATTRIBUTE_TYPE, 1), + mOptions(chip::CharSpan("options"), 20, ATTRIBUTE_MASK_WRITABLE, ZCL_BITMAP8_ATTRIBUTE_TYPE, 1) { } @@ -19,11 +20,13 @@ struct ThirdCluster : public GeneratedCluster { return std::vector({ static_cast(&mSomeEnum), + static_cast(&mOptions), }); } Attribute mSomeEnum; + Attribute mOptions; }; } diff --git a/scripts/idl/tests/outputs/several_clusters/jni/ThirdClient-InvokeSubscribeImpl.cpp b/scripts/idl/tests/outputs/several_clusters/jni/ThirdClient-InvokeSubscribeImpl.cpp index d39226d54dd769..125e9a9818ea28 100644 --- a/scripts/idl/tests/outputs/several_clusters/jni/ThirdClient-InvokeSubscribeImpl.cpp +++ b/scripts/idl/tests/outputs/several_clusters/jni/ThirdClient-InvokeSubscribeImpl.cpp @@ -51,6 +51,27 @@ JNI_METHOD(void, ThirdCluster, subscribeSomeEnumAttribute)(JNIEnv * env, jobject err = cppCluster->SubscribeAttribute(onSuccess->mContext, successFn->mCall, failureFn->mCall, static_cast(minInterval), static_cast(maxInterval), CHIPInt8uAttributeCallback::OnSubscriptionEstablished); VerifyOrReturn(err == CHIP_NO_ERROR, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error subscribing to attribute", err)); + onSuccess.release(); + onFailure.release(); +}JNI_METHOD(void, ThirdCluster, subscribeOptionsAttribute)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint minInterval, jint maxInterval) +{ + chip::DeviceLayer::StackLock lock;std::unique_ptr onSuccess(Platform::New(callback, true), chip::Platform::Delete); + VerifyOrReturn(onSuccess.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native success callback", CHIP_ERROR_NO_MEMORY)); + + std::unique_ptr onFailure(Platform::New(callback), chip::Platform::Delete); + VerifyOrReturn(onFailure.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native failure callback", CHIP_ERROR_NO_MEMORY)); + + CHIP_ERROR err = CHIP_NO_ERROR; + ThirdCluster * cppCluster = reinterpret_cast(clusterPtr); + VerifyOrReturn(cppCluster != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Could not get native cluster", CHIP_ERROR_INCORRECT_STATE)); + + using TypeInfo = chip::app::Clusters::Third::Attributes::Options::TypeInfo; + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); + + err = cppCluster->SubscribeAttribute(onSuccess->mContext, successFn->mCall, failureFn->mCall, static_cast(minInterval), static_cast(maxInterval), CHIPInt8uAttributeCallback::OnSubscriptionEstablished); + VerifyOrReturn(err == CHIP_NO_ERROR, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error subscribing to attribute", err)); + onSuccess.release(); onFailure.release(); } diff --git a/scripts/idl/tests/outputs/several_clusters/jni/ThirdClient-ReadImpl.cpp b/scripts/idl/tests/outputs/several_clusters/jni/ThirdClient-ReadImpl.cpp index a18afd78cffdb1..2cc8eb152609db 100644 --- a/scripts/idl/tests/outputs/several_clusters/jni/ThirdClient-ReadImpl.cpp +++ b/scripts/idl/tests/outputs/several_clusters/jni/ThirdClient-ReadImpl.cpp @@ -36,3 +36,27 @@ JNI_METHOD(void, ThirdCluster, readSomeEnumAttribute)(JNIEnv * env, jobject self } +JNI_METHOD(void, ThirdCluster, readOptionsAttribute)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback) +{ + chip::DeviceLayer::StackLock lock; + using TypeInfo = chip::app::Clusters::Third::Attributes::Options::TypeInfo; + std::unique_ptr onSuccess(chip::Platform::New(callback, false), chip::Platform::Delete); + VerifyOrReturn(onSuccess.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native success callback", CHIP_ERROR_NO_MEMORY)); + + std::unique_ptr onFailure(chip::Platform::New(callback), chip::Platform::Delete); + VerifyOrReturn(onFailure.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native failure callback", CHIP_ERROR_NO_MEMORY)); + + CHIP_ERROR err = CHIP_NO_ERROR; + chip::Controller::ThirdCluster * cppCluster = reinterpret_cast(clusterPtr); + VerifyOrReturn(cppCluster != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Could not get native cluster", CHIP_ERROR_INCORRECT_STATE)); + + auto successFn = chip::Callback::Callback::FromCancelable(onSuccess->Cancel()); + auto failureFn = chip::Callback::Callback::FromCancelable(onFailure->Cancel()); + err = cppCluster->ReadAttribute(onSuccess->mContext, successFn->mCall, failureFn->mCall); + VerifyOrReturn(err == CHIP_NO_ERROR, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error reading attribute", err)); + + onSuccess.release(); + onFailure.release(); +} + +