mirror of
https://github.com/espressif/openthread.git
synced 2026-08-31 14:29:54 +00:00
[locator] adding Get<Type> to InstanceLocator (#3714)
This commit changes how the objects in OpenThread access each other. It adds a template `Get<Type>()` method in `InstanceLocator`. This method returns a reference to a given `Type` object belonging to the OpenThread instance (e.g. `Get<MeshForwarder>()` returns a reference to `MeshForwarder` object on the OpenThread instance). The `InstanceLocator` is used as base class of all OpenThread classes so every class can easily access any other object. This commit also changes how the main instance is retrieved in `InstanceLocator` for the single-instance case. The method `GetInstance()` directly uses the raw buffer `gInstanceRaw`. This change helps make the `GetInstance()` and in turn all `Get<Type>()` methods in-line. This commit also removes the existing getters across all classes to use the new `Get<Type>()` model.
This commit is contained in:
committed by
Jonathan Hui
parent
9dfa4e2b31
commit
8f112eeb5a
@@ -88,7 +88,7 @@ void VerifyChildIp6Addresses(const Child &aChild, uint8_t aAddressListLength, co
|
||||
{
|
||||
VerifyOrQuit(addressObserved[index], "Child::GetNextIp6Address() missed an entry from the expected list\n");
|
||||
|
||||
if (sInstance->GetThreadNetif().GetMle().IsMeshLocalAddress(aAddressList[index]))
|
||||
if (sInstance->Get<Mle::MleRouter>().IsMeshLocalAddress(aAddressList[index]))
|
||||
{
|
||||
SuccessOrQuit(aChild.GetMeshLocalIp6Address(*sInstance, address),
|
||||
"Child::GetMeshLocalIp6Address() failed\n");
|
||||
@@ -127,7 +127,7 @@ void TestChildIp6Address(void)
|
||||
numAddresses = 0;
|
||||
|
||||
// First addresses uses the mesh local prefix (mesh-local address).
|
||||
addresses[numAddresses] = sInstance->GetThreadNetif().GetMle().GetMeshLocal64();
|
||||
addresses[numAddresses] = sInstance->Get<Mle::MleRouter>().GetMeshLocal64();
|
||||
addresses[numAddresses].SetIid(meshLocalIid);
|
||||
|
||||
numAddresses++;
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace ot {
|
||||
|
||||
ot::Instance * sInstance;
|
||||
Ip6::Ip6 * sIp6;
|
||||
ThreadNetif * sThreadNetif;
|
||||
Lowpan::Lowpan *sLowpan;
|
||||
|
||||
void TestIphcVector::GetCompressedStream(uint8_t *aIphc, uint16_t &aIphcLength)
|
||||
@@ -110,7 +109,7 @@ void TestIphcVector::GetUncompressedStream(Message &aMessage)
|
||||
static void Init()
|
||||
{
|
||||
otMeshLocalPrefix meshLocalPrefix = {{0xfd, 0x00, 0xca, 0xfe, 0xfa, 0xce, 0x12, 0x34}};
|
||||
sThreadNetif->GetMle().SetMeshLocalPrefix(meshLocalPrefix);
|
||||
sInstance->Get<Mle::MleRouter>().SetMeshLocalPrefix(meshLocalPrefix);
|
||||
|
||||
// Emulate global prefixes with contextes.
|
||||
uint8_t mockNetworkData[] = {
|
||||
@@ -128,12 +127,12 @@ static void Init()
|
||||
0x02, 0x40 // Context ID = 2, C = FALSE
|
||||
};
|
||||
|
||||
Message *message = sInstance->GetMessagePool().New(Message::kTypeIp6, 0);
|
||||
Message *message = sInstance->Get<MessagePool>().New(Message::kTypeIp6, 0);
|
||||
VerifyOrQuit(message != NULL, "6lo: Ip6::NewMessage failed");
|
||||
|
||||
SuccessOrQuit(message->Append(mockNetworkData, sizeof(mockNetworkData)), "6lo: Message::Append failed");
|
||||
|
||||
sThreadNetif->GetNetworkDataLeader().SetNetworkData(0, 0, true, *message, 0);
|
||||
sInstance->Get<NetworkData::Leader>().SetNetworkData(0, 0, true, *message, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +179,7 @@ static void Test(TestIphcVector &aVector, bool aCompress, bool aDecompress)
|
||||
{
|
||||
Lowpan::BufferWriter buffer(result, 127);
|
||||
|
||||
VerifyOrQuit((message = sInstance->GetMessagePool().New(Message::kTypeIp6, 0)) != NULL,
|
||||
VerifyOrQuit((message = sInstance->Get<MessagePool>().New(Message::kTypeIp6, 0)) != NULL,
|
||||
"6lo: Ip6::NewMessage failed");
|
||||
|
||||
aVector.GetUncompressedStream(*message);
|
||||
@@ -210,7 +209,7 @@ static void Test(TestIphcVector &aVector, bool aCompress, bool aDecompress)
|
||||
|
||||
if (aDecompress)
|
||||
{
|
||||
VerifyOrQuit((message = sInstance->GetMessagePool().New(Message::kTypeIp6, 0)) != NULL,
|
||||
VerifyOrQuit((message = sInstance->Get<MessagePool>().New(Message::kTypeIp6, 0)) != NULL,
|
||||
"6lo: Ip6::NewMessage failed");
|
||||
|
||||
int decompressedBytes =
|
||||
@@ -1754,9 +1753,8 @@ void TestLowpanIphc(void)
|
||||
|
||||
VerifyOrQuit(sInstance != NULL, "NULL instance");
|
||||
|
||||
sIp6 = &sInstance->GetIp6();
|
||||
sThreadNetif = &sInstance->GetThreadNetif();
|
||||
sLowpan = &sThreadNetif->GetLowpan();
|
||||
sIp6 = &sInstance->Get<Ip6::Ip6>();
|
||||
sLowpan = &sInstance->Get<Lowpan::Lowpan>();
|
||||
|
||||
Init();
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ void TestMessage(void)
|
||||
instance = static_cast<ot::Instance *>(testInitInstance());
|
||||
VerifyOrQuit(instance != NULL, "Null OpenThread instance\n");
|
||||
|
||||
messagePool = &instance->GetMessagePool();
|
||||
messagePool = &instance->Get<ot::MessagePool>();
|
||||
|
||||
for (unsigned i = 0; i < sizeof(writeBuffer); i++)
|
||||
{
|
||||
|
||||
@@ -86,7 +86,7 @@ void TestMessageQueue(void)
|
||||
sInstance = testInitInstance();
|
||||
VerifyOrQuit(sInstance != NULL, "Null instance");
|
||||
|
||||
sMessagePool = &sInstance->GetMessagePool();
|
||||
sMessagePool = &sInstance->Get<ot::MessagePool>();
|
||||
|
||||
for (int i = 0; i < kNumTestMessages; i++)
|
||||
{
|
||||
|
||||
@@ -381,7 +381,7 @@ void TestNcpFrameBuffer(void)
|
||||
NcpFrameBuffer::WritePosition pos1, pos2;
|
||||
|
||||
sInstance = testInitInstance();
|
||||
sMessagePool = &sInstance->GetMessagePool();
|
||||
sMessagePool = &sInstance->Get<MessagePool>();
|
||||
|
||||
for (i = 0; i < sizeof(buffer); i++)
|
||||
{
|
||||
@@ -1006,7 +1006,7 @@ void TestFuzzNcpFrameBuffer(void)
|
||||
uint32_t lensArrayCount[kNumPrios];
|
||||
|
||||
sInstance = testInitInstance();
|
||||
sMessagePool = &sInstance->GetMessagePool();
|
||||
sMessagePool = &sInstance->Get<MessagePool>();
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ void TestPriorityQueue(void)
|
||||
instance = testInitInstance();
|
||||
VerifyOrQuit(instance != NULL, "Null OpenThread instance\n");
|
||||
|
||||
messagePool = &instance->GetMessagePool();
|
||||
messagePool = &instance->Get<ot::MessagePool>();
|
||||
|
||||
// Use the function "New()" to allocate messages with different priorities
|
||||
for (int i = 0; i < kNumNewPriorityTestMessages; i++)
|
||||
|
||||
Reference in New Issue
Block a user