From 1996d42d9d65e0e2b08cd7be048fda81d82225ab Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 13 Dec 2019 17:15:44 -0800 Subject: [PATCH] [mle] update Mle::GetParent() to return reference (#4419) --- src/core/api/thread_api.cpp | 10 +++------- src/core/mac/data_poll_sender.cpp | 2 +- src/core/thread/key_manager.cpp | 2 +- src/core/thread/mle.cpp | 5 ----- src/core/thread/mle.hpp | 6 +++--- src/core/utils/child_supervision.cpp | 2 +- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 835cb5229..478f32c55 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -311,7 +311,7 @@ otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) VerifyOrExit(instance.Get().GetRole() == OT_DEVICE_ROLE_CHILD, error = OT_ERROR_INVALID_STATE); #endif - parent = instance.Get().GetParent(); + parent = &instance.Get().GetParent(); aParentInfo->mExtAddress = parent->GetExtAddress(); aParentInfo->mRloc16 = parent->GetRloc16(); @@ -334,12 +334,10 @@ otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi) { otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - Router * parent; assert(aParentRssi != NULL); - parent = instance.Get().GetParent(); - *aParentRssi = parent->GetLinkInfo().GetAverageRss(); + *aParentRssi = instance.Get().GetParent().GetLinkInfo().GetAverageRss(); VerifyOrExit(*aParentRssi != OT_RADIO_RSSI_INVALID, error = OT_ERROR_FAILED); @@ -351,12 +349,10 @@ otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi) { otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - Router * parent; assert(aLastRssi != NULL); - parent = instance.Get().GetParent(); - *aLastRssi = parent->GetLinkInfo().GetLastRss(); + *aLastRssi = instance.Get().GetParent().GetLinkInfo().GetLastRss(); VerifyOrExit(*aLastRssi != OT_RADIO_RSSI_INVALID, error = OT_ERROR_FAILED); diff --git a/src/core/mac/data_poll_sender.cpp b/src/core/mac/data_poll_sender.cpp index fcb519832..189139bbc 100644 --- a/src/core/mac/data_poll_sender.cpp +++ b/src/core/mac/data_poll_sender.cpp @@ -138,7 +138,7 @@ otError DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_ABORT); - if ((Get().GetShortAddress() == Mac::kShortAddrInvalid) || (parent != Get().GetParent())) + if ((Get().GetShortAddress() == Mac::kShortAddrInvalid) || (parent != &Get().GetParent())) { aDest.SetExtended(parent->GetExtAddress()); } diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index 527c0efbe..97781a8db 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -119,7 +119,7 @@ otError KeyManager::SetMasterKey(const MasterKey &aKey) ComputeKey(mKeySequence, mKey); // reset parent frame counters - parent = Get().GetParent(); + parent = &Get().GetParent(); parent->SetKeySequence(0); parent->SetLinkFrameCounter(0); parent->SetMleFrameCounter(0); diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 4bfe4aa5e..f45fecaf5 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -3959,11 +3959,6 @@ bool Mle::IsMeshLocalAddress(const Ip6::Address &aAddress) const return aAddress.PrefixMatch(GetMeshLocal16()) >= Ip6::Address::kMeshLocalPrefixLength; } -Router *Mle::GetParent(void) -{ - return &mParent; -} - Router *Mle::GetParentCandidate(void) { Router *rval; diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index eaf101a9c..4230c9476 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -747,12 +747,12 @@ public: } /** - * This method returns a pointer to the parent when operating in End Device mode. + * This method gets the parent when operating in End Device mode. * - * @returns A pointer to the parent. + * @returns A reference to the parent. * */ - Router *GetParent(void); + Router &GetParent(void) { return mParent; } /** * This method returns a pointer to the parent candidate or parent. diff --git a/src/core/utils/child_supervision.cpp b/src/core/utils/child_supervision.cpp index e69efb5bc..522dfeb0f 100644 --- a/src/core/utils/child_supervision.cpp +++ b/src/core/utils/child_supervision.cpp @@ -209,7 +209,7 @@ void SupervisionListener::UpdateOnReceive(const Mac::Address &aSourceAddress, bo // If listener is enabled and device is a child and it received a secure frame from its parent, restart the timer. VerifyOrExit(mTimer.IsRunning() && aIsSecure && (Get().GetRole() == OT_DEVICE_ROLE_CHILD) && - (Get().GetNeighbor(aSourceAddress) == Get().GetParent())); + (Get().GetNeighbor(aSourceAddress) == &Get().GetParent())); RestartTimer();