[mle] reorganize Detacher methods (#11734)

This commit moves the `Detacher::Detach()` method implementation to
group it with other `Detacher` method definitions.

When the `Detacher` class was added in PR #11723, its methods were
intentionally kept in their original locations to keep the `git diff`
smaller and easier to review.

This is a pure code-move refactoring to improve code organization and
has no functional changes.
This commit is contained in:
Abtin Keshavarzian
2025-07-16 15:23:27 -07:00
committed by GitHub
parent 86590870d3
commit 3019d3c6c4
+45 -45
View File
@@ -4258,51 +4258,6 @@ exit:
}
#endif // OPENTHREAD_CONFIG_WAKEUP_COORDINATOR_ENABLE
Error Mle::Detacher::Detach(DetachCallback aCallback, void *aContext)
{
Error error = kErrorNone;
uint32_t timeout = kTimeout;
VerifyOrExit(mState == kIdle, error = kErrorBusy);
mCallback.Set(aCallback, aContext);
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
Get<BorderRouter::RoutingManager>().RequestStop();
#endif
switch (Get<Mle>().GetRole())
{
case kRoleLeader:
break;
case kRoleRouter:
#if OPENTHREAD_FTD
Get<Mle>().SendAddressRelease();
#endif
break;
case kRoleChild:
IgnoreError(Get<Mle>().SendChildUpdateRequestToParent(kAppendZeroTimeout));
break;
case kRoleDisabled:
case kRoleDetached:
// If device is already detached or disabled, we start the timer
// with zero duration to stop and invoke the callback when the
// timer fires, so the operation finishes immediately and
// asynchronously.
timeout = 0;
break;
}
mState = kDetaching;
mTimer.Start(timeout);
exit:
return error;
}
//---------------------------------------------------------------------------------------------------------------------
// TlvList
@@ -5386,6 +5341,51 @@ Mle::Detacher::Detacher(Instance &aInstance)
{
}
Error Mle::Detacher::Detach(DetachCallback aCallback, void *aContext)
{
Error error = kErrorNone;
uint32_t timeout = kTimeout;
VerifyOrExit(mState == kIdle, error = kErrorBusy);
mCallback.Set(aCallback, aContext);
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
Get<BorderRouter::RoutingManager>().RequestStop();
#endif
switch (Get<Mle>().GetRole())
{
case kRoleLeader:
break;
case kRoleRouter:
#if OPENTHREAD_FTD
Get<Mle>().SendAddressRelease();
#endif
break;
case kRoleChild:
IgnoreError(Get<Mle>().SendChildUpdateRequestToParent(kAppendZeroTimeout));
break;
case kRoleDisabled:
case kRoleDetached:
// If device is already detached or disabled, we start the timer
// with zero duration to stop and invoke the callback when the
// timer fires, so the operation finishes immediately and
// asynchronously.
timeout = 0;
break;
}
mState = kDetaching;
mTimer.Start(timeout);
exit:
return error;
}
void Mle::Detacher::HandleTimer(void)
{
if (mState == kDetaching)