From 3019d3c6c4438d2d9cbf7035c3f0d3a4885f8a63 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 16 Jul 2025 15:23:27 -0700 Subject: [PATCH] [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. --- src/core/thread/mle.cpp | 90 ++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 50ba28953..9e36bc222 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -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().RequestStop(); -#endif - - switch (Get().GetRole()) - { - case kRoleLeader: - break; - - case kRoleRouter: -#if OPENTHREAD_FTD - Get().SendAddressRelease(); -#endif - break; - - case kRoleChild: - IgnoreError(Get().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().RequestStop(); +#endif + + switch (Get().GetRole()) + { + case kRoleLeader: + break; + + case kRoleRouter: +#if OPENTHREAD_FTD + Get().SendAddressRelease(); +#endif + break; + + case kRoleChild: + IgnoreError(Get().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)