[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:
Abtin Keshavarzian
2019-04-02 09:07:25 -07:00
committed by Jonathan Hui
parent 9dfa4e2b31
commit 8f112eeb5a
120 changed files with 1846 additions and 2508 deletions
+2 -2
View File
@@ -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++;