mirror of
https://github.com/espressif/openthread.git
synced 2026-09-17 06:30:10 +00:00
[topology] have Neighbor/Child/Router inherit from InstanceLocatorInit (#4569)
This commit changes the `Neighbor` class (and therefore its sub-classes `Child` and `Router`) to inherit from `InstanceLoatorInit`. It adds `Init()` method to them as well and ensures that they are initialized before use from `ChildTable`, `RouterTable` and `Mle` classes.
This commit is contained in:
committed by
Jonathan Hui
parent
67c5081d14
commit
fb65c77c1a
@@ -102,7 +102,11 @@ ChildTable::ChildTable(Instance &aInstance)
|
|||||||
: InstanceLocator(aInstance)
|
: InstanceLocator(aInstance)
|
||||||
, mMaxChildrenAllowed(kMaxChildren)
|
, mMaxChildrenAllowed(kMaxChildren)
|
||||||
{
|
{
|
||||||
Clear();
|
for (Child *child = &mChildren[0]; child < OT_ARRAY_END(mChildren); child++)
|
||||||
|
{
|
||||||
|
child->Init(aInstance);
|
||||||
|
child->Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChildTable::Clear(void)
|
void ChildTable::Clear(void)
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ Mle::Mle(Instance &aInstance)
|
|||||||
{
|
{
|
||||||
otMeshLocalPrefix meshLocalPrefix;
|
otMeshLocalPrefix meshLocalPrefix;
|
||||||
|
|
||||||
|
mParent.Init(aInstance);
|
||||||
|
mParentCandidate.Init(aInstance);
|
||||||
|
|
||||||
mLeaderData.Clear();
|
mLeaderData.Clear();
|
||||||
mParentLeaderData.Clear();
|
mParentLeaderData.Clear();
|
||||||
mParent.Clear();
|
mParent.Clear();
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ RouterTable::RouterTable(Instance &aInstance)
|
|||||||
, mRouterIdSequence(Random::NonCrypto::GetUint8())
|
, mRouterIdSequence(Random::NonCrypto::GetUint8())
|
||||||
, mActiveRouterCount(0)
|
, mActiveRouterCount(0)
|
||||||
{
|
{
|
||||||
|
for (uint8_t index = 0; index < Mle::kMaxRouters; index++)
|
||||||
|
{
|
||||||
|
mRouters[index].Init(aInstance);
|
||||||
|
}
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,12 @@
|
|||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
|
|
||||||
|
void Neighbor::Init(Instance &aInstance)
|
||||||
|
{
|
||||||
|
InstanceLocatorInit::Init(aInstance);
|
||||||
|
SetState(kStateInvalid);
|
||||||
|
}
|
||||||
|
|
||||||
bool Neighbor::IsStateValidOrAttaching(void) const
|
bool Neighbor::IsStateValidOrAttaching(void) const
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
@@ -105,8 +111,10 @@ void Neighbor::GenerateChallenge(void)
|
|||||||
|
|
||||||
void Child::Clear(void)
|
void Child::Clear(void)
|
||||||
{
|
{
|
||||||
|
Instance &instance = GetInstance();
|
||||||
|
|
||||||
memset(reinterpret_cast<void *>(this), 0, sizeof(Child));
|
memset(reinterpret_cast<void *>(this), 0, sizeof(Child));
|
||||||
SetState(kStateInvalid);
|
Init(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Child::ClearIp6Addresses(void)
|
void Child::ClearIp6Addresses(void)
|
||||||
@@ -282,8 +290,10 @@ void Child::GenerateChallenge(void)
|
|||||||
|
|
||||||
void Router::Clear(void)
|
void Router::Clear(void)
|
||||||
{
|
{
|
||||||
|
Instance &instance = GetInstance();
|
||||||
|
|
||||||
memset(reinterpret_cast<void *>(this), 0, sizeof(Router));
|
memset(reinterpret_cast<void *>(this), 0, sizeof(Router));
|
||||||
SetState(kStateInvalid);
|
Init(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ot
|
} // namespace ot
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include <openthread/thread_ftd.h>
|
#include <openthread/thread_ftd.h>
|
||||||
|
|
||||||
|
#include "common/locator.hpp"
|
||||||
#include "common/message.hpp"
|
#include "common/message.hpp"
|
||||||
#include "common/random.hpp"
|
#include "common/random.hpp"
|
||||||
#include "common/timer.hpp"
|
#include "common/timer.hpp"
|
||||||
@@ -50,13 +51,11 @@
|
|||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
|
|
||||||
class Instance;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a Thread neighbor.
|
* This class represents a Thread neighbor.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Neighbor
|
class Neighbor : public InstanceLocatorInit
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -420,6 +419,15 @@ public:
|
|||||||
void SetTimeSyncEnabled(bool aEnabled) { mTimeSyncEnabled = aEnabled; }
|
void SetTimeSyncEnabled(bool aEnabled) { mTimeSyncEnabled = aEnabled; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* This method initializes the `Neighbor` object.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance A reference to OpenThread instance.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void Init(Instance &aInstance);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mac::ExtAddress mMacAddr; ///< The IEEE 802.15.4 Extended Address
|
Mac::ExtAddress mMacAddr; ///< The IEEE 802.15.4 Extended Address
|
||||||
TimeMilli mLastHeard; ///< Time when last heard.
|
TimeMilli mLastHeard; ///< Time when last heard.
|
||||||
@@ -511,6 +519,14 @@ public:
|
|||||||
otChildIp6AddressIterator mIndex;
|
otChildIp6AddressIterator mIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method initializes the `Child` object.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance A reference to OpenThread instance.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void Init(Instance &aInstance) { Neighbor::Init(aInstance); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method clears the child entry.
|
* This method clears the child entry.
|
||||||
*
|
*
|
||||||
@@ -726,6 +742,14 @@ private:
|
|||||||
class Router : public Neighbor
|
class Router : public Neighbor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* This method initializes the `Router` object.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance A reference to OpenThread instance.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void Init(Instance &aInstance) { Neighbor::Init(aInstance); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method clears the router entry.
|
* This method clears the router entry.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ void TestChildIp6Address(void)
|
|||||||
sInstance = testInitInstance();
|
sInstance = testInitInstance();
|
||||||
VerifyOrQuit(sInstance != NULL, "Null instance");
|
VerifyOrQuit(sInstance != NULL, "Null instance");
|
||||||
|
|
||||||
|
child.Init(*sInstance);
|
||||||
|
|
||||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
printf("\nConverting IPv6 addresses from string");
|
printf("\nConverting IPv6 addresses from string");
|
||||||
|
|||||||
Reference in New Issue
Block a user