diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index bfffe29cb5010f..44aad058f9ee7f 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -28,6 +28,7 @@ #include #include +#include extern bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); @@ -1370,19 +1371,14 @@ bool InteractionModelEngine::HasActiveRead() }) == Loop::Break)); } -uint16_t InteractionModelEngine::GetMinSubscriptionsPerFabric() const +uint16_t InteractionModelEngine::GetMinGuaranteedSubscriptionsPerFabric() const { - uint8_t fabricCount = mpFabricTable->FabricCount(); - const size_t readHandlerPoolCapacity = GetReadHandlerPoolCapacityForSubscriptions(); - - if (fabricCount == 0) - { - return kMinSupportedSubscriptionsPerFabric; - } - - size_t perFabricSubscriptionCapacity = readHandlerPoolCapacity / fabricCount; - - return static_cast(perFabricSubscriptionCapacity); +#if CHIP_SYSTEM_CONFIG_POOL_USE_HEAP + return UINT16_MAX; +#else + return static_cast( + min(GetReadHandlerPoolCapacityForSubscriptions() / GetConfigMaxFabrics(), static_cast(UINT16_MAX))); +#endif } size_t InteractionModelEngine::GetNumDirtySubscriptions() const diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index c3a5248978d789..e5e414bc746a9f 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -87,8 +87,8 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, * Spec 8.5.1 A publisher SHALL always ensure that every fabric the node is commissioned into can create at least three * subscriptions to the publisher and that each subscription SHALL support at least 3 attribute/event paths. */ - static constexpr size_t kMinSupportedSubscriptionsPerFabric = 2; - static constexpr size_t kMinSupportedPathsPerSubscription = 2; + static constexpr size_t kMinSupportedSubscriptionsPerFabric = 3; + static constexpr size_t kMinSupportedPathsPerSubscription = 3; static constexpr size_t kMinSupportedPathsPerReadRequest = 9; static constexpr size_t kMinSupportedReadRequestsPerFabric = 1; static constexpr size_t kReadHandlerPoolSize = CHIP_IM_MAX_NUM_SUBSCRIPTIONS + CHIP_IM_MAX_NUM_READS; @@ -260,7 +260,13 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, */ bool TrimFabricForRead(FabricIndex aFabricIndex); - uint16_t GetMinSubscriptionsPerFabric() const; + /** + * Returns the minimal value of guaranteed subscriptions per fabic. UINT16_MAX will be returned if current app is configured to + * use heap for the object pools used by interaction model engine. + * + * @retval the minimal value of guaranteed subscriptions per fabic. + */ + uint16_t GetMinGuaranteedSubscriptionsPerFabric() const; #if CONFIG_BUILD_FOR_HOST_UNIT_TEST // diff --git a/src/app/clusters/basic/basic.cpp b/src/app/clusters/basic/basic.cpp index 7d628459b8cde6..7ee7d3890d306e 100644 --- a/src/app/clusters/basic/basic.cpp +++ b/src/app/clusters/basic/basic.cpp @@ -275,7 +275,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib constexpr uint16_t kMinCaseSessionsPerFabricMandatedBySpec = 3; capabilityMinima.caseSessionsPerFabric = kMinCaseSessionsPerFabricMandatedBySpec; - capabilityMinima.subscriptionsPerFabric = InteractionModelEngine::GetInstance()->GetMinSubscriptionsPerFabric(); + capabilityMinima.subscriptionsPerFabric = InteractionModelEngine::GetInstance()->GetMinGuaranteedSubscriptionsPerFabric(); status = aEncoder.Encode(capabilityMinima); break;