in source/core_mqtt_state.c [928:997]
MQTTStatus_t MQTT_UpdateStateAck( MQTTContext_t * pMqttContext,
uint16_t packetId,
MQTTPubAckType_t packetType,
MQTTStateOperation_t opType,
MQTTPublishState_t * pNewState )
{
MQTTPublishState_t newState = MQTTStateNull;
MQTTPublishState_t currentState = MQTTStateNull;
bool isOutgoingPublish = isPublishOutgoing( packetType, opType );
MQTTQoS_t qos = MQTTQoS0;
size_t recordIndex = MQTT_STATE_ARRAY_MAX_COUNT;
MQTTPubAckInfo_t * records = NULL;
MQTTStatus_t status = MQTTBadResponse;
if( ( pMqttContext == NULL ) || ( pNewState == NULL ) )
{
LogError( ( "Argument cannot be NULL: pMqttContext=%p, pNewState=%p.",
( void * ) pMqttContext,
( void * ) pNewState ) );
status = MQTTBadParameter;
}
else if( packetId == MQTT_PACKET_ID_INVALID )
{
LogError( ( "Packet ID must be nonzero." ) );
status = MQTTBadParameter;
}
else if( packetType > MQTTPubcomp )
{
LogError( ( "Invalid packet type %u.", ( unsigned int ) packetType ) );
status = MQTTBadParameter;
}
else
{
if( isOutgoingPublish == true )
{
records = pMqttContext->outgoingPublishRecords;
}
else
{
records = pMqttContext->incomingPublishRecords;
}
recordIndex = findInRecord( records,
MQTT_STATE_ARRAY_MAX_COUNT,
packetId,
&qos,
¤tState );
}
if( recordIndex < MQTT_STATE_ARRAY_MAX_COUNT )
{
newState = MQTT_CalculateStateAck( packetType, opType, qos );
/* Validate state transition and update state record. */
status = updateStateAck( records, recordIndex, packetId, currentState, newState );
/* Update the output parameter. */
if( status == MQTTSuccess )
{
*pNewState = newState;
}
}
else
{
LogError( ( "No matching record found for publish: PacketId=%u.",
( unsigned int ) packetId ) );
}
return status;
}