mirror of
https://github.com/espressif/openthread.git
synced 2026-09-24 09:57:38 +00:00
[netata] simplify RemoveTemporaryData() (#9975)
This commit simplifies `MutableNetworkData::RemoveTemporaryData()`: - The `RemoveTemporaryDataIn()` methods return a `bool` indicating whether the whole TLV can be removed. - The code is refactored to combine the call to `RemoveTlv()` for all TLV types.
This commit is contained in:
@@ -615,54 +615,34 @@ void MutableNetworkData::RemoveTemporaryData(void)
|
||||
|
||||
while (cur < GetTlvsEnd())
|
||||
{
|
||||
bool shouldRemove = false;
|
||||
|
||||
switch (cur->GetType())
|
||||
{
|
||||
case NetworkDataTlv::kTypePrefix:
|
||||
{
|
||||
PrefixTlv *prefix = As<PrefixTlv>(cur);
|
||||
|
||||
RemoveTemporaryDataIn(*prefix);
|
||||
|
||||
if (prefix->GetSubTlvsLength() == 0)
|
||||
{
|
||||
RemoveTlv(cur);
|
||||
continue;
|
||||
}
|
||||
|
||||
shouldRemove = RemoveTemporaryDataIn(*As<PrefixTlv>(cur));
|
||||
break;
|
||||
}
|
||||
|
||||
case NetworkDataTlv::kTypeService:
|
||||
{
|
||||
ServiceTlv *service = As<ServiceTlv>(cur);
|
||||
|
||||
RemoveTemporaryDataIn(*service);
|
||||
|
||||
if (service->GetSubTlvsLength() == 0)
|
||||
{
|
||||
RemoveTlv(cur);
|
||||
continue;
|
||||
}
|
||||
shouldRemove = RemoveTemporaryDataIn(*As<ServiceTlv>(cur));
|
||||
break;
|
||||
|
||||
default:
|
||||
shouldRemove = !cur->IsStable();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// remove temporary tlv
|
||||
if (!cur->IsStable())
|
||||
{
|
||||
RemoveTlv(cur);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
if (shouldRemove)
|
||||
{
|
||||
RemoveTlv(cur);
|
||||
continue;
|
||||
}
|
||||
|
||||
cur = cur->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
void MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix)
|
||||
bool MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix)
|
||||
{
|
||||
NetworkDataTlv *cur = aPrefix.GetSubTlvs();
|
||||
|
||||
@@ -723,9 +703,11 @@ void MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix)
|
||||
aPrefix.SetSubTlvsLength(aPrefix.GetSubTlvsLength() - subTlvSize);
|
||||
}
|
||||
}
|
||||
|
||||
return (aPrefix.GetSubTlvsLength() == 0);
|
||||
}
|
||||
|
||||
void MutableNetworkData::RemoveTemporaryDataIn(ServiceTlv &aService)
|
||||
bool MutableNetworkData::RemoveTemporaryDataIn(ServiceTlv &aService)
|
||||
{
|
||||
NetworkDataTlv *cur = aService.GetSubTlvs();
|
||||
|
||||
@@ -754,6 +736,8 @@ void MutableNetworkData::RemoveTemporaryDataIn(ServiceTlv &aService)
|
||||
aService.SetSubTlvsLength(aService.GetSubTlvsLength() - subTlvSize);
|
||||
}
|
||||
}
|
||||
|
||||
return (aService.GetSubTlvsLength() == 0);
|
||||
}
|
||||
|
||||
NetworkDataTlv *MutableNetworkData::AppendTlv(uint16_t aTlvSize)
|
||||
|
||||
@@ -769,8 +769,8 @@ protected:
|
||||
void RemoveTemporaryData(void);
|
||||
|
||||
private:
|
||||
void RemoveTemporaryDataIn(PrefixTlv &aPrefix);
|
||||
void RemoveTemporaryDataIn(ServiceTlv &aService);
|
||||
bool RemoveTemporaryDataIn(PrefixTlv &aPrefix);
|
||||
bool RemoveTemporaryDataIn(ServiceTlv &aService);
|
||||
|
||||
uint8_t mSize;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user