[coap] add new helper to allocate and init CoAP message (#7631)

This commit adds new helper methods in `Coap` to allocate a new
message and initialize it as a confirmable or non-confirmable post to
a given URI path. It also adds a new helper method to allocate a CoAP
response message for a given request. These methods help simplify the
preparation of CoAP and TMF messages.
This commit is contained in:
Abtin Keshavarzian
2022-05-06 10:27:55 -07:00
committed by GitHub
parent 3a125c66d2
commit cc003b3a42
24 changed files with 254 additions and 278 deletions
+4 -8
View File
@@ -455,10 +455,8 @@ void DuaManager::PerformNextRegistration(void)
}
// Prepare DUA.req
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kDuaRegistrationRequest));
SuccessOrExit(error = message->SetPayloadMarker());
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kDuaRegistrationRequest);
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
#if OPENTHREAD_CONFIG_DUA_ENABLE
if (mDuaState == kToRegister && mDelay.mFields.mRegistrationDelay == 0)
@@ -728,10 +726,8 @@ void DuaManager::SendAddressNotification(Ip6::Address & aAddress,
Tmf::MessageInfo messageInfo(GetInstance());
Error error;
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kDuaRegistrationNotify));
SuccessOrExit(error = message->SetPayloadMarker());
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kDuaRegistrationNotify);
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = Tlv::Append<ThreadStatusTlv>(*message, aStatus));
SuccessOrExit(error = Tlv::Append<ThreadTargetTlv>(*message, aAddress));