00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00085
00086 #if defined(__cplusplus)
00087 extern "C" {
00088 #endif
00089
00090 #if !defined(MQTTASYNC_H)
00091 #define MQTTASYNC_H
00092
00093 #if defined(WIN32) || defined(WIN64)
00094 #define DLLImport __declspec(dllimport)
00095 #define DLLExport __declspec(dllexport)
00096 #else
00097 #define DLLImport extern
00098 #define DLLExport __attribute__ ((visibility ("default")))
00099 #endif
00100
00101 #include <stdio.h>
00103
00104 #if !defined(NO_PERSISTENCE)
00105 #include "MQTTClientPersistence.h"
00106 #endif
00107
00112 #define MQTTASYNC_SUCCESS 0
00113
00117 #define MQTTASYNC_FAILURE -1
00118
00119
00120
00121 #define MQTTASYNC_PERSISTENCE_ERROR -2
00122
00126 #define MQTTASYNC_DISCONNECTED -3
00127
00131 #define MQTTASYNC_MAX_MESSAGES_INFLIGHT -4
00132
00135 #define MQTTASYNC_BAD_UTF8_STRING -5
00136
00139 #define MQTTASYNC_NULL_PARAMETER -6
00140
00145 #define MQTTASYNC_TOPICNAME_TRUNCATED -7
00146
00150 #define MQTTASYNC_BAD_STRUCTURE -8
00151
00154 #define MQTTASYNC_BAD_QOS -9
00155
00158 #define MQTTASYNC_NO_MORE_MSGIDS -10
00159
00162 #define MQTTASYNC_OPERATION_INCOMPLETE -11
00163
00166 #define MQTTASYNC_MAX_BUFFERED_MESSAGES -12
00167
00170 #define MQTTASYNC_SSL_NOT_SUPPORTED -13
00171
00175 #define MQTTVERSION_DEFAULT 0
00176
00179 #define MQTTVERSION_3_1 3
00180
00183 #define MQTTVERSION_3_1_1 4
00184
00187 #define MQTT_BAD_SUBSCRIBE 0x80
00188
00189
00193 typedef struct
00194 {
00196 char struct_id[4];
00198 int struct_version;
00200 int do_openssl_init;
00201 } MQTTAsync_init_options;
00202
00203 #define MQTTAsync_init_options_initializer { {'M', 'Q', 'T', 'G'}, 0, 0 }
00204
00209 void MQTTAsync_global_init(MQTTAsync_init_options* inits);
00210
00215 typedef void* MQTTAsync;
00225 typedef int MQTTAsync_token;
00226
00233 typedef struct
00234 {
00236 char struct_id[4];
00238 int struct_version;
00240 int payloadlen;
00242 void* payload;
00256 int qos;
00275 int retained;
00282 int dup;
00286 int msgid;
00287 } MQTTAsync_message;
00288
00289 #define MQTTAsync_message_initializer { {'M', 'Q', 'T', 'M'}, 0, 0, NULL, 0, 0, 0, 0 }
00290
00317 typedef int MQTTAsync_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message);
00318
00337 typedef void MQTTAsync_deliveryComplete(void* context, MQTTAsync_token token);
00338
00354 typedef void MQTTAsync_connectionLost(void* context, char* cause);
00355
00356
00369 typedef void MQTTAsync_connected(void* context, char* cause);
00370
00371
00372
00374 typedef struct
00375 {
00377 MQTTAsync_token token;
00379 int code;
00381 const char *message;
00382 } MQTTAsync_failureData;
00383
00385 typedef struct
00386 {
00388 MQTTAsync_token token;
00390 union
00391 {
00393 int qos;
00395 int* qosList;
00397 struct
00398 {
00399 MQTTAsync_message message;
00400 char* destinationName;
00401 } pub;
00402
00403 struct
00404 {
00405 char* serverURI;
00406 int MQTTVersion;
00407 int sessionPresent;
00408 } connect;
00409 } alt;
00410 } MQTTAsync_successData;
00411
00422 typedef void MQTTAsync_onSuccess(void* context, MQTTAsync_successData* response);
00423
00434 typedef void MQTTAsync_onFailure(void* context, MQTTAsync_failureData* response);
00435
00436 typedef struct
00437 {
00439 char struct_id[4];
00441 int struct_version;
00447 MQTTAsync_onSuccess* onSuccess;
00453 MQTTAsync_onFailure* onFailure;
00459 void* context;
00460 MQTTAsync_token token;
00461 } MQTTAsync_responseOptions;
00462
00463 #define MQTTAsync_responseOptions_initializer { {'M', 'Q', 'T', 'R'}, 0, NULL, NULL, 0, 0 }
00464
00465
00494 DLLExport int MQTTAsync_setCallbacks(MQTTAsync handle, void* context, MQTTAsync_connectionLost* cl,
00495 MQTTAsync_messageArrived* ma, MQTTAsync_deliveryComplete* dc);
00496
00497
00510 DLLExport int MQTTAsync_setConnected(MQTTAsync handle, void* context, MQTTAsync_connected* co);
00511
00512
00521 DLLExport int MQTTAsync_reconnect(MQTTAsync handle);
00522
00523
00565 DLLExport int MQTTAsync_create(MQTTAsync* handle, const char* serverURI, const char* clientId,
00566 int persistence_type, void* persistence_context);
00567
00568 typedef struct
00569 {
00571 char struct_id[4];
00573 int struct_version;
00575 int sendWhileDisconnected;
00577 int maxBufferedMessages;
00578 } MQTTAsync_createOptions;
00579
00580 #define MQTTAsync_createOptions_initializer { {'M', 'Q', 'C', 'O'}, 0, 0, 100 }
00581
00582
00583 DLLExport int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const char* clientId,
00584 int persistence_type, void* persistence_context, MQTTAsync_createOptions* options);
00585
00598 typedef struct
00599 {
00601 char struct_id[4];
00605 int struct_version;
00607 const char* topicName;
00609 const char* message;
00613 int retained;
00618 int qos;
00620 struct
00621 {
00622 int len;
00623 const void* data;
00624 } payload;
00625 } MQTTAsync_willOptions;
00626
00627 #define MQTTAsync_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 1, NULL, NULL, 0, 0, { 0, NULL } }
00628
00641 typedef struct
00642 {
00644 char struct_id[4];
00646 int struct_version;
00647
00649 const char* trustStore;
00650
00654 const char* keyStore;
00655
00659 const char* privateKey;
00661 const char* privateKeyPassword;
00662
00671 const char* enabledCipherSuites;
00672
00674 int enableServerCertAuth;
00675
00676 } MQTTAsync_SSLOptions;
00677
00678 #define MQTTAsync_SSLOptions_initializer { {'M', 'Q', 'T', 'S'}, 0, NULL, NULL, NULL, NULL, NULL, 1 }
00679
00685 typedef struct
00686 {
00688 char struct_id[4];
00696 int struct_version;
00707 int keepAliveInterval;
00729 int cleansession;
00733 int maxInflight;
00739 MQTTAsync_willOptions* will;
00745 const char* username;
00751 const char* password;
00755 int connectTimeout;
00759 int retryInterval;
00764 MQTTAsync_SSLOptions* ssl;
00770 MQTTAsync_onSuccess* onSuccess;
00776 MQTTAsync_onFailure* onFailure;
00782 void* context;
00786 int serverURIcount;
00795 char* const* serverURIs;
00802 int MQTTVersion;
00806 int automaticReconnect;
00810 int minRetryInterval;
00814 int maxRetryInterval;
00818 struct {
00819 int len;
00820 const void* data;
00821 } binarypwd;
00822 } MQTTAsync_connectOptions;
00823
00824
00825 #define MQTTAsync_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 5, 60, 1, 10, NULL, NULL, NULL, 30, 0,\
00826 NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 1, 60, {0, NULL}}
00827
00848 DLLExport int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options);
00849
00850
00851 typedef struct
00852 {
00854 char struct_id[4];
00856 int struct_version;
00861 int timeout;
00867 MQTTAsync_onSuccess* onSuccess;
00873 MQTTAsync_onFailure* onFailure;
00879 void* context;
00880 } MQTTAsync_disconnectOptions;
00881
00882 #define MQTTAsync_disconnectOptions_initializer { {'M', 'Q', 'T', 'D'}, 0, 0, NULL, NULL, NULL }
00883
00884
00903 DLLExport int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions* options);
00904
00905
00913 DLLExport int MQTTAsync_isConnected(MQTTAsync handle);
00914
00915
00930 DLLExport int MQTTAsync_subscribe(MQTTAsync handle, const char* topic, int qos, MQTTAsync_responseOptions* response);
00931
00932
00950 DLLExport int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char* const* topic, int* qos, MQTTAsync_responseOptions* response);
00951
00964 DLLExport int MQTTAsync_unsubscribe(MQTTAsync handle, const char* topic, MQTTAsync_responseOptions* response);
00965
00978 DLLExport int MQTTAsync_unsubscribeMany(MQTTAsync handle, int count, char* const* topic, MQTTAsync_responseOptions* response);
00979
00980
00999 DLLExport int MQTTAsync_send(MQTTAsync handle, const char* destinationName, int payloadlen, void* payload, int qos, int retained,
01000 MQTTAsync_responseOptions* response);
01001
01002
01018 DLLExport int MQTTAsync_sendMessage(MQTTAsync handle, const char* destinationName, const MQTTAsync_message* msg, MQTTAsync_responseOptions* response);
01019
01020
01039 DLLExport int MQTTAsync_getPendingTokens(MQTTAsync handle, MQTTAsync_token **tokens);
01040
01049 #define MQTTASYNC_TRUE 1
01050 DLLExport int MQTTAsync_isComplete(MQTTAsync handle, MQTTAsync_token token);
01051
01052
01063 DLLExport int MQTTAsync_waitForCompletion(MQTTAsync handle, MQTTAsync_token token, unsigned long timeout);
01064
01065
01076 DLLExport void MQTTAsync_freeMessage(MQTTAsync_message** msg);
01077
01086 DLLExport void MQTTAsync_free(void* ptr);
01087
01095 DLLExport void MQTTAsync_destroy(MQTTAsync* handle);
01096
01097
01098
01099 enum MQTTASYNC_TRACE_LEVELS
01100 {
01101 MQTTASYNC_TRACE_MAXIMUM = 1,
01102 MQTTASYNC_TRACE_MEDIUM,
01103 MQTTASYNC_TRACE_MINIMUM,
01104 MQTTASYNC_TRACE_PROTOCOL,
01105 MQTTASYNC_TRACE_ERROR,
01106 MQTTASYNC_TRACE_SEVERE,
01107 MQTTASYNC_TRACE_FATAL,
01108 };
01109
01110
01116 DLLExport void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level);
01117
01118
01127 typedef void MQTTAsync_traceCallback(enum MQTTASYNC_TRACE_LEVELS level, char* message);
01128
01135 DLLExport void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback* callback);
01136
01137
01138 typedef struct
01139 {
01140 const char* name;
01141 const char* value;
01142 } MQTTAsync_nameValue;
01143
01150 DLLExport MQTTAsync_nameValue* MQTTAsync_getVersionInfo(void);
01151
01152
01709 #endif
01710
01711 #ifdef __cplusplus
01712 }
01713 #endif