From f538240cd2d6db1280dd55bdb811417ef0b5f990 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 8 Apr 2022 13:46:21 -0700 Subject: [PATCH] [instance] move `otMessageGetBufferInfo()` impl to `Instance` (#7573) This commit moves the implementation of `otMessageGetBufferInfo()` from the `message_api.cpp` file to `Instance` class. --- src/core/api/message_api.cpp | 57 +----------------------------------- src/core/common/instance.cpp | 46 +++++++++++++++++++++++++++++ src/core/common/instance.hpp | 17 +++++++++++ 3 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/core/api/message_api.cpp b/src/core/api/message_api.cpp index 81d9baf3b..ecc3bfc4d 100644 --- a/src/core/api/message_api.cpp +++ b/src/core/api/message_api.cpp @@ -145,61 +145,6 @@ exit: #if OPENTHREAD_MTD || OPENTHREAD_FTD void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo) { - uint16_t messages, buffers; - Instance &instance = AsCoreType(aInstance); - - aBufferInfo->mTotalBuffers = instance.Get().GetTotalBufferCount(); - - aBufferInfo->mFreeBuffers = instance.Get().GetFreeBufferCount(); - - instance.Get().GetSendQueue().GetInfo(aBufferInfo->m6loSendMessages, aBufferInfo->m6loSendBuffers); - - instance.Get().GetReassemblyQueue().GetInfo(aBufferInfo->m6loReassemblyMessages, - aBufferInfo->m6loReassemblyBuffers); - -#if OPENTHREAD_FTD - instance.Get().GetResolvingQueue().GetInfo(aBufferInfo->mArpMessages, aBufferInfo->mArpBuffers); -#else - aBufferInfo->mArpMessages = 0; - aBufferInfo->mArpBuffers = 0; -#endif - - instance.Get().GetSendQueue().GetInfo(aBufferInfo->mIp6Messages, aBufferInfo->mIp6Buffers); - -#if OPENTHREAD_FTD - instance.Get().GetBufferedMessageSet().GetInfo(aBufferInfo->mMplMessages, aBufferInfo->mMplBuffers); -#else - aBufferInfo->mMplMessages = 0; - aBufferInfo->mMplBuffers = 0; -#endif - - instance.Get().GetMessageQueue().GetInfo(aBufferInfo->mMleMessages, aBufferInfo->mMleBuffers); - - instance.Get().GetRequestMessages().GetInfo(aBufferInfo->mCoapMessages, aBufferInfo->mCoapBuffers); - instance.Get().GetCachedResponses().GetInfo(messages, buffers); - aBufferInfo->mCoapMessages += messages; - aBufferInfo->mCoapBuffers += buffers; - -#if OPENTHREAD_CONFIG_DTLS_ENABLE - instance.Get().GetRequestMessages().GetInfo(aBufferInfo->mCoapSecureMessages, - aBufferInfo->mCoapSecureBuffers); - instance.Get().GetCachedResponses().GetInfo(messages, buffers); - aBufferInfo->mCoapSecureMessages += messages; - aBufferInfo->mCoapSecureBuffers += buffers; -#else - aBufferInfo->mCoapSecureMessages = 0; - aBufferInfo->mCoapSecureBuffers = 0; -#endif - -#if OPENTHREAD_CONFIG_COAP_API_ENABLE - instance.GetApplicationCoap().GetRequestMessages().GetInfo(aBufferInfo->mApplicationCoapMessages, - aBufferInfo->mApplicationCoapBuffers); - instance.GetApplicationCoap().GetCachedResponses().GetInfo(messages, buffers); - aBufferInfo->mApplicationCoapMessages += messages; - aBufferInfo->mApplicationCoapBuffers += buffers; -#else - aBufferInfo->mApplicationCoapMessages = 0; - aBufferInfo->mApplicationCoapBuffers = 0; -#endif + AsCoreType(aInstance).GetBufferInfo(AsCoreType(aBufferInfo)); } #endif // OPENTHREAD_MTD || OPENTHREAD_FTD diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index 5e87a7e7b..72a768d6a 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -233,6 +233,7 @@ exit: } #if OPENTHREAD_MTD || OPENTHREAD_FTD + void Instance::FactoryReset(void) { Get().Wipe(); @@ -250,6 +251,51 @@ exit: return error; } +void Instance::GetBufferInfo(BufferInfo &aInfo) +{ + uint16_t messages, buffers; + + aInfo.Clear(); + + aInfo.mTotalBuffers = Get().GetTotalBufferCount(); + aInfo.mFreeBuffers = Get().GetFreeBufferCount(); + + Get().GetSendQueue().GetInfo(aInfo.m6loSendMessages, aInfo.m6loSendBuffers); + + Get().GetReassemblyQueue().GetInfo(aInfo.m6loReassemblyMessages, aInfo.m6loReassemblyBuffers); + +#if OPENTHREAD_FTD + Get().GetResolvingQueue().GetInfo(aInfo.mArpMessages, aInfo.mArpBuffers); +#endif + + Get().GetSendQueue().GetInfo(aInfo.mIp6Messages, aInfo.mIp6Buffers); + +#if OPENTHREAD_FTD + Get().GetBufferedMessageSet().GetInfo(aInfo.mMplMessages, aInfo.mMplBuffers); +#endif + + Get().GetMessageQueue().GetInfo(aInfo.mMleMessages, aInfo.mMleBuffers); + + Get().GetRequestMessages().GetInfo(aInfo.mCoapMessages, aInfo.mCoapBuffers); + Get().GetCachedResponses().GetInfo(messages, buffers); + aInfo.mCoapMessages += messages; + aInfo.mCoapBuffers += buffers; + +#if OPENTHREAD_CONFIG_DTLS_ENABLE + Get().GetRequestMessages().GetInfo(aInfo.mCoapSecureMessages, aInfo.mCoapSecureBuffers); + Get().GetCachedResponses().GetInfo(messages, buffers); + aInfo.mCoapSecureMessages += messages; + aInfo.mCoapSecureBuffers += buffers; +#endif + +#if OPENTHREAD_CONFIG_COAP_API_ENABLE + GetApplicationCoap().GetRequestMessages().GetInfo(aInfo.mApplicationCoapMessages, aInfo.mApplicationCoapBuffers); + GetApplicationCoap().GetCachedResponses().GetInfo(messages, buffers); + aInfo.mApplicationCoapMessages += messages; + aInfo.mApplicationCoapBuffers += buffers; +#endif +} + #endif // OPENTHREAD_MTD || OPENTHREAD_FTD } // namespace ot diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index 4daa0ae2b..026613e7e 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -113,6 +113,14 @@ namespace ot { class Instance : public otInstance, private NonCopyable { public: + /** + * This type represents the message buffer information (number of messages/buffers in all OT stack message queues). + * + */ + class BufferInfo : public otBufferInfo, public Clearable + { + }; + #if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE /** * This static method initializes the OpenThread instance. @@ -281,6 +289,14 @@ public: static bool IsDnsNameCompressionEnabled(void) { return sDnsNameCompressionEnabled; } #endif + /** + * This method retrieves the the Message Buffer information. + * + * @param[out] aInfo A `BufferInfo` where information is written. + * + */ + void GetBufferInfo(BufferInfo &aInfo); + #endif // OPENTHREAD_MTD || OPENTHREAD_FTD /** @@ -408,6 +424,7 @@ private: }; DefineCoreType(otInstance, Instance); +DefineCoreType(otBufferInfo, Instance::BufferInfo); // Specializations of the `Get()` method.