diff --git a/examples/tv-app/android/java/ChannelManager.cpp b/examples/tv-app/android/java/ChannelManager.cpp index 14d7509600b66f..d471bebf3075f6 100644 --- a/examples/tv-app/android/java/ChannelManager.cpp +++ b/examples/tv-app/android/java/ChannelManager.cpp @@ -60,7 +60,7 @@ CHIP_ERROR ChannelManager::HandleGetChannelList(AttributeValueEncoder & aEncoder CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleGetChannelList"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -137,7 +137,7 @@ CHIP_ERROR ChannelManager::HandleGetLineup(AttributeValueEncoder & aEncoder) CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleGetLineup"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -200,7 +200,7 @@ CHIP_ERROR ChannelManager::HandleGetCurrentChannel(AttributeValueEncoder & aEnco CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleGetCurrentChannel"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -275,7 +275,7 @@ void ChannelManager::HandleChangeChannel(CommandResponseHelper needToFreePrograms; std::vector needToFreeChannels; @@ -593,7 +593,7 @@ bool ChannelManager::HandleRecordProgram(const chip::CharSpan & programIdentifie jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleRecordProgram"); VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null")); @@ -630,7 +630,7 @@ bool ChannelManager::HandleCancelRecordProgram(const chip::CharSpan & programIde jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleCancelRecordProgram"); VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null")); diff --git a/examples/tv-app/android/java/ContentLauncherManager.cpp b/examples/tv-app/android/java/ContentLauncherManager.cpp index 936b053fa3eae1..aec5319a567f27 100644 --- a/examples/tv-app/android/java/ContentLauncherManager.cpp +++ b/examples/tv-app/android/java/ContentLauncherManager.cpp @@ -55,7 +55,7 @@ void ContentLauncherManager::HandleLaunchContent(CommandResponseHelper acceptedHeadersList; VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ContentLauncherManager::GetAcceptHeader"); VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -207,7 +207,7 @@ uint32_t ContentLauncherManager::HandleGetSupportedStreamingProtocols() JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); uint32_t supportedStreamingProtocols = 0; VerifyOrReturnValue(env != nullptr, 0, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ContentLauncherManager::GetSupportedStreamingProtocols"); VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); diff --git a/examples/tv-app/android/java/KeypadInputManager.cpp b/examples/tv-app/android/java/KeypadInputManager.cpp index 386c2aeeb98bc1..2b642a825b0bef 100644 --- a/examples/tv-app/android/java/KeypadInputManager.cpp +++ b/examples/tv-app/android/java/KeypadInputManager.cpp @@ -50,7 +50,7 @@ void KeypadInputManager::HandleSendKey(CommandResponseHelperNewGlobalRef(managerObject); VerifyOrReturn(mKeypadInputManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef KeypadInputManager")); diff --git a/examples/tv-app/android/java/LevelManager.cpp b/examples/tv-app/android/java/LevelManager.cpp index 0051c99b86c75d..cefb26ecfe325d 100644 --- a/examples/tv-app/android/java/LevelManager.cpp +++ b/examples/tv-app/android/java/LevelManager.cpp @@ -92,7 +92,7 @@ CHIP_ERROR LevelManager::InitializeWithObjects(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnLogError(env != nullptr, CHIP_ERROR_INCORRECT_STATE); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); mLevelManagerObject = env->NewGlobalRef(managerObject); VerifyOrReturnLogError(mLevelManagerObject != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -117,7 +117,7 @@ void LevelManager::HandleLevelChanged(uint8_t value) JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mLevelManagerObject != nullptr, ChipLogProgress(Zcl, "mLevelManagerObject null")); VerifyOrReturn(mHandleLevelChangedMethod != nullptr, ChipLogProgress(Zcl, "mHandleLevelChangedMethod null")); diff --git a/examples/tv-app/android/java/LowPowerManager.cpp b/examples/tv-app/android/java/LowPowerManager.cpp index d375bd3fc3e383..9b21a1ce872c31 100644 --- a/examples/tv-app/android/java/LowPowerManager.cpp +++ b/examples/tv-app/android/java/LowPowerManager.cpp @@ -46,7 +46,7 @@ void LowPowerManager::InitializeWithObjects(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for LowPowerManager")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); mLowPowerManagerObject = env->NewGlobalRef(managerObject); VerifyOrReturn(mLowPowerManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef LowPowerManager")); @@ -66,7 +66,7 @@ bool LowPowerManager::HandleSleep() { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received LowPowerManager::Sleep"); VerifyOrExit(mLowPowerManagerObject != nullptr, ChipLogError(Zcl, "mLowPowerManagerObject null")); diff --git a/examples/tv-app/android/java/MediaInputManager.cpp b/examples/tv-app/android/java/MediaInputManager.cpp index ca96d7df41ecaa..1c183c205c6628 100644 --- a/examples/tv-app/android/java/MediaInputManager.cpp +++ b/examples/tv-app/android/java/MediaInputManager.cpp @@ -54,7 +54,7 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetInputList"); VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -125,7 +125,7 @@ uint8_t MediaInputManager::HandleGetCurrentInput() jint index = -1; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, 0, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetCurrentInput"); VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -157,7 +157,7 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index) jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleSelectInput %d", index); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); @@ -182,7 +182,7 @@ bool MediaInputManager::HandleShowInputStatus() jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleShowInputStatus"); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); @@ -207,7 +207,7 @@ bool MediaInputManager::HandleHideInputStatus() jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleHideInputStatus"); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); @@ -233,7 +233,7 @@ bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharS jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleRenameInput %d to %s", index, name.data()); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); diff --git a/examples/tv-app/android/java/MediaPlaybackManager.cpp b/examples/tv-app/android/java/MediaPlaybackManager.cpp index 64843fd3a45e4f..52666e8da9bfda 100644 --- a/examples/tv-app/android/java/MediaPlaybackManager.cpp +++ b/examples/tv-app/android/java/MediaPlaybackManager.cpp @@ -105,7 +105,7 @@ CHIP_ERROR MediaPlaybackManager::HandleGetActiveTrack(bool audio, AttributeValue CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleGetActiveAudioTrack"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -173,7 +173,7 @@ CHIP_ERROR MediaPlaybackManager::HandleGetAvailableTracks(bool audio, AttributeV CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleGetAvailableAudioTracks"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -323,7 +323,7 @@ bool MediaPlaybackManager::HandleActivateTrack(bool audio, const chip::CharSpan CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleActivateAudioTrack"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -354,7 +354,7 @@ bool MediaPlaybackManager::HandleDeactivateTextTrack() CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleDeactivateTextTrack"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -443,7 +443,7 @@ uint64_t MediaPlaybackManager::HandleMediaRequestGetAttribute(MediaPlaybackReque CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, ret, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaPlaybackManager::HandleMediaRequestGetAttribute:%d", attribute); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -483,7 +483,7 @@ long MediaPlaybackManager::HandleMediaRequestGetLongAttribute(MediaPlaybackReque CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaPlaybackManager::HandleMediaRequestGetLongAttribute:%d", attribute); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -519,7 +519,7 @@ Commands::PlaybackResponse::Type MediaPlaybackManager::HandleMediaRequest(MediaP CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, response, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::Request %d-%ld", mediaPlaybackRequest, static_cast(deltaPositionMilliseconds)); @@ -558,7 +558,7 @@ CHIP_ERROR MediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncoder CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleGetSampledPosition"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); diff --git a/examples/tv-app/android/java/OnOffManager.cpp b/examples/tv-app/android/java/OnOffManager.cpp index 57ed3478b4cb3b..bf6796d4cb9542 100644 --- a/examples/tv-app/android/java/OnOffManager.cpp +++ b/examples/tv-app/android/java/OnOffManager.cpp @@ -92,7 +92,7 @@ CHIP_ERROR OnOffManager::InitializeWithObjects(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); mOnOffManagerObject = env->NewGlobalRef(managerObject); VerifyOrReturnLogError(mOnOffManagerObject != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -117,7 +117,7 @@ void OnOffManager::HandleOnOffChanged(bool value) JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mOnOffManagerObject != nullptr, ChipLogProgress(Zcl, "mOnOffManagerObject null")); VerifyOrReturn(mHandleOnOffChangedMethod != nullptr, ChipLogProgress(Zcl, "mHandleOnOffChangedMethod null")); diff --git a/examples/tv-app/android/java/WakeOnLanManager.cpp b/examples/tv-app/android/java/WakeOnLanManager.cpp index 3189bf98eb443f..7c1a08fd37877a 100644 --- a/examples/tv-app/android/java/WakeOnLanManager.cpp +++ b/examples/tv-app/android/java/WakeOnLanManager.cpp @@ -55,7 +55,7 @@ CHIP_ERROR WakeOnLanManager::HandleGetMacAddress(chip::app::AttributeValueEncode CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); chip::CharSpan macValue; ChipLogProgress(Zcl, "Received WakeOnLanManager::HandleGetMacAddress"); @@ -87,7 +87,7 @@ void WakeOnLanManager::InitializeWithObjects(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); mWakeOnLanManagerObject = env->NewGlobalRef(managerObject); VerifyOrReturn(mWakeOnLanManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef WakeOnLanManager")); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp index 566efbecfb5f1b..30c1e1d233c2cb 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp @@ -203,7 +203,7 @@ jobject CurrentStateSuccessHandlerJNI::ConvertToJObject( ChipLogProgress(AppServer, "CurrentStateSuccessHandlerJNI::ConvertToJObject called"); JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, nullptr); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jclass enumClass = nullptr; CHIP_ERROR err = @@ -254,7 +254,7 @@ jobject SampledPositionSuccessHandlerJNI::ConvertToJObject( ChipLogProgress(AppServer, "SampledPositionSuccessHandlerJNI::ConvertToJObject called"); JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, nullptr); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject jSampledPosition = nullptr; if (!responseData.IsNull()) @@ -323,7 +323,7 @@ jobject TargetListSuccessHandlerJNI::ConvertToJObject( JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, nullptr); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject jArrayList; chip::JniReferences::GetInstance().CreateArrayList(jArrayList); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayer-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayer-JNI.cpp index 2c0fe914232778..ba5a8e765908f1 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayer-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayer-JNI.cpp @@ -77,7 +77,7 @@ JNI_METHOD(jobject, VerifyOrEstablishConnection) JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(AppServer, "ConnectCallback, env == nullptr")); // Ensures proper cleanup of local references to Java objects. - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); // Ensures proper cleanup of global references to Java objects. JniGlobalRefWrapper globalRefWrapper(completableFutureObjGlobalRef); diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 6b800a2213a2fb..12be70af10e867 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -13,7 +13,6 @@ # limitations under the License. import("//build_overrides/chip.gni") -import("//build_overrides/nlio.gni") import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/src/lib/core/core.gni") import("${chip_root}/src/platform/device.gni") @@ -344,7 +343,6 @@ static_library("app") { "${chip_root}/src/messaging", "${chip_root}/src/protocols/interaction_model", "${chip_root}/src/system", - "${nlio_root}:nlio", ] if (chip_enable_read_client) { diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 300e934a3674c4..98cb6ff156a653 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -57,7 +57,7 @@ using Protocols::InteractionModel::Status; Global sInteractionModelEngine; -InteractionModelEngine::InteractionModelEngine() {} +InteractionModelEngine::InteractionModelEngine() : mReportingEngine(this) {} InteractionModelEngine * InteractionModelEngine::GetInstance() { diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index 4b89cab1ff7a4a..8ed201a0d934e6 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -407,6 +407,8 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, ReadHandler::ApplicationCallback * GetAppCallback() override { return mpReadHandlerApplicationCallback; } + InteractionModelEngine * GetInteractionModelEngine() override { return this; } + CHIP_ERROR OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader, ExchangeDelegate *& newDelegate) override; /** diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index df8516dd17a30e..bd63503a10493f 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -68,7 +68,7 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Messaging::ExchangeCon mInteractionType = aInteractionType; mLastWrittenEventsBytes = 0; - mTransactionStartGeneration = InteractionModelEngine::GetInstance()->GetReportingEngine().GetDirtySetGeneration(); + mTransactionStartGeneration = mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().GetDirtySetGeneration(); mFlags.ClearAll(); SetStateFlag(ReadHandlerFlags::PrimingReports); @@ -102,7 +102,7 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, for (size_t i = 0; i < resumptionSessionEstablisher.mSubscriptionInfo.mAttributePaths.AllocatedSize(); i++) { AttributePathParams params = resumptionSessionEstablisher.mSubscriptionInfo.mAttributePaths[i].GetParams(); - CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, params); + CHIP_ERROR err = mManagementCallback.GetInteractionModelEngine()->PushFrontAttributePathList(mpAttributePathList, params); if (err != CHIP_NO_ERROR) { Close(); @@ -112,7 +112,7 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, for (size_t i = 0; i < resumptionSessionEstablisher.mSubscriptionInfo.mEventPaths.AllocatedSize(); i++) { EventPathParams params = resumptionSessionEstablisher.mSubscriptionInfo.mEventPaths[i].GetParams(); - CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, params); + CHIP_ERROR err = mManagementCallback.GetInteractionModelEngine()->PushFrontEventPathParamsList(mpEventPathList, params); if (err != CHIP_NO_ERROR) { Close(); @@ -137,7 +137,7 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, ObjectList * attributePath = mpAttributePathList; while (attributePath) { - InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(attributePath->mValue); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().SetDirty(attributePath->mValue); attributePath = attributePath->mpNext; } } @@ -156,11 +156,11 @@ ReadHandler::~ReadHandler() if (IsAwaitingReportResponse()) { - InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm(); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().OnReportConfirm(); } - InteractionModelEngine::GetInstance()->ReleaseAttributePathList(mpAttributePathList); - InteractionModelEngine::GetInstance()->ReleaseEventPathList(mpEventPathList); - InteractionModelEngine::GetInstance()->ReleaseDataVersionFilterList(mpDataVersionFilterList); + mManagementCallback.GetInteractionModelEngine()->ReleaseAttributePathList(mpAttributePathList); + mManagementCallback.GetInteractionModelEngine()->ReleaseEventPathList(mpEventPathList); + mManagementCallback.GetInteractionModelEngine()->ReleaseDataVersionFilterList(mpDataVersionFilterList); } void ReadHandler::Close(CloseOptions options) @@ -168,7 +168,7 @@ void ReadHandler::Close(CloseOptions options) #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS if (IsType(InteractionType::Subscribe) && options == CloseOptions::kDropPersistedSubscription) { - auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); + auto * subscriptionResumptionStorage = mManagementCallback.GetInteractionModelEngine()->GetSubscriptionResumptionStorage(); if (subscriptionResumptionStorage) { subscriptionResumptionStorage->Delete(GetInitiatorNodeId(), GetAccessingFabricIndex(), mSubscriptionId); @@ -285,7 +285,8 @@ CHIP_ERROR ReadHandler::SendStatusReport(Protocols::InteractionModel::Status aSt #if CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE auto exchange = mExchangeMgr->NewContext(mSessionHandle.Get().Value(), this); #else // CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE - auto exchange = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); + auto exchange = + mManagementCallback.GetInteractionModelEngine()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); #endif // CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE VerifyOrReturnLogError(exchange != nullptr, CHIP_ERROR_INCORRECT_STATE); mExchangeCtx.Grab(exchange); @@ -310,7 +311,8 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b #if CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE auto exchange = mExchangeMgr->NewContext(mSessionHandle.Get().Value(), this); #else // CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE - auto exchange = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); + auto exchange = + mManagementCallback.GetInteractionModelEngine()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); #endif // CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE VerifyOrReturnLogError(exchange != nullptr, CHIP_ERROR_INCORRECT_STATE); mExchangeCtx.Grab(exchange); @@ -320,7 +322,8 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b if (!IsReporting()) { - mCurrentReportsBeginGeneration = InteractionModelEngine::GetInstance()->GetReportingEngine().GetDirtySetGeneration(); + mCurrentReportsBeginGeneration = + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().GetDirtySetGeneration(); } SetStateFlag(ReadHandlerFlags::ChunkedReport, aMoreChunks); bool responseExpected = IsType(InteractionType::Subscribe) || aMoreChunks; @@ -339,7 +342,7 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b { // Make sure we're not treated as an in-flight report waiting for a // response by the reporting engine. - InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm(); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().OnReportConfirm(); } // If we just finished a non-priming subscription report, notify our observers. @@ -353,7 +356,7 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b { mPreviousReportsBeginGeneration = mCurrentReportsBeginGeneration; ClearForceDirtyFlag(); - InteractionModelEngine::GetInstance()->ReleaseDataVersionFilterList(mpDataVersionFilterList); + mManagementCallback.GetInteractionModelEngine()->ReleaseDataVersionFilterList(mpDataVersionFilterList); } return err; @@ -489,12 +492,13 @@ CHIP_ERROR ReadHandler::ProcessAttributePaths(AttributePathIBs::Parser & aAttrib AttributePathIB::Parser path; ReturnErrorOnFailure(path.Init(reader)); ReturnErrorOnFailure(path.ParsePath(attribute)); - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, attribute)); + ReturnErrorOnFailure( + mManagementCallback.GetInteractionModelEngine()->PushFrontAttributePathList(mpAttributePathList, attribute)); } // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - InteractionModelEngine::GetInstance()->RemoveDuplicateConcreteAttributePath(mpAttributePathList); + mManagementCallback.GetInteractionModelEngine()->RemoveDuplicateConcreteAttributePath(mpAttributePathList); mAttributePathExpandIterator = AttributePathExpandIterator(mpAttributePathList); err = CHIP_NO_ERROR; } @@ -521,8 +525,8 @@ CHIP_ERROR ReadHandler::ProcessDataVersionFilterList(DataVersionFilterIBs::Parse ReturnErrorOnFailure(path.GetEndpoint(&(versionFilter.mEndpointId))); ReturnErrorOnFailure(path.GetCluster(&(versionFilter.mClusterId))); VerifyOrReturnError(versionFilter.IsValidDataVersionFilter(), CHIP_ERROR_IM_MALFORMED_DATA_VERSION_FILTER_IB); - ReturnErrorOnFailure( - InteractionModelEngine::GetInstance()->PushFrontDataVersionFilterList(mpDataVersionFilterList, versionFilter)); + ReturnErrorOnFailure(mManagementCallback.GetInteractionModelEngine()->PushFrontDataVersionFilterList( + mpDataVersionFilterList, versionFilter)); } if (CHIP_END_OF_TLV == err) @@ -544,7 +548,7 @@ CHIP_ERROR ReadHandler::ProcessEventPaths(EventPathIBs::Parser & aEventPathsPars EventPathIB::Parser path; ReturnErrorOnFailure(path.Init(reader)); ReturnErrorOnFailure(path.ParsePath(event)); - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, event)); + ReturnErrorOnFailure(mManagementCallback.GetInteractionModelEngine()->PushFrontEventPathParamsList(mpEventPathList, event)); } // if we have exhausted this container @@ -604,7 +608,7 @@ void ReadHandler::MoveToState(const HandlerState aTargetState) if (IsAwaitingReportResponse() && aTargetState != HandlerState::AwaitingReportResponse) { - InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm(); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().OnReportConfirm(); } mState = aTargetState; @@ -618,7 +622,7 @@ void ReadHandler::MoveToState(const HandlerState aTargetState) { if (ShouldReportUnscheduled()) { - InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun(); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().ScheduleRun(); } else { @@ -814,7 +818,7 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP void ReadHandler::PersistSubscription() { - auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); + auto * subscriptionResumptionStorage = mManagementCallback.GetInteractionModelEngine()->GetSubscriptionResumptionStorage(); VerifyOrReturn(subscriptionResumptionStorage != nullptr); SubscriptionResumptionStorage::SubscriptionInfo subscriptionInfo = { .mNodeId = GetInitiatorNodeId(), @@ -843,7 +847,7 @@ void ReadHandler::AttributePathIsDirty(const AttributePathParams & aAttributeCha { ConcreteAttributePath path; - mDirtyGeneration = InteractionModelEngine::GetInstance()->GetReportingEngine().GetDirtySetGeneration(); + mDirtyGeneration = mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().GetDirtySetGeneration(); // We won't reset the path iterator for every AttributePathIsDirty call to reduce the number of full data reports. // The iterator will be reset after finishing each report session. diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index 28097868c2f79a..d602273a8611a9 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -153,6 +153,11 @@ class ReadHandler : public Messaging::ExchangeDelegate * issues w.r.t the ReadHandler itself. */ virtual ApplicationCallback * GetAppCallback() = 0; + + /* + * Retrieve the InteractionalModelEngine that holds this ReadHandler. + */ + virtual InteractionModelEngine * GetInteractionModelEngine() = 0; }; // TODO (#27675) : Merge existing callback and observer into one class and have an observer pool in the Readhandler to notify diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 2530ec7eff59ae..80dec7ed6d3cd1 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -38,6 +38,9 @@ using namespace chip::Access; namespace chip { namespace app { namespace reporting { + +Engine::Engine(InteractionModelEngine * apImEngine) : mpImEngine(apImEngine) {} + CHIP_ERROR Engine::Init() { mNumReportsInFlight = 0; @@ -616,7 +619,7 @@ CHIP_ERROR Engine::ScheduleRun() return CHIP_NO_ERROR; } - Messaging::ExchangeManager * exchangeManager = InteractionModelEngine::GetInstance()->GetExchangeManager(); + Messaging::ExchangeManager * exchangeManager = mpImEngine->GetExchangeManager(); if (exchangeManager == nullptr) { return CHIP_ERROR_INCORRECT_STATE; @@ -640,17 +643,16 @@ void Engine::Run() { uint32_t numReadHandled = 0; - InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance(); - // We may be deallocating read handlers as we go. Track how many we had // initially, so we make sure to go through all of them. - size_t initialAllocated = imEngine->mReadHandlers.Allocated(); + size_t initialAllocated = mpImEngine->mReadHandlers.Allocated(); while ((mNumReportsInFlight < CHIP_IM_MAX_REPORTS_IN_FLIGHT) && (numReadHandled < initialAllocated)) { - ReadHandler * readHandler = imEngine->ActiveHandlerAt(mCurReadHandlerIdx % (uint32_t) imEngine->mReadHandlers.Allocated()); + ReadHandler * readHandler = + mpImEngine->ActiveHandlerAt(mCurReadHandlerIdx % (uint32_t) mpImEngine->mReadHandlers.Allocated()); VerifyOrDie(readHandler != nullptr); - if (readHandler->ShouldReportUnscheduled() || imEngine->GetReportScheduler()->IsReportableNow(readHandler)) + if (readHandler->ShouldReportUnscheduled() || mpImEngine->GetReportScheduler()->IsReportableNow(readHandler)) { mRunningReadHandler = readHandler; @@ -674,14 +676,14 @@ void Engine::Run() // This isn't strictly necessary, but does make it easier to debug issues in this code if they // do arise. // - if (mCurReadHandlerIdx >= imEngine->mReadHandlers.Allocated()) + if (mCurReadHandlerIdx >= mpImEngine->mReadHandlers.Allocated()) { mCurReadHandlerIdx = 0; } bool allReadClean = true; - imEngine->mReadHandlers.ForEachActiveObject([&allReadClean](ReadHandler * handler) { + mpImEngine->mReadHandlers.ForEachActiveObject([&allReadClean](ReadHandler * handler) { if (handler->IsDirty()) { allReadClean = false; @@ -839,26 +841,25 @@ CHIP_ERROR Engine::SetDirty(AttributePathParams & aAttributePath) BumpDirtySetGeneration(); bool intersectsInterestPath = false; - InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject( - [&aAttributePath, &intersectsInterestPath](ReadHandler * handler) { - // We call AttributePathIsDirty for both read interactions and subscribe interactions, since we may send inconsistent - // attribute data between two chunks. AttributePathIsDirty will not schedule a new run for read handlers which are - // waiting for a response to the last message chunk for read interactions. - if (handler->CanStartReporting() || handler->IsAwaitingReportResponse()) + mpImEngine->mReadHandlers.ForEachActiveObject([&aAttributePath, &intersectsInterestPath](ReadHandler * handler) { + // We call AttributePathIsDirty for both read interactions and subscribe interactions, since we may send inconsistent + // attribute data between two chunks. AttributePathIsDirty will not schedule a new run for read handlers which are + // waiting for a response to the last message chunk for read interactions. + if (handler->CanStartReporting() || handler->IsAwaitingReportResponse()) + { + for (auto object = handler->GetAttributePathList(); object != nullptr; object = object->mpNext) { - for (auto object = handler->GetAttributePathList(); object != nullptr; object = object->mpNext) + if (object->mValue.Intersects(aAttributePath)) { - if (object->mValue.Intersects(aAttributePath)) - { - handler->AttributePathIsDirty(aAttributePath); - intersectsInterestPath = true; - break; - } + handler->AttributePathIsDirty(aAttributePath); + intersectsInterestPath = true; + break; } } + } - return Loop::Continue; - }); + return Loop::Continue; + }); if (!intersectsInterestPath) { @@ -899,7 +900,7 @@ void Engine::OnReportConfirm() void Engine::GetMinEventLogPosition(uint32_t & aMinLogPosition) { - InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([&aMinLogPosition](ReadHandler * handler) { + mpImEngine->mReadHandlers.ForEachActiveObject([&aMinLogPosition](ReadHandler * handler) { if (handler->IsType(ReadHandler::InteractionType::Read)) { return Loop::Continue; @@ -934,13 +935,13 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBy // we don't need to call schedule run for event. // If schedule run is called, actually we would not delivery events as well. // Just wanna save one schedule run here - if (InteractionModelEngine::GetInstance()->mEventPathPool.Allocated() == 0) + if (mpImEngine->mEventPathPool.Allocated() == 0) { return CHIP_NO_ERROR; } bool isUrgentEvent = false; - InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([&aPath, &isUrgentEvent](ReadHandler * handler) { + mpImEngine->mReadHandlers.ForEachActiveObject([&aPath, &isUrgentEvent](ReadHandler * handler) { if (handler->IsType(ReadHandler::InteractionType::Read)) { return Loop::Continue; @@ -971,7 +972,7 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBy void Engine::ScheduleUrgentEventDeliverySync(Optional fabricIndex) { - InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([fabricIndex](ReadHandler * handler) { + mpImEngine->mReadHandlers.ForEachActiveObject([fabricIndex](ReadHandler * handler) { if (handler->IsType(ReadHandler::InteractionType::Read)) { return Loop::Continue; diff --git a/src/app/reporting/Engine.h b/src/app/reporting/Engine.h index 5a8638185549f3..01115b96d6f1a7 100644 --- a/src/app/reporting/Engine.h +++ b/src/app/reporting/Engine.h @@ -25,6 +25,7 @@ #pragma once #include +#include #include #include #include @@ -56,6 +57,11 @@ namespace reporting { class Engine { public: + /** + * Constructor Engine with a valid InteractionModelEngine pointer. + */ + Engine(InteractionModelEngine * apImEngine); + /** * Initializes the reporting engine. Should only be called once. * @@ -279,6 +285,8 @@ class Engine uint32_t mReservedSize = 0; uint32_t mMaxAttributesPerChunk = UINT32_MAX; #endif + + InteractionModelEngine * mpImEngine = nullptr; }; }; // namespace reporting diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 4f26604542b118..9e8bc58e5d87da 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -285,6 +285,10 @@ class NullReadHandlerCallback : public chip::app::ReadHandler::ManagementCallbac public: void OnDone(chip::app::ReadHandler & apReadHandlerObj) override {} chip::app::ReadHandler::ApplicationCallback * GetAppCallback() override { return nullptr; } + chip::app::InteractionModelEngine * GetInteractionModelEngine() override + { + return chip::app::InteractionModelEngine::GetInstance(); + } }; } // namespace diff --git a/src/app/tests/TestReportScheduler.cpp b/src/app/tests/TestReportScheduler.cpp index af6f367af8ccc6..5219943136847d 100644 --- a/src/app/tests/TestReportScheduler.cpp +++ b/src/app/tests/TestReportScheduler.cpp @@ -34,6 +34,10 @@ class NullReadHandlerCallback : public chip::app::ReadHandler::ManagementCallbac public: void OnDone(chip::app::ReadHandler & apReadHandlerObj) override {} chip::app::ReadHandler::ApplicationCallback * GetAppCallback() override { return nullptr; } + chip::app::InteractionModelEngine * GetInteractionModelEngine() override + { + return chip::app::InteractionModelEngine::GetInstance(); + } }; } // namespace diff --git a/src/app/tests/TestReportingEngine.cpp b/src/app/tests/TestReportingEngine.cpp index 5a198455dfe579..618a2e892e789b 100644 --- a/src/app/tests/TestReportingEngine.cpp +++ b/src/app/tests/TestReportingEngine.cpp @@ -120,6 +120,10 @@ class DummyDelegate : public ReadHandler::ManagementCallback public: void OnDone(ReadHandler & apHandler) override {} chip::app::ReadHandler::ApplicationCallback * GetAppCallback() override { return nullptr; } + chip::app::InteractionModelEngine * GetInteractionModelEngine() override + { + return chip::app::InteractionModelEngine::GetInstance(); + } }; void TestReportingEngine::TestBuildAndSendSingleReportData(nlTestSuite * apSuite, void * apContext) diff --git a/src/controller/java/AndroidCallbacks.cpp b/src/controller/java/AndroidCallbacks.cpp index 2a275f7394a125..f4f62b6b0ec4c7 100644 --- a/src/controller/java/AndroidCallbacks.cpp +++ b/src/controller/java/AndroidCallbacks.cpp @@ -91,7 +91,7 @@ void GetConnectedDeviceCallback::OnDeviceConnectedFn(void * context, Messaging:: VerifyOrReturn(self->mJavaCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mJavaCallbackRef is not valid in %s", __func__)); jobject javaCallback = self->mJavaCallbackRef.ObjectRef(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); // Release wrapper's global ref so application can clean up the actual callback underneath. VerifyOrReturn(self->mWrapperCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mWrapperCallbackRef is not valid in %s", __func__)); @@ -124,7 +124,7 @@ void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, VerifyOrReturn(self->mJavaCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mJavaCallbackRef is not valid in %s", __func__)); jobject javaCallback = self->mJavaCallbackRef.ObjectRef(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jclass getConnectedDeviceCallbackCls = nullptr; JniReferences::GetInstance().GetLocalClassRef( @@ -185,7 +185,7 @@ void ReportCallback::OnReportBegin() { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jclass nodeStateCls = nullptr; CHIP_ERROR err = JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/model/NodeState", nodeStateCls); VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Could not get NodeState class")); @@ -229,7 +229,7 @@ void ReportCallback::OnReportEnd() CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mReportCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mReportCallbackRef is not valid in %s", __func__)); jobject reportCallback = mReportCallbackRef.ObjectRef(); @@ -276,7 +276,7 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject attributePathObj = nullptr; err = CreateChipAttributePath(env, aPath, attributePathObj); @@ -562,7 +562,7 @@ void ReportCallback::OnDone(app::ReadClient *) CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mWrapperCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mWrapperCallbackRef is not valid in %s", __func__)); JniGlobalReference globalRef(std::move(mWrapperCallbackRef)); @@ -588,7 +588,7 @@ void ReportCallback::OnSubscriptionEstablished(SubscriptionId aSubscriptionId) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); DeviceLayer::StackUnlock unlock; VerifyOrReturn(mSubscriptionEstablishedCallbackRef.HasValidObjectRef(), ChipLogError(Controller, " mSubscriptionEstablishedCallbackRef is not valid in %s", __func__)); @@ -600,7 +600,7 @@ CHIP_ERROR ReportCallback::OnResubscriptionNeeded(app::ReadClient * apReadClient JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT); ReturnErrorOnFailure(app::ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause)); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jmethodID onResubscriptionAttemptMethod; VerifyOrReturnLogError(mResubscriptionAttemptCallbackRef.HasValidObjectRef(), CHIP_ERROR_INCORRECT_STATE); jobject resubscriptionAttemptCallbackRef = mResubscriptionAttemptCallbackRef.ObjectRef(); @@ -631,7 +631,7 @@ void ReportCallback::ReportError(jobject attributePath, jobject eventPath, const CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mReportCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mReportCallbackRef is not valid in %s", __func__)); jobject reportCallback = mReportCallbackRef.ObjectRef(); @@ -674,7 +674,7 @@ void WriteAttributesCallback::OnResponse(const app::WriteClient * apWriteClient, CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject attributePathObj = nullptr; err = CreateChipAttributePath(env, aPath, attributePathObj); @@ -708,7 +708,7 @@ void WriteAttributesCallback::OnDone(app::WriteClient *) CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mWrapperCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mWrapperCallbackRef is not valid in %s", __func__)); JniGlobalReference globalRef(std::move(mWrapperCallbackRef)); @@ -738,7 +738,7 @@ void WriteAttributesCallback::ReportError(jobject attributePath, const char * me CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogError(Controller, "WriteAttributesCallback::ReportError is called with %u", errorCode); jthrowable exception; err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, message, errorCode, exception); @@ -782,7 +782,7 @@ void InvokeCallback::OnResponse(app::CommandSender * apCommandSender, const app: VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); jobject invokeElementObj = nullptr; jmethodID onResponseMethod; - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); err = CreateInvokeElement(env, aPath, apData, invokeElementObj); VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to create Java InvokeElement: %s", ErrorStr(err))); VerifyOrReturn(mJavaCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mJavaCallbackRef is not valid in %s", __func__)); @@ -814,7 +814,7 @@ void InvokeCallback::OnDone(app::CommandSender * apCommandSender) CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mWrapperCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mWrapperCallbackRef is not valid in %s", __func__)); JniGlobalReference globalRef(std::move(mWrapperCallbackRef)); @@ -844,7 +844,7 @@ void InvokeCallback::ReportError(const char * message, ChipError::StorageType er CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogError(Controller, "InvokeCallback::ReportError is called with %u", errorCode); jthrowable exception; err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, message, errorCode, exception); diff --git a/src/controller/java/AndroidCommissioningWindowOpener.cpp b/src/controller/java/AndroidCommissioningWindowOpener.cpp index 222edcb441f9c8..0429c72bf12ad5 100644 --- a/src/controller/java/AndroidCommissioningWindowOpener.cpp +++ b/src/controller/java/AndroidCommissioningWindowOpener.cpp @@ -121,7 +121,7 @@ void AndroidCommissioningWindowOpener::OnOpenCommissioningWindowResponse(void * auto * self = static_cast(context); JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrExit(self->mJavaCallback != nullptr, ChipLogError(Controller, "mJavaCallback is not allocated.")); @@ -160,7 +160,7 @@ void AndroidCommissioningWindowOpener::OnOpenBasicCommissioningWindowResponse(vo { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); if (status == CHIP_NO_ERROR) { if (self->mOnSuccessMethod != nullptr) diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index a29dd5c5043976..29f055560527d6 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -716,7 +716,7 @@ void AndroidDeviceControllerWrapper::OnCommissioningStatusUpdate(PeerId peerId, chip::DeviceLayer::StackUnlock unlock; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jmethodID onCommissioningStatusUpdateMethod; CHIP_ERROR err = JniReferences::GetInstance().FindMethod(env, mJavaObjectRef, "onCommissioningStatusUpdate", "(JLjava/lang/String;I)V", &onCommissioningStatusUpdateMethod); @@ -754,7 +754,7 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( jmethodID javaMethod; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); @@ -970,7 +970,7 @@ void AndroidDeviceControllerWrapper::OnICDRegistrationComplete(chip::NodeId icdN JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jmethodID onICDRegistrationCompleteMethod; jclass icdDeviceInfoClass = nullptr; jmethodID icdDeviceInfoStructCtor = nullptr; diff --git a/src/controller/java/AndroidOperationalCredentialsIssuer.cpp b/src/controller/java/AndroidOperationalCredentialsIssuer.cpp index 99ef1893325ecf..f63f1a46ecbbe3 100644 --- a/src/controller/java/AndroidOperationalCredentialsIssuer.cpp +++ b/src/controller/java/AndroidOperationalCredentialsIssuer.cpp @@ -129,7 +129,7 @@ CHIP_ERROR AndroidOperationalCredentialsIssuer::GenerateNOCChain(const ByteSpan { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_ERROR_INCORRECT_STATE); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); if (mUseJavaCallbackForNOCRequest) { diff --git a/src/controller/java/AttestationTrustStoreBridge.cpp b/src/controller/java/AttestationTrustStoreBridge.cpp index 90c4e4cb840f3b..056c87c4d1b464 100644 --- a/src/controller/java/AttestationTrustStoreBridge.cpp +++ b/src/controller/java/AttestationTrustStoreBridge.cpp @@ -71,7 +71,7 @@ CHIP_ERROR AttestationTrustStoreBridge::GetPaaCertFromJava(const chip::ByteSpan JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_ERROR_INCORRECT_STATE); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/AttestationTrustStoreDelegate", attestationTrustStoreDelegateCls); diff --git a/src/controller/java/BdxOTASender.cpp b/src/controller/java/BdxOTASender.cpp index 41f116762f9f8b..119789ce4ad8b9 100644 --- a/src/controller/java/BdxOTASender.cpp +++ b/src/controller/java/BdxOTASender.cpp @@ -179,7 +179,7 @@ CHIP_ERROR BdxOTASender::OnTransferSessionBegin(TransferSession::OutputEvent & e JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); UtfString fileDesignator(env, fileDesignatorSpan); uint64_t offset = mTransfer.GetStartOffset(); @@ -269,7 +269,7 @@ CHIP_ERROR BdxOTASender::OnBlockQuery(TransferSession::OutputEvent & event) JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jmethodID handleBDXQueryMethod; CHIP_ERROR err = JniReferences::GetInstance().FindMethod( env, mOtaDelegate, "handleBDXQuery", "(JIJJ)Lchip/devicecontroller/OTAProviderDelegate$BDXData;", &handleBDXQueryMethod); diff --git a/src/controller/java/CHIPDefaultCallbacks.cpp b/src/controller/java/CHIPDefaultCallbacks.cpp index 5adfb002a789b4..4600c5c9877a14 100644 --- a/src/controller/java/CHIPDefaultCallbacks.cpp +++ b/src/controller/java/CHIPDefaultCallbacks.cpp @@ -104,7 +104,7 @@ void chip::CHIPDefaultFailureCallback::CallbackFn(void * context, CHIP_ERROR err jmethodID javaMethod; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject javaCallbackRef; jthrowable exception; diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index e24ec5297f3119..b32c207fcf92f9 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -2180,7 +2180,7 @@ JNI_METHOD(jobject, getICDClientInfo)(JNIEnv * env, jobject self, jlong handle, jmethodID constructor; jclass infoClass; - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); err = JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ICDClientInfo", infoClass); VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr, diff --git a/src/controller/java/DeviceAttestationDelegateBridge.cpp b/src/controller/java/DeviceAttestationDelegateBridge.cpp index 2e1b1ba2b1f54f..5c695da3b4f9bb 100644 --- a/src/controller/java/DeviceAttestationDelegateBridge.cpp +++ b/src/controller/java/DeviceAttestationDelegateBridge.cpp @@ -72,7 +72,7 @@ void DeviceAttestationDelegateBridge::OnDeviceAttestationCompleted( { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jclass deviceAttestationDelegateCls = nullptr; JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/DeviceAttestationDelegate", deviceAttestationDelegateCls); diff --git a/src/controller/java/OTAProviderDelegateBridge.cpp b/src/controller/java/OTAProviderDelegateBridge.cpp index 85b259f288572e..10f9ae12801558 100644 --- a/src/controller/java/OTAProviderDelegateBridge.cpp +++ b/src/controller/java/OTAProviderDelegateBridge.cpp @@ -110,7 +110,7 @@ void OTAProviderDelegateBridge::HandleQueryImage(CommandHandler * commandObj, co JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - chip::JniLocalReferenceManager manager(env); + chip::JniLocalReferenceScope scope(env); jobject otaProviderDelegate = nullptr; jmethodID handleQueryImageMethod = nullptr; @@ -375,7 +375,7 @@ void OTAProviderDelegateBridge::HandleApplyUpdateRequest(CommandHandler * comman jmethodID getActionMethod; jmethodID getDelayedActionTimeMethod; - chip::JniLocalReferenceManager manager(env); + chip::JniLocalReferenceScope scope(env); Commands::ApplyUpdateResponse::Type response; Commands::ApplyUpdateResponse::Type errorResponse; diff --git a/src/lib/support/JniTypeWrappers.h b/src/lib/support/JniTypeWrappers.h index 6a70b1e04f8b5d..f2f040e93d8e9e 100644 --- a/src/lib/support/JniTypeWrappers.h +++ b/src/lib/support/JniTypeWrappers.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2024 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. @@ -183,10 +183,10 @@ class JniGlobalRefWrapper jobject mGlobalRef = nullptr; }; -class JniLocalReferenceManager +class JniLocalReferenceScope { public: - explicit JniLocalReferenceManager(JNIEnv * env) : mEnv(env) + explicit JniLocalReferenceScope(JNIEnv * env) : mEnv(env) { if (mEnv->PushLocalFrame(JNI_LOCAL_REF_COUNT) == 0) { @@ -194,7 +194,7 @@ class JniLocalReferenceManager } } - ~JniLocalReferenceManager() + ~JniLocalReferenceScope() { if (mlocalFramePushed) { @@ -204,8 +204,8 @@ class JniLocalReferenceManager } // Delete copy constructor and copy assignment operator - JniLocalReferenceManager(const JniLocalReferenceManager &) = delete; - JniLocalReferenceManager & operator=(const JniLocalReferenceManager &) = delete; + JniLocalReferenceScope(const JniLocalReferenceScope &) = delete; + JniLocalReferenceScope & operator=(const JniLocalReferenceScope &) = delete; private: JNIEnv * const mEnv; diff --git a/src/platform/android/DiagnosticDataProviderImpl.cpp b/src/platform/android/DiagnosticDataProviderImpl.cpp index 0be3480d8e6beb..9be5c59a2fbe16 100644 --- a/src/platform/android/DiagnosticDataProviderImpl.cpp +++ b/src/platform/android/DiagnosticDataProviderImpl.cpp @@ -99,7 +99,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(DeviceLayer, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrExit(mDiagnosticDataProviderManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(mGetNifMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); {