Skip to content

Commit

Permalink
[IM] Update GetMinSubscriptionsPerFabric (#20207)
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing authored and pull[bot] committed Aug 23, 2022
1 parent f933501 commit 1101778
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
20 changes: 8 additions & 12 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <cinttypes>

#include <lib/core/CHIPTLVUtilities.hpp>
#include <lib/support/CodeUtils.h>

extern bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId);

Expand Down Expand Up @@ -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<uint16_t>(perFabricSubscriptionCapacity);
#if CHIP_SYSTEM_CONFIG_POOL_USE_HEAP
return UINT16_MAX;
#else
return static_cast<uint16_t>(
min(GetReadHandlerPoolCapacityForSubscriptions() / GetConfigMaxFabrics(), static_cast<size_t>(UINT16_MAX)));
#endif
}

size_t InteractionModelEngine::GetNumDirtySubscriptions() const
Expand Down
12 changes: 9 additions & 3 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
//
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/basic/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1101778

Please sign in to comment.