From c304cd42c95959448475f526d4a32ebf31c4014e Mon Sep 17 00:00:00 2001 From: ActoryOu Date: Wed, 30 Jul 2025 06:34:30 +0000 Subject: [PATCH] Move static arrays from function MQTTAgent_Init to MQTTAgentContext_t. --- source/core_mqtt_agent.c | 16 ++-------------- source/include/core_mqtt_agent.h | 14 ++++++++------ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/source/core_mqtt_agent.c b/source/core_mqtt_agent.c index cbc9598..5c0f840 100644 --- a/source/core_mqtt_agent.c +++ b/source/core_mqtt_agent.c @@ -973,18 +973,6 @@ MQTTStatus_t MQTTAgent_Init( MQTTAgentContext_t * pMqttAgentContext, { MQTTStatus_t returnStatus; - /** - * @brief Array used to maintain the outgoing publish records and their - * state by the coreMQTT library. - */ - static MQTTPubAckInfo_t pIncomingPublishRecords[ MQTT_AGENT_MAX_OUTSTANDING_ACKS ]; - - /** - * @brief Array used to maintain the outgoing publish records and their - * state by the coreMQTT library. - */ - static MQTTPubAckInfo_t pOutgoingPublishRecords[ MQTT_AGENT_MAX_OUTSTANDING_ACKS ]; - if( ( pMqttAgentContext == NULL ) || ( pMsgInterface == NULL ) || ( pTransportInterface == NULL ) || @@ -1017,9 +1005,9 @@ MQTTStatus_t MQTTAgent_Init( MQTTAgentContext_t * pMqttAgentContext, if( returnStatus == MQTTSuccess ) { returnStatus = MQTT_InitStatefulQoS( &( pMqttAgentContext->mqttContext ), - pOutgoingPublishRecords, + pMqttAgentContext->pOutgoingPublishRecords, MQTT_AGENT_MAX_OUTSTANDING_ACKS, - pIncomingPublishRecords, + pMqttAgentContext->pIncomingPublishRecords, MQTT_AGENT_MAX_OUTSTANDING_ACKS ); } } diff --git a/source/include/core_mqtt_agent.h b/source/include/core_mqtt_agent.h index 1f6a11d..9398d52 100644 --- a/source/include/core_mqtt_agent.h +++ b/source/include/core_mqtt_agent.h @@ -151,12 +151,14 @@ typedef void (* MQTTAgentIncomingPublishCallback_t )( struct MQTTAgentContext * */ typedef struct MQTTAgentContext { - MQTTContext_t mqttContext; /**< MQTT connection information used by coreMQTT. */ - MQTTAgentMessageInterface_t agentInterface; /**< Struct of function pointers for agent messaging. */ - MQTTAgentAckInfo_t pPendingAcks[ MQTT_AGENT_MAX_OUTSTANDING_ACKS ]; /**< List of pending acknowledgment packets. */ - MQTTAgentIncomingPublishCallback_t pIncomingCallback; /**< Callback to invoke for incoming publishes. */ - void * pIncomingCallbackContext; /**< Context for incoming publish callback. */ - bool packetReceivedInLoop; /**< Whether a MQTT_ProcessLoop() call received a packet. */ + MQTTContext_t mqttContext; /**< MQTT connection information used by coreMQTT. */ + MQTTAgentMessageInterface_t agentInterface; /**< Struct of function pointers for agent messaging. */ + MQTTAgentAckInfo_t pPendingAcks[ MQTT_AGENT_MAX_OUTSTANDING_ACKS ]; /**< List of pending acknowledgment packets. */ + MQTTAgentIncomingPublishCallback_t pIncomingCallback; /**< Callback to invoke for incoming publishes. */ + void * pIncomingCallbackContext; /**< Context for incoming publish callback. */ + bool packetReceivedInLoop; /**< Whether a MQTT_ProcessLoop() call received a packet. */ + MQTTPubAckInfo_t pIncomingPublishRecords[ MQTT_AGENT_MAX_OUTSTANDING_ACKS ]; /**< Array used to maintain the incoming publish records and their state by the coreMQTT library. */ + MQTTPubAckInfo_t pOutgoingPublishRecords[ MQTT_AGENT_MAX_OUTSTANDING_ACKS ]; /**< Array used to maintain the outgoing publish records and their state by the coreMQTT library. */ } MQTTAgentContext_t; /**