mirror of
https://github.com/espressif/openthread.git
synced 2026-08-12 13:47:47 +00:00
[coap] introduce Coap::Msg to simplify method calls (#12285)
This commit introduces `Coap::Msg`, a class that encapsulates `Coap::Message` and its associated `Ip6::MessageInfo`. `Coap` methods and TMF resource handlers are updated to use `Coap::Msg` when handling received messages. This change simplifies method signatures by reducing the number of parameters and enables future extensibility for tracking additional information related to received CoAP messages.
This commit is contained in:
+15
-15
@@ -3568,22 +3568,22 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
template <> void Mle::HandleTmf<kUriAddressSolicit>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
template <> void Mle::HandleTmf<kUriAddressSolicit>(Coap::Msg &aMsg)
|
||||
{
|
||||
Coap::Message *response = nullptr;
|
||||
AddrSolicitInfo info;
|
||||
|
||||
VerifyOrExit(IsLeader() && !IsAttaching());
|
||||
|
||||
Log(kMessageReceive, kTypeAddressSolicit, aMessageInfo.GetPeerAddr());
|
||||
Log(kMessageReceive, kTypeAddressSolicit, aMsg.mMessageInfo.GetPeerAddr());
|
||||
|
||||
SuccessOrExit(info.ParseFrom(aMessage));
|
||||
SuccessOrExit(info.ParseFrom(aMsg.mMessage));
|
||||
|
||||
ProcessAddressSolicit(info);
|
||||
|
||||
// Prepare and send response
|
||||
|
||||
response = Get<Tmf::Agent>().NewPriorityResponseMessage(aMessage);
|
||||
response = Get<Tmf::Agent>().NewPriorityResponseMessage(aMsg.mMessage);
|
||||
VerifyOrExit(response != nullptr);
|
||||
|
||||
SuccessOrExit(Tlv::Append<ThreadStatusTlv>(*response, info.mResponse));
|
||||
@@ -3601,10 +3601,10 @@ template <> void Mle::HandleTmf<kUriAddressSolicit>(Coap::Message &aMessage, con
|
||||
SuccessOrExit(routerMaskTlv.AppendTo(*response));
|
||||
}
|
||||
|
||||
SuccessOrExit(Get<Tmf::Agent>().SendMessage(*response, aMessageInfo));
|
||||
SuccessOrExit(Get<Tmf::Agent>().SendMessage(*response, aMsg.mMessageInfo));
|
||||
response = nullptr;
|
||||
|
||||
Log(kMessageSend, kTypeAddressReply, aMessageInfo.GetPeerAddr());
|
||||
Log(kMessageSend, kTypeAddressReply, aMsg.mMessageInfo.GetPeerAddr());
|
||||
|
||||
// If assigning a new RLOC16 (e.g., on promotion of a child to
|
||||
// router role) we clear any address cache entries associated
|
||||
@@ -3617,8 +3617,8 @@ template <> void Mle::HandleTmf<kUriAddressSolicit>(Coap::Message &aMessage, con
|
||||
{
|
||||
uint16_t oldRloc16;
|
||||
|
||||
VerifyOrExit(IsRoutingLocator(aMessageInfo.GetPeerAddr()));
|
||||
oldRloc16 = aMessageInfo.GetPeerAddr().GetIid().GetLocator();
|
||||
VerifyOrExit(IsRoutingLocator(aMsg.mMessageInfo.GetPeerAddr()));
|
||||
oldRloc16 = aMsg.mMessageInfo.GetPeerAddr().GetIid().GetLocator();
|
||||
|
||||
VerifyOrExit(oldRloc16 != info.mRouter->GetRloc16());
|
||||
VerifyOrExit(!RouterIdMatch(oldRloc16, GetRloc16()));
|
||||
@@ -3629,7 +3629,7 @@ exit:
|
||||
FreeMessage(response);
|
||||
}
|
||||
|
||||
template <> void Mle::HandleTmf<kUriAddressRelease>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
template <> void Mle::HandleTmf<kUriAddressRelease>(Coap::Msg &aMsg)
|
||||
{
|
||||
uint16_t rloc16;
|
||||
Mac::ExtAddress extAddress;
|
||||
@@ -3638,12 +3638,12 @@ template <> void Mle::HandleTmf<kUriAddressRelease>(Coap::Message &aMessage, con
|
||||
|
||||
VerifyOrExit(mRole == kRoleLeader);
|
||||
|
||||
VerifyOrExit(aMessage.IsConfirmablePostRequest());
|
||||
VerifyOrExit(aMsg.mMessage.IsConfirmablePostRequest());
|
||||
|
||||
Log(kMessageReceive, kTypeAddressRelease, aMessageInfo.GetPeerAddr());
|
||||
Log(kMessageReceive, kTypeAddressRelease, aMsg.mMessageInfo.GetPeerAddr());
|
||||
|
||||
SuccessOrExit(Tlv::Find<ThreadRloc16Tlv>(aMessage, rloc16));
|
||||
SuccessOrExit(Tlv::Find<ThreadExtMacAddressTlv>(aMessage, extAddress));
|
||||
SuccessOrExit(Tlv::Find<ThreadRloc16Tlv>(aMsg.mMessage, rloc16));
|
||||
SuccessOrExit(Tlv::Find<ThreadExtMacAddressTlv>(aMsg.mMessage, extAddress));
|
||||
|
||||
routerId = RouterIdFromRloc16(rloc16);
|
||||
router = mRouterTable.FindRouterById(routerId);
|
||||
@@ -3652,9 +3652,9 @@ template <> void Mle::HandleTmf<kUriAddressRelease>(Coap::Message &aMessage, con
|
||||
|
||||
IgnoreError(mRouterTable.Release(routerId));
|
||||
|
||||
SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMessage, aMessageInfo));
|
||||
SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMsg));
|
||||
|
||||
Log(kMessageSend, kTypeAddressReleaseReply, aMessageInfo.GetPeerAddr());
|
||||
Log(kMessageSend, kTypeAddressReleaseReply, aMsg.mMessageInfo.GetPeerAddr());
|
||||
|
||||
exit:
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user