Skip to content

Commit db0eb92

Browse files
Add MQTT_InitStatefulQoS API
1 parent ca1e6a7 commit db0eb92

File tree

4 files changed

+75
-6
lines changed

4 files changed

+75
-6
lines changed

source/core_mqtt.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2737,7 +2737,9 @@ MQTTStatus_t MQTT_InitStatefulQoS( MQTTContext_t * pContext,
27372737
MQTTPubAckInfo_t * pOutgoingPublishRecords,
27382738
size_t outgoingPublishCount,
27392739
MQTTPubAckInfo_t * pIncomingPublishRecords,
2740-
size_t incomingPublishCount )
2740+
size_t incomingPublishCount,
2741+
uint8_t * pAckPropsBuf,
2742+
size_t ackPropsBufLength )
27412743
{
27422744
MQTTStatus_t status = MQTTSuccess;
27432745

@@ -2783,6 +2785,16 @@ MQTTStatus_t MQTT_InitStatefulQoS( MQTTContext_t * pContext,
27832785
pContext->incomingPublishRecords = pIncomingPublishRecords;
27842786
pContext->outgoingPublishRecordMaxCount = outgoingPublishCount;
27852787
pContext->outgoingPublishRecords = pOutgoingPublishRecords;
2788+
2789+
if( ( pAckPropsBuf != NULL ) && ( ackPropsBufLength != 0U ) )
2790+
{
2791+
status = MQTTPropertyBuilder_Init( &pContext->ackPropsBuffer, pAckPropsBuf, ackPropsBufLength );
2792+
}
2793+
else
2794+
{
2795+
pContext->ackPropsBuffer.pBuffer = NULL;
2796+
pContext->ackPropsBuffer.bufferLength = 0;
2797+
}
27862798
}
27872799

27882800
return status;

source/core_mqtt_serializer.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,3 +2750,31 @@ MQTTStatus_t MQTT_InitConnect( MQTTConnectionProperties_t * pConnectProperties )
27502750
}
27512751

27522752
/*-----------------------------------------------------------*/
2753+
2754+
MQTTStatus_t MQTTPropertyBuilder_Init( MQTTPropBuilder_t * pPropertyBuilder,
2755+
uint8_t * buffer,
2756+
size_t length )
2757+
{
2758+
MQTTStatus_t status = MQTTSuccess;
2759+
2760+
if( ( pPropertyBuilder == NULL ) || ( buffer == NULL ) || ( length == 0U ) )
2761+
{
2762+
LogError( ( "Invalid arguments passed to MQTTPropertyBuilder_Init. "
2763+
"pPropertyBuilder must be non-NULL; "
2764+
"buffer must be non-NULL; "
2765+
"and length must be non-zero. " ) );
2766+
status = MQTTBadParameter;
2767+
}
2768+
2769+
if( status == MQTTSuccess )
2770+
{
2771+
pPropertyBuilder->pBuffer = buffer;
2772+
pPropertyBuilder->currentIndex = 0;
2773+
pPropertyBuilder->bufferLength = length;
2774+
pPropertyBuilder->fieldSet = 0; /* 0 means no field is set. */
2775+
}
2776+
2777+
return status;
2778+
}
2779+
2780+
/*-----------------------------------------------------------*/

source/include/core_mqtt.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,10 @@ MQTTStatus_t MQTT_Init( MQTTContext_t * pContext,
438438
* publishes.
439439
* @param[in] incomingPublishCount Maximum number of records which can be kept in the memory
440440
* pointed to by @p pIncomingPublishRecords.
441-
*
442-
* @return #MQTTBadParameter if invalid parameters are passed;
443-
* #MQTTSuccess otherwise.
441+
* @param[in] pAckPropsBuf Pointer to memory which will be used to store properties of outgoing publish-ACKS.
442+
* @param[in] ackPropsBufLength Length of the buffer pointed to by @p pBuffer.
443+
* @return #MQTTBadParameter if invalid parameters are passed;<br>
444+
* #MQTTSuccess otherwise.<br>
444445
*
445446
* <b>Example</b>
446447
* @code{c}
@@ -483,7 +484,16 @@ MQTTStatus_t MQTT_Init( MQTTContext_t * pContext,
483484
* {
484485
* // We do not expect any incoming publishes in this example, therefore the incoming
485486
* // publish pointer is NULL and the count is zero.
486-
* status = MQTT_InitStatefulQoS( &mqttContext, outgoingPublishes, outgoingPublishCount, NULL, 0 );
487+
* // The buffer is used to store properties of outgoing publish-ACKS.
488+
* uint8_t ackPropsBuf[ 500 ];
489+
* size_t ackPropsBufLength = sizeof( ackPropsBuf );
490+
* status = MQTT_InitStatefulQoS( &mqttContext,
491+
* outgoingPublishes,
492+
* outgoingPublishCount,
493+
* NULL,
494+
* 0,
495+
* ackPropsBuf,
496+
* ackPropsBufLength );
487497
*
488498
* // Now QoS1 and/or QoS2 publishes can be sent with this context.
489499
* }
@@ -494,7 +504,9 @@ MQTTStatus_t MQTT_InitStatefulQoS( MQTTContext_t * pContext,
494504
MQTTPubAckInfo_t * pOutgoingPublishRecords,
495505
size_t outgoingPublishCount,
496506
MQTTPubAckInfo_t * pIncomingPublishRecords,
497-
size_t incomingPublishCount );
507+
size_t incomingPublishCount,
508+
uint8_t * pAckPropsBuf,
509+
size_t ackPropsBufLength );
498510
/* @[declare_mqtt_initstatefulqos] */
499511

500512
/**

source/include/core_mqtt_serializer.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,23 @@ uint8_t * MQTT_SerializeUnsubscribeHeader( size_t remainingLength,
14201420
MQTTStatus_t MQTT_InitConnect( MQTTConnectionProperties_t * pConnectProperties );
14211421
/* @[declare_mqtt_initconnect] */
14221422

1423+
/**
1424+
* @brief Initialize the property builder.
1425+
*
1426+
* @param[out] pPropertyBuilder Property builder to initialize.
1427+
* @param[in] buffer Buffer to store the properties.
1428+
* @param[in] length Length of the buffer.
1429+
*
1430+
* @return
1431+
* - #MQTTBadParameter if invalid parameters are passed.
1432+
* - #MQTTSuccess otherwise.
1433+
*/
1434+
/* @[declare_mqttpropertybuilder_init] */
1435+
MQTTStatus_t MQTTPropertyBuilder_Init( MQTTPropBuilder_t * pPropertyBuilder,
1436+
uint8_t * buffer,
1437+
size_t length );
1438+
/* @[declare_mqttpropertybuilder_init] */
1439+
14231440
/* *INDENT-OFF* */
14241441
#ifdef __cplusplus
14251442
}

0 commit comments

Comments
 (0)