@@ -121,7 +121,7 @@ void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, con
121
121
122
122
ReportCallback::ReportCallback (jobject wrapperCallback, jobject subscriptionEstablishedCallback, jobject reportCallback,
123
123
jobject resubscriptionAttemptCallback) :
124
- mBufferedReadAdapter (*this )
124
+ mClusterCacheAdapter (*this )
125
125
{
126
126
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
127
127
VerifyOrReturn (env != nullptr , ChipLogError (Controller, " Could not get JNIEnv for current thread" ));
@@ -186,6 +186,8 @@ void ReportCallback::OnReportBegin()
186
186
187
187
void ReportCallback::OnReportEnd ()
188
188
{
189
+ UpdateClusterDataVersion ();
190
+
189
191
// Transform C++ jobject pair list to a Java HashMap, and call onReport() on the Java callback.
190
192
CHIP_ERROR err = CHIP_NO_ERROR;
191
193
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
@@ -280,7 +282,43 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat
280
282
VerifyOrReturn (err == CHIP_NO_ERROR, ChipLogError (Controller, " Could not find addAttribute method" ));
281
283
env->CallVoidMethod (mNodeStateObj , addAttributeMethod, static_cast <jint>(aPath.mEndpointId ),
282
284
static_cast <jlong>(aPath.mClusterId ), static_cast <jlong>(aPath.mAttributeId ), attributeStateObj);
283
- VerifyOrReturnError (!env->ExceptionCheck (), env->ExceptionDescribe ());
285
+ VerifyOrReturn (!env->ExceptionCheck (), env->ExceptionDescribe ());
286
+
287
+ UpdateClusterDataVersion ();
288
+ }
289
+
290
+ void ReportCallback::UpdateClusterDataVersion ()
291
+ {
292
+ JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
293
+ chip::app::ConcreteClusterPath lastConcreteClusterPath;
294
+
295
+ if (mClusterCacheAdapter .GetLastReportDataPath (lastConcreteClusterPath) != CHIP_NO_ERROR)
296
+ {
297
+ return ;
298
+ }
299
+
300
+ if (!lastConcreteClusterPath.IsValidConcreteClusterPath ())
301
+ {
302
+ return ;
303
+ }
304
+
305
+ chip::Optional<chip::DataVersion> committedDataVersion;
306
+ if (mClusterCacheAdapter .GetVersion (lastConcreteClusterPath, committedDataVersion) != CHIP_NO_ERROR)
307
+ {
308
+ return ;
309
+ }
310
+ if (!committedDataVersion.HasValue ())
311
+ {
312
+ return ;
313
+ }
314
+
315
+ // SetDataVersion to NodeState
316
+ jmethodID setDataVersionMethod;
317
+ CHIP_ERROR err = JniReferences::GetInstance ().FindMethod (env, mNodeStateObj , " setDataVersion" , " (IJI)V" , &setDataVersionMethod);
318
+ VerifyOrReturn (err == CHIP_NO_ERROR, ChipLogError (Controller, " Could not find setDataVersion method" ));
319
+ env->CallVoidMethod (mNodeStateObj , setDataVersionMethod, static_cast <jint>(lastConcreteClusterPath.mEndpointId ),
320
+ static_cast <jlong>(lastConcreteClusterPath.mClusterId ), static_cast <jint>(committedDataVersion.Value ()));
321
+ VerifyOrReturn (!env->ExceptionCheck (), env->ExceptionDescribe ());
284
322
}
285
323
286
324
void ReportCallback::OnEventData (const app::EventHeader & aEventHeader, TLV::TLVReader * apData, const app::StatusIB * apStatus)
@@ -356,7 +394,7 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV
356
394
env->CallVoidMethod (mNodeStateObj , addEventMethod, static_cast <jint>(aEventHeader.mPath .mEndpointId ),
357
395
static_cast <jlong>(aEventHeader.mPath .mClusterId ), static_cast <jlong>(aEventHeader.mPath .mEventId ),
358
396
eventStateObj);
359
- VerifyOrReturnError (!env->ExceptionCheck (), env->ExceptionDescribe ());
397
+ VerifyOrReturn (!env->ExceptionCheck (), env->ExceptionDescribe ());
360
398
}
361
399
362
400
CHIP_ERROR ReportCallback::CreateChipAttributePath (const app::ConcreteDataAttributePath & aPath, jobject & outObj)
@@ -628,7 +666,7 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV
628
666
env->CallVoidMethod (mNodeStateObj , addEventMethod, static_cast <jint>(aEventHeader.mPath .mEndpointId ),
629
667
static_cast <jlong>(aEventHeader.mPath .mClusterId ), static_cast <jlong>(aEventHeader.mPath .mEventId ),
630
668
eventStateObj);
631
- VerifyOrReturnError (!env->ExceptionCheck (), env->ExceptionDescribe ());
669
+ VerifyOrReturn (!env->ExceptionCheck (), env->ExceptionDescribe ());
632
670
}
633
671
634
672
CHIP_ERROR ReportEventCallback::CreateChipEventPath (const app::ConcreteEventPath & aPath, jobject & outObj)
0 commit comments