[locator] adding OwnerLocator (#2346)

This commit adds a new class `OwnerLocator` which is used by the
callback providing types (like `Timer` or `Tasklet`) to remember the
owner of the object. This change help simplify the handling of
callbacks from such objects. The object itself can be used to get
to its owner using `GetOwner<Type>()` method.  If support for multiple
OpenThread instances is enabled, an `OwnerLocator`  object maintains a
pointer to the owner. But for the single OpenThread instance scenario,
the owner is derived from the single `ot::Instance` object.
This commit is contained in:
Abtin Keshavarzian
2017-11-28 14:42:54 -08:00
committed by Jonathan Hui
parent 513903061a
commit 5fc97364f3
66 changed files with 381 additions and 529 deletions
+3 -3
View File
@@ -3536,13 +3536,13 @@ void Interpreter::SetUserCommands(const otCliCommand *aCommands, uint8_t aLength
mUserCommandsLength = aLength;
}
Interpreter &Interpreter::GetOwner(const Context &aContext)
Interpreter &Interpreter::GetOwner(OwnerLocator &aOwnerLocator)
{
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Interpreter &interpreter = *static_cast<Interpreter *>(aContext.GetContext());
Interpreter &interpreter = (aOwnerLocator.GetOwner<Interpreter>());
#else
Interpreter &interpreter = Uart::sUartServer->GetInterpreter();
OT_UNUSED_VARIABLE(aContext);
OT_UNUSED_VARIABLE(aOwnerLocator);
#endif
return interpreter;
}