[cli] enhance buffer info (#5831)

This commit enhances buffer info when using heap for message buffers.
This commit is contained in:
Yakun Xu
2020-11-20 18:22:23 -08:00
committed by GitHub
parent acbd38a5f1
commit 76022b2e55
4 changed files with 24 additions and 7 deletions
+1 -1
View File
@@ -174,7 +174,7 @@ void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo)
uint16_t messages, buffers;
Instance &instance = *static_cast<Instance *>(aInstance);
aBufferInfo->mTotalBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS;
aBufferInfo->mTotalBuffers = instance.Get<MessagePool>().GetTotalBufferCount();
aBufferInfo->mFreeBuffers = instance.Get<MessagePool>().GetFreeBufferCount();
+14
View File
@@ -42,6 +42,11 @@
#include "net/ip6.hpp"
#if OPENTHREAD_MTD || OPENTHREAD_FTD
#if OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE && !OPENTHREAD_CONFIG_DTLS_ENABLE
#error "OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE is strongly discouraged when OPENTHREAD_CONFIG_DTLS_ENABLE is off."
#endif
namespace ot {
MessagePool::MessagePool(Instance &aInstance)
@@ -169,6 +174,15 @@ uint16_t MessagePool::GetFreeBufferCount(void) const
return rval;
}
uint16_t MessagePool::GetTotalBufferCount(void) const
{
#if OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE
return static_cast<uint16_t>(GetInstance().GetHeap().GetCapacity() / sizeof(Buffer));
#else
return OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS;
#endif
}
const Message::Settings Message::Settings::kDefault(Message::kWithLinkSecurity, Message::kPriorityNormal);
Message::Settings::Settings(LinkSecurityMode aSecurityMode, Priority aPriority)
+8
View File
@@ -1468,6 +1468,14 @@ public:
*/
uint16_t GetFreeBufferCount(void) const;
/**
* This method returns the total number of buffers.
*
* @returns The total number of buffers.
*
*/
uint16_t GetTotalBufferCount(void) const;
private:
Buffer *NewBuffer(Message::Priority aPriority);
void FreeBuffers(Buffer *aBuffer);
@@ -546,13 +546,8 @@
"(and OPENTHREAD_CONFIG_LOG_DEFINE_AS_MACRO_ONLY)"
#endif
#if OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE
#if !OPENTHREAD_CONFIG_DTLS_ENABLE
#error "OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE is strongly discouraged when OPENTHREAD_CONFIG_DTLS_ENABLE is off."
#endif
#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
#if OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE && OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
#error "OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE conflicts with OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT."
#endif
#endif
#endif // OPENTHREAD_CORE_CONFIG_CHECK_H_