mirror of
https://github.com/espressif/openthread.git
synced 2026-10-26 09:13:52 +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())
|
while (cur < GetTlvsEnd())
|
||||||
{
|
{
|
||||||
|
bool shouldRemove = false;
|
||||||
|
|
||||||
switch (cur->GetType())
|
switch (cur->GetType())
|
||||||
{
|
{
|
||||||
case NetworkDataTlv::kTypePrefix:
|
case NetworkDataTlv::kTypePrefix:
|
||||||
{
|
shouldRemove = RemoveTemporaryDataIn(*As<PrefixTlv>(cur));
|
||||||
PrefixTlv *prefix = As<PrefixTlv>(cur);
|
|
||||||
|
|
||||||
RemoveTemporaryDataIn(*prefix);
|
|
||||||
|
|
||||||
if (prefix->GetSubTlvsLength() == 0)
|
|
||||||
{
|
|
||||||
RemoveTlv(cur);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case NetworkDataTlv::kTypeService:
|
case NetworkDataTlv::kTypeService:
|
||||||
{
|
shouldRemove = RemoveTemporaryDataIn(*As<ServiceTlv>(cur));
|
||||||
ServiceTlv *service = As<ServiceTlv>(cur);
|
break;
|
||||||
|
|
||||||
RemoveTemporaryDataIn(*service);
|
|
||||||
|
|
||||||
if (service->GetSubTlvsLength() == 0)
|
|
||||||
{
|
|
||||||
RemoveTlv(cur);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
shouldRemove = !cur->IsStable();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
if (shouldRemove)
|
||||||
// remove temporary tlv
|
{
|
||||||
if (!cur->IsStable())
|
RemoveTlv(cur);
|
||||||
{
|
continue;
|
||||||
RemoveTlv(cur);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = cur->GetNext();
|
cur = cur->GetNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix)
|
bool MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix)
|
||||||
{
|
{
|
||||||
NetworkDataTlv *cur = aPrefix.GetSubTlvs();
|
NetworkDataTlv *cur = aPrefix.GetSubTlvs();
|
||||||
|
|
||||||
@@ -723,9 +703,11 @@ void MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix)
|
|||||||
aPrefix.SetSubTlvsLength(aPrefix.GetSubTlvsLength() - subTlvSize);
|
aPrefix.SetSubTlvsLength(aPrefix.GetSubTlvsLength() - subTlvSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (aPrefix.GetSubTlvsLength() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MutableNetworkData::RemoveTemporaryDataIn(ServiceTlv &aService)
|
bool MutableNetworkData::RemoveTemporaryDataIn(ServiceTlv &aService)
|
||||||
{
|
{
|
||||||
NetworkDataTlv *cur = aService.GetSubTlvs();
|
NetworkDataTlv *cur = aService.GetSubTlvs();
|
||||||
|
|
||||||
@@ -754,6 +736,8 @@ void MutableNetworkData::RemoveTemporaryDataIn(ServiceTlv &aService)
|
|||||||
aService.SetSubTlvsLength(aService.GetSubTlvsLength() - subTlvSize);
|
aService.SetSubTlvsLength(aService.GetSubTlvsLength() - subTlvSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (aService.GetSubTlvsLength() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkDataTlv *MutableNetworkData::AppendTlv(uint16_t aTlvSize)
|
NetworkDataTlv *MutableNetworkData::AppendTlv(uint16_t aTlvSize)
|
||||||
|
|||||||
@@ -769,8 +769,8 @@ protected:
|
|||||||
void RemoveTemporaryData(void);
|
void RemoveTemporaryData(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RemoveTemporaryDataIn(PrefixTlv &aPrefix);
|
bool RemoveTemporaryDataIn(PrefixTlv &aPrefix);
|
||||||
void RemoveTemporaryDataIn(ServiceTlv &aService);
|
bool RemoveTemporaryDataIn(ServiceTlv &aService);
|
||||||
|
|
||||||
uint8_t mSize;
|
uint8_t mSize;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user