kmMqtt 0.0.1
MQTT Client Library
Loading...
Searching...
No Matches
kmMqtt::mqtt::ISessionStatePersistantStore Class Referenceabstract

Interface for storing and retrieving MQTT session state. More...

#include <ISessionStatePersistantStore.h>

Public Member Functions

virtual bool initialize (const char *clientId)=0
 Initializes the session state store for a specific client ID.
virtual bool write (const char *clientId, uint32_t sessionExpiryInterval, const SavedData &data)=0
 Writes a Publish packets to the session state persistant storage.
virtual bool readAll (const char *clientId, std::vector< const SavedData > &outData)=0
 Reads all persisted Publish packets from the session state store.
virtual bool removeMessage (const char *clientId, std::uint16_t packetId)=0
 Removes a specific Publish packets from the session state store.
virtual bool updateMessage (const char *clientId, std::uint16_t packetId, PublishMessageStatus newStatus, bool bringToEnd)=0
 Updates a specific Publish packet in the session state store.
virtual bool removeFromStore (const char *clientId)=0
 Remove all data associated with this client id from store.
virtual bool removeExpiredFromStore ()=0
 Remove all expired session states in store.

Detailed Description

Interface for storing and retrieving MQTT session state.

This interface allows SDK users to implement custom persistence mechanisms for MQTT session state, specifically for QoS 1 and QoS 2 publish messages that need to be tracked across sessions.

Member Function Documentation

◆ initialize()

virtual bool kmMqtt::mqtt::ISessionStatePersistantStore::initialize ( const char * clientId)
pure virtual

Initializes the session state store for a specific client ID.

This method is called when an MQTT client finishes connecting.

Parameters
clientIdThe identifier of the mqtt client.
Returns
true if the initialization was successful, false otherwise.

◆ readAll()

virtual bool kmMqtt::mqtt::ISessionStatePersistantStore::readAll ( const char * clientId,
std::vector< const SavedData > & outData )
pure virtual

Reads all persisted Publish packets from the session state store.

These NEED to be read in the same order as they have been written. I.E. Last message written needs to be the last message in the outMsgData vector.

This method is called when an MQTT client attempts to resume a valid session (after broker connect response).

Parameters
clientIdThe identifier of the mqtt client.
[out]packetsA vector that will be populated with the Publish packets read from the session state.
Returns
true if the session state was successfully read (even if no packets were stored), false if an error occurred during reading.

◆ removeExpiredFromStore()

virtual bool kmMqtt::mqtt::ISessionStatePersistantStore::removeExpiredFromStore ( )
pure virtual

Remove all expired session states in store.

Called at MQTT start-up before connection.

Returns
true if expired session have been removed or none to remove were found.

◆ removeFromStore()

virtual bool kmMqtt::mqtt::ISessionStatePersistantStore::removeFromStore ( const char * clientId)
pure virtual

Remove all data associated with this client id from store.

This might be called when a clean session is started, or when the user explicitly requests to clear any stored session data.

Parameters
clientIdThe identifier of the mqtt client.
Returns
true if the session state was successfully cleared or not found, false otherwise.

◆ removeMessage()

virtual bool kmMqtt::mqtt::ISessionStatePersistantStore::removeMessage ( const char * clientId,
std::uint16_t packetId )
pure virtual

Removes a specific Publish packets from the session state store.

This method will be called after a QoS 1 message is acknowledged, a QoS 2 message is fully acknowledged, or when a message is deemed no longer necessary to keep in the session state.

Parameters
clientIdThe identifier of the mqtt client.
packetIdThe identifier of the packet to remove.
Returns
true if the packet was successfully removed or was not found, false if an error occurred during removal.

◆ updateMessage()

virtual bool kmMqtt::mqtt::ISessionStatePersistantStore::updateMessage ( const char * clientId,
std::uint16_t packetId,
PublishMessageStatus newStatus,
bool bringToEnd )
pure virtual

Updates a specific Publish packet in the session state store.

Parameters
clientIdThe identifier of the mqtt client.
packetIdThe identifier of the packet to update.
newStatusThe new status of the packet.
bringToFrontIf true, the packet will be moved to the end of the list.
Returns
true if the packet was successfully updated, false otherwise.

◆ write()

virtual bool kmMqtt::mqtt::ISessionStatePersistantStore::write ( const char * clientId,
uint32_t sessionExpiryInterval,
const SavedData & data )
pure virtual

Writes a Publish packets to the session state persistant storage.

This method is called when an outgoing QoS 1 or QoS 2 PUBLISH packet is sent, or when an incoming QoS 2 PUBLISH packet is received but not yet fully acknowledged.

Parameters
clientIdThe identifier of the mqtt client.
sessionExpiryIntervalThe session expiry interval after which session is considered obsolete.
msgDataThe Publish packet to be stored.
Returns
true if the packet was successfully written to the session state storage, false otherwise.

The documentation for this class was generated from the following file: