Skip to content

Commit

Permalink
Add a FabricTable API to get the next available fabric index.
Browse files Browse the repository at this point in the history
This can be used during controller startup to map the fabric index (which is
allocated to the controller partway through startup and then used immediately
for storage keys) to the controller instance being started.
  • Loading branch information
bzbarsky-apple committed Jul 30, 2023
1 parent 2a681e3 commit 8ea4d18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/credentials/FabricTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2080,4 +2080,19 @@ CHIP_ERROR FabricTable::GetFabricLabel(FabricIndex fabricIndex, CharSpan & outFa
return CHIP_NO_ERROR;
}

CHIP_ERROR FabricTable::GetNextFabricAdditionIndex(FabricIndex * nextIndex)
{
EnsureNextAvailableFabricIndexUpdated();
if (!mNextAvailableFabricIndex.HasValue())
{
return CHIP_ERROR_NO_MEMORY;
}

FabricIndex index = mNextAvailableFabricIndex.Value();
VerifyOrReturnError(IsValidFabricIndex(index), CHIP_ERROR_INVALID_FABRIC_INDEX);

*nextIndex = index;
return CHIP_NO_ERROR;
}

} // namespace chip
8 changes: 8 additions & 0 deletions src/credentials/FabricTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,14 @@ class DLL_EXPORT FabricTable
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
}

/**
* Get the fabric index that will be used for the next fabric that will be
* added. Returns error if no more fabrics can be added, otherwise writes
* the fabric index that will be used for the next addition into the
* outparam.
*/
CHIP_ERROR GetNextFabricAdditionIndex(FabricIndex * nextIndex);

private:
enum class StateFlags : uint16_t
{
Expand Down

0 comments on commit 8ea4d18

Please sign in to comment.