From c0f4cccc65bf728a2df7c4a828955cae891135dc Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 1 Dec 2025 10:21:01 -0800 Subject: [PATCH] [tmf] introduce `DeclareTmfResponseHandlerIn` helper macros (#12187) This commit introduces two new macros, `DeclareTmfResponseHandlerIn` and `DeclareTmfResponseHandlerFullParamIn`, to simplify the definition of TMF/CoAP response handlers. These macros generate the boilerplate code for the `static` callback method within a class and delegate the call to a non-static member method with the same name. This removes the repetitive pattern of manually defining the `static` wrapper in each class. The existing response handlers across various core components are updated to use the new helper macros. --- src/core/meshcop/commissioner.cpp | 60 ++--------------------- src/core/meshcop/commissioner.hpp | 28 ++--------- src/core/meshcop/joiner.cpp | 13 +---- src/core/meshcop/joiner.hpp | 6 +-- src/core/meshcop/joiner_router.cpp | 15 +----- src/core/meshcop/joiner_router.hpp | 6 +-- src/core/thread/dua_manager.cpp | 12 +---- src/core/thread/dua_manager.hpp | 6 +-- src/core/thread/mle.hpp | 7 +-- src/core/thread/mle_ftd.cpp | 9 ---- src/core/thread/mlr_manager.cpp | 15 +----- src/core/thread/mlr_manager.hpp | 7 +-- src/core/thread/network_data_notifier.cpp | 11 +---- src/core/thread/network_data_notifier.hpp | 13 ++--- src/core/thread/network_diagnostic.cpp | 6 --- src/core/thread/network_diagnostic.hpp | 6 +-- src/core/thread/tmf.hpp | 47 ++++++++++++++++++ src/core/utils/mesh_diag.cpp | 13 +---- src/core/utils/mesh_diag.hpp | 9 +--- 19 files changed, 77 insertions(+), 212 deletions(-) diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index e05c51a34..ce8f50498 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -630,21 +630,8 @@ exit: return error; } -void Commissioner::HandleMgmtCommissionerGetResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void Commissioner::HandleMgmtCommissionerGetResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleMgmtCommissionerGetResponse(AsCoapMessagePtr(aMessage), - AsCoreTypePtr(aMessageInfo), aResult); -} - -void Commissioner::HandleMgmtCommissionerGetResponse(Coap::Message *aMessage, - const Ip6::MessageInfo *aMessageInfo, - Error aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); - VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged); LogInfo("Received %s response", UriToString()); @@ -701,21 +688,8 @@ exit: return error; } -void Commissioner::HandleMgmtCommissionerSetResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void Commissioner::HandleMgmtCommissionerSetResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleMgmtCommissionerSetResponse(AsCoapMessagePtr(aMessage), - AsCoreTypePtr(aMessageInfo), aResult); -} - -void Commissioner::HandleMgmtCommissionerSetResponse(Coap::Message *aMessage, - const Ip6::MessageInfo *aMessageInfo, - Error aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); - Error error; uint8_t state; @@ -754,21 +728,8 @@ exit: return error; } -void Commissioner::HandleLeaderPetitionResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void Commissioner::HandleLeaderPetitionResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleLeaderPetitionResponse(AsCoapMessagePtr(aMessage), - AsCoreTypePtr(aMessageInfo), aResult); -} - -void Commissioner::HandleLeaderPetitionResponse(Coap::Message *aMessage, - const Ip6::MessageInfo *aMessageInfo, - Error aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); - uint8_t state; bool retransmit = false; @@ -841,21 +802,8 @@ exit: LogWarnOnError(error, "send keep alive"); } -void Commissioner::HandleLeaderKeepAliveResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void Commissioner::HandleLeaderKeepAliveResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleLeaderKeepAliveResponse(AsCoapMessagePtr(aMessage), - AsCoreTypePtr(aMessageInfo), aResult); -} - -void Commissioner::HandleLeaderKeepAliveResponse(Coap::Message *aMessage, - const Ip6::MessageInfo *aMessageInfo, - Error aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); - uint8_t state; VerifyOrExit(mState == kStateActive); diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index 6de9e2c9f..8e7dc4d5f 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -393,30 +393,10 @@ private: void HandleTimer(void); void HandleJoinerExpirationTimer(void); - static void HandleMgmtCommissionerSetResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleMgmtCommissionerSetResponse(Coap::Message *aMessage, - const Ip6::MessageInfo *aMessageInfo, - Error aResult); - static void HandleMgmtCommissionerGetResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleMgmtCommissionerGetResponse(Coap::Message *aMessage, - const Ip6::MessageInfo *aMessageInfo, - Error aResult); - static void HandleLeaderPetitionResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleLeaderPetitionResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, otError aResult); - static void HandleLeaderKeepAliveResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - Error aResult); - void HandleLeaderKeepAliveResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); + DeclareTmfResponseHandlerIn(Commissioner, HandleMgmtCommissionerSetResponse); + DeclareTmfResponseHandlerIn(Commissioner, HandleMgmtCommissionerGetResponse); + DeclareTmfResponseHandlerIn(Commissioner, HandleLeaderPetitionResponse); + DeclareTmfResponseHandlerIn(Commissioner, HandleLeaderKeepAliveResponse); static void HandleSecureAgentConnectEvent(Dtls::Session::ConnectEvent aEvent, void *aContext); void HandleSecureAgentConnectEvent(Dtls::Session::ConnectEvent aEvent); diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 4e7cf7fbf..802bd8187 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -472,19 +472,8 @@ exit: return; } -void Joiner::HandleJoinerFinalizeResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void Joiner::HandleJoinerFinalizeResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleJoinerFinalizeResponse(AsCoapMessagePtr(aMessage), &AsCoreType(aMessageInfo), - aResult); -} - -void Joiner::HandleJoinerFinalizeResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); - uint8_t state; VerifyOrExit(mState == kStateConnected && aResult == kErrorNone); diff --git a/src/core/meshcop/joiner.hpp b/src/core/meshcop/joiner.hpp index 3cdde0ae1..c88de2399 100644 --- a/src/core/meshcop/joiner.hpp +++ b/src/core/meshcop/joiner.hpp @@ -196,11 +196,7 @@ private: static void HandleSecureCoapClientConnect(Dtls::Session::ConnectEvent aEvent, void *aContext); void HandleSecureCoapClientConnect(Dtls::Session::ConnectEvent aEvent); - static void HandleJoinerFinalizeResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleJoinerFinalizeResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); + DeclareTmfResponseHandlerIn(Joiner, HandleJoinerFinalizeResponse); template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index b93ed9a0b..b7c103804 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -306,21 +306,8 @@ exit: return message; } -void JoinerRouter::HandleJoinerEntrustResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void JoinerRouter::HandleJoinerEntrustResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleJoinerEntrustResponse(AsCoapMessagePtr(aMessage), - AsCoreTypePtr(aMessageInfo), aResult); -} - -void JoinerRouter::HandleJoinerEntrustResponse(Coap::Message *aMessage, - const Ip6::MessageInfo *aMessageInfo, - Error aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); - SendDelayedJoinerEntrust(); VerifyOrExit(aResult == kErrorNone && aMessage != nullptr); diff --git a/src/core/meshcop/joiner_router.hpp b/src/core/meshcop/joiner_router.hpp index 76b8f421b..51fb2121d 100644 --- a/src/core/meshcop/joiner_router.hpp +++ b/src/core/meshcop/joiner_router.hpp @@ -98,11 +98,7 @@ private: template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); - static void HandleJoinerEntrustResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleJoinerEntrustResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); + DeclareTmfResponseHandlerIn(JoinerRouter, HandleJoinerEntrustResponse); void HandleTimer(void); diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index 16a9d5c27..886756415 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -539,18 +539,8 @@ exit: FreeMessageOnError(message, error); } -void DuaManager::HandleDuaResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void DuaManager::HandleDuaResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleDuaResponse(AsCoapMessagePtr(aMessage), AsCoreTypePtr(aMessageInfo), - aResult); -} - -void DuaManager::HandleDuaResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); Error error; mIsDuaPending = false; diff --git a/src/core/thread/dua_manager.hpp b/src/core/thread/dua_manager.hpp index 36d8e7a1c..43f368252 100644 --- a/src/core/thread/dua_manager.hpp +++ b/src/core/thread/dua_manager.hpp @@ -219,11 +219,7 @@ private: void UpdateTimeTickerRegistration(void); - static void HandleDuaResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleDuaResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); + DeclareTmfResponseHandlerIn(DuaManager, HandleDuaResponse); template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index e4ae026e6..ee63bb8e6 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -2414,11 +2414,12 @@ private: bool ShouldDowngrade(uint8_t aNeighborId, const RouteTlv &aRouteTlv) const; bool NeighborHasComparableConnectivity(const RouteTlv &aRouteTlv, uint8_t aNeighborId) const; void HandleAdvertiseTrickleTimer(void); - void HandleAddressSolicitResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); void HandleTimeTick(void); template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); + DeclareTmfResponseHandlerFullParamIn(Mle, HandleAddressSolicitResponse); + #if OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE void SignalDuaAddressEvent(const Child &aChild, const Ip6::Address &aOldDua) const; #endif @@ -2426,10 +2427,6 @@ private: static bool IsMessageMleSubType(const Message &aMessage); static bool IsMessageChildUpdateRequest(const Message &aMessage); static void HandleAdvertiseTrickleTimer(TrickleTimer &aTimer); - static void HandleAddressSolicitResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); #if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) const char *RouterUpgradeReasonToString(uint8_t aReason); diff --git a/src/core/thread/mle_ftd.cpp b/src/core/thread/mle_ftd.cpp index adce6418c..a8f3f73ae 100644 --- a/src/core/thread/mle_ftd.cpp +++ b/src/core/thread/mle_ftd.cpp @@ -3332,15 +3332,6 @@ exit: LogSendError(kTypeAddressRelease, error); } -void Mle::HandleAddressSolicitResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) -{ - static_cast(aContext)->HandleAddressSolicitResponse(AsCoapMessagePtr(aMessage), AsCoreTypePtr(aMessageInfo), - aResult); -} - void Mle::HandleAddressSolicitResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult) { uint8_t status; diff --git a/src/core/thread/mlr_manager.cpp b/src/core/thread/mlr_manager.cpp index c1f8189d6..6c6fffab5 100644 --- a/src/core/thread/mlr_manager.cpp +++ b/src/core/thread/mlr_manager.cpp @@ -335,26 +335,15 @@ exit: return error; } -void MlrManager::HandleRegisterResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void MlrManager::HandleRegisterResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleRegisterResponse(AsCoapMessagePtr(aMessage), AsCoreTypePtr(aMessageInfo), - aResult); -} - -void MlrManager::HandleRegisterResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); - uint8_t status; Error error; AddressArray failedAddresses; mRegisterPending = false; - error = ParseMlrResponse(aResult, AsCoapMessagePtr(aMessage), status, failedAddresses); + error = ParseMlrResponse(aResult, aMessage, status, failedAddresses); mRegisterCallback.InvokeAndClearIfSet(error, status, failedAddresses.GetArrayBuffer(), failedAddresses.GetLength()); } diff --git a/src/core/thread/mlr_manager.hpp b/src/core/thread/mlr_manager.hpp index 2fc69bf7c..c401f6b55 100644 --- a/src/core/thread/mlr_manager.hpp +++ b/src/core/thread/mlr_manager.hpp @@ -54,6 +54,7 @@ #include "net/netif.hpp" #include "thread/child.hpp" #include "thread/thread_tlvs.hpp" +#include "thread/tmf.hpp" namespace ot { @@ -167,11 +168,7 @@ private: AddressArray &aFailedAddresses); #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE - static void HandleRegisterResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleRegisterResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult); + DeclareTmfResponseHandlerIn(MlrManager, HandleRegisterResponse); #endif #if OPENTHREAD_CONFIG_MLR_ENABLE diff --git a/src/core/thread/network_data_notifier.cpp b/src/core/thread/network_data_notifier.cpp index 4b5cb72e5..0e3fdf929 100644 --- a/src/core/thread/network_data_notifier.cpp +++ b/src/core/thread/network_data_notifier.cpp @@ -246,19 +246,10 @@ void Notifier::HandleNotifierEvents(Events aEvents) void Notifier::HandleTimer(void) { SynchronizeServerData(); } -void Notifier::HandleCoapResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void Notifier::HandleCoapResponse(Coap::Message *aMessage, Error aResult) { OT_UNUSED_VARIABLE(aMessage); - OT_UNUSED_VARIABLE(aMessageInfo); - static_cast(aContext)->HandleCoapResponse(aResult); -} - -void Notifier::HandleCoapResponse(Error aResult) -{ mWaitingForResponse = false; switch (aResult) diff --git a/src/core/thread/network_data_notifier.hpp b/src/core/thread/network_data_notifier.hpp index 96c1e2b96..75474fde5 100644 --- a/src/core/thread/network_data_notifier.hpp +++ b/src/core/thread/network_data_notifier.hpp @@ -40,12 +40,12 @@ #include -#include "coap/coap.hpp" #include "common/message.hpp" #include "common/non_copyable.hpp" #include "common/notifier.hpp" #include "common/tasklet.hpp" #include "common/time_ticker.hpp" +#include "thread/tmf.hpp" namespace ot { namespace NetworkData { @@ -130,13 +130,10 @@ private: Error UpdateInconsistentData(void); #endif - void HandleNotifierEvents(Events aEvents); - void HandleTimer(void); - static void HandleCoapResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleCoapResponse(Error aResult); + void HandleNotifierEvents(Events aEvents); + void HandleTimer(void); + + DeclareTmfResponseHandlerIn(Notifier, HandleCoapResponse); #if OPENTHREAD_CONFIG_BORDER_ROUTER_SIGNAL_NETWORK_DATA_FULL void HandleNetDataFull(void); diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index bd2c60059..ffc27c4a8 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -1220,12 +1220,6 @@ exit: return error; } -void Client::HandleGetResponse(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult) -{ - static_cast(aContext)->HandleGetResponse(AsCoapMessagePtr(aMessage), AsCoreTypePtr(aMessageInfo), - aResult); -} - void Client::HandleGetResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult) { SuccessOrExit(aResult); diff --git a/src/core/thread/network_diagnostic.hpp b/src/core/thread/network_diagnostic.hpp index 1efcd981d..621a1e840 100644 --- a/src/core/thread/network_diagnostic.hpp +++ b/src/core/thread/network_diagnostic.hpp @@ -372,11 +372,7 @@ private: Coap::ResponseHandler aHandler = nullptr, void *aContext = nullptr); - static void HandleGetResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - void HandleGetResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); + DeclareTmfResponseHandlerFullParamIn(Client, HandleGetResponse); template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); diff --git a/src/core/thread/tmf.hpp b/src/core/thread/tmf.hpp index 31fecd9cc..37ba47820 100644 --- a/src/core/thread/tmf.hpp +++ b/src/core/thread/tmf.hpp @@ -38,6 +38,7 @@ #include "coap/coap.hpp" #include "coap/coap_secure.hpp" +#include "common/as_core_type.hpp" #include "common/locator.hpp" namespace ot { @@ -56,6 +57,52 @@ namespace Tmf { #define DeclareTmfHandler(Type, kUri) \ template <> void Type::HandleTmf(Coap::Message & aMessage, const Ip6::MessageInfo &aMessageInfo) +/** + * Declares a TMF/CoAP response handler method in a given class `Type`. + * + * This macro simplifies the definition of a TMF/CoAP response handler. It defines a `static` handler method which + * can be used as a callback function pointer (`Coap::ResponseHandler`). The `static` handler acts as a wrapper, + * casting the `aContext` pointer back to a `Type` object and invoking its member method with the same `MethodName`. + * + * This macro is intended for cases where the response handler method does not require the `aMessageInfo`. + * + * The `Type` class MUST implement the following member method which will be invoked by the `static` handler: + * + * void MethodName(Coap::Message *aMessage, Error aResult); + * + * @param[in] Type The class `Type` in which the TMF response handler is declared. + * @param[in] MethodName The handler method name. + */ +#define DeclareTmfResponseHandlerIn(Type, MethodName) \ + static void MethodName(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult) \ + { \ + OT_UNUSED_VARIABLE(aMessageInfo); \ + static_cast(aContext)->MethodName(AsCoapMessagePtr(aMessage), aResult); \ + } \ + \ + void MethodName(Coap::Message *aMessage, Error aResult) + +/** + * Declares a TMF/CoAP response handler with access to `MessageInfo` in a given class `Type`. + * + * This macro is a variant of `DeclareTmfResponseHandlerIn` and is intended for cases where the response handler needs + * access to the full parameters including `Ip6::MessageInfo`. + * + * The `Type` class MUST implement the following member method which will be invoked by the `static` handler: + * + * void MethodName(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); + * + * @param[in] Type The class `Type` in which the TMF response handler is declared. + * @param[in] MethodName The handler method name. + */ +#define DeclareTmfResponseHandlerFullParamIn(Type, MethodName) \ + static void MethodName(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult) \ + { \ + static_cast(aContext)->MethodName(AsCoapMessagePtr(aMessage), AsCoreTypePtr(aMessageInfo), aResult); \ + } \ + \ + void MethodName(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult) + constexpr uint16_t kUdpPort = 61631; ///< TMF UDP Port typedef Coap::Message Message; ///< A TMF message. diff --git a/src/core/utils/mesh_diag.cpp b/src/core/utils/mesh_diag.cpp index 48b9b8a89..25432710c 100644 --- a/src/core/utils/mesh_diag.cpp +++ b/src/core/utils/mesh_diag.cpp @@ -113,19 +113,8 @@ exit: return error; } -void MeshDiag::HandleDiagGetResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void MeshDiag::HandleDiagGetResponse(Coap::Message *aMessage, Error aResult) { - static_cast(aContext)->HandleDiagGetResponse(AsCoapMessagePtr(aMessage), AsCoreTypePtr(aMessageInfo), - aResult); -} - -void MeshDiag::HandleDiagGetResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult) -{ - OT_UNUSED_VARIABLE(aMessageInfo); - Error error; RouterInfo routerInfo; Ip6AddrIterator ip6AddrIterator; diff --git a/src/core/utils/mesh_diag.hpp b/src/core/utils/mesh_diag.hpp index c2283c554..e740582ed 100644 --- a/src/core/utils/mesh_diag.hpp +++ b/src/core/utils/mesh_diag.hpp @@ -44,7 +44,6 @@ #include -#include "coap/coap.hpp" #include "common/callback.hpp" #include "common/locator.hpp" #include "common/message.hpp" @@ -52,6 +51,7 @@ #include "net/ip6_address.hpp" #include "thread/network_diagnostic.hpp" #include "thread/network_diagnostic_tlvs.hpp" +#include "thread/tmf.hpp" struct otMeshDiagIp6AddrIterator { @@ -306,12 +306,7 @@ private: bool ProcessChildrenIp6AddrsAnswer(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); bool ProcessRouterNeighborTableAnswer(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); - void HandleDiagGetResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); - - static void HandleDiagGetResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); + DeclareTmfResponseHandlerIn(MeshDiag, HandleDiagGetResponse); using TimeoutTimer = TimerMilliIn;