#include #include "mqttmsg.h" ///////////////////////////////////////////////////////////////////////////// // CMqttMessagePool::CMqttMessagePool(void) { for(int i = 0; i < _MSG_POOL_SIZE; i++) { CMqttMessage *pMsg = CMqttMessage::CreateMessage(); pMsg->SetPoolMsg(true); pMsg->SetAvailable(true); m_pool[i] = pMsg; } } CMqttMessagePool::~CMqttMessagePool(void) { for(auto i = m_pool.begin(); i != m_pool.end(); ++i) { CMqttMessage *pMsg = *i; pMsg->Release(true); } } CMqttMessage* CMqttMessagePool::GetMsgFromPool(void) { for(auto i = m_pool.begin(); i != m_pool.end(); ++i) { CMqttMessage *pMsg = *i; if(pMsg->IsAvailable()) { pMsg->SetAvailable(false); return pMsg; } } return NULL; } void CMqttMessagePool::ReturnMsgToPool(CMqttMessage *pMsg) { if(pMsg) pMsg->SetAvailable(true); }