天嵌二次封装库使用手册  V2.1.2
MQTTClientPersistence.h 文件参考

This structure represents a persistent data store, used to store outbound and inbound messages, in order to achieve reliable messaging. 更多...

此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

struct  MQTTClient_persistence
 A structure containing the function pointers to a persistence implementation and the context or state that will be shared across all the persistence functions. 更多...
 

宏定义

#define MQTTCLIENT_PERSISTENCE_DEFAULT   0
 
#define MQTTCLIENT_PERSISTENCE_NONE   1
 
#define MQTTCLIENT_PERSISTENCE_USER   2
 
#define MQTTCLIENT_PERSISTENCE_ERROR   -2
 

类型定义

typedef int(* Persistence_open) (void **handle, const char *clientID, const char *serverURI, void *context)
 Initialize the persistent store. 更多...
 
typedef int(* Persistence_close) (void *handle)
 Close the persistent store referred to by the handle. 更多...
 
typedef int(* Persistence_put) (void *handle, char *key, int bufcount, char *buffers[], int buflens[])
 Put the specified data into the persistent store. 更多...
 
typedef int(* Persistence_get) (void *handle, char *key, char **buffer, int *buflen)
 Retrieve the specified data from the persistent store. 更多...
 
typedef int(* Persistence_remove) (void *handle, char *key)
 Remove the data for the specified key from the store. 更多...
 
typedef int(* Persistence_keys) (void *handle, char ***keys, int *nkeys)
 Returns the keys in this persistent data store. 更多...
 
typedef int(* Persistence_clear) (void *handle)
 Clears the persistence store, so that it no longer contains any persisted data. 更多...
 
typedef int(* Persistence_containskey) (void *handle, char *key)
 Returns whether any data has been persisted using the specified key. 更多...
 
typedef int MQTTPersistence_beforeWrite(void *context, int bufcount, char *buffers[], int buflens[])
 
typedef int MQTTPersistence_afterRead(void *context, char **buffer, int *buflen)
 

详细描述

This structure represents a persistent data store, used to store outbound and inbound messages, in order to achieve reliable messaging.

The MQTT Client persists QoS1 and QoS2 messages in order to meet the assurances of delivery associated with these qos levels. The messages are saved in persistent storage The type and context of the persistence implementation are specified when the MQTT client is created (see MQTTClient_create()). The default persistence type (MQTTCLIENT_PERSISTENCE_DEFAULT) uses a file system-based persistence mechanism. The persistence_context argument passed to MQTTClient_create() when using the default peristence is a string representing the location of the persistence directory. If the context argument is NULL, the working directory will be used.

To use memory-based persistence, an application passes MQTTCLIENT_PERSISTENCE_NONE as the persistence_type to MQTTClient_create(). This can lead to message loss in certain situations, but can be appropriate in some cases (see qos).

Client applications can provide their own persistence mechanism by passing MQTTCLIENT_PERSISTENCE_USER as the persistence_type. To implement a custom persistence mechanism, the application must pass an initialized MQTTClient_persistence structure as the persistence_context argument to MQTTClient_create().

If the functions defined return an MQTTCLIENT_PERSISTENCE_ERROR then the state of the persisted data should remain as it was prior to the function being called. For example, if Persistence_put() returns MQTTCLIENT_PERSISTENCE_ERROR, then it is assumed tha tthe persistent store does not contain the data that was passed to the function. Similarly, if Persistence_remove() returns MQTTCLIENT_PERSISTENCE_ERROR then it is assumed that the data to be removed is still held in the persistent store.

It is up to the persistence implementation to log any error information that may be required to diagnose a persistence mechanism failure.

在文件 MQTTClientPersistence.h 中定义.

宏定义说明

#define MQTTCLIENT_PERSISTENCE_DEFAULT   0

This persistence_type value specifies the default file system-based persistence mechanism (see MQTTClient_create()).

在文件 MQTTClientPersistence.h69 行定义.

#define MQTTCLIENT_PERSISTENCE_ERROR   -2

Application-specific persistence functions must return this error code if there is a problem executing the function.

在文件 MQTTClientPersistence.h85 行定义.

#define MQTTCLIENT_PERSISTENCE_NONE   1

This persistence_type value specifies a memory-based persistence mechanism (see MQTTClient_create()).

在文件 MQTTClientPersistence.h74 行定义.

#define MQTTCLIENT_PERSISTENCE_USER   2

This persistence_type value specifies an application-specific persistence mechanism (see MQTTClient_create()).

在文件 MQTTClientPersistence.h79 行定义.

类型定义说明

typedef int MQTTPersistence_afterRead(void *context, char **buffer, int *buflen)

A callback which is invoked just after a read from persistence. This can be used to transform the data, for instance to decrypt it.

参数
contextThe context as set in MQTTAsync_setAfterPersistenceRead
bufferThe address of a pointer to a buffer.
buflenThe address of an int that is the length of the buffer.
返回
Return 0 if the function completes successfully, otherwise non 0.

在文件 MQTTClientPersistence.h275 行定义.

typedef int MQTTPersistence_beforeWrite(void *context, int bufcount, char *buffers[], int buflens[])

A callback which is invoked just before a write to persistence. This can be used to transform the data, for instance to encrypt it.

参数
contextThe context as set in MQTTAsync_setBeforePersistenceWrite
bufcountThe number of buffers to write to the persistence store.
buffersAn array of pointers to the data buffers.
buflensAn array of lengths of the data buffers.
返回
Return 0 if the function completes successfully, otherwise non 0.

在文件 MQTTClientPersistence.h264 行定义.

typedef int(* Persistence_clear) (void *handle)

Clears the persistence store, so that it no longer contains any persisted data.

参数
handleThe handle pointer from a successful call to Persistence_open().
返回
Return 0 if the function completes successfully, otherwise return MQTTCLIENT_PERSISTENCE_ERROR.

在文件 MQTTClientPersistence.h197 行定义.

typedef int(* Persistence_close) (void *handle)

Close the persistent store referred to by the handle.

参数
handleThe handle pointer from a successful call to Persistence_open().
返回
Return 0 if the function completes successfully, otherwise return MQTTCLIENT_PERSISTENCE_ERROR.

在文件 MQTTClientPersistence.h123 行定义.

typedef int(* Persistence_containskey) (void *handle, char *key)

Returns whether any data has been persisted using the specified key.

参数
handleThe handle pointer from a successful call to Persistence_open().
keyThe string to be tested for existence in the store.
返回
Return 0 if the key was found in the store, otherwise return MQTTCLIENT_PERSISTENCE_ERROR.

在文件 MQTTClientPersistence.h208 行定义.

typedef int(* Persistence_get) (void *handle, char *key, char **buffer, int *buflen)

Retrieve the specified data from the persistent store.

参数
handleThe handle pointer from a successful call to Persistence_open().
keyA string that is the key for the data to be retrieved. This is the same key used to save the data to the store with Persistence_put().
bufferThe address of a pointer to a buffer. This function sets the pointer to point at the retrieved data, if successful.
buflenThe address of an int that is set to the length of buffer by this function if successful.
返回
Return 0 if the function completes successfully, otherwise return MQTTCLIENT_PERSISTENCE_ERROR.

在文件 MQTTClientPersistence.h156 行定义.

typedef int(* Persistence_keys) (void *handle, char ***keys, int *nkeys)

Returns the keys in this persistent data store.

参数
handleThe handle pointer from a successful call to Persistence_open().
keysThe address of a pointer to pointers to strings. Assuming successful execution, this function allocates memory to hold the returned keys (strings used to store the data with Persistence_put()). It also allocates memory to hold an array of pointers to these strings. keys is set to point to the array of pointers to strings.
nkeysA pointer to the number of keys in this persistent data store. This function sets the number of keys, if successful.
返回
Return 0 if the function completes successfully, otherwise return MQTTCLIENT_PERSISTENCE_ERROR.

在文件 MQTTClientPersistence.h186 行定义.

typedef int(* Persistence_open) (void **handle, const char *clientID, const char *serverURI, void *context)

Initialize the persistent store.

Either open the existing persistent store for this client ID or create a new one if one doesn't exist. If the persistent store is already open, return without taking any action.

An application can use the same client identifier to connect to many different servers. The clientid in conjunction with the serverURI uniquely identifies the persistence store required.

参数
handleThe address of a pointer to a handle for this persistence implementation. This function must set handle to a valid reference to the persistence following a successful return. The handle pointer is passed as an argument to all the other persistence functions. It may include the context parameter and/or any other data for use by the persistence functions.
clientIDThe client identifier for which the persistent store should be opened.
serverURIThe connection string specified when the MQTT client was created (see MQTTClient_create()).
contextA pointer to any data required to initialize the persistent store (see MQTTClient_persistence).
返回
Return 0 if the function completes successfully, otherwise return MQTTCLIENT_PERSISTENCE_ERROR.

在文件 MQTTClientPersistence.h113 行定义.

typedef int(* Persistence_put) (void *handle, char *key, int bufcount, char *buffers[], int buflens[])

Put the specified data into the persistent store.

参数
handleThe handle pointer from a successful call to Persistence_open().
keyA string used as the key for the data to be put in the store. The key is later used to retrieve data from the store with Persistence_get().
bufcountThe number of buffers to write to the persistence store.
buffersAn array of pointers to the data buffers associated with this key.
buflensAn array of lengths of the data buffers. buflen[n] gives the length of buffer[n].
返回
Return 0 if the function completes successfully, otherwise return MQTTCLIENT_PERSISTENCE_ERROR.

在文件 MQTTClientPersistence.h140 行定义.

typedef int(* Persistence_remove) (void *handle, char *key)

Remove the data for the specified key from the store.

参数
handleThe handle pointer from a successful call to Persistence_open().
keyA string that is the key for the data to be removed from the store. This is the same key used to save the data to the store with Persistence_put().
返回
Return 0 if the function completes successfully, otherwise return MQTTCLIENT_PERSISTENCE_ERROR.

在文件 MQTTClientPersistence.h169 行定义.