MQTT C Client Libraries Internals
Macros | Functions
MQTTPersistence.c File Reference

Functions that apply to persistence operations. More...

#include <stdio.h>
#include <string.h>
#include "MQTTPersistence.h"
#include "MQTTPersistenceDefault.h"
#include "MQTTProtocolClient.h"
#include "Heap.h"
#include "StackTrace.h"
Include dependency graph for MQTTPersistence.c:

Macros

#define MAX_NO_OF_BUFFERS   9
 

Functions

static MQTTPersistence_qEntryMQTTPersistence_restoreQueueEntry (char *buffer, size_t buflen, int MQTTVersion)
 
static void MQTTPersistence_insertInSeqOrder (List *list, MQTTPersistence_qEntry *qEntry, size_t size)
 
int MQTTPersistence_create (MQTTClient_persistence **persistence, int type, void *pcontext)
 Creates a MQTTClient_persistence structure representing a persistence implementation. More...
 
int MQTTPersistence_initialize (Clients *c, const char *serverURI)
 Open persistent store and restore any persisted messages. More...
 
int MQTTPersistence_close (Clients *c)
 Close persistent store. More...
 
int MQTTPersistence_clear (Clients *c)
 Clears the persistent store. More...
 
int MQTTPersistence_restorePackets (Clients *c)
 Restores the persisted records to the outbound and inbound message queues of the client. More...
 
void * MQTTPersistence_restorePacket (int MQTTVersion, char *buffer, size_t buflen)
 Returns a MQTT packet restored from persisted data. More...
 
void MQTTPersistence_insertInOrder (List *list, void *content, size_t size)
 Inserts the specified message into the list, maintaining message ID order. More...
 
int MQTTPersistence_putPacket (SOCKET socket, char *buf0, size_t buf0len, int count, char **buffers, size_t *buflens, int htype, int msgId, int scr, int MQTTVersion)
 Adds a record to the persistent store. More...
 
int MQTTPersistence_remove (Clients *c, char *type, int qos, int msgId)
 Deletes a record from the persistent store. More...
 
void MQTTPersistence_wrapMsgID (Clients *client)
 Checks whether the message IDs wrapped by looking for the largest gap between two consecutive message IDs in the outboundMsgs queue. More...
 
int MQTTPersistence_unpersistQueueEntry (Clients *client, MQTTPersistence_qEntry *qe)
 
int MQTTPersistence_persistQueueEntry (Clients *aclient, MQTTPersistence_qEntry *qe)
 
int MQTTPersistence_restoreMessageQueue (Clients *c)
 Restores a queue of messages from persistence to memory. More...
 

Detailed Description

Functions that apply to persistence operations.

Function Documentation

◆ MQTTPersistence_clear()

int MQTTPersistence_clear ( Clients c)

Clears the persistent store.

Parameters
clientthe client as Clients.
Returns
0 if success, MQTTCLIENT_PERSISTENCE_ERROR otherwise.

◆ MQTTPersistence_close()

int MQTTPersistence_close ( Clients c)

Close persistent store.

Parameters
clientthe client as Clients.
Returns
0 if success, MQTTCLIENT_PERSISTENCE_ERROR otherwise.
Here is the call graph for this function:

◆ MQTTPersistence_create()

int MQTTPersistence_create ( MQTTClient_persistence **  persistence,
int  type,
void *  pcontext 
)

Creates a MQTTClient_persistence structure representing a persistence implementation.

Parameters
persistencethe MQTTClient_persistence structure.
typethe type of the persistence implementation. See MQTTClient_create.
pcontextthe context for this persistence implementation. See MQTTClient_create.
Returns
0 if success, MQTTCLIENT_PERSISTENCE_ERROR otherwise.
Here is the call graph for this function:

◆ MQTTPersistence_initialize()

int MQTTPersistence_initialize ( Clients c,
const char *  serverURI 
)

Open persistent store and restore any persisted messages.

Parameters
clientthe client as Clients.
serverURIthe URI of the remote end.
Returns
0 if success, MQTTCLIENT_PERSISTENCE_ERROR otherwise.
Here is the call graph for this function:

◆ MQTTPersistence_insertInOrder()

void MQTTPersistence_insertInOrder ( List list,
void *  content,
size_t  size 
)

Inserts the specified message into the list, maintaining message ID order.

Parameters
listthe list to insert the message into.
contentthe message to add.
sizesize of the message.
Here is the call graph for this function:

◆ MQTTPersistence_putPacket()

int MQTTPersistence_putPacket ( SOCKET  socket,
char *  buf0,
size_t  buf0len,
int  count,
char **  buffers,
size_t *  buflens,
int  htype,
int  msgId,
int  scr,
int  MQTTVersion 
)

Adds a record to the persistent store.

This function must not be called for QoS0 messages.

Parameters
socketthe socket of the client.
buf0fixed header.
buf0lenlength of the fixed header.
countnumber of buffers representing the variable header and/or the payload.
buffersthe buffers representing the variable header and/or the payload.
buflenslength of the buffers representing the variable header and/or the payload.
htypeMQTT packet type - PUBLISH or PUBREL
msgIdthe message ID.
scr0 indicates message in the sending direction; 1 indicates message in the receiving direction.
theMQTT version being used (>= MQTTVERSION_5 means properties included)
Returns
0 if success, MQTTCLIENT_PERSISTENCE_ERROR otherwise.

◆ MQTTPersistence_remove()

int MQTTPersistence_remove ( Clients c,
char *  type,
int  qos,
int  msgId 
)

Deletes a record from the persistent store.

Parameters
clientthe client as Clients.
typethe type of the persisted record: #PERSISTENCE_PUBLISH_SENT, #PERSISTENCE_PUBREL or #PERSISTENCE_PUBLISH_RECEIVED.
qosthe qos field of the message.
msgIdthe message ID.
Returns
0 if success, MQTTCLIENT_PERSISTENCE_ERROR otherwise.
Here is the call graph for this function:

◆ MQTTPersistence_restoreMessageQueue()

int MQTTPersistence_restoreMessageQueue ( Clients c)

Restores a queue of messages from persistence to memory.

Parameters
cthe client as Clients - the client object to restore the messages to
Returns
return code, 0 if successful

◆ MQTTPersistence_restorePacket()

void* MQTTPersistence_restorePacket ( int  MQTTVersion,
char *  buffer,
size_t  buflen 
)

Returns a MQTT packet restored from persisted data.

Parameters
bufferthe persisted data.
buflenthe number of bytes of the data buffer.

◆ MQTTPersistence_restorePackets()

int MQTTPersistence_restorePackets ( Clients c)

Restores the persisted records to the outbound and inbound message queues of the client.

Parameters
clientthe client as Clients.
Returns
0 if success, MQTTCLIENT_PERSISTENCE_ERROR otherwise.
Here is the call graph for this function:

◆ MQTTPersistence_wrapMsgID()

void MQTTPersistence_wrapMsgID ( Clients client)

Checks whether the message IDs wrapped by looking for the largest gap between two consecutive message IDs in the outboundMsgs queue.

Parameters
clientthe client as Clients.
Here is the call graph for this function: