00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00103
00104 #if defined(__cplusplus)
00105 extern "C" {
00106 #endif
00107 #if !defined(MQTTCLIENT_H)
00108 #define MQTTCLIENT_H
00109
00110 #if defined(WIN32) || defined(WIN64)
00111 #define DLLImport __declspec(dllimport)
00112 #define DLLExport __declspec(dllexport)
00113 #else
00114 #define DLLImport extern
00115 #define DLLExport __attribute__ ((visibility ("default")))
00116 #endif
00117
00118 #include <stdio.h>
00120
00121 #if !defined(NO_PERSISTENCE)
00122 #include "MQTTClientPersistence.h"
00123 #endif
00124
00129 #define MQTTCLIENT_SUCCESS 0
00130
00134 #define MQTTCLIENT_FAILURE -1
00135
00136
00137
00141 #define MQTTCLIENT_DISCONNECTED -3
00142
00146 #define MQTTCLIENT_MAX_MESSAGES_INFLIGHT -4
00147
00150 #define MQTTCLIENT_BAD_UTF8_STRING -5
00151
00154 #define MQTTCLIENT_NULL_PARAMETER -6
00155
00160 #define MQTTCLIENT_TOPICNAME_TRUNCATED -7
00161
00165 #define MQTTCLIENT_BAD_STRUCTURE -8
00166
00169 #define MQTTCLIENT_BAD_QOS -9
00170
00173 #define MQTTCLIENT_SSL_NOT_SUPPORTED -10
00174
00178 #define MQTTVERSION_DEFAULT 0
00179
00182 #define MQTTVERSION_3_1 3
00183
00186 #define MQTTVERSION_3_1_1 4
00187
00190 #define MQTT_BAD_SUBSCRIBE 0x80
00191
00195 typedef struct
00196 {
00198 char struct_id[4];
00200 int struct_version;
00202 int do_openssl_init;
00203 } MQTTClient_init_options;
00204
00205 #define MQTTClient_init_options_initializer { {'M', 'Q', 'T', 'G'}, 0, 0 }
00206
00211 void MQTTClient_global_init(MQTTClient_init_options* inits);
00212
00217 typedef void* MQTTClient;
00228 typedef int MQTTClient_deliveryToken;
00229 typedef int MQTTClient_token;
00230
00237 typedef struct
00238 {
00240 char struct_id[4];
00242 int struct_version;
00244 int payloadlen;
00246 void* payload;
00260 int qos;
00279 int retained;
00286 int dup;
00290 int msgid;
00291 } MQTTClient_message;
00292
00293 #define MQTTClient_message_initializer { {'M', 'Q', 'T', 'M'}, 0, 0, NULL, 0, 0, 0, 0 }
00294
00321 typedef int MQTTClient_messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* message);
00322
00343 typedef void MQTTClient_deliveryComplete(void* context, MQTTClient_deliveryToken dt);
00344
00360 typedef void MQTTClient_connectionLost(void* context, char* cause);
00361
00389 DLLExport int MQTTClient_setCallbacks(MQTTClient handle, void* context, MQTTClient_connectionLost* cl,
00390 MQTTClient_messageArrived* ma, MQTTClient_deliveryComplete* dc);
00391
00392
00435 DLLExport int MQTTClient_create(MQTTClient* handle, const char* serverURI, const char* clientId,
00436 int persistence_type, void* persistence_context);
00437
00450 typedef struct
00451 {
00453 char struct_id[4];
00457 int struct_version;
00459 const char* topicName;
00461 const char* message;
00465 int retained;
00470 int qos;
00472 struct
00473 {
00474 int len;
00475 const void* data;
00476 } payload;
00477 } MQTTClient_willOptions;
00478
00479 #define MQTTClient_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 1, NULL, NULL, 0, 0, {0, NULL} }
00480
00493 typedef struct
00494 {
00496 char struct_id[4];
00498 int struct_version;
00499
00501 const char* trustStore;
00502
00506 const char* keyStore;
00507
00511 const char* privateKey;
00513 const char* privateKeyPassword;
00514
00523 const char* enabledCipherSuites;
00524
00526 int enableServerCertAuth;
00527
00528 } MQTTClient_SSLOptions;
00529
00530 #define MQTTClient_SSLOptions_initializer { {'M', 'Q', 'T', 'S'}, 0, NULL, NULL, NULL, NULL, NULL, 1 }
00531
00546 typedef struct
00547 {
00549 char struct_id[4];
00557 int struct_version;
00567 int keepAliveInterval;
00589 int cleansession;
00599 int reliable;
00605 MQTTClient_willOptions* will;
00611 const char* username;
00617 const char* password;
00621 int connectTimeout;
00625 int retryInterval;
00630 MQTTClient_SSLOptions* ssl;
00634 int serverURIcount;
00645 char* const* serverURIs;
00652 int MQTTVersion;
00656 struct
00657 {
00658 const char* serverURI;
00659 int MQTTVersion;
00660 int sessionPresent;
00661 } returned;
00665 struct {
00666 int len;
00667 const void* data;
00668 } binarypwd;
00669 } MQTTClient_connectOptions;
00670
00671 #define MQTTClient_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 5, 60, 1, 1, NULL, NULL, NULL, 30, 20, NULL, 0, NULL, 0, {NULL, 0, 0}, {0, NULL} }
00672
00680 typedef struct
00681 {
00682 const char* name;
00683 const char* value;
00684 } MQTTClient_nameValue;
00685
00691 DLLExport MQTTClient_nameValue* MQTTClient_getVersionInfo(void);
00692
00713 DLLExport int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options);
00714
00733 DLLExport int MQTTClient_disconnect(MQTTClient handle, int timeout);
00734
00742 DLLExport int MQTTClient_isConnected(MQTTClient handle);
00743
00744
00745
00746
00747
00761 DLLExport int MQTTClient_subscribe(MQTTClient handle, const char* topic, int qos);
00762
00779 DLLExport int MQTTClient_subscribeMany(MQTTClient handle, int count, char* const* topic, int* qos);
00780
00792 DLLExport int MQTTClient_unsubscribe(MQTTClient handle, const char* topic);
00793
00805 DLLExport int MQTTClient_unsubscribeMany(MQTTClient handle, int count, char* const* topic);
00806
00828 DLLExport int MQTTClient_publish(MQTTClient handle, const char* topicName, int payloadlen, void* payload, int qos, int retained,
00829 MQTTClient_deliveryToken* dt);
00849 DLLExport int MQTTClient_publishMessage(MQTTClient handle, const char* topicName, MQTTClient_message* msg, MQTTClient_deliveryToken* dt);
00850
00851
00867 DLLExport int MQTTClient_waitForCompletion(MQTTClient handle, MQTTClient_deliveryToken dt, unsigned long timeout);
00868
00869
00888 DLLExport int MQTTClient_getPendingDeliveryTokens(MQTTClient handle, MQTTClient_deliveryToken **tokens);
00889
00896 DLLExport void MQTTClient_yield(void);
00897
00929 DLLExport int MQTTClient_receive(MQTTClient handle, char** topicName, int* topicLen, MQTTClient_message** message,
00930 unsigned long timeout);
00931
00942 DLLExport void MQTTClient_freeMessage(MQTTClient_message** msg);
00943
00952 DLLExport void MQTTClient_free(void* ptr);
00953
00961 DLLExport void MQTTClient_destroy(MQTTClient* handle);
00962
00963 #endif
00964 #ifdef __cplusplus
00965 }
00966 #endif
00967