diff --git a/src/core/api/instance_api.cpp b/src/core/api/instance_api.cpp index f87d8cac5..53c41404a 100644 --- a/src/core/api/instance_api.cpp +++ b/src/core/api/instance_api.cpp @@ -87,7 +87,7 @@ otInstance::otInstance(void) : mTimerMicroScheduler(*this), #endif mIp6(*this), - mThreadNetif(mIp6), + mThreadNetif(*this), #if OPENTHREAD_ENABLE_RAW_LINK_API mLinkRaw(*this), #endif // OPENTHREAD_ENABLE_RAW_LINK_API diff --git a/src/core/coap/coap.cpp b/src/core/coap/coap.cpp index 1703f2de6..6e04532b5 100644 --- a/src/core/coap/coap.cpp +++ b/src/core/coap/coap.cpp @@ -48,15 +48,15 @@ namespace ot { namespace Coap { -CoapBase::CoapBase(ThreadNetif &aNetif, Timer::Handler aRetransmissionTimerHandler, +CoapBase::CoapBase(otInstance &aInstance, Timer::Handler aRetransmissionTimerHandler, Timer::Handler aResponsesQueueTimerHandler): - ThreadNetifLocator(aNetif), - mSocket(aNetif.GetIp6().mUdp), - mRetransmissionTimer(aNetif.GetInstance(), aRetransmissionTimerHandler, this), + InstanceLocator(aInstance), + mSocket(aInstance.mThreadNetif.GetIp6().mUdp), + mRetransmissionTimer(aInstance, aRetransmissionTimerHandler, this), mResources(NULL), mContext(NULL), mInterceptor(NULL), - mResponsesQueue(aNetif.GetInstance(), aResponsesQueueTimerHandler, this), + mResponsesQueue(aInstance, aResponsesQueueTimerHandler, this), mDefaultHandler(NULL), mDefaultHandlerContext(NULL) { @@ -911,8 +911,8 @@ uint32_t EnqueuedResponseHeader::GetRemainingTime(void) const return remainingTime >= 0 ? static_cast(remainingTime) : 0; } -Coap::Coap(ThreadNetif &aNetif): - CoapBase(aNetif, &Coap::HandleRetransmissionTimer, &Coap::HandleResponsesQueueTimer) +Coap::Coap(otInstance &aInstance): + CoapBase(aInstance, &Coap::HandleRetransmissionTimer, &Coap::HandleResponsesQueueTimer) { } @@ -940,8 +940,7 @@ void Coap::HandleResponsesQueueTimer(Timer &aTimer) #if OPENTHREAD_ENABLE_APPLICATION_COAP ApplicationCoap::ApplicationCoap(otInstance &aInstance): - CoapBase(aInstance.mThreadNetif, &ApplicationCoap::HandleRetransmissionTimer, - &ApplicationCoap::HandleResponsesQueueTimer) + CoapBase(aInstance, &ApplicationCoap::HandleRetransmissionTimer, &ApplicationCoap::HandleResponsesQueueTimer) { } diff --git a/src/core/coap/coap.hpp b/src/core/coap/coap.hpp index dbb8a7bea..3cfddba11 100644 --- a/src/core/coap/coap.hpp +++ b/src/core/coap/coap.hpp @@ -430,7 +430,7 @@ private: * This class implements the common base for CoAP client and server. * */ -class CoapBase: public ThreadNetifLocator +class CoapBase: public InstanceLocator { friend class ResponsesQueue; @@ -651,12 +651,12 @@ protected: /** * This constructor initializes the object. * - * @param[in] aNetif A reference to the Netif object. + * @param[in] aInstance A reference to the OpenThread instance. * @param[in] aRetransmissionTimerHandler A timer handler provided by sub-class for `mRetranmissionTimer`. * @param[in] aResponsesQueueTimerHandler A timer handler provided by sub-class for `mReponsesQueue` timer. * */ - CoapBase(ThreadNetif &aNetif, Timer::Handler aRetransmissionTimerHandler, + CoapBase(otInstance &aInstance, Timer::Handler aRetransmissionTimerHandler, Timer::Handler aResponsesQueueTimerHandler); /** @@ -744,10 +744,10 @@ public: /** * This constructor initializes the object. * - * @param[in] aNetif A reference to the Netif object. + * @param[in] aInstance A reference to the OpenThread instance. * */ - Coap(ThreadNetif &aNetif); + Coap(otInstance &aInstance); private: static Coap &GetOwner(const Context &aContext); @@ -767,7 +767,7 @@ public: /** * This constructor initializes the object. * - * @param[in] aNetif A reference to the otInstance + * @param[in] aInstance A reference to the OpenThread instance. * */ ApplicationCoap(otInstance &aInstance); diff --git a/src/core/coap/coap_secure.cpp b/src/core/coap/coap_secure.cpp index 64d469766..5404b70df 100644 --- a/src/core/coap/coap_secure.cpp +++ b/src/core/coap/coap_secure.cpp @@ -45,14 +45,14 @@ namespace ot { namespace Coap { -CoapSecure::CoapSecure(ThreadNetif &aNetif): - CoapBase(aNetif, &CoapSecure::HandleRetransmissionTimer, &CoapSecure::HandleResponsesQueueTimer), +CoapSecure::CoapSecure(otInstance &aInstance): + CoapBase(aInstance, &CoapSecure::HandleRetransmissionTimer, &CoapSecure::HandleResponsesQueueTimer), mConnectedCallback(NULL), mConnectedContext(NULL), mTransportCallback(NULL), mTransportContext(NULL), mTransmitMessage(NULL), - mTransmitTask(aNetif.GetInstance(), &CoapSecure::HandleUdpTransmit, this) + mTransmitTask(aInstance, &CoapSecure::HandleUdpTransmit, this) { } diff --git a/src/core/coap/coap_secure.hpp b/src/core/coap/coap_secure.hpp index 25360d67e..0f897b6b6 100644 --- a/src/core/coap/coap_secure.hpp +++ b/src/core/coap/coap_secure.hpp @@ -70,10 +70,10 @@ public: /** * This constructor initializes the object. * - * @param[in] aNetif A reference to the network interface that the secure CoAP agent is bound to. + * @param[in] aInstance A reference to the OpenThread instance. * */ - CoapSecure(ThreadNetif &aNetif); + CoapSecure(otInstance &aInstance); /** * This method starts the secure CoAP agent. diff --git a/src/core/common/locator.cpp b/src/core/common/locator.cpp index c96b23e0d..5317cdb68 100644 --- a/src/core/common/locator.cpp +++ b/src/core/common/locator.cpp @@ -40,23 +40,14 @@ namespace ot { -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - -otInstance &ThreadNetifLocator::GetInstance(void) const +Ip6::Ip6 &InstanceLocator::GetIp6(void) const { - return *otInstanceFromThreadNetif(&GetNetif()); + return GetInstance().mIp6; } -otInstance &MeshForwarderLocator::GetInstance(void) const +ThreadNetif &InstanceLocator::GetNetif(void) const { - return *otInstanceFromThreadNetif(&GetMeshForwarder().GetNetif()); + return GetInstance().mThreadNetif; } -otInstance &Ip6Locator::GetInstance(void) const -{ - return *otInstanceFromIp6(&GetIp6()); -} - -#endif // #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - } // namespace ot diff --git a/src/core/common/locator.hpp b/src/core/common/locator.hpp index 641835edf..4a27fc800 100644 --- a/src/core/common/locator.hpp +++ b/src/core/common/locator.hpp @@ -43,175 +43,24 @@ namespace ot { class ThreadNetif; -class MeshForwarder; -class TaskletScheduler; namespace Ip6 { class Ip6; } /** * @addtogroup core-locator * * @brief - * This module includes definitions for locator base class for OpenThread objects. + * This module includes definitions for OpenThread instance locator. * * @{ * */ -/** - * This template class implements the base locator for OpenThread objects. - * - */ -template -class Locator -{ -protected: - /** - * This constructor initializes the locator. - * - * @param[in] aObject A reference to the object. - * - */ - Locator(Type &aObject) -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - : mLocatorObject(aObject) -#endif - { - OT_UNUSED_VARIABLE(aObject); - } - -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - Type &mLocatorObject; -#endif -}; /** - * This class implements a locator for ThreadNetif object. + * This class implements locator for otInstance object. * */ -class ThreadNetifLocator: private Locator -{ -public: - /** - * This method returns a reference to the thread network interface. - * - * @returns A reference to the thread network interface. - * - */ -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - ThreadNetif &GetNetif(void) const { return mLocatorObject; } -#else - ThreadNetif &GetNetif(void) const { return otGetThreadNetif(); } -#endif - - /** - * This method returns the reference to the parent otInstance structure. - * - * @returns A reference to the parent otInstance structure. - * - */ -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - otInstance &GetInstance(void) const; -#else - otInstance &GetInstance(void) const { return *otGetInstance(); } -#endif - -protected: - /** - * This constructor initializes the object. - * - * @param[in] aThreadNetif A reference to the thread network interface. - * - */ - ThreadNetifLocator(ThreadNetif &aThreadNetif): Locator(aThreadNetif) { } -}; - -/** - * This class implements a locator for MeshForwarder object. - * - */ -class MeshForwarderLocator: private Locator -{ -public: - /** - * This method returns a reference to the MeshForwarder. - * - * @returns A reference to the MeshForwarder. - * - */ -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - MeshForwarder &GetMeshForwarder(void) const { return mLocatorObject; } -#else - MeshForwarder &GetMeshForwarder(void) const { return otGetMeshForwarder(); } -#endif - - /** - * This method returns the reference to the parent otInstance structure. - * - * @returns A reference to the parent otInstance structure. - * - */ -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - otInstance &GetInstance(void) const; -#else - otInstance &GetInstance(void) const { return *otGetInstance(); } -#endif - -protected: - /** - * This constructor initializes the object. - * - * @param[in] aMeshForwarder A reference to the MeshForwarder. - * - */ - MeshForwarderLocator(MeshForwarder &aMeshForwarder): Locator(aMeshForwarder) { } -}; - -/** - * This class implements a locator for Ip6 object. - * - */ -class Ip6Locator: private Locator -{ -public: - /** - * This method returns a reference to the Ip6. - * - * @returns A reference to the Ip6. - * - */ -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - Ip6::Ip6 &GetIp6(void) const { return mLocatorObject; } -#else - Ip6::Ip6 &GetIp6(void) const { return otGetIp6(); } -#endif - - /** - * This method returns the reference to the parent otInstance structure. - * - * @returns A reference to the parent otInstance structure. - * - */ -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - otInstance &GetInstance(void) const; -#else - otInstance &GetInstance(void) const { return *otGetInstance(); } -#endif - -protected: - /** - * This constructor initializes the object. - * - * @param[in] aIp6 A reference to the Ip6. - * - */ - Ip6Locator(Ip6::Ip6 &aIp6): Locator(aIp6) { } -}; - -/** - * This class implements locator for otInstance object - * - */ -class InstanceLocator: private Locator +class InstanceLocator { public: /** @@ -221,11 +70,27 @@ public: * */ #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - otInstance &GetInstance(void) const { return mLocatorObject; } + otInstance &GetInstance(void) const { return mInstance; } #else otInstance &GetInstance(void) const { return *otGetInstance(); } #endif + /** + * This method returns a reference to the Ip6. + * + * @returns A reference to the Ip6. + * + */ + Ip6::Ip6 &GetIp6(void) const; + + /** + * This method returns a reference to the thread network interface. + * + * @returns A reference to the thread network interface. + * + */ + ThreadNetif &GetNetif(void) const; + protected: /** * This constructor initializes the object. @@ -233,7 +98,18 @@ protected: * @param[in] aInstance A pointer to the otInstance. * */ - InstanceLocator(otInstance &aInstance): Locator(aInstance) { } + InstanceLocator(otInstance &aInstance) +#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES + : mInstance(aInstance) +#endif + { + OT_UNUSED_VARIABLE(aInstance); + } + +#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES +private: + otInstance &mInstance; +#endif }; /** diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index a30208456..715f4af8d 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -136,11 +136,11 @@ void Mac::StartCsmaBackoff(void) } } -Mac::Mac(ThreadNetif &aThreadNetif): - ThreadNetifLocator(aThreadNetif), - mMacTimer(aThreadNetif.GetInstance(), &Mac::HandleMacTimer, this), - mBackoffTimer(aThreadNetif.GetInstance(), &Mac::HandleBeginTransmit, this), - mReceiveTimer(aThreadNetif.GetInstance(), &Mac::HandleReceiveTimer, this), +Mac::Mac(otInstance &aInstance): + InstanceLocator(aInstance), + mMacTimer(aInstance, &Mac::HandleMacTimer, this), + mBackoffTimer(aInstance, &Mac::HandleBeginTransmit, this), + mReceiveTimer(aInstance, &Mac::HandleReceiveTimer, this), mShortAddress(kShortAddrInvalid), mPanId(kPanIdBroadcast), mChannel(OPENTHREAD_CONFIG_DEFAULT_CHANNEL), @@ -170,13 +170,13 @@ Mac::Mac(ThreadNetif &aThreadNetif): mEnergyScanCurrentMaxRssi(kInvalidRssiValue), mScanContext(NULL), mActiveScanHandler(NULL), // Initialize `mActiveScanHandler` and `mEnergyScanHandler` union - mEnergyScanSampleRssiTask(aThreadNetif.GetInstance(), &Mac::HandleEnergyScanSampleRssi, this), + mEnergyScanSampleRssiTask(aInstance, &Mac::HandleEnergyScanSampleRssi, this), mPcapCallback(NULL), mPcapCallbackContext(NULL), #if OPENTHREAD_ENABLE_MAC_FILTER mFilter(), #endif // OPENTHREAD_ENABLE_MAC_FILTER - mTxFrame(static_cast(otPlatRadioGetTransmitBuffer(&aThreadNetif.GetInstance()))), + mTxFrame(static_cast(otPlatRadioGetTransmitBuffer(&aInstance))), mKeyIdMode2FrameCounter(0) { GenerateExtAddress(&mExtAddress); diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 7eb9f638e..7ee25b051 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -211,16 +211,16 @@ private: * This class implements the IEEE 802.15.4 MAC. * */ -class Mac: public ThreadNetifLocator +class Mac: public InstanceLocator { public: /** * This constructor initializes the MAC object. * - * @param[in] aThreadNetif A reference to the network interface using this MAC. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit Mac(ThreadNetif &aThreadNetif); + explicit Mac(otInstance &aInstance); /** * This function pointer is called on receiving an IEEE 802.15.4 Beacon during an Active Scan. diff --git a/src/core/meshcop/announce_begin_client.cpp b/src/core/meshcop/announce_begin_client.cpp index 864d1027d..2075965c0 100644 --- a/src/core/meshcop/announce_begin_client.cpp +++ b/src/core/meshcop/announce_begin_client.cpp @@ -51,8 +51,8 @@ namespace ot { -AnnounceBeginClient::AnnounceBeginClient(ThreadNetif &aThreadNetif): - ThreadNetifLocator(aThreadNetif) +AnnounceBeginClient::AnnounceBeginClient(otInstance &aInstance): + InstanceLocator(aInstance) { } diff --git a/src/core/meshcop/announce_begin_client.hpp b/src/core/meshcop/announce_begin_client.hpp index b9bb3a391..99526ea68 100644 --- a/src/core/meshcop/announce_begin_client.hpp +++ b/src/core/meshcop/announce_begin_client.hpp @@ -47,14 +47,14 @@ namespace ot { * This class implements handling Announce Begin Requests. * */ -class AnnounceBeginClient: public ThreadNetifLocator +class AnnounceBeginClient: public InstanceLocator { public: /** * This constructor initializes the object. * */ - AnnounceBeginClient(ThreadNetif &aThreadNetif); + AnnounceBeginClient(otInstance &aInstance); /** * This method sends a Announce Begin message. diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index a65da06b8..026ef7fc8 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -60,16 +60,16 @@ using ot::Encoding::BigEndian::HostSwap64; namespace ot { namespace MeshCoP { -Commissioner::Commissioner(ThreadNetif &aThreadNetif): - ThreadNetifLocator(aThreadNetif), - mAnnounceBegin(aThreadNetif), - mEnergyScan(aThreadNetif), - mPanIdQuery(aThreadNetif), +Commissioner::Commissioner(otInstance &aInstance): + InstanceLocator(aInstance), + mAnnounceBegin(aInstance), + mEnergyScan(aInstance), + mPanIdQuery(aInstance), mState(OT_COMMISSIONER_STATE_DISABLED), mJoinerPort(0), mJoinerRloc(0), - mJoinerExpirationTimer(aThreadNetif.GetInstance(), HandleJoinerExpirationTimer, this), - mTimer(aThreadNetif.GetInstance(), HandleTimer, this), + mJoinerExpirationTimer(aInstance, HandleJoinerExpirationTimer, this), + mTimer(aInstance, HandleTimer, this), mSessionId(0), mTransmitAttempts(0), mRelayReceive(OT_URI_PATH_RELAY_RX, &Commissioner::HandleRelayReceive, this), diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index ca56f0d2f..c9fb38f4e 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -56,16 +56,16 @@ class ThreadNetif; namespace MeshCoP { -class Commissioner: public ThreadNetifLocator +class Commissioner: public InstanceLocator { public: /** * This constructor initializes the Commissioner object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - Commissioner(ThreadNetif &aThreadNetif); + Commissioner(otInstance &aInstance); /** * This method starts the Commissioner service. diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index ab6ccd78f..d16f5cce8 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -59,12 +59,12 @@ namespace ot { namespace MeshCoP { -DatasetManager::DatasetManager(ThreadNetif &aThreadNetif, const Tlv::Type aType, const char *aUriSet, +DatasetManager::DatasetManager(otInstance &aInstance, const Tlv::Type aType, const char *aUriSet, const char *aUriGet, Timer::Handler aTimerHandler): - ThreadNetifLocator(aThreadNetif), - mLocal(aThreadNetif.GetInstance(), aType), + InstanceLocator(aInstance), + mLocal(aInstance, aType), mNetwork(aType), - mTimer(aThreadNetif.GetInstance(), aTimerHandler, this), + mTimer(aInstance, aTimerHandler, this), mUriSet(aUriSet), mUriGet(aUriGet) { @@ -959,12 +959,12 @@ static ActiveDatasetBase &GetActiveDatasetOwner(const Context &aContext) return activeDataset; } -ActiveDatasetBase::ActiveDatasetBase(ThreadNetif &aThreadNetif): - DatasetManager(aThreadNetif, Tlv::kActiveTimestamp, OT_URI_PATH_ACTIVE_SET, OT_URI_PATH_ACTIVE_GET, +ActiveDatasetBase::ActiveDatasetBase(otInstance &aInstance): + DatasetManager(aInstance, Tlv::kActiveTimestamp, OT_URI_PATH_ACTIVE_SET, OT_URI_PATH_ACTIVE_GET, &ActiveDatasetBase::HandleTimer), mResourceGet(OT_URI_PATH_ACTIVE_GET, &ActiveDatasetBase::HandleGet, this) { - aThreadNetif.GetCoap().AddResource(mResourceGet); + GetNetif().GetCoap().AddResource(mResourceGet); } otError ActiveDatasetBase::Restore(void) @@ -1057,13 +1057,13 @@ static PendingDatasetBase &GetPendingDatasetOwner(const Context &aContext) return pendingDataset; } -PendingDatasetBase::PendingDatasetBase(ThreadNetif &aThreadNetif): - DatasetManager(aThreadNetif, Tlv::kPendingTimestamp, OT_URI_PATH_PENDING_SET, OT_URI_PATH_PENDING_GET, +PendingDatasetBase::PendingDatasetBase(otInstance &aInstance): + DatasetManager(aInstance, Tlv::kPendingTimestamp, OT_URI_PATH_PENDING_SET, OT_URI_PATH_PENDING_GET, &PendingDatasetBase::HandleTimer), - mDelayTimer(aThreadNetif.GetInstance(), &PendingDatasetBase::HandleDelayTimer, this), + mDelayTimer(aInstance, &PendingDatasetBase::HandleDelayTimer, this), mResourceGet(OT_URI_PATH_PENDING_GET, &PendingDatasetBase::HandleGet, this) { - aThreadNetif.GetCoap().AddResource(mResourceGet); + GetNetif().GetCoap().AddResource(mResourceGet); } otError PendingDatasetBase::Restore(void) diff --git a/src/core/meshcop/dataset_manager.hpp b/src/core/meshcop/dataset_manager.hpp index aacd9f024..d2882dbb0 100644 --- a/src/core/meshcop/dataset_manager.hpp +++ b/src/core/meshcop/dataset_manager.hpp @@ -54,7 +54,7 @@ class ThreadNetif; namespace MeshCoP { -class DatasetManager: public ThreadNetifLocator +class DatasetManager: public InstanceLocator { public: /** @@ -125,14 +125,14 @@ protected: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * @param[in] aType Identifies Active or Pending Operational Dataset. * @param[in] aUriSet The URI-PATH for setting the Operational Dataset. * @param[in] aUriGet The URI-PATH for getting the Operational Dataset. * @param[in] aTimerHandler The registration timer handler. * */ - DatasetManager(ThreadNetif &aThreadNetif, const Tlv::Type aType, const char *aUriSet, const char *aUriGet, + DatasetManager(otInstance &aInstance, const Tlv::Type aType, const char *aUriSet, const char *aUriGet, TimerMilli::Handler aTimerHandler); /** @@ -279,10 +279,10 @@ public: /** * Constructor. * - * @param[in] aThreadNetif The Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - ActiveDatasetBase(ThreadNetif &aThreadNetif); + ActiveDatasetBase(otInstance &aInstance); /** * This method restores the Active Operational Dataset from non-volatile memory. @@ -364,7 +364,7 @@ public: * @param[in] The Thread network interface. * */ - PendingDatasetBase(ThreadNetif &aThreadNetif); + PendingDatasetBase(otInstance &aInstance); /** * This method restores the Operational Dataset from non-volatile memory. diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 6699aed8d..a6f4a32e2 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -60,8 +60,8 @@ namespace ot { namespace MeshCoP { -ActiveDataset::ActiveDataset(ThreadNetif &aThreadNetif): - ActiveDatasetBase(aThreadNetif), +ActiveDataset::ActiveDataset(otInstance &aInstance): + ActiveDatasetBase(aInstance), mResourceSet(OT_URI_PATH_ACTIVE_SET, &ActiveDataset::HandleSet, this) { } @@ -207,8 +207,8 @@ exit: return; } -PendingDataset::PendingDataset(ThreadNetif &aThreadNetif): - PendingDatasetBase(aThreadNetif), +PendingDataset::PendingDataset(otInstance &aInstance): + PendingDatasetBase(aInstance), mResourceSet(OT_URI_PATH_PENDING_SET, &PendingDataset::HandleSet, this) { } diff --git a/src/core/meshcop/dataset_manager_ftd.hpp b/src/core/meshcop/dataset_manager_ftd.hpp index 858fc1780..d9b0ac5f2 100644 --- a/src/core/meshcop/dataset_manager_ftd.hpp +++ b/src/core/meshcop/dataset_manager_ftd.hpp @@ -53,7 +53,7 @@ namespace MeshCoP { class ActiveDataset: public ActiveDatasetBase { public: - ActiveDataset(ThreadNetif &aThreadNetif); + ActiveDataset(otInstance &aInstance); otError GenerateLocal(void); @@ -74,7 +74,7 @@ private: class PendingDataset: public PendingDatasetBase { public: - PendingDataset(ThreadNetif &aThreadNetif); + PendingDataset(otInstance &aInstance); void StartLeader(void); diff --git a/src/core/meshcop/dataset_manager_mtd.hpp b/src/core/meshcop/dataset_manager_mtd.hpp index 95fce9ad7..23e7f0848 100644 --- a/src/core/meshcop/dataset_manager_mtd.hpp +++ b/src/core/meshcop/dataset_manager_mtd.hpp @@ -48,7 +48,7 @@ namespace MeshCoP { class ActiveDataset: public ActiveDatasetBase { public: - ActiveDataset(ThreadNetif &aThreadNetif) : ActiveDatasetBase(aThreadNetif) { } + ActiveDataset(otInstance &aInstance) : ActiveDatasetBase(aInstance) { } otError GenerateLocal(void) { return OT_ERROR_NOT_IMPLEMENTED; } }; @@ -56,7 +56,7 @@ public: class PendingDataset: public PendingDatasetBase { public: - PendingDataset(ThreadNetif &aThreadNetif) : PendingDatasetBase(aThreadNetif) { } + PendingDataset(otInstance &aInstance) : PendingDatasetBase(aInstance) { } }; } // namespace MeshCoP diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index 6f51e45e1..bee8596ce 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -52,11 +52,11 @@ namespace ot { namespace MeshCoP { -Dtls::Dtls(ThreadNetif &aNetif): - ThreadNetifLocator(aNetif), +Dtls::Dtls(otInstance &aInstance): + InstanceLocator(aInstance), mPskLength(0), mStarted(false), - mTimer(aNetif.GetInstance(), &Dtls::HandleTimer, this), + mTimer(aInstance, &Dtls::HandleTimer, this), mTimerIntermediate(0), mTimerSet(false), mReceiveMessage(NULL), diff --git a/src/core/meshcop/dtls.hpp b/src/core/meshcop/dtls.hpp index 1f8959f34..c107b048d 100644 --- a/src/core/meshcop/dtls.hpp +++ b/src/core/meshcop/dtls.hpp @@ -57,7 +57,7 @@ class ThreadNetif; namespace MeshCoP { -class Dtls: public ThreadNetifLocator +class Dtls: public InstanceLocator { public: enum @@ -72,7 +72,7 @@ public: * @param[in] aNetif A reference to the Thread network interface. * */ - Dtls(ThreadNetif &aNetif); + Dtls(otInstance &aInstance); /** * This function pointer is called when a connection is established or torn down. diff --git a/src/core/meshcop/energy_scan_client.cpp b/src/core/meshcop/energy_scan_client.cpp index e61cd031c..124a07265 100644 --- a/src/core/meshcop/energy_scan_client.cpp +++ b/src/core/meshcop/energy_scan_client.cpp @@ -54,13 +54,13 @@ using ot::Encoding::BigEndian::HostSwap32; namespace ot { -EnergyScanClient::EnergyScanClient(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), +EnergyScanClient::EnergyScanClient(otInstance &aInstance) : + InstanceLocator(aInstance), mEnergyScan(OT_URI_PATH_ENERGY_REPORT, &EnergyScanClient::HandleReport, this) { mContext = NULL; mCallback = NULL; - aThreadNetif.GetCoap().AddResource(mEnergyScan); + GetNetif().GetCoap().AddResource(mEnergyScan); } otError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod, diff --git a/src/core/meshcop/energy_scan_client.hpp b/src/core/meshcop/energy_scan_client.hpp index 4dbb2b07c..5f272bf48 100644 --- a/src/core/meshcop/energy_scan_client.hpp +++ b/src/core/meshcop/energy_scan_client.hpp @@ -51,14 +51,14 @@ class ThreadNetif; * This class implements handling PANID Query Requests. * */ -class EnergyScanClient: public ThreadNetifLocator +class EnergyScanClient: public InstanceLocator { public: /** * This constructor initializes the object. * */ - EnergyScanClient(ThreadNetif &aThreadNetif); + EnergyScanClient(otInstance &aInstance); /** * This method sends an Energy Scan Query message. diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index f2e8ad302..682e95a1a 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -58,8 +58,8 @@ using ot::Encoding::BigEndian::HostSwap64; namespace ot { namespace MeshCoP { -Joiner::Joiner(ThreadNetif &aNetif): - ThreadNetifLocator(aNetif), +Joiner::Joiner(otInstance &aInstance): + InstanceLocator(aInstance), mState(OT_JOINER_STATE_IDLE), mCallback(NULL), mContext(NULL), @@ -69,11 +69,11 @@ Joiner::Joiner(ThreadNetif &aNetif): mVendorModel(NULL), mVendorSwVersion(NULL), mVendorData(NULL), - mTimer(aNetif.GetInstance(), &Joiner::HandleTimer, this), + mTimer(aInstance, &Joiner::HandleTimer, this), mJoinerEntrust(OT_URI_PATH_JOINER_ENTRUST, &Joiner::HandleJoinerEntrust, this) { memset(mJoinerRouters, 0, sizeof(mJoinerRouters)); - aNetif.GetCoap().AddResource(mJoinerEntrust); + GetNetif().GetCoap().AddResource(mJoinerEntrust); } otError Joiner::Start(const char *aPSKd, const char *aProvisioningUrl, diff --git a/src/core/meshcop/joiner.hpp b/src/core/meshcop/joiner.hpp index 9b9cf7685..f05547806 100644 --- a/src/core/meshcop/joiner.hpp +++ b/src/core/meshcop/joiner.hpp @@ -54,16 +54,16 @@ class ThreadNetif; namespace MeshCoP { -class Joiner: public ThreadNetifLocator +class Joiner: public InstanceLocator { public: /** * This constructor initializes the Joiner object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - Joiner(ThreadNetif &aThreadNetif); + Joiner(otInstance &aInstance); /** * This method starts the Joiner service. diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index 3be39a7a1..9ed8ab494 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -55,19 +55,19 @@ using ot::Encoding::BigEndian::HostSwap64; namespace ot { namespace MeshCoP { -JoinerRouter::JoinerRouter(ThreadNetif &aNetif): - ThreadNetifLocator(aNetif), - mSocket(aNetif.GetIp6().mUdp), +JoinerRouter::JoinerRouter(otInstance &aInstance): + InstanceLocator(aInstance), + mSocket(aInstance.mThreadNetif.GetIp6().mUdp), mRelayTransmit(OT_URI_PATH_RELAY_TX, &JoinerRouter::HandleRelayTransmit, this), - mTimer(aNetif.GetInstance(), &JoinerRouter::HandleTimer, this), + mTimer(aInstance, &JoinerRouter::HandleTimer, this), mJoinerUdpPort(0), mIsJoinerPortConfigured(false), mExpectJoinEntRsp(false) { mSocket.GetSockName().mPort = OPENTHREAD_CONFIG_JOINER_UDP_PORT; - aNetif.GetCoap().AddResource(mRelayTransmit); + GetNetif().GetCoap().AddResource(mRelayTransmit); mNetifCallback.Set(HandleNetifStateChanged, this); - aNetif.RegisterCallback(mNetifCallback); + GetNetif().RegisterCallback(mNetifCallback); } void JoinerRouter::HandleNetifStateChanged(uint32_t aFlags, void *aContext) diff --git a/src/core/meshcop/joiner_router.hpp b/src/core/meshcop/joiner_router.hpp index 9e1dfc5c8..dde52d78d 100644 --- a/src/core/meshcop/joiner_router.hpp +++ b/src/core/meshcop/joiner_router.hpp @@ -54,16 +54,16 @@ class ThreadNetif; namespace MeshCoP { -class JoinerRouter: public ThreadNetifLocator +class JoinerRouter: public InstanceLocator { public: /** * This constructor initializes the Joiner Router object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - JoinerRouter(ThreadNetif &aNetif); + JoinerRouter(otInstance &aInstance); /** * This method returns the Joiner UDP Port. diff --git a/src/core/meshcop/leader.cpp b/src/core/meshcop/leader.cpp index a13cdd448..6c4104857 100644 --- a/src/core/meshcop/leader.cpp +++ b/src/core/meshcop/leader.cpp @@ -54,16 +54,16 @@ namespace ot { namespace MeshCoP { -Leader::Leader(ThreadNetif &aThreadNetif): - ThreadNetifLocator(aThreadNetif), +Leader::Leader(otInstance &aInstance): + InstanceLocator(aInstance), mPetition(OT_URI_PATH_LEADER_PETITION, Leader::HandlePetition, this), mKeepAlive(OT_URI_PATH_LEADER_KEEP_ALIVE, Leader::HandleKeepAlive, this), - mTimer(aThreadNetif.GetInstance(), HandleTimer, this), + mTimer(aInstance, HandleTimer, this), mDelayTimerMinimal(DelayTimerTlv::kDelayTimerMinimal), mSessionId(0xffff) { - aThreadNetif.GetCoap().AddResource(mPetition); - aThreadNetif.GetCoap().AddResource(mKeepAlive); + GetNetif().GetCoap().AddResource(mPetition); + GetNetif().GetCoap().AddResource(mKeepAlive); } void Leader::HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, diff --git a/src/core/meshcop/leader.hpp b/src/core/meshcop/leader.hpp index b62165c24..78ec3b1aa 100644 --- a/src/core/meshcop/leader.hpp +++ b/src/core/meshcop/leader.hpp @@ -61,16 +61,16 @@ public: SteeringDataTlv mSteeringData; } OT_TOOL_PACKED_END; -class Leader: public ThreadNetifLocator +class Leader: public InstanceLocator { public: /** * This constructor initializes the Leader object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - Leader(ThreadNetif &aThreadNetif); + Leader(otInstance &aInstance); /** * This method sends a MGMT_DATASET_CHANGED message to commissioner. diff --git a/src/core/meshcop/panid_query_client.cpp b/src/core/meshcop/panid_query_client.cpp index 2828535fa..b629b462e 100644 --- a/src/core/meshcop/panid_query_client.cpp +++ b/src/core/meshcop/panid_query_client.cpp @@ -50,13 +50,13 @@ namespace ot { -PanIdQueryClient::PanIdQueryClient(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), +PanIdQueryClient::PanIdQueryClient(otInstance &aInstance) : + InstanceLocator(aInstance), mCallback(NULL), mContext(NULL), mPanIdQuery(OT_URI_PATH_PANID_CONFLICT, &PanIdQueryClient::HandleConflict, this) { - aThreadNetif.GetCoap().AddResource(mPanIdQuery); + GetNetif().GetCoap().AddResource(mPanIdQuery); } otError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, const Ip6::Address &aAddress, diff --git a/src/core/meshcop/panid_query_client.hpp b/src/core/meshcop/panid_query_client.hpp index b6b09abd7..8dffbc595 100644 --- a/src/core/meshcop/panid_query_client.hpp +++ b/src/core/meshcop/panid_query_client.hpp @@ -51,14 +51,14 @@ class ThreadNetif; * This class implements handling PANID Query Requests. * */ -class PanIdQueryClient: public ThreadNetifLocator +class PanIdQueryClient: public InstanceLocator { public: /** * This constructor initializes the object. * */ - PanIdQueryClient(ThreadNetif &aThreadNetif); + PanIdQueryClient(otInstance &aInstance); /** * This method sends a PAN ID Query message. diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index 9090c5c71..57b76141a 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -38,6 +38,7 @@ #include #include +#include "openthread-instance.h" #include "common/code_utils.hpp" #include "common/encoding.hpp" #include "common/logging.hpp" @@ -55,10 +56,10 @@ namespace ot { namespace Dhcp6 { -Dhcp6Client::Dhcp6Client(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), - mTrickleTimer(aThreadNetif.GetInstance(), &Dhcp6Client::HandleTrickleTimer, NULL, this), - mSocket(aThreadNetif.GetIp6().mUdp), +Dhcp6Client::Dhcp6Client(otInstance &aInstance) : + InstanceLocator(aInstance), + mTrickleTimer(aInstance, &Dhcp6Client::HandleTrickleTimer, NULL, this), + mSocket(aInstance.mThreadNetif.GetIp6().mUdp), mStartTime(0), mAddresses(NULL), mNumAddresses(0) diff --git a/src/core/net/dhcp6_client.hpp b/src/core/net/dhcp6_client.hpp index 14abf540e..177682efe 100644 --- a/src/core/net/dhcp6_client.hpp +++ b/src/core/net/dhcp6_client.hpp @@ -170,16 +170,16 @@ private: * This class implements DHCPv6 Client. * */ -class Dhcp6Client: public ThreadNetifLocator +class Dhcp6Client: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit Dhcp6Client(ThreadNetif &aThreadNetif); + explicit Dhcp6Client(otInstance &aInstance); /** * This method update addresses that shall be automatically created using DHCP. diff --git a/src/core/net/dhcp6_server.cpp b/src/core/net/dhcp6_server.cpp index 880bc1a06..81e20d038 100644 --- a/src/core/net/dhcp6_server.cpp +++ b/src/core/net/dhcp6_server.cpp @@ -51,9 +51,9 @@ using ot::Encoding::BigEndian::HostSwap32; namespace ot { namespace Dhcp6 { -Dhcp6Server::Dhcp6Server(ThreadNetif &aThreadNetif): - ThreadNetifLocator(aThreadNetif), - mSocket(aThreadNetif.GetIp6().mUdp) +Dhcp6Server::Dhcp6Server(otInstance &aInstance): + InstanceLocator(aInstance), + mSocket(GetNetif().GetIp6().mUdp) { for (uint8_t i = 0; i < OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES; i++) { diff --git a/src/core/net/dhcp6_server.hpp b/src/core/net/dhcp6_server.hpp index 1d1c47631..1990c2713 100644 --- a/src/core/net/dhcp6_server.hpp +++ b/src/core/net/dhcp6_server.hpp @@ -102,16 +102,16 @@ private: otIp6Prefix mIp6Prefix; ///< prefix } OT_TOOL_PACKED_END; -class Dhcp6Server: public ThreadNetifLocator +class Dhcp6Server: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit Dhcp6Server(ThreadNetif &aThreadNetif); + explicit Dhcp6Server(otInstance &aInstance); /** * This method updates DHCP Agents and DHCP Alocs. diff --git a/src/core/net/icmp6.cpp b/src/core/net/icmp6.cpp index 64a6f3e42..98909d1d3 100644 --- a/src/core/net/icmp6.cpp +++ b/src/core/net/icmp6.cpp @@ -48,8 +48,8 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { namespace Ip6 { -Icmp::Icmp(Ip6 &aIp6): - Ip6Locator(aIp6), +Icmp::Icmp(otInstance &aInstance): + InstanceLocator(aInstance), mHandlers(NULL), mEchoSequence(1), mIsEchoEnabled(true) diff --git a/src/core/net/icmp6.hpp b/src/core/net/icmp6.hpp index 77a1e35dc..dcfa05d76 100644 --- a/src/core/net/icmp6.hpp +++ b/src/core/net/icmp6.hpp @@ -222,16 +222,16 @@ private: * This class implements ICMPv6. * */ -class Icmp: public Ip6Locator +class Icmp: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aInstance A reference to the OpenThread instance. * */ - Icmp(Ip6 &aIp6); + Icmp(otInstance &aInstance); /** * This method returns a new ICMP message with sufficient header space reserved. diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index da4d0157d..172454495 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -52,10 +52,10 @@ namespace Ip6 { Ip6::Ip6(otInstance &aInstance): InstanceLocator(aInstance), - mRoutes(*this), - mIcmp(*this), - mUdp(*this), - mMpl(*this), + mRoutes(aInstance), + mIcmp(aInstance), + mUdp(aInstance), + mMpl(aInstance), mForwardingEnabled(false), mSendQueueTask(aInstance, HandleSendQueue, this), mReceiveIp6DatagramCallback(NULL), diff --git a/src/core/net/ip6_mpl.cpp b/src/core/net/ip6_mpl.cpp index 531b89e23..b46c3e64d 100644 --- a/src/core/net/ip6_mpl.cpp +++ b/src/core/net/ip6_mpl.cpp @@ -53,10 +53,10 @@ void MplBufferedMessageMetadata::GenerateNextTransmissionTime(uint32_t aCurrentT SetIntervalOffset(aInterval - t); } -Mpl::Mpl(Ip6 &aIp6): - Ip6Locator(aIp6), - mSeedSetTimer(aIp6.GetInstance(), &Mpl::HandleSeedSetTimer, this), - mRetransmissionTimer(aIp6.GetInstance(), &Mpl::HandleRetransmissionTimer, this), +Mpl::Mpl(otInstance &aInstance): + InstanceLocator(aInstance), + mSeedSetTimer(aInstance, &Mpl::HandleSeedSetTimer, this), + mRetransmissionTimer(aInstance, &Mpl::HandleRetransmissionTimer, this), mTimerExpirations(0), mSequence(0), mSeedId(0), diff --git a/src/core/net/ip6_mpl.hpp b/src/core/net/ip6_mpl.hpp index a22444323..94c6db75b 100644 --- a/src/core/net/ip6_mpl.hpp +++ b/src/core/net/ip6_mpl.hpp @@ -430,16 +430,16 @@ private: * This class implements MPL message processing. * */ -class Mpl: public Ip6Locator +class Mpl: public InstanceLocator { public: /** * This constructor initializes the MPL object. * - * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aInstance A reference to the OpenThread instance. * */ - Mpl(Ip6 &aIp6); + Mpl(otInstance &aInstance); /** * This method initializes the MPL option. diff --git a/src/core/net/ip6_routes.cpp b/src/core/net/ip6_routes.cpp index 32b0eaab8..8fd74c08b 100644 --- a/src/core/net/ip6_routes.cpp +++ b/src/core/net/ip6_routes.cpp @@ -41,8 +41,8 @@ namespace ot { namespace Ip6 { -Routes::Routes(Ip6 &aIp6): - Ip6Locator(aIp6), +Routes::Routes(otInstance &aInstance): + InstanceLocator(aInstance), mRoutes(NULL) { } diff --git a/src/core/net/ip6_routes.hpp b/src/core/net/ip6_routes.hpp index cecdd1cbf..900e9c0df 100644 --- a/src/core/net/ip6_routes.hpp +++ b/src/core/net/ip6_routes.hpp @@ -71,16 +71,16 @@ struct Route * This class implements IPv6 route management. * */ -class Routes: public Ip6Locator +class Routes: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aInstance A reference to the OpenThread instance. * */ - Routes(Ip6 &aIp6); + Routes(otInstance &aInstance); /** * This method adds an IPv6 route. diff --git a/src/core/net/netif.cpp b/src/core/net/netif.cpp index dfde80089..ef444a96c 100644 --- a/src/core/net/netif.cpp +++ b/src/core/net/netif.cpp @@ -90,14 +90,14 @@ const otNetifMulticastAddress Netif::kLinkLocalAllRoutersMulticastAddress = }; -Netif::Netif(Ip6 &aIp6, int8_t aInterfaceId): - Ip6Locator(aIp6), +Netif::Netif(otInstance &aInstance, int8_t aInterfaceId): + InstanceLocator(aInstance), mCallbacks(NULL), mUnicastAddresses(NULL), mMulticastAddresses(NULL), mInterfaceId(aInterfaceId), mMulticastPromiscuous(false), - mStateChangedTask(aIp6.GetInstance(), &Netif::HandleStateChangedTask, this), + mStateChangedTask(aInstance, &Netif::HandleStateChangedTask, this), mNext(NULL), mStateChangedFlags(0) { diff --git a/src/core/net/netif.hpp b/src/core/net/netif.hpp index a82de1dda..9835a22a8 100644 --- a/src/core/net/netif.hpp +++ b/src/core/net/netif.hpp @@ -252,7 +252,7 @@ private: * This class implements an IPv6 network interface. * */ -class Netif: public Ip6Locator +class Netif: public InstanceLocator { friend class Ip6; @@ -260,11 +260,11 @@ public: /** * This constructor initializes the network interface. * - * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInterfaceId The interface ID for this object. * */ - Netif(Ip6 &aIp6, int8_t aInterfaceId); + Netif(otInstance &aInstance, int8_t aInterfaceId); /** * This method returns the next network interface in the list. diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index b08bf0950..49ae56db0 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -138,8 +138,8 @@ exit: return error; } -Udp::Udp(Ip6 &aIp6): - Ip6Locator(aIp6), +Udp::Udp(otInstance &aInstance): + InstanceLocator(aInstance), mEphemeralPort(kDynamicPortMin), mSockets(NULL) { diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index fc965340c..310b26242 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -164,7 +164,7 @@ private: * This class implements core UDP message handling. * */ -class Udp: public Ip6Locator +class Udp: public InstanceLocator { friend class UdpSocket; @@ -172,10 +172,10 @@ public: /** * This constructor initializes the object. * - * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aIp6 A reference to OpenThread instance. * */ - Udp(Ip6 &aIp6); + Udp(otInstance &aInstance); /** * This method adds a UDP socket. diff --git a/src/core/openthread-instance.h b/src/core/openthread-instance.h index 9e3f34845..0768bb918 100644 --- a/src/core/openthread-instance.h +++ b/src/core/openthread-instance.h @@ -108,14 +108,4 @@ typedef struct otInstance } otInstance; -static inline otInstance *otInstanceFromIp6(ot::Ip6::Ip6 *aIp6) -{ - return (otInstance *)CONTAINING_RECORD(aIp6, otInstance, mIp6); -} - -static inline otInstance *otInstanceFromThreadNetif(ot::ThreadNetif *aThreadNetif) -{ - return (otInstance *)CONTAINING_RECORD(aThreadNetif, otInstance, mThreadNetif); -} - #endif // OPENTHREADINSTANCE_H_ diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index 47ac83fbf..71ec4517b 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -56,21 +56,21 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { -AddressResolver::AddressResolver(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), +AddressResolver::AddressResolver(otInstance &aInstance) : + InstanceLocator(aInstance), mAddressError(OT_URI_PATH_ADDRESS_ERROR, &AddressResolver::HandleAddressError, this), mAddressQuery(OT_URI_PATH_ADDRESS_QUERY, &AddressResolver::HandleAddressQuery, this), mAddressNotification(OT_URI_PATH_ADDRESS_NOTIFY, &AddressResolver::HandleAddressNotification, this), mIcmpHandler(&AddressResolver::HandleIcmpReceive, this), - mTimer(aThreadNetif.GetInstance(), &AddressResolver::HandleTimer, this) + mTimer(aInstance, &AddressResolver::HandleTimer, this) { Clear(); - aThreadNetif.GetCoap().AddResource(mAddressError); - aThreadNetif.GetCoap().AddResource(mAddressQuery); - aThreadNetif.GetCoap().AddResource(mAddressNotification); + GetNetif().GetCoap().AddResource(mAddressError); + GetNetif().GetCoap().AddResource(mAddressQuery); + GetNetif().GetCoap().AddResource(mAddressNotification); - aThreadNetif.GetIp6().mIcmp.RegisterHandler(mIcmpHandler); + GetNetif().GetIp6().mIcmp.RegisterHandler(mIcmpHandler); } void AddressResolver::Clear() diff --git a/src/core/thread/address_resolver.hpp b/src/core/thread/address_resolver.hpp index efee31eea..0892c3479 100644 --- a/src/core/thread/address_resolver.hpp +++ b/src/core/thread/address_resolver.hpp @@ -66,14 +66,14 @@ class ThreadTargetTlv; * This class implements the EID-to-RLOC mapping and caching. * */ -class AddressResolver: public ThreadNetifLocator +class AddressResolver: public InstanceLocator { public: /** * This constructor initializes the object. * */ - explicit AddressResolver(ThreadNetif &aThreadNetif); + explicit AddressResolver(otInstance &aInstance); /** * This method clears the EID-to-RLOC cache. diff --git a/src/core/thread/announce_begin_server.cpp b/src/core/thread/announce_begin_server.cpp index 065eafe09..1fb008b72 100644 --- a/src/core/thread/announce_begin_server.cpp +++ b/src/core/thread/announce_begin_server.cpp @@ -50,16 +50,16 @@ using ot::Encoding::BigEndian::HostSwap32; namespace ot { -AnnounceBeginServer::AnnounceBeginServer(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), +AnnounceBeginServer::AnnounceBeginServer(otInstance &aInstance) : + InstanceLocator(aInstance), mChannelMask(0), mPeriod(0), mCount(0), mChannel(0), - mTimer(aThreadNetif.GetInstance(), &AnnounceBeginServer::HandleTimer, this), + mTimer(aInstance, &AnnounceBeginServer::HandleTimer, this), mAnnounceBegin(OT_URI_PATH_ANNOUNCE_BEGIN, &AnnounceBeginServer::HandleRequest, this) { - aThreadNetif.GetCoap().AddResource(mAnnounceBegin); + GetNetif().GetCoap().AddResource(mAnnounceBegin); } otError AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask) diff --git a/src/core/thread/announce_begin_server.hpp b/src/core/thread/announce_begin_server.hpp index 32358380a..201b02c9e 100644 --- a/src/core/thread/announce_begin_server.hpp +++ b/src/core/thread/announce_begin_server.hpp @@ -49,14 +49,14 @@ namespace ot { * This class implements handling Announce Begin Requests. * */ -class AnnounceBeginServer: public ThreadNetifLocator +class AnnounceBeginServer: public InstanceLocator { public: /** * This constructor initializes the object. * */ - AnnounceBeginServer(ThreadNetif &aThreadNetif); + AnnounceBeginServer(otInstance &aInstance); /** * This method begins the MLE Announce transmission process using Count=3 and Period=1s. diff --git a/src/core/thread/data_poll_manager.cpp b/src/core/thread/data_poll_manager.cpp index c8ace6cd3..40d934fbe 100644 --- a/src/core/thread/data_poll_manager.cpp +++ b/src/core/thread/data_poll_manager.cpp @@ -49,9 +49,9 @@ namespace ot { -DataPollManager::DataPollManager(MeshForwarder &aMeshForwarder): - MeshForwarderLocator(aMeshForwarder), - mTimer(aMeshForwarder.GetInstance(), &DataPollManager::HandlePollTimer, this), +DataPollManager::DataPollManager(otInstance &aInstance): + InstanceLocator(aInstance), + mTimer(aInstance, &DataPollManager::HandlePollTimer, this), mTimerStartTime(0), mExternalPollPeriod(0), mPollPeriod(0), @@ -70,7 +70,7 @@ otError DataPollManager::StartPolling(void) otError error = OT_ERROR_NONE; VerifyOrExit(!mEnabled, error = OT_ERROR_ALREADY); - VerifyOrExit((GetMeshForwarder().GetNetif().GetMle().GetDeviceMode() & Mle::ModeTlv::kModeFFD) == 0, + VerifyOrExit((GetNetif().GetMle().GetDeviceMode() & Mle::ModeTlv::kModeFFD) == 0, error = OT_ERROR_INVALID_STATE); mEnabled = true; @@ -94,20 +94,20 @@ void DataPollManager::StopPolling(void) otError DataPollManager::SendDataPoll(void) { - MeshForwarder &meshForwarder = GetMeshForwarder(); + ThreadNetif &netif = GetNetif(); otError error; Message *message; Neighbor *parent; VerifyOrExit(mEnabled, error = OT_ERROR_INVALID_STATE); - VerifyOrExit(!meshForwarder.GetNetif().GetMac().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE); + VerifyOrExit(!netif.GetMac().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE); - parent = meshForwarder.GetNetif().GetMle().GetParent(); + parent = netif.GetMle().GetParent(); VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE); mTimer.Stop(); - for (message = meshForwarder.GetSendQueue().GetHead(); message; message = message->GetNext()) + for (message = netif.GetMeshForwarder().GetSendQueue().GetHead(); message; message = message->GetNext()) { VerifyOrExit(message->GetType() != Message::kTypeMacDataPoll, error = OT_ERROR_ALREADY); } @@ -115,7 +115,7 @@ otError DataPollManager::SendDataPoll(void) message = GetInstance().mMessagePool.New(Message::kTypeMacDataPoll, 0); VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); - error = meshForwarder.SendMessage(*message); + error = netif.GetMeshForwarder().SendMessage(*message); if (error != OT_ERROR_NONE) { @@ -426,7 +426,7 @@ DataPollManager &DataPollManager::GetOwner(Context &aContext) uint32_t DataPollManager::GetDefaultPollPeriod(void) const { - return TimerMilli::SecToMsec(GetMeshForwarder().GetNetif().GetMle().GetTimeout()) - + return TimerMilli::SecToMsec(GetNetif().GetMle().GetTimeout()) - static_cast(kRetxPollPeriod) * kMaxPollRetxAttempts; } diff --git a/src/core/thread/data_poll_manager.hpp b/src/core/thread/data_poll_manager.hpp index 57a88a925..7cc5315f8 100644 --- a/src/core/thread/data_poll_manager.hpp +++ b/src/core/thread/data_poll_manager.hpp @@ -59,7 +59,7 @@ namespace ot { * */ -class DataPollManager: public MeshForwarderLocator +class DataPollManager: public InstanceLocator { public: enum @@ -71,10 +71,10 @@ public: /** * This constructor initializes the data poll manager object. * - * @param[in] aMeshForwarder A reference to the Mesh Forwarder. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit DataPollManager(MeshForwarder &aMeshForwarder); + explicit DataPollManager(otInstance &aInstance); /** * This method instructs the data poll manager to start sending periodic data polls. diff --git a/src/core/thread/energy_scan_server.cpp b/src/core/thread/energy_scan_server.cpp index 5b7066488..b0702c943 100644 --- a/src/core/thread/energy_scan_server.cpp +++ b/src/core/thread/energy_scan_server.cpp @@ -49,8 +49,8 @@ namespace ot { -EnergyScanServer::EnergyScanServer(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), +EnergyScanServer::EnergyScanServer(otInstance &aInstance) : + InstanceLocator(aInstance), mChannelMask(0), mChannelMaskCurrent(0), mPeriod(0), @@ -58,13 +58,13 @@ EnergyScanServer::EnergyScanServer(ThreadNetif &aThreadNetif) : mCount(0), mActive(false), mScanResultsLength(0), - mTimer(aThreadNetif.GetInstance(), &EnergyScanServer::HandleTimer, this), + mTimer(aInstance, &EnergyScanServer::HandleTimer, this), mEnergyScan(OT_URI_PATH_ENERGY_SCAN, &EnergyScanServer::HandleRequest, this) { mNetifCallback.Set(&EnergyScanServer::HandleNetifStateChanged, this); - aThreadNetif.RegisterCallback(mNetifCallback); + GetNetif().RegisterCallback(mNetifCallback); - aThreadNetif.GetCoap().AddResource(mEnergyScan); + GetNetif().GetCoap().AddResource(mEnergyScan); } void EnergyScanServer::HandleRequest(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, diff --git a/src/core/thread/energy_scan_server.hpp b/src/core/thread/energy_scan_server.hpp index 4419f1655..0b10e6e71 100644 --- a/src/core/thread/energy_scan_server.hpp +++ b/src/core/thread/energy_scan_server.hpp @@ -56,14 +56,14 @@ class ThreadTargetTlv; * This class implements handling Energy Scan Requests. * */ -class EnergyScanServer: public ThreadNetifLocator +class EnergyScanServer: public InstanceLocator { public: /** * This constructor initializes the object. * */ - EnergyScanServer(ThreadNetif &aThreadNetif); + EnergyScanServer(otInstance &aInstance); private: enum diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index 814e9c8b3..e76dc18c2 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -47,8 +47,8 @@ static const uint8_t kThreadString[] = 'T', 'h', 'r', 'e', 'a', 'd', }; -KeyManager::KeyManager(ThreadNetif &aThreadNetif): - ThreadNetifLocator(aThreadNetif), +KeyManager::KeyManager(otInstance &aInstance): + InstanceLocator(aInstance), mKeySequence(0), mMacFrameCounter(0), mMleFrameCounter(0), @@ -58,7 +58,7 @@ KeyManager::KeyManager(ThreadNetif &aThreadNetif): mKeyRotationTime(kDefaultKeyRotationTime), mKeySwitchGuardTime(kDefaultKeySwitchGuardTime), mKeySwitchGuardEnabled(false), - mKeyRotationTimer(aThreadNetif.GetInstance(), &KeyManager::HandleKeyRotationTimer, this), + mKeyRotationTimer(aInstance, &KeyManager::HandleKeyRotationTimer, this), mKekFrameCounter(0), mSecurityPolicyFlags(0xff) { diff --git a/src/core/thread/key_manager.hpp b/src/core/thread/key_manager.hpp index c3bec5280..198dab7bb 100644 --- a/src/core/thread/key_manager.hpp +++ b/src/core/thread/key_manager.hpp @@ -55,7 +55,7 @@ namespace ot { * @{ */ -class KeyManager: public ThreadNetifLocator +class KeyManager: public InstanceLocator { public: enum @@ -66,10 +66,10 @@ public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit KeyManager(ThreadNetif &aThreadNetif); + explicit KeyManager(otInstance &aInstance); /** * This method starts KeyManager rotation timer and sets guard timer to initial value. diff --git a/src/core/thread/lowpan.cpp b/src/core/thread/lowpan.cpp index 138738958..aa7f702c4 100644 --- a/src/core/thread/lowpan.cpp +++ b/src/core/thread/lowpan.cpp @@ -46,8 +46,8 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { namespace Lowpan { -Lowpan::Lowpan(ThreadNetif &aThreadNetif): - ThreadNetifLocator(aThreadNetif) +Lowpan::Lowpan(otInstance &aInstance): + InstanceLocator(aInstance) { } diff --git a/src/core/thread/lowpan.hpp b/src/core/thread/lowpan.hpp index 629e15673..f3dae69d3 100644 --- a/src/core/thread/lowpan.hpp +++ b/src/core/thread/lowpan.hpp @@ -78,16 +78,16 @@ struct Context * This class implements LOWPAN_IPHC header compression. * */ -class Lowpan: public ThreadNetifLocator +class Lowpan: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit Lowpan(ThreadNetif &aThreadNetif); + explicit Lowpan(otInstance &aInstance); /** * This method indicates whether or not the header is a LOWPAN_IPHC header. diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 8c7aa2eff..7c326f37b 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -56,12 +56,12 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { -MeshForwarder::MeshForwarder(ThreadNetif &aThreadNetif): - ThreadNetifLocator(aThreadNetif), +MeshForwarder::MeshForwarder(otInstance &aInstance): + InstanceLocator(aInstance), mMacReceiver(&MeshForwarder::HandleReceivedFrame, &MeshForwarder::HandleDataPollTimeout, this), mMacSender(&MeshForwarder::HandleFrameRequest, &MeshForwarder::HandleSentFrame, this), - mDiscoverTimer(aThreadNetif.GetInstance(), &MeshForwarder::HandleDiscoverTimer, this), - mReassemblyTimer(aThreadNetif.GetInstance(), &MeshForwarder::HandleReassemblyTimer, this), + mDiscoverTimer(aInstance, &MeshForwarder::HandleDiscoverTimer, this), + mReassemblyTimer(aInstance, &MeshForwarder::HandleReassemblyTimer, this), mMessageNextOffset(0), mSendMessageFrameCounter(0), mSendMessage(NULL), @@ -74,18 +74,18 @@ MeshForwarder::MeshForwarder(ThreadNetif &aThreadNetif): mMeshDest(Mac::kShortAddrInvalid), mAddMeshHeader(false), mSendBusy(false), - mScheduleTransmissionTask(aThreadNetif.GetInstance(), ScheduleTransmissionTask, this), + mScheduleTransmissionTask(aInstance, ScheduleTransmissionTask, this), mEnabled(false), mScanChannels(0), mScanChannel(0), mRestoreChannel(0), mRestorePanId(Mac::kPanIdBroadcast), mScanning(false), - mDataPollManager(*this), - mSourceMatchController(*this) + mDataPollManager(aInstance), + mSourceMatchController(aInstance) { mFragTag = static_cast(otPlatRandomGet()); - aThreadNetif.GetMac().RegisterReceiver(mMacReceiver); + GetNetif().GetMac().RegisterReceiver(mMacReceiver); mMacSource.mLength = 0; mMacDest.mLength = 0; diff --git a/src/core/thread/mesh_forwarder.hpp b/src/core/thread/mesh_forwarder.hpp index 3ffa5ac00..2fcd0ef15 100644 --- a/src/core/thread/mesh_forwarder.hpp +++ b/src/core/thread/mesh_forwarder.hpp @@ -71,16 +71,16 @@ class MleRouter; * This class implements mesh forwarding within Thread. * */ -class MeshForwarder: public ThreadNetifLocator +class MeshForwarder: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit MeshForwarder(ThreadNetif &aThreadNetif); + explicit MeshForwarder(otInstance &aInstance); /** * This method enables mesh forwarding and the IEEE 802.15.4 MAC layer. diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 3fef3eef5..1e3bb71ea 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -60,15 +60,15 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { namespace Mle { -Mle::Mle(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), +Mle::Mle(otInstance &aInstance) : + InstanceLocator(aInstance), mRetrieveNewNetworkData(false), mRole(OT_DEVICE_ROLE_DISABLED), mDeviceMode(ModeTlv::kModeRxOnWhenIdle | ModeTlv::kModeSecureDataRequest), mParentRequestState(kParentIdle), mReattachState(kReattachStop), - mParentRequestTimer(aThreadNetif.GetInstance(), &Mle::HandleParentRequestTimer, this), - mDelayedResponseTimer(aThreadNetif.GetInstance(), &Mle::HandleDelayedResponseTimer, this), + mParentRequestTimer(aInstance, &Mle::HandleParentRequestTimer, this), + mDelayedResponseTimer(aInstance, &Mle::HandleDelayedResponseTimer, this), mLastPartitionId(0), mLastPartitionRouterIdSequence(0), mLastPartitionIdTimeout(0), @@ -81,9 +81,9 @@ Mle::Mle(ThreadNetif &aThreadNetif) : mChildUpdateAttempts(0), mParentLinkMargin(0), mParentIsSingleton(false), - mSocket(aThreadNetif.GetIp6().mUdp), + mSocket(aInstance.mThreadNetif.GetIp6().mUdp), mTimeout(kMleEndDeviceTimeout), - mSendChildUpdateRequest(aThreadNetif.GetInstance(), &Mle::HandleSendChildUpdateRequest, this), + mSendChildUpdateRequest(aInstance, &Mle::HandleSendChildUpdateRequest, this), mDiscoverHandler(NULL), mDiscoverContext(NULL), mIsDiscoverInProgress(false), @@ -111,11 +111,11 @@ Mle::Mle(ThreadNetif &aThreadNetif) : // link-local 64 mLinkLocal64.GetAddress().mFields.m16[0] = HostSwap16(0xfe80); - mLinkLocal64.GetAddress().SetIid(*aThreadNetif.GetMac().GetExtAddress()); + mLinkLocal64.GetAddress().SetIid(*GetNetif().GetMac().GetExtAddress()); mLinkLocal64.mPrefixLength = 64; mLinkLocal64.mPreferred = true; mLinkLocal64.mValid = true; - aThreadNetif.AddUnicastAddress(mLinkLocal64); + GetNetif().AddUnicastAddress(mLinkLocal64); // Leader Aloc mLeaderAloc.mPrefixLength = 128; @@ -126,7 +126,7 @@ Mle::Mle(ThreadNetif &aThreadNetif) : // initialize Mesh Local Prefix meshLocalPrefix[0] = 0xfd; - memcpy(meshLocalPrefix + 1, aThreadNetif.GetMac().GetExtendedPanId(), 5); + memcpy(meshLocalPrefix + 1, GetNetif().GetMac().GetExtendedPanId(), 5); meshLocalPrefix[6] = 0x00; meshLocalPrefix[7] = 0x00; @@ -154,7 +154,7 @@ Mle::Mle(ThreadNetif &aThreadNetif) : mMeshLocal16.mRloc = true; // Store RLOC address reference in MPL module. - aThreadNetif.GetIp6().mMpl.SetMatchingAddress(mMeshLocal16.GetAddress()); + GetNetif().GetIp6().mMpl.SetMatchingAddress(mMeshLocal16.GetAddress()); // link-local all thread nodes mLinkLocalAllThreadNodes.GetAddress().mFields.m16[0] = HostSwap16(0xff32); @@ -172,7 +172,7 @@ Mle::Mle(ThreadNetif &aThreadNetif) : // to the Link- and Realm-Local All Thread Nodes multicast addresses. mNetifCallback.Set(&Mle::HandleNetifStateChanged, this); - aThreadNetif.RegisterCallback(mNetifCallback); + GetNetif().RegisterCallback(mNetifCallback); } otError Mle::Enable(void) diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 247062b32..bf5ad2713 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -449,16 +449,16 @@ private: * This class implements MLE functionality required by the Thread EndDevices, Router, and Leader roles. * */ -class Mle: public ThreadNetifLocator +class Mle: public InstanceLocator { public: /** * This constructor initializes the MLE object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit Mle(ThreadNetif &aThreadNetif); + explicit Mle(otInstance &aInstance); /** * This method enables MLE. diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 91b54f5d9..887896e41 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -56,10 +56,10 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { namespace Mle { -MleRouter::MleRouter(ThreadNetif &aThreadNetif): - Mle(aThreadNetif), - mAdvertiseTimer(aThreadNetif.GetInstance(), &MleRouter::HandleAdvertiseTimer, NULL, this), - mStateUpdateTimer(aThreadNetif.GetInstance(), &MleRouter::HandleStateUpdateTimer, this), +MleRouter::MleRouter(otInstance &aInstance): + Mle(aInstance), + mAdvertiseTimer(aInstance, &MleRouter::HandleAdvertiseTimer, NULL, this), + mStateUpdateTimer(aInstance, &MleRouter::HandleStateUpdateTimer, this), mAddressSolicit(OT_URI_PATH_ADDRESS_SOLICIT, &MleRouter::HandleAddressSolicit, this), mAddressRelease(OT_URI_PATH_ADDRESS_RELEASE, &MleRouter::HandleAddressRelease, this), mRouterIdSequence(0), diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index b0d5c5e0d..2e450f8ae 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -79,10 +79,10 @@ public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit MleRouter(ThreadNetif &aThreadNetif); + explicit MleRouter(otInstance &aInstance); /** * This method indicates whether or not the Router Role is enabled. diff --git a/src/core/thread/mle_router_mtd.hpp b/src/core/thread/mle_router_mtd.hpp index cffc08bed..488ba1560 100644 --- a/src/core/thread/mle_router_mtd.hpp +++ b/src/core/thread/mle_router_mtd.hpp @@ -50,7 +50,7 @@ class MleRouter: public Mle friend class Mle; public: - explicit MleRouter(ThreadNetif &aThreadNetif) : Mle(aThreadNetif) { } + explicit MleRouter(otInstance &aInstance) : Mle(aInstance) { } bool IsSingleton(void) { return false; } diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index 964ae9595..dd3252f2a 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -49,8 +49,8 @@ namespace ot { namespace NetworkData { -NetworkData::NetworkData(ThreadNetif &aThreadNetif, bool aLocal): - ThreadNetifLocator(aThreadNetif), +NetworkData::NetworkData(otInstance &aInstance, bool aLocal): + InstanceLocator(aInstance), mLocal(aLocal), mLastAttemptWait(false), mLastAttempt(0) diff --git a/src/core/thread/network_data.hpp b/src/core/thread/network_data.hpp index c9033ebf5..62945312c 100644 --- a/src/core/thread/network_data.hpp +++ b/src/core/thread/network_data.hpp @@ -86,7 +86,7 @@ namespace NetworkData { * This class implements Network Data processing. * */ -class NetworkData: public ThreadNetifLocator +class NetworkData: public InstanceLocator { public: enum @@ -97,11 +97,11 @@ public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * @param[in] aLocal TRUE if this represents local network data, FALSE otherwise. * */ - NetworkData(ThreadNetif &aThreadNetif, bool aLocal); + NetworkData(otInstance &aInstance, bool aLocal); /** * This method clears the network data. diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index 5567fa644..a247c5d2d 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -56,8 +56,8 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { namespace NetworkData { -LeaderBase::LeaderBase(ThreadNetif &aThreadNetif): - NetworkData(aThreadNetif, false) +LeaderBase::LeaderBase(otInstance &aInstance): + NetworkData(aInstance, false) { Reset(); } diff --git a/src/core/thread/network_data_leader.hpp b/src/core/thread/network_data_leader.hpp index 1065dcfe7..47a969cb3 100644 --- a/src/core/thread/network_data_leader.hpp +++ b/src/core/thread/network_data_leader.hpp @@ -70,10 +70,10 @@ public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit LeaderBase(ThreadNetif &aThreadNetif); + explicit LeaderBase(otInstance &aInstance); /** * This method reset the Thread Network Data. diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index cdf0dc725..221ee865f 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -61,9 +61,9 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { namespace NetworkData { -Leader::Leader(ThreadNetif &aThreadNetif): - LeaderBase(aThreadNetif), - mTimer(aThreadNetif.GetInstance(), &Leader::HandleTimer, this), +Leader::Leader(otInstance &aInstance): + LeaderBase(aInstance), + mTimer(aInstance, &Leader::HandleTimer, this), mServerData(OT_URI_PATH_SERVER_DATA, &Leader::HandleServerData, this), mCommissioningDataGet(OT_URI_PATH_COMMISSIONER_GET, &Leader::HandleCommissioningGet, this), mCommissioningDataSet(OT_URI_PATH_COMMISSIONER_SET, &Leader::HandleCommissioningSet, this) diff --git a/src/core/thread/network_data_leader_ftd.hpp b/src/core/thread/network_data_leader_ftd.hpp index 2928e586d..92166eefb 100644 --- a/src/core/thread/network_data_leader_ftd.hpp +++ b/src/core/thread/network_data_leader_ftd.hpp @@ -70,10 +70,10 @@ public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit Leader(ThreadNetif &aThreadNetif); + explicit Leader(otInstance &aInstance); /** * This method reset the Thread Network Data. diff --git a/src/core/thread/network_data_leader_mtd.hpp b/src/core/thread/network_data_leader_mtd.hpp index 5ed3dfd1c..27df60c48 100644 --- a/src/core/thread/network_data_leader_mtd.hpp +++ b/src/core/thread/network_data_leader_mtd.hpp @@ -47,7 +47,7 @@ namespace NetworkData { class Leader: public LeaderBase { public: - explicit Leader(ThreadNetif &aThreadNetif) : LeaderBase(aThreadNetif) { } + explicit Leader(otInstance &aInstance) : LeaderBase(aInstance) { } void Start(void) { } void Stop(void) { } diff --git a/src/core/thread/network_data_local.cpp b/src/core/thread/network_data_local.cpp index 54ba8d44d..194dccd7f 100644 --- a/src/core/thread/network_data_local.cpp +++ b/src/core/thread/network_data_local.cpp @@ -44,8 +44,8 @@ namespace ot { namespace NetworkData { -Local::Local(ThreadNetif &aThreadNetif): - NetworkData(aThreadNetif, true), +Local::Local(otInstance &aInstance): + NetworkData(aInstance, true), mOldRloc(Mac::kShortAddrInvalid) { } diff --git a/src/core/thread/network_data_local.hpp b/src/core/thread/network_data_local.hpp index 873c46ce6..9e6cce31d 100644 --- a/src/core/thread/network_data_local.hpp +++ b/src/core/thread/network_data_local.hpp @@ -66,7 +66,7 @@ public: * @param[in] aNetif A reference to the Thread network interface. * */ - explicit Local(ThreadNetif &aNetif); + explicit Local(otInstance &aInstance); /** * This method adds a Border Router entry to the Thread Network Data. diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index afda895c9..17ff06c08 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -59,8 +59,8 @@ namespace ot { namespace NetworkDiagnostic { -NetworkDiagnostic::NetworkDiagnostic(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), +NetworkDiagnostic::NetworkDiagnostic(otInstance &aInstance) : + InstanceLocator(aInstance), mDiagnosticGetRequest(OT_URI_PATH_DIAGNOSTIC_GET_REQUEST, &NetworkDiagnostic::HandleDiagnosticGetRequest, this), mDiagnosticGetQuery(OT_URI_PATH_DIAGNOSTIC_GET_QUERY, &NetworkDiagnostic::HandleDiagnosticGetQuery, this), mDiagnosticGetAnswer(OT_URI_PATH_DIAGNOSTIC_GET_ANSWER, &NetworkDiagnostic::HandleDiagnosticGetAnswer, this), @@ -68,10 +68,10 @@ NetworkDiagnostic::NetworkDiagnostic(ThreadNetif &aThreadNetif) : mReceiveDiagnosticGetCallback(NULL), mReceiveDiagnosticGetCallbackContext(NULL) { - aThreadNetif.GetCoap().AddResource(mDiagnosticGetRequest); - aThreadNetif.GetCoap().AddResource(mDiagnosticGetQuery); - aThreadNetif.GetCoap().AddResource(mDiagnosticGetAnswer); - aThreadNetif.GetCoap().AddResource(mDiagnosticReset); + GetNetif().GetCoap().AddResource(mDiagnosticGetRequest); + GetNetif().GetCoap().AddResource(mDiagnosticGetQuery); + GetNetif().GetCoap().AddResource(mDiagnosticGetAnswer); + GetNetif().GetCoap().AddResource(mDiagnosticReset); } void NetworkDiagnostic::SetReceiveDiagnosticGetCallback(otReceiveDiagnosticGetCallback aCallback, diff --git a/src/core/thread/network_diagnostic.hpp b/src/core/thread/network_diagnostic.hpp index c0bef15aa..ec1dfeb68 100644 --- a/src/core/thread/network_diagnostic.hpp +++ b/src/core/thread/network_diagnostic.hpp @@ -63,14 +63,14 @@ class NetworkDiagnosticTlv; * This class implements the Network Diagnostic processing. * */ -class NetworkDiagnostic: public ThreadNetifLocator +class NetworkDiagnostic: public InstanceLocator { public: /** * This constructor initializes the object. * */ - explicit NetworkDiagnostic(ThreadNetif &aThreadNetif); + explicit NetworkDiagnostic(otInstance &aInstance); /** * This method registers a callback to provide received raw DIAG_GET.rsp or an DIAG_GET.ans payload. diff --git a/src/core/thread/panid_query_server.cpp b/src/core/thread/panid_query_server.cpp index 4ef9a1fd4..7a45087bb 100644 --- a/src/core/thread/panid_query_server.cpp +++ b/src/core/thread/panid_query_server.cpp @@ -49,14 +49,14 @@ namespace ot { -PanIdQueryServer::PanIdQueryServer(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), +PanIdQueryServer::PanIdQueryServer(otInstance &aInstance) : + InstanceLocator(aInstance), mChannelMask(0), mPanId(Mac::kPanIdBroadcast), - mTimer(aThreadNetif.GetInstance(), &PanIdQueryServer::HandleTimer, this), + mTimer(aInstance, &PanIdQueryServer::HandleTimer, this), mPanIdQuery(OT_URI_PATH_PANID_QUERY, &PanIdQueryServer::HandleQuery, this) { - aThreadNetif.GetCoap().AddResource(mPanIdQuery); + GetNetif().GetCoap().AddResource(mPanIdQuery); } void PanIdQueryServer::HandleQuery(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, diff --git a/src/core/thread/panid_query_server.hpp b/src/core/thread/panid_query_server.hpp index 8bccb9686..cfdb182cf 100644 --- a/src/core/thread/panid_query_server.hpp +++ b/src/core/thread/panid_query_server.hpp @@ -56,14 +56,14 @@ class ThreadTargetTlv; * This class implements handling PANID Query Requests. * */ -class PanIdQueryServer: public ThreadNetifLocator +class PanIdQueryServer: public InstanceLocator { public: /** * This constructor initializes the object. * */ - PanIdQueryServer(ThreadNetif &aThreadNetif); + PanIdQueryServer(otInstance &aInstance); private: enum diff --git a/src/core/thread/src_match_controller.cpp b/src/core/thread/src_match_controller.cpp index a9cedb3e4..a71531566 100644 --- a/src/core/thread/src_match_controller.cpp +++ b/src/core/thread/src_match_controller.cpp @@ -43,8 +43,8 @@ namespace ot { -SourceMatchController::SourceMatchController(MeshForwarder &aMeshForwarder) : - MeshForwarderLocator(aMeshForwarder), +SourceMatchController::SourceMatchController(otInstance &aInstance) : + InstanceLocator(aInstance), mEnabled(false) { ClearTable(); @@ -220,7 +220,7 @@ otError SourceMatchController::AddPendingEntries(void) uint8_t numChildren; Child *child; - child = GetMeshForwarder().GetNetif().GetMle().GetChildren(&numChildren); + child = GetNetif().GetMle().GetChildren(&numChildren); for (uint8_t i = 0; i < numChildren; i++, child++) { diff --git a/src/core/thread/src_match_controller.hpp b/src/core/thread/src_match_controller.hpp index 254f99bf3..86aa46938 100644 --- a/src/core/thread/src_match_controller.hpp +++ b/src/core/thread/src_match_controller.hpp @@ -65,16 +65,16 @@ namespace ot { * address or an extended/long address can be added to the source address match table. * */ -class SourceMatchController: public MeshForwarderLocator +class SourceMatchController: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aMeshForwarder A reference to the Mesh Forwarder. + * @param[in] aInstance A reference to the OpenThread instance * */ - explicit SourceMatchController(MeshForwarder &aMeshForwarder); + explicit SourceMatchController(otInstance &aInstance); /** * This method returns the current state of source address matching. diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 94791156d..5fd4c6a29 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -57,58 +57,58 @@ static const otMasterKey kThreadMasterKey = } }; -ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6): - Netif(aIp6, OT_NETIF_INTERFACE_ID_THREAD), - mCoap(*this), +ThreadNetif::ThreadNetif(otInstance &aInstance): + Netif(aInstance, OT_NETIF_INTERFACE_ID_THREAD), + mCoap(aInstance), #if OPENTHREAD_ENABLE_DHCP6_CLIENT - mDhcp6Client(*this), + mDhcp6Client(aInstance), #endif // OPENTHREAD_ENABLE_DHCP6_CLIENT #if OPENTHREAD_ENABLE_DHCP6_SERVER - mDhcp6Server(*this), + mDhcp6Server(aInstance), #endif // OPENTHREAD_ENABLE_DHCP6_SERVER #if OPENTHREAD_ENABLE_DNS_CLIENT - mDnsClient(*this), + mDnsClient(aInstance.mThreadNetif), #endif // OPENTHREAD_ENABLE_DNS_CLIENT - mActiveDataset(*this), - mPendingDataset(*this), - mKeyManager(*this), - mLowpan(*this), - mMac(*this), - mMeshForwarder(*this), - mMleRouter(*this), + mActiveDataset(aInstance), + mPendingDataset(aInstance), + mKeyManager(aInstance), + mLowpan(aInstance), + mMac(aInstance), + mMeshForwarder(aInstance), + mMleRouter(aInstance), #if OPENTHREAD_ENABLE_BORDER_ROUTER - mNetworkDataLocal(*this), + mNetworkDataLocal(aInstance), #endif - mNetworkDataLeader(*this), + mNetworkDataLeader(aInstance), #if OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC - mNetworkDiagnostic(*this), + mNetworkDiagnostic(aInstance), #endif #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD - mCommissioner(*this), + mCommissioner(aInstance), #endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #if OPENTHREAD_ENABLE_DTLS - mDtls(*this), - mCoapSecure(*this), + mDtls(aInstance), + mCoapSecure(aInstance), #endif #if OPENTHREAD_ENABLE_JOINER - mJoiner(*this), + mJoiner(aInstance), #endif // OPENTHREAD_ENABLE_JOINER #if OPENTHREAD_ENABLE_JAM_DETECTION - mJamDetector(*this), + mJamDetector(aInstance), #endif // OPENTHREAD_ENABLE_JAM_DETECTTION #if OPENTHREAD_FTD #if OPENTHREAD_ENABLE_TMF_PROXY mTmfProxy(mMleRouter.GetMeshLocal16(), mCoap), #endif // OPENTHREAD_ENABLE_TMF_PROXY - mJoinerRouter(*this), - mLeader(*this), - mAddressResolver(*this), + mJoinerRouter(aInstance), + mLeader(aInstance), + mAddressResolver(aInstance), #endif // OPENTHREAD_FTD - mChildSupervisor(*this), - mSupervisionListener(*this), - mAnnounceBegin(*this), - mPanIdQuery(*this), - mEnergyScan(*this) + mChildSupervisor(aInstance), + mSupervisionListener(aInstance), + mAnnounceBegin(aInstance), + mPanIdQuery(aInstance), + mEnergyScan(aInstance) { mKeyManager.SetMasterKey(kThreadMasterKey); diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index d16c7141f..bccb70f66 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -101,10 +101,10 @@ public: /** * This constructor initializes the Thread network interface. * - * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aInstance A reference to the OpenThread instance. * */ - ThreadNetif(Ip6::Ip6 &aIp6); + ThreadNetif(otInstance &aInstance); /** * This method enables the Thread network interface. diff --git a/src/core/utils/child_supervision.cpp b/src/core/utils/child_supervision.cpp index aeed16044..5be49e136 100644 --- a/src/core/utils/child_supervision.cpp +++ b/src/core/utils/child_supervision.cpp @@ -48,9 +48,9 @@ namespace Utils { #if OPENTHREAD_FTD -ChildSupervisor::ChildSupervisor(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), - mTimer(aThreadNetif.GetInstance(), &ChildSupervisor::HandleTimer, this), +ChildSupervisor::ChildSupervisor(otInstance &aInstance) : + InstanceLocator(aInstance), + mTimer(aInstance, &ChildSupervisor::HandleTimer, this), mSupervisionInterval(kDefaultSupervisionInterval) { } @@ -178,9 +178,9 @@ ChildSupervisor &ChildSupervisor::GetOwner(const Context &aContext) #endif // #if OPENTHREAD_FTD -SupervisionListener::SupervisionListener(ThreadNetif &aThreadNetif) : - ThreadNetifLocator(aThreadNetif), - mTimer(aThreadNetif.GetInstance(), &SupervisionListener::HandleTimer, this), +SupervisionListener::SupervisionListener(otInstance &aInstance) : + InstanceLocator(aInstance), + mTimer(aInstance, &SupervisionListener::HandleTimer, this), mTimeout(0) { SetTimeout(kDefaultTimeout); diff --git a/src/core/utils/child_supervision.hpp b/src/core/utils/child_supervision.hpp index e3f2962cc..da76f107c 100644 --- a/src/core/utils/child_supervision.hpp +++ b/src/core/utils/child_supervision.hpp @@ -86,16 +86,16 @@ namespace Utils { * This class implements a child supervisor. * */ -class ChildSupervisor: public ThreadNetifLocator +class ChildSupervisor: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit ChildSupervisor(ThreadNetif &aThreadNetif); + explicit ChildSupervisor(otInstance &aInstance); /** * This method starts the child supervision process on parent. @@ -168,7 +168,7 @@ private: class ChildSupervisor { public: - explicit ChildSupervisor(ThreadNetif &) { } + explicit ChildSupervisor(otInstance &) { } void Start(void) { } void Stop(void) { } void SetSupervisionInterval(uint16_t) { } @@ -185,16 +185,16 @@ public: * This class implements a child supervision listener. * */ -class SupervisionListener: public ThreadNetifLocator +class SupervisionListener: public InstanceLocator { public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit SupervisionListener(ThreadNetif &aThreadNetif); + explicit SupervisionListener(otInstance &aInstance); /** * This method starts the supervision listener operation. @@ -260,7 +260,7 @@ private: class SupervisionListener { public: - SupervisionListener(ThreadNetif &) { } + SupervisionListener(otInstance &) { } void Start(void) { } void Stop(void) { } void SetTimeout(uint16_t) { } diff --git a/src/core/utils/jam_detector.cpp b/src/core/utils/jam_detector.cpp index 3593ce16b..183b0a352 100644 --- a/src/core/utils/jam_detector.cpp +++ b/src/core/utils/jam_detector.cpp @@ -45,12 +45,12 @@ namespace ot { namespace Utils { -JamDetector::JamDetector(ThreadNetif &aNetif) : - ThreadNetifLocator(aNetif), +JamDetector::JamDetector(otInstance &aInstance) : + InstanceLocator(aInstance), mHandler(NULL), mContext(NULL), mRssiThreshold(kDefaultRssiThreshold), - mTimer(aNetif.GetInstance(), &JamDetector::HandleTimer, this), + mTimer(aInstance, &JamDetector::HandleTimer, this), mHistoryBitmap(0), mCurSecondStartTime(0), mSampleInterval(0), diff --git a/src/core/utils/jam_detector.hpp b/src/core/utils/jam_detector.hpp index 93bef3ac6..ae8dac2ee 100644 --- a/src/core/utils/jam_detector.hpp +++ b/src/core/utils/jam_detector.hpp @@ -46,7 +46,7 @@ class ThreadNetif; namespace Utils { -class JamDetector: public ThreadNetifLocator +class JamDetector: public InstanceLocator { public: @@ -62,10 +62,10 @@ public: /** * This constructor initializes the object. * - * @param[in] aThreadNetif A reference to the Thread network interface. + * @param[in] aInstance A reference to the OpenThread instance. * */ - explicit JamDetector(ThreadNetif &aThreadNetif); + explicit JamDetector(otInstance &aInstance); /** * Start the jamming detection. diff --git a/tests/unit/test_network_data.cpp b/tests/unit/test_network_data.cpp index 5a777d370..8b34740c4 100644 --- a/tests/unit/test_network_data.cpp +++ b/tests/unit/test_network_data.cpp @@ -40,7 +40,7 @@ class TestNetworkData: public NetworkData::NetworkData { public: TestNetworkData(otInstance *aInstance, const uint8_t *aTlvs, uint8_t aTlvsLength): - NetworkData::NetworkData(aInstance->mThreadNetif, false) { + NetworkData::NetworkData(*aInstance, false) { memcpy(mTlvs, aTlvs, aTlvsLength); mLength = aTlvsLength; }