Skip to content

Commit 43aed2a

Browse files
author
Dakshit Babbar
committed
Resolve memory stats, spell check, doxygen example and comments
1 parent 0753992 commit 43aed2a

File tree

4 files changed

+112
-37
lines changed

4 files changed

+112
-37
lines changed

docs/doxygen/include/size_table.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</tr>
1010
<tr>
1111
<td>core_mqtt.c</td>
12-
<td><center>4.4K</center></td>
13-
<td><center>3.8K</center></td>
12+
<td><center>4.9K</center></td>
13+
<td><center>4.2K</center></td>
1414
</tr>
1515
<tr>
1616
<td>core_mqtt_state.c</td>
@@ -19,12 +19,12 @@
1919
</tr>
2020
<tr>
2121
<td>core_mqtt_serializer.c</td>
22-
<td><center>2.8K</center></td>
23-
<td><center>2.2K</center></td>
22+
<td><center>2.9K</center></td>
23+
<td><center>2.3K</center></td>
2424
</tr>
2525
<tr>
2626
<td><b>Total estimates</b></td>
27-
<td><b><center>8.9K</center></b></td>
28-
<td><b><center>7.3K</center></b></td>
27+
<td><b><center>9.5K</center></b></td>
28+
<td><b><center>7.8K</center></b></td>
2929
</tr>
3030
</table>

source/core_mqtt.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ static MQTTStatus_t handlePublishAcks( MQTTContext_t * pContext,
16061606
( pContext->clearFunction != NULL ) &&
16071607
( pContext->clearFunction( pContext, packetIdentifier ) != true ) )
16081608
{
1609-
LogWarn( ( "Clear callback function failed\n" ) );
1609+
LogWarn( ( "Failed to clear copied publish on receiving an ack.\n" ) );
16101610
}
16111611
}
16121612

@@ -2204,21 +2204,26 @@ static MQTTStatus_t sendPublishWithoutCopy( MQTTContext_t * pContext,
22042204
totalMessageLength += pPublishInfo->payloadLength;
22052205
}
22062206

2207-
/* store a copy of the publish with duplicate flag set for retransmission purposes */
2207+
/* if not already set, set the dup flag before storing a copy of the publish
2208+
* this is because on retrieving back this copy we will get it in the form of an
2209+
* array of TransportOutVector_t that holds the data in a const pointer which cannot be
2210+
* changed after retrieving.*/
22082211
if( pPublishInfo->dup != true )
22092212
{
22102213
MQTT_UpdateDuplicatePublishFlag( pMqttHeader, true );
22112214

22122215
dupFlagChanged = true;
22132216
}
22142217

2218+
/* store a copy of the publish for retransmission purposes */
22152219
if( ( pPublishInfo->qos > MQTTQoS0 ) &&
22162220
( pContext->storeFunction != NULL ) &&
22172221
( pContext->storeFunction( pContext, packetId, pIoVector, ioVectorLength ) != true ) )
22182222
{
22192223
status = MQTTPublishStoreFailed;
22202224
}
22212225

2226+
/* change the value of the dup flag to its original, if it was changed */
22222227
if( dupFlagChanged )
22232228
{
22242229
MQTT_UpdateDuplicatePublishFlag( pMqttHeader, false );
@@ -2545,7 +2550,7 @@ static MQTTStatus_t handleUncleanSessionResumption( MQTTContext_t * pContext )
25452550
status = MQTTPublishRetrieveFailed;
25462551
}
25472552

2548-
/* Resend all the PUBLISH for which PUBCK/PUBREC is not received
2553+
/* Resend all the PUBLISH for which PUBACK/PUBREC is not received
25492554
* after session is reestablished. */
25502555
while( ( packetId != MQTT_PACKET_ID_INVALID ) &&
25512556
( status == MQTTSuccess ) )
@@ -2775,10 +2780,10 @@ MQTTStatus_t MQTT_InitStatefulQoS( MQTTContext_t * pContext,
27752780
/*-----------------------------------------------------------*/
27762781

27772782
MQTTStatus_t MQTT_InitRetransmits( MQTTContext_t * pContext,
2778-
MQTTRetransmitStorePacket storeFunction,
2779-
MQTTRetransmitRetrievePacket retrieveFunction,
2780-
MQTTRetransmitClearPacket clearFunction,
2781-
MQTTRetransmitClearAllPackets clearAllFunction )
2783+
MQTTStorePacketForRetransmit storeFunction,
2784+
MQTTRetrievePacketForRetransmit retrieveFunction,
2785+
MQTTClearPacketForRetransmit clearFunction,
2786+
MQTTClearAllPacketsForRetransmit clearAllFunction )
27822787
{
27832788
MQTTStatus_t status = MQTTSuccess;
27842789

source/core_mqtt_serializer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
#define UINT8_SET_BIT( x, position ) ( ( x ) = ( uint8_t ) ( ( x ) | ( 0x01U << ( position ) ) ) )
103103

104104
/**
105-
* @brief Set a bit in an 8-bit unsigned integer.
105+
* @brief Clear a bit in an 8-bit unsigned integer.
106106
*/
107107
#define UINT8_CLEAR_BIT( x, position ) ( ( x ) = ( uint8_t ) ( ( x ) & ( ~( 0x01U << ( position ) ) ) ) )
108108

source/include/core_mqtt.h

Lines changed: 93 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ typedef void (* MQTTEventCallback_t )( struct MQTTContext * pContext,
102102
struct MQTTDeserializedInfo * pDeserializedInfo );
103103

104104
/**
105-
* @brief User defined API used to store outgoing publishes. Used to track any publish
105+
* @brief User defined callback used to store outgoing publishes. Used to track any publish
106106
* retransmit on an unclean session connection.
107107
*
108108
* @param[in] pContext Initialised MQTT Context.
@@ -113,14 +113,14 @@ typedef void (* MQTTEventCallback_t )( struct MQTTContext * pContext,
113113
* @return True if the copy is successful else false.
114114
*/
115115
/* @[define_mqtt_retransmitstorepacket] */
116-
typedef bool ( * MQTTRetransmitStorePacket)( struct MQTTContext * pContext,
117-
uint16_t packetId,
118-
TransportOutVector_t * pIoVec,
119-
size_t ioVecCount );
116+
typedef bool ( * MQTTStorePacketForRetransmit)( struct MQTTContext * pContext,
117+
uint16_t packetId,
118+
TransportOutVector_t * pIoVec,
119+
size_t ioVecCount );
120120
/* @[define_mqtt_retransmitstorepacket] */
121121

122122
/**
123-
* @brief User defined API used to retreive a copied publish for resend operation. Used to
123+
* @brief User defined callback used to retreive a copied publish for resend operation. Used to
124124
* track any publish retransmit on an unclean session connection.
125125
*
126126
* @param[in] pContext Initialised MQTT Context.
@@ -131,14 +131,14 @@ typedef bool ( * MQTTRetransmitStorePacket)( struct MQTTContext * pContext,
131131
* @return True if the retreive is successful else false.
132132
*/
133133
/* @[define_mqtt_retransmitretrievepacket] */
134-
typedef bool ( * MQTTRetransmitRetrievePacket)( struct MQTTContext * pContext,
135-
uint16_t packetId,
136-
TransportOutVector_t ** pIoVec,
137-
size_t * ioVecCount );
134+
typedef bool ( * MQTTRetrievePacketForRetransmit)( struct MQTTContext * pContext,
135+
uint16_t packetId,
136+
TransportOutVector_t ** pIoVec,
137+
size_t * ioVecCount );
138138
/* @[define_mqtt_retransmitretrievepacket] */
139139

140140
/**
141-
* @brief User defined API used to clear a particular copied publish packet. Used to
141+
* @brief User defined callback used to clear a particular copied publish packet. Used to
142142
* track any publish retransmit on an unclean session connection.
143143
*
144144
* @param[in] pContext Initialised MQTT Context.
@@ -147,20 +147,20 @@ typedef bool ( * MQTTRetransmitRetrievePacket)( struct MQTTContext * pContext,
147147
* @return True if the clear is successful else false.
148148
*/
149149
/* @[define_mqtt_retransmitclearpacket] */
150-
typedef bool (* MQTTRetransmitClearPacket)( struct MQTTContext * pContext,
151-
uint16_t packetId );
150+
typedef bool (*MQTTClearPacketForRetransmit)( struct MQTTContext * pContext,
151+
uint16_t packetId );
152152
/* @[define_mqtt_retransmitclearpacket] */
153153

154154
/**
155-
* @brief User defined API used to clear all copied publish packets. Used to
155+
* @brief User defined callback used to clear all copied publish packets. Used to
156156
* when connecting with a clean session.
157157
*
158158
* @param[in] pContext Initialised MQTT Context.
159159
*
160160
* @return True if the clear all is successful else false.
161161
*/
162162
/* @[define_mqtt_retransmitclearallpackets] */
163-
typedef bool (* MQTTRetransmitClearAllPackets)( struct MQTTContext * pContext );
163+
typedef bool (*MQTTClearAllPacketsForRetransmit)( struct MQTTContext * pContext );
164164
/* @[define_mqtt_retransmitclearallpackets] */
165165

166166
/**
@@ -313,22 +313,22 @@ typedef struct MQTTContext
313313
/**
314314
* @brief User defined API used to store outgoing publishes.
315315
*/
316-
MQTTRetransmitStorePacket storeFunction;
316+
MQTTStorePacketForRetransmit storeFunction;
317317

318318
/**
319319
* @brief User defined API used to retreive a copied publish for resend operation.
320320
*/
321-
MQTTRetransmitRetrievePacket retrieveFunction;
321+
MQTTRetrievePacketForRetransmit retrieveFunction;
322322

323323
/**
324324
* @brief User defined API used to clear a particular copied publish packet.
325325
*/
326-
MQTTRetransmitClearPacket clearFunction;
326+
MQTTClearPacketForRetransmit clearFunction;
327327

328328
/**
329329
* @brief User defined API used to clear all copied publish packets.
330330
*/
331-
MQTTRetransmitClearAllPackets clearAllFunction;
331+
MQTTClearAllPacketsForRetransmit clearAllFunction;
332332
} MQTTContext_t;
333333

334334
/**
@@ -510,16 +510,86 @@ MQTTStatus_t MQTT_InitStatefulQoS( MQTTContext_t * pContext,
510510
*
511511
* @return #MQTTBadParameter if invalid parameters are passed;
512512
* #MQTTSuccess otherwise.
513+
*
514+
* <b>Example</b>
515+
* @code{c}
516+
*
517+
* // Function for obtaining a timestamp.
518+
* uint32_t getTimeStampMs();
519+
* // Callback function for receiving packets.
520+
* void eventCallback(
521+
* MQTTContext_t * pContext,
522+
* MQTTPacketInfo_t * pPacketInfo,
523+
* MQTTDeserializedInfo_t * pDeserializedInfo
524+
* );
525+
* // Network send.
526+
* int32_t networkSend( NetworkContext_t * pContext, const void * pBuffer, size_t bytes );
527+
* // Network receive.
528+
* int32_t networkRecv( NetworkContext_t * pContext, void * pBuffer, size_t bytes );
529+
* // User defined callback used to store outgoing publishes
530+
* bool publishStoreCallback(struct MQTTContext* pContext,
531+
* uint16_t packetId,
532+
* TransportOutVector_t* pIoVec,
533+
* size_t ioVecCount);
534+
* // User defined callback used to retreive a copied publish for resend operation
535+
* bool publishRetrieveCallback(struct MQTTContext* pContext,
536+
* uint16_t packetId,
537+
* TransportOutVector_t** pIoVec,
538+
* size_t* ioVecCount);
539+
* // User defined callback used to clear a particular copied publish packet
540+
* bool publishClearCallback(struct MQTTContext* pContext,
541+
* uint16_t packetId);
542+
* // User defined callback used to clear all copied publish packets
543+
* bool publishClearAllCallback(struct MQTTContext* pContext);
544+
*
545+
* MQTTContext_t mqttContext;
546+
* TransportInterface_t transport;
547+
* MQTTFixedBuffer_t fixedBuffer;
548+
* uint8_t buffer[ 1024 ];
549+
* const size_t outgoingPublishCount = 30;
550+
* MQTTPubAckInfo_t outgoingPublishes[ outgoingPublishCount ];
551+
*
552+
* // Clear context.
553+
* memset( ( void * ) &mqttContext, 0x00, sizeof( MQTTContext_t ) );
554+
*
555+
* // Set transport interface members.
556+
* transport.pNetworkContext = &someTransportContext;
557+
* transport.send = networkSend;
558+
* transport.recv = networkRecv;
559+
*
560+
* // Set buffer members.
561+
* fixedBuffer.pBuffer = buffer;
562+
* fixedBuffer.size = 1024;
563+
*
564+
* status = MQTT_Init( &mqttContext, &transport, getTimeStampMs, eventCallback, &fixedBuffer );
513565
*
566+
* if( status == MQTTSuccess )
567+
* {
568+
* // We do not expect any incoming publishes in this example, therefore the incoming
569+
* // publish pointer is NULL and the count is zero.
570+
* status = MQTT_InitStatefulQoS( &mqttContext, outgoingPublishes, outgoingPublishCount, NULL, 0 );
571+
*
572+
* // Now QoS1 and/or QoS2 publishes can be sent with this context.
573+
* }
574+
*
575+
* if( status == MQTTSuccess )
576+
* {
577+
* status = MQTT_InitRetransmits( &mqttContext, publishStoreCallback,
578+
* publishRetrieveCallback,
579+
* publishClearCallback,
580+
* publishClearAllCallback );
581+
*
582+
* // Now unacked Publishes can be resent on an unclean session resumption.
583+
* }
514584
* @endcode
515585
*/
516586

517587
/* @[declare_mqtt_initretransmits] */
518588
MQTTStatus_t MQTT_InitRetransmits( MQTTContext_t * pContext,
519-
MQTTRetransmitStorePacket storeFunction,
520-
MQTTRetransmitRetrievePacket retrieveFunction,
521-
MQTTRetransmitClearPacket clearFunction,
522-
MQTTRetransmitClearAllPackets clearAllFunction );
589+
MQTTStorePacketForRetransmit storeFunction,
590+
MQTTRetrievePacketForRetransmit retrieveFunction,
591+
MQTTClearPacketForRetransmit clearFunction,
592+
MQTTClearAllPacketsForRetransmit clearAllFunction );
523593
/* @[declare_mqtt_initretransmits] */
524594

525595
/**

0 commit comments

Comments
 (0)