mirror of
https://github.com/espressif/openthread.git
synced 2026-08-30 22:09:54 +00:00
[tmf] new model for handling TMF URI resources (#8233)
This commit updates and simplifies the handling of TMF URI resources. The new model centralizes the processing and dispatching of URI handlers in `Tmf::Agent`. It should help reduce memory (RAM and code) use as well. - A new enumeration `Uri` type is defined specifying all the TMF URIs along with functions to map between `Uri` and the related URI path string. - We use binary search in a sorted table to match a path string (e.g., from a received CoAP message) to its corresponding URI. - `Coap` class is updated to allow sub-classes to register an optional `ResourceHandler` to handle URI resources. - `Tmf::Agent` uses the new `ResourceHandler` to process the TMF URI resources and invoke the related handlers on the proper module (e.g., passing `kUriAddressQuery` to `AddressResolver` module, `kUriActiveSet` to `MeshCoP::ActiveDatasetManager`, etc). - The TMF handlers are defined as `HandleTmf<Uri>()` template method specializations which are defined on the proper module. - Most URI handlers can be processed at any time but some perform additional checks, e.g., `kUriAddressSolicit` is passed to `Mle::MleRouter` which checks that device role is leader before processing the request.
This commit is contained in:
@@ -55,7 +55,6 @@ RegisterLogModule("DuaManager");
|
||||
DuaManager::DuaManager(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, mRegistrationTask(aInstance)
|
||||
, mDuaNotification(UriPath::kDuaRegistrationNotify, &DuaManager::HandleDuaNotification, this)
|
||||
, mIsDuaPending(false)
|
||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||
, mDuaState(kNotExist)
|
||||
@@ -77,8 +76,6 @@ DuaManager::DuaManager(Instance &aInstance)
|
||||
mChildDuaMask.Clear();
|
||||
mChildDuaRegisteredMask.Clear();
|
||||
#endif
|
||||
|
||||
Get<Tmf::Agent>().AddResource(mDuaNotification);
|
||||
}
|
||||
|
||||
void DuaManager::HandleDomainPrefixUpdate(BackboneRouter::Leader::DomainPrefixState aState)
|
||||
@@ -450,7 +447,7 @@ void DuaManager::PerformNextRegistration(void)
|
||||
}
|
||||
|
||||
// Prepare DUA.req
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kDuaRegistrationRequest);
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(kUriDuaRegistrationRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||
@@ -580,11 +577,8 @@ exit:
|
||||
LogInfo("Received DUA.rsp: %s", ErrorToString(error));
|
||||
}
|
||||
|
||||
void DuaManager::HandleDuaNotification(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
|
||||
{
|
||||
static_cast<DuaManager *>(aContext)->HandleDuaNotification(AsCoapMessage(aMessage), AsCoreType(aMessageInfo));
|
||||
}
|
||||
void DuaManager::HandleDuaNotification(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
template <>
|
||||
void DuaManager::HandleTmf<kUriDuaRegistrationNotify>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||
|
||||
@@ -721,7 +715,7 @@ void DuaManager::SendAddressNotification(Ip6::Address & aAddress,
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Error error;
|
||||
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kDuaRegistrationNotify);
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(kUriDuaRegistrationNotify);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<ThreadStatusTlv>(*message, aStatus));
|
||||
|
||||
Reference in New Issue
Block a user