@@ -2277,32 +2277,26 @@ - (void)_removeCachedAttribute:(NSNumber *)attributeID fromCluster:(MTRClusterPa
2277
2277
[clusterData removeValueForAttribute:attributeID];
2278
2278
}
2279
2279
2280
- - (void)_createDataVersionFilterListFromDictionary:(NSDictionary<MTRClusterPath *, NSNumber *> *)dataVersions dataVersionFilterList:(DataVersionFilter **)dataVersionFilterList count:(size_t *)count sizeReduction:(size_t)sizeReduction
2280
+ - (void)_createDataVersionFilterListFromDictionary:(NSDictionary<MTRClusterPath *, NSNumber *> *)dataVersions dataVersionFilterList:(DataVersionFilter **)dataVersionFilterList count:(size_t *)count
2281
2281
{
2282
- size_t maxDataVersionFilterSize = dataVersions.count;
2282
+ size_t dataVersionFilterSize = dataVersions.count;
2283
2283
2284
2284
// Check if any filter list should be generated
2285
- if (!dataVersions.count || (maxDataVersionFilterSize <= sizeReduction) ) {
2285
+ if (dataVersionFilterSize == 0 ) {
2286
2286
*count = 0;
2287
2287
*dataVersionFilterList = nullptr;
2288
2288
return;
2289
2289
}
2290
- maxDataVersionFilterSize -= sizeReduction;
2291
2290
2292
- DataVersionFilter * dataVersionFilterArray = new DataVersionFilter[maxDataVersionFilterSize ];
2291
+ DataVersionFilter * dataVersionFilterArray = new DataVersionFilter[dataVersionFilterSize ];
2293
2292
size_t i = 0;
2294
2293
for (MTRClusterPath * path in dataVersions) {
2295
2294
NSNumber * dataVersionNumber = dataVersions[path];
2296
- if (dataVersionNumber) {
2297
- dataVersionFilterArray[i++] = DataVersionFilter(static_cast<chip::EndpointId>(path.endpoint.unsignedShortValue), static_cast<chip::ClusterId>(path.cluster.unsignedLongValue), static_cast<chip::DataVersion>(dataVersionNumber.unsignedLongValue));
2298
- }
2299
- if (i == maxDataVersionFilterSize) {
2300
- break;
2301
- }
2295
+ dataVersionFilterArray[i++] = DataVersionFilter(static_cast<chip::EndpointId>(path.endpoint.unsignedShortValue), static_cast<chip::ClusterId>(path.cluster.unsignedLongValue), static_cast<chip::DataVersion>(dataVersionNumber.unsignedLongValue));
2302
2296
}
2303
2297
2304
2298
*dataVersionFilterList = dataVersionFilterArray;
2305
- *count = maxDataVersionFilterSize ;
2299
+ *count = dataVersionFilterSize ;
2306
2300
}
2307
2301
2308
2302
- (void)_setupConnectivityMonitoring
@@ -2530,75 +2524,55 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason
2530
2524
auto readClient = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), exchangeManager,
2531
2525
clusterStateCache->GetBufferedCallback(), ReadClient::InteractionType::Subscribe);
2532
2526
2533
- // Subscribe with data version filter list and retry with smaller list if out of packet space
2534
- CHIP_ERROR err;
2535
- NSDictionary<MTRClusterPath *, NSNumber *> * dataVersions = [self _getCachedDataVersions];
2536
- size_t dataVersionFilterListSizeReduction = 0;
2537
- for (;;) {
2538
- // Wildcard endpoint, cluster, attribute, event.
2539
- auto attributePath = std::make_unique<AttributePathParams>();
2540
- auto eventPath = std::make_unique<EventPathParams>();
2541
- // We want to get event reports at the minInterval, not the maxInterval.
2542
- eventPath->mIsUrgentEvent = true;
2543
- ReadPrepareParams readParams(session.Value());
2544
-
2545
- readParams.mMinIntervalFloorSeconds = 0;
2546
- // Select a max interval based on the device's claimed idle sleep interval.
2547
- auto idleSleepInterval = std::chrono::duration_cast<System::Clock::Seconds32>(
2548
- session.Value()->GetRemoteMRPConfig().mIdleRetransTimeout);
2549
-
2550
- auto maxIntervalCeilingMin = System::Clock::Seconds32(MTR_DEVICE_SUBSCRIPTION_MAX_INTERVAL_MIN);
2551
- if (idleSleepInterval < maxIntervalCeilingMin) {
2552
- idleSleepInterval = maxIntervalCeilingMin;
2553
- }
2554
-
2555
- auto maxIntervalCeilingMax = System::Clock::Seconds32(MTR_DEVICE_SUBSCRIPTION_MAX_INTERVAL_MAX);
2556
- if (idleSleepInterval > maxIntervalCeilingMax) {
2557
- idleSleepInterval = maxIntervalCeilingMax;
2558
- }
2527
+ // Wildcard endpoint, cluster, attribute, event.
2528
+ auto attributePath = std::make_unique<AttributePathParams>();
2529
+ auto eventPath = std::make_unique<EventPathParams>();
2530
+ // We want to get event reports at the minInterval, not the maxInterval.
2531
+ eventPath->mIsUrgentEvent = true;
2532
+ ReadPrepareParams readParams(session.Value());
2533
+
2534
+ readParams.mMinIntervalFloorSeconds = 0;
2535
+ // Select a max interval based on the device's claimed idle sleep interval.
2536
+ auto idleSleepInterval = std::chrono::duration_cast<System::Clock::Seconds32>(
2537
+ session.Value()->GetRemoteMRPConfig().mIdleRetransTimeout);
2538
+
2539
+ auto maxIntervalCeilingMin = System::Clock::Seconds32(MTR_DEVICE_SUBSCRIPTION_MAX_INTERVAL_MIN);
2540
+ if (idleSleepInterval < maxIntervalCeilingMin) {
2541
+ idleSleepInterval = maxIntervalCeilingMin;
2542
+ }
2543
+
2544
+ auto maxIntervalCeilingMax = System::Clock::Seconds32(MTR_DEVICE_SUBSCRIPTION_MAX_INTERVAL_MAX);
2545
+ if (idleSleepInterval > maxIntervalCeilingMax) {
2546
+ idleSleepInterval = maxIntervalCeilingMax;
2547
+ }
2559
2548
#ifdef DEBUG
2560
- if (maxIntervalOverride.HasValue()) {
2561
- idleSleepInterval = maxIntervalOverride.Value();
2562
- }
2563
- #endif
2564
- readParams.mMaxIntervalCeilingSeconds = static_cast<uint16_t>(idleSleepInterval.count());
2565
-
2566
- readParams.mpAttributePathParamsList = attributePath.get();
2567
- readParams.mAttributePathParamsListSize = 1;
2568
- readParams.mpEventPathParamsList = eventPath.get();
2569
- readParams.mEventPathParamsListSize = 1;
2570
- readParams.mKeepSubscriptions = true;
2571
- readParams.mIsFabricFiltered = false;
2572
- size_t dataVersionFilterListSize = 0;
2573
- DataVersionFilter * dataVersionFilterList;
2574
- [self _createDataVersionFilterListFromDictionary:dataVersions dataVersionFilterList:&dataVersionFilterList count:&dataVersionFilterListSize sizeReduction:dataVersionFilterListSizeReduction];
2575
- readParams.mDataVersionFilterListSize = dataVersionFilterListSize;
2576
- readParams.mpDataVersionFilterList = dataVersionFilterList;
2577
- attributePath.release();
2578
- eventPath.release();
2579
-
2580
- // TODO: Change from local filter list generation to rehydrating ClusterStateCache ot take advantage of existing filter list sorting algorithm
2581
-
2582
- // SendAutoResubscribeRequest cleans up the params, even on failure.
2583
- err = readClient->SendAutoResubscribeRequest(std::move(readParams));
2584
- if (err == CHIP_NO_ERROR) {
2585
- break;
2586
- }
2587
-
2588
- // If error is not a "no memory" issue, then break and go through regular resubscribe logic
2589
- if (err != CHIP_ERROR_NO_MEMORY) {
2590
- break;
2591
- }
2592
-
2593
- // If "no memory" error is not caused by data version filter list, break as well
2594
- if (!dataVersionFilterListSize) {
2595
- break;
2596
- }
2597
-
2598
- // Now "no memory" could mean subscribe request packet space ran out. Reduce size and try again immediately
2599
- dataVersionFilterListSizeReduction++;
2549
+ if (maxIntervalOverride.HasValue()) {
2550
+ idleSleepInterval = maxIntervalOverride.Value();
2600
2551
}
2552
+ #endif
2553
+ readParams.mMaxIntervalCeilingSeconds = static_cast<uint16_t>(idleSleepInterval.count());
2554
+
2555
+ readParams.mpAttributePathParamsList = attributePath.get();
2556
+ readParams.mAttributePathParamsListSize = 1;
2557
+ readParams.mpEventPathParamsList = eventPath.get();
2558
+ readParams.mEventPathParamsListSize = 1;
2559
+ readParams.mKeepSubscriptions = true;
2560
+ readParams.mIsFabricFiltered = false;
2561
+
2562
+ // Subscribe with data version filter list from our cache.
2563
+ size_t dataVersionFilterListSize = 0;
2564
+ DataVersionFilter * dataVersionFilterList;
2565
+ [self _createDataVersionFilterListFromDictionary:[self _getCachedDataVersions] dataVersionFilterList:&dataVersionFilterList count:&dataVersionFilterListSize];
2566
+
2567
+ readParams.mDataVersionFilterListSize = dataVersionFilterListSize;
2568
+ readParams.mpDataVersionFilterList = dataVersionFilterList;
2569
+ attributePath.release();
2570
+ eventPath.release();
2571
+
2572
+ // TODO: Change from local filter list generation to rehydrating ClusterStateCache to take advantage of existing filter list sorting algorithm
2601
2573
2574
+ // SendAutoResubscribeRequest cleans up the params, even on failure.
2575
+ CHIP_ERROR err = readClient->SendAutoResubscribeRequest(std::move(readParams));
2602
2576
if (err != CHIP_NO_ERROR) {
2603
2577
NSError * error = [MTRError errorForCHIPErrorCode:err logContext:self];
2604
2578
MTR_LOG_ERROR("%@ SendAutoResubscribeRequest error %@", self, error);
@@ -2610,7 +2584,7 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason
2610
2584
return;
2611
2585
}
2612
2586
2613
- MTR_LOG("%@ Subscribe with data version list size %lu, reduced by %lu ", self, static_cast<unsigned long>(dataVersions.count), static_cast<unsigned long>(dataVersionFilterListSizeReduction ));
2587
+ MTR_LOG("%@ Subscribe with data version list size %lu", self, static_cast<unsigned long>(dataVersionFilterListSize ));
2614
2588
2615
2589
// Callback and ClusterStateCache and ReadClient will be deleted
2616
2590
// when OnDone is called.
0 commit comments