mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 01:17:46 +00:00
[bbr-local] simplify 'Add/RemoveService()' (#6130)
This commit updates `AddServcie()` and `RemoveService()` in `BackboneRouter::Local` class such that the methods themselves after adding/removing the service entry in local network data inform `NetworkData::Notifier` to send the update to leader. This helps simplify their use.
This commit is contained in:
committed by
Jonathan Hui
parent
1d03d71a20
commit
6a0acacaf7
@@ -75,16 +75,9 @@ otError otBackboneRouterSetConfig(otInstance *aInstance, const otBackboneRouterC
|
||||
|
||||
otError otBackboneRouterRegister(otInstance *aInstance)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
SuccessOrExit(error = instance.Get<BackboneRouter::Local>().AddService(true /* Force registration */));
|
||||
|
||||
instance.Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||
|
||||
exit:
|
||||
return error;
|
||||
return instance.Get<BackboneRouter::Local>().AddService(true /* Force registration */);
|
||||
}
|
||||
|
||||
uint8_t otBackboneRouterGetRegistrationJitter(otInstance *aInstance)
|
||||
|
||||
@@ -92,12 +92,10 @@ void Local::SetEnabled(bool aEnable)
|
||||
else
|
||||
{
|
||||
RemoveDomainPrefixFromNetworkData();
|
||||
IgnoreError(RemoveService());
|
||||
RemoveService();
|
||||
SetState(OT_BACKBONE_ROUTER_STATE_DISABLED);
|
||||
}
|
||||
|
||||
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
@@ -106,10 +104,7 @@ void Local::Reset(void)
|
||||
{
|
||||
VerifyOrExit(mState != OT_BACKBONE_ROUTER_STATE_DISABLED);
|
||||
|
||||
if (RemoveService() == OT_ERROR_NONE)
|
||||
{
|
||||
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||
}
|
||||
RemoveService();
|
||||
|
||||
if (mState == OT_BACKBONE_ROUTER_STATE_PRIMARY)
|
||||
{
|
||||
@@ -166,10 +161,7 @@ otError Local::SetConfig(const BackboneRouterConfig &aConfig)
|
||||
{
|
||||
Get<Notifier>().Signal(kEventThreadBackboneRouterLocalChanged);
|
||||
|
||||
if (AddService() == OT_ERROR_NONE)
|
||||
{
|
||||
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||
}
|
||||
IgnoreError(AddService());
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -200,13 +192,14 @@ otError Local::AddService(bool aForce)
|
||||
reinterpret_cast<const uint8_t *>(&serverData), sizeof(serverData)));
|
||||
|
||||
mIsServiceAdded = true;
|
||||
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||
|
||||
exit:
|
||||
LogBackboneRouterService("Add", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Local::RemoveService(void)
|
||||
void Local::RemoveService(void)
|
||||
{
|
||||
otError error;
|
||||
uint8_t serviceData = NetworkData::ServiceTlv::kServiceDataBackboneRouter;
|
||||
@@ -215,10 +208,10 @@ otError Local::RemoveService(void)
|
||||
&serviceData, sizeof(serviceData)));
|
||||
|
||||
mIsServiceAdded = false;
|
||||
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||
|
||||
exit:
|
||||
LogBackboneRouterService("Remove", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
void Local::SetState(BackboneRouterState aState)
|
||||
|
||||
@@ -239,10 +239,10 @@ public:
|
||||
void SetDomainPrefixCallback(otBackboneRouterDomainPrefixCallback aCallback, void *aContext);
|
||||
|
||||
private:
|
||||
void SetState(BackboneRouterState aState);
|
||||
otError RemoveService(void);
|
||||
void AddDomainPrefixToNetworkData(void);
|
||||
void RemoveDomainPrefixFromNetworkData(void);
|
||||
void SetState(BackboneRouterState aState);
|
||||
void RemoveService(void);
|
||||
void AddDomainPrefixToNetworkData(void);
|
||||
void RemoveDomainPrefixFromNetworkData(void);
|
||||
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1)
|
||||
void LogBackboneRouterService(const char *aAction, otError aError);
|
||||
void LogDomainPrefix(const char *aAction, otError aError);
|
||||
|
||||
Reference in New Issue
Block a user