[neighbor-table] introduce core Iterator type (#13020)

This commit introduces `NeighborTable::Iterator` and
`NeighborTable::kIteratorInit` as core type aliases for
the public `otNeighborInfoIterator` and its initializer
`OT_NEIGHBOR_INFO_ITERATOR_INIT`.
This commit is contained in:
Abtin Keshavarzian
2026-04-30 16:31:08 -07:00
committed by GitHub
parent fe3594e4e6
commit e0650292e2
3 changed files with 21 additions and 9 deletions
+5 -5
View File
@@ -197,7 +197,7 @@ exit:
return neighbor;
}
Error NeighborTable::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, Neighbor::Info &aNeighInfo)
Error NeighborTable::GetNextNeighborInfo(Iterator &aIterator, Neighbor::Info &aNeighInfo)
{
Error error = kErrorNone;
int16_t index;
@@ -239,12 +239,12 @@ Error NeighborTable::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, Neig
aNeighInfo.SetFrom(*router);
aNeighInfo.mIsChild = false;
index++;
aIterator = static_cast<otNeighborInfoIterator>(-index);
aIterator = static_cast<Iterator>(-index);
ExitNow();
}
}
aIterator = static_cast<otNeighborInfoIterator>(-index);
aIterator = static_cast<Iterator>(-index);
error = kErrorNotFound;
exit:
@@ -255,11 +255,11 @@ exit:
#if OPENTHREAD_MTD
Error NeighborTable::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, Neighbor::Info &aNeighInfo)
Error NeighborTable::GetNextNeighborInfo(Iterator &aIterator, Neighbor::Info &aNeighInfo)
{
Error error = kErrorNotFound;
VerifyOrExit(aIterator == OT_NEIGHBOR_INFO_ITERATOR_INIT);
VerifyOrExit(aIterator == kIteratorInit);
aIterator++;
VerifyOrExit(Get<Mle::Mle>().GetParent().IsStateValid());
+14 -2
View File
@@ -63,6 +63,16 @@ public:
*/
typedef otNeighborTableEntryInfo EntryInfo;
/**
* Iterator used to iterate through neighbor table.
*/
typedef otNeighborInfoIterator Iterator;
/**
* Initializer value for `Iterator`.
*/
static constexpr Iterator kIteratorInit = OT_NEIGHBOR_INFO_ITERATOR_INIT;
/**
* Defines the constants used in `NeighborTable::Callback` to indicate whether a child or router
* neighbor is being added or removed.
@@ -196,13 +206,13 @@ public:
* the neighbor table.
*
* @param[in,out] aIterator A reference to the iterator context. To get the first neighbor entry
it should be set to OT_NEIGHBOR_INFO_ITERATOR_INIT.
it should be set to `kIteratorInit`.
* @param[out] aNeighInfo The neighbor information.
*
* @retval kErrorNone Successfully found the next neighbor entry in table.
* @retval kErrorNotFound No subsequent neighbor entry exists in the table.
*/
Error GetNextNeighborInfo(otNeighborInfoIterator &aIterator, Neighbor::Info &aNeighInfo);
Error GetNextNeighborInfo(Iterator &aIterator, Neighbor::Info &aNeighInfo);
/**
* Registers the "neighbor table changed" callback function.
@@ -234,6 +244,8 @@ private:
Callback mCallback;
};
DefineMapEnum(otNeighborTableEvent, NeighborTable::Event);
} // namespace ot
#endif // OT_CORE_THREAD_NEIGHBOR_TABLE_HPP_
+2 -2
View File
@@ -124,8 +124,8 @@ void LinkMetricsManager::Update(void)
// This method updates the Link Metrics Subject in the subject list. It adds new neighbors to the list.
void LinkMetricsManager::UpdateSubjects(void)
{
Neighbor::Info neighborInfo;
otNeighborInfoIterator iterator = OT_NEIGHBOR_INFO_ITERATOR_INIT;
Neighbor::Info neighborInfo;
NeighborTable::Iterator iterator = NeighborTable::kIteratorInit;
while (Get<NeighborTable>().GetNextNeighborInfo(iterator, neighborInfo) == kErrorNone)
{