Skip to content

Commit 3c77c52

Browse files
authored
[mlr] extract registration criteria into ShouldRegister() helper (openthread#13073)
This commit introduces a new private helper method, `ShouldRegister()`, to the `Manager` class. This method consolidates the checks required to determine if the device should perform MLR.
1 parent 129afad commit 3c77c52

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/core/thread/mlr_manager.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,28 @@ void Manager::UpdateTimeTickerRegistration(void)
209209
}
210210
}
211211

212+
bool Manager::ShouldRegister(void) const
213+
{
214+
bool shouldRegister = false;
215+
216+
VerifyOrExit(Get<Mle::Mle>().IsFullThreadDevice() || Get<Mle::Mle>().GetParent().IsThreadVersion1p1());
217+
VerifyOrExit(Get<BackboneRouter::Leader>().HasPrimary());
218+
219+
shouldRegister = true;
220+
221+
exit:
222+
return shouldRegister;
223+
}
224+
212225
void Manager::Send(void)
213226
{
214227
Error error;
215228
AddressArray addresses;
216229

217230
VerifyOrExit(!mPending, error = kErrorBusy);
231+
218232
VerifyOrExit(Get<Mle::Mle>().IsAttached(), error = kErrorInvalidState);
219-
VerifyOrExit(Get<Mle::Mle>().IsFullThreadDevice() || Get<Mle::Mle>().GetParent().IsThreadVersion1p1(),
220-
error = kErrorInvalidState);
221-
VerifyOrExit(Get<BackboneRouter::Leader>().HasPrimary(), error = kErrorInvalidState);
233+
VerifyOrExit(ShouldRegister(), error = kErrorInvalidState);
222234

223235
#if OPENTHREAD_CONFIG_MLR_ENABLE
224236
// Append Netif multicast addresses
@@ -568,8 +580,7 @@ void Manager::Reregister(void)
568580

569581
void Manager::UpdateReregistrationDelay(bool aRereg)
570582
{
571-
bool needSend = (Get<Mle::Mle>().IsFullThreadDevice() || Get<Mle::Mle>().GetParent().IsThreadVersion1p1()) &&
572-
Get<BackboneRouter::Leader>().HasPrimary();
583+
bool needSend = ShouldRegister();
573584

574585
if (!needSend)
575586
{

src/core/thread/mlr_manager.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ class Manager : public InstanceLocator, private NonCopyable
150150
void AddUnique(const Ip6::Address &aAddress);
151151
};
152152

153-
void HandleNotifierEvents(Events aEvents);
154-
153+
void HandleNotifierEvents(Events aEvents);
154+
bool ShouldRegister(void) const;
155155
void Send(void);
156156
Error SendMessage(const Ip6::Address *aAddresses,
157157
uint8_t aAddressNum,

0 commit comments

Comments
 (0)