From f22cddb9ee4edf44c5fa57d955f8188c5848d4d9 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Mon, 23 Jul 2018 22:14:23 +0800 Subject: [PATCH] [core] move border agent into thread_netif (#2893) --- src/core/api/commissioner_api.cpp | 4 ++-- src/core/common/instance.cpp | 3 --- src/core/common/instance.hpp | 8 +------- src/core/thread/mle.cpp | 4 ++-- src/core/thread/thread_netif.cpp | 3 +++ src/core/thread/thread_netif.hpp | 15 +++++++++++++++ 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/core/api/commissioner_api.cpp b/src/core/api/commissioner_api.cpp index 1aa11d0d4..9af9ddaaf 100644 --- a/src/core/api/commissioner_api.cpp +++ b/src/core/api/commissioner_api.cpp @@ -47,7 +47,7 @@ otError otCommissionerStart(otInstance *aInstance) Instance &instance = *static_cast(aInstance); #if OPENTHREAD_ENABLE_BORDER_AGENT - SuccessOrExit(error = instance.GetBorderAgent().Stop()); + SuccessOrExit(error = instance.Get().Stop()); #endif SuccessOrExit(error = instance.GetThreadNetif().GetCommissioner().Start()); exit: @@ -65,7 +65,7 @@ otError otCommissionerStop(otInstance *aInstance) SuccessOrExit(error = instance.GetThreadNetif().GetCommissioner().Stop()); #if OPENTHREAD_ENABLE_BORDER_AGENT - SuccessOrExit(error = instance.GetBorderAgent().Start()); + SuccessOrExit(error = instance.Get().Start()); #endif exit: #endif diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index 47a4142ab..2c7522d54 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -64,9 +64,6 @@ Instance::Instance(void) , mSettings(*this) , mIp6(*this) , mThreadNetif(*this) -#if OPENTHREAD_ENABLE_BORDER_AGENT - , mBorderAgent(*this) -#endif #if OPENTHREAD_ENABLE_APPLICATION_COAP , mApplicationCoap(*this) #endif diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index ef3c222f2..c68d0848f 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -366,9 +366,6 @@ public: */ MessagePool &GetMessagePool(void) { return mMessagePool; } -#if OPENTHREAD_ENABLE_BORDER_AGENT - MeshCoP::BorderAgent &GetBorderAgent(void) { return mBorderAgent; } -#endif #endif // OPENTHREAD_MTD || OPENTHREAD_FTD /** @@ -424,9 +421,6 @@ private: Ip6::Ip6 mIp6; ThreadNetif mThreadNetif; -#if OPENTHREAD_ENABLE_BORDER_AGENT - MeshCoP::BorderAgent mBorderAgent; -#endif #if OPENTHREAD_ENABLE_APPLICATION_COAP Coap::ApplicationCoap mApplicationCoap; @@ -651,7 +645,7 @@ template <> inline Utils::ChannelManager &Instance::Get(void) #if OPENTHREAD_ENABLE_BORDER_AGENT template <> inline MeshCoP::BorderAgent &Instance::Get(void) { - return mBorderAgent; + return GetThreadNetif().GetBorderAgent(); } #endif diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 06aa04727..6296a5c11 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -308,11 +308,11 @@ void Mle::SetRole(otDeviceRole aRole) // Start border agent if (aRole == OT_DEVICE_ROLE_ROUTER || aRole == OT_DEVICE_ROLE_LEADER || aRole == OT_DEVICE_ROLE_CHILD) { - SuccessOrExit(GetInstance().GetBorderAgent().Start()); + SuccessOrExit(GetInstance().Get().Start()); } else { - SuccessOrExit(GetInstance().GetBorderAgent().Stop()); + SuccessOrExit(GetInstance().Get().Stop()); } #endif diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 80be150b8..757fdd776 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -76,6 +76,9 @@ ThreadNetif::ThreadNetif(Instance &aInstance) , mNetworkDiagnostic(aInstance) #endif , mIsUp(false) +#if OPENTHREAD_ENABLE_BORDER_AGENT + , mBorderAgent(aInstance) +#endif #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD , mCommissioner(aInstance) #endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index d950e0004..49d392ecb 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -42,6 +42,9 @@ #include "coap/coap_secure.hpp" #include "mac/mac.hpp" +#if OPENTHREAD_ENABLE_BORDER_AGENT +#include "meshcop/border_agent.hpp" +#endif #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #include "meshcop/commissioner.hpp" #endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD @@ -319,6 +322,15 @@ public: */ AnnounceBeginServer &GetAnnounceBeginServer(void) { return mAnnounceBegin; } +#if OPENTHREAD_ENABLE_BORDER_AGENT + /** + * This method returns a reference to the border agent object. + * + * @returns A reference to the border agent object. + * + */ + MeshCoP::BorderAgent &GetBorderAgent(void) { return mBorderAgent; } +#endif #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD /** * This method returns a reference to the commissioner object. @@ -448,6 +460,9 @@ private: #endif // OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC bool mIsUp; +#if OPENTHREAD_ENABLE_BORDER_AGENT + MeshCoP::BorderAgent mBorderAgent; +#endif #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD MeshCoP::Commissioner mCommissioner; #endif // OPENTHREAD_ENABLE_COMMISSIONER