From 7bbff74893d8d85975fc9dfd2fb1d652e1ae4522 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 17 Dec 2025 19:59:55 -0800 Subject: [PATCH] [coap] ensure `InvokeResponseFallback()` adheres to style guide (#12223) This commit moves the implementation of `InvokeResponseFallback()` to the `cpp` file. It also ensures that the implementation follows the style guide requirement of single `return` from any method/function. --- src/core/coap/coap.cpp | 15 ++++++++++++++- src/core/coap/coap.hpp | 10 +--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/core/coap/coap.cpp b/src/core/coap/coap.cpp index 6816e8bc8..549eab93b 100644 --- a/src/core/coap/coap.cpp +++ b/src/core/coap/coap.cpp @@ -1310,7 +1310,9 @@ exit: if (error == kErrorNone && request == nullptr) { - if (!InvokeResponseFallback(aMessage, aMessageInfo) && aMessage.RequireResetOnError()) + bool didHandle = InvokeResponseFallback(aMessage, aMessageInfo); + + if (!didHandle && aMessage.RequireResetOnError()) { // Successfully parsed a header but no matching request was // found - reject the message by sending reset. @@ -1319,6 +1321,17 @@ exit: } } +bool CoapBase::InvokeResponseFallback(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) const +{ + bool didHandle = false; + + VerifyOrExit(mResponseFallback.IsSet()); + didHandle = mResponseFallback.Invoke(&aMessage, &aMessageInfo); + +exit: + return didHandle; +} + void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { char uriPath[Message::kMaxReceivedUriPath + 1]; diff --git a/src/core/coap/coap.hpp b/src/core/coap/coap.hpp index f8ff74caf..92cb9ae5b 100644 --- a/src/core/coap/coap.hpp +++ b/src/core/coap/coap.hpp @@ -849,15 +849,7 @@ private: Message *aResponse, const Ip6::MessageInfo *aMessageInfo, Error aResult); - - inline bool InvokeResponseFallback(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) - { - if (mResponseFallback.IsSet()) - { - return mResponseFallback.Invoke(&aMessage, &aMessageInfo); - } - return false; - } + bool InvokeResponseFallback(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) const; #if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE void FreeLastBlockResponse(void);