CommsChampion Ecosystem MQTT v3.1.1 Client
MQTT v3.1.1 Client Library.
common.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved.
3 //
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 
10 
11 #pragma once
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #else // #ifdef __cplusplus
16 #include <stdbool.h>
17 #endif // #ifdef __cplusplus
18 
21 #define CC_MQTT311_CLIENT_MAJOR_VERSION 1U
22 
25 #define CC_MQTT311_CLIENT_MINOR_VERSION 0U
26 
29 #define CC_MQTT311_CLIENT_PATCH_VERSION 0U
30 
33 #define CC_MQTT311_CLIENT_MAKE_VERSION(major_, minor_, patch_) \
34  ((static_cast<unsigned>(major_) << 24) | \
35  (static_cast<unsigned>(minor_) << 8) | \
36  (static_cast<unsigned>(patch_)))
37 
40 #define CC_MQTT311_CLIENT_VERSION CC_MQTT311_CLIENT_MAKE_VERSION(CC_MQTT311_CLIENT_MAJOR_VERSION, CC_MQTT311_CLIENT_MINOR_VERSION, CC_MQTT311_CLIENT_PATCH_VERSION)
41 
44 typedef enum
45 {
51 
54 typedef enum
55 {
73 
76 typedef enum
77 {
88 
91 typedef enum
92 {
97 
100 typedef enum
101 {
107 
110 typedef enum
111 {
120 
123 typedef enum
124 {
130 
133 struct CC_Mqtt311Client;
134 
138 typedef struct CC_Mqtt311Client* CC_Mqtt311ClientHandle;
139 
142 struct CC_Mqtt311Connect;
143 
147 typedef struct CC_Mqtt311Connect* CC_Mqtt311ConnectHandle;
148 
151 struct CC_Mqtt311Disconnect;
152 
156 typedef struct CC_Mqtt311Disconnect* CC_Mqtt311DisconnectHandle;
157 
160 struct CC_Mqtt311Subscribe;
161 
165 typedef struct CC_Mqtt311Subscribe* CC_Mqtt311SubscribeHandle;
166 
169 struct CC_Mqtt311Unsubscribe;
170 
174 typedef struct CC_Mqtt311Unsubscribe* CC_Mqtt311UnsubscribeHandle;
175 
178 struct CC_Mqtt311Publish;
179 
183 typedef struct CC_Mqtt311Publish* CC_Mqtt311PublishHandle;
184 
188 typedef struct
189 {
190  const char* m_clientId;
191  const char* m_username;
192  const unsigned char* m_password;
193  unsigned m_passwordLen;
194  unsigned m_keepAlive;
197 
201 typedef struct
202 {
203  const char* m_topic;
204  const unsigned char* m_data;
205  unsigned m_dataLen;
207  bool m_retain;
209 
212 typedef struct
213 {
217 
221 typedef struct
222 {
223  const char* m_topic;
226 
229 typedef struct
230 {
234 
238 typedef struct
239 {
240  const char* m_topic;
242 
245 typedef struct
246 {
247  const char* m_topic;
248  const unsigned char* m_data;
249  unsigned m_dataLen;
251  bool m_retained;
253 
257 typedef struct
258 {
259  const char* m_topic;
260  const unsigned char* m_data;
261  unsigned m_dataLen;
263  bool m_retain;
265 
274 typedef void (*CC_Mqtt311NextTickProgramCb)(void* data, unsigned duration);
275 
283 typedef unsigned (*CC_Mqtt311CancelNextTickWaitCb)(void* data);
284 
298 typedef void (*CC_Mqtt311SendOutputDataCb)(void* data, const unsigned char* buf, unsigned bufLen);
299 
306 
313 typedef void (*CC_Mqtt311MessageReceivedReportCb)(void* data, const CC_Mqtt311MessageInfo* info);
314 
320 typedef void (*CC_Mqtt311ErrorLogCb)(void* data, const char* msg);
321 
330 typedef void (*CC_Mqtt311ConnectCompleteCb)(void* data, CC_Mqtt311AsyncOpStatus status, const CC_Mqtt311ConnectResponse* response);
331 
345 
356 
367 
368 #ifdef __cplusplus
369 }
370 #endif
void(* CC_Mqtt311NextTickProgramCb)(void *data, unsigned duration)
Callback used to request time measurement.
Definition: common.h:274
void(* CC_Mqtt311SendOutputDataCb)(void *data, const unsigned char *buf, unsigned bufLen)
Callback used to request to send data to the broker.
Definition: common.h:298
void(* CC_Mqtt311MessageReceivedReportCb)(void *data, const CC_Mqtt311MessageInfo *info)
Callback used to report new message received of the broker.
Definition: common.h:313
unsigned(* CC_Mqtt311CancelNextTickWaitCb)(void *data)
Callback used to request termination of existing time measurement.
Definition: common.h:283
void(* CC_Mqtt311ErrorLogCb)(void *data, const char *msg)
Callback used to report discovered errors.
Definition: common.h:320
struct CC_Mqtt311Client * CC_Mqtt311ClientHandle
Handle used to access client specific data structures.
Definition: common.h:138
void(* CC_Mqtt311BrokerDisconnectReportCb)(void *data, CC_Mqtt311BrokerDisconnectReason reason)
Callback used to report unsolicited disconnection of the broker.
Definition: common.h:305
CC_Mqtt311ConnectReturnCode
"Connect Return Code" as defined in MQTT v3.1.1 specification
Definition: common.h:111
void(* CC_Mqtt311ConnectCompleteCb)(void *data, CC_Mqtt311AsyncOpStatus status, const CC_Mqtt311ConnectResponse *response)
Callback used to report completion of the "connect" operation.
Definition: common.h:330
struct CC_Mqtt311Connect * CC_Mqtt311ConnectHandle
Handle for "connect" operation.
Definition: common.h:147
@ CC_Mqtt311ConnectReturnCode_ServerUnavailable
value Server is Unavailable.
Definition: common.h:115
@ CC_Mqtt311ConnectReturnCode_NotAuthorized
value No Subscription Existed.
Definition: common.h:117
@ CC_Mqtt311ConnectReturnCode_ValuesLimit
Upper limit of the values.
Definition: common.h:118
@ CC_Mqtt311ConnectReturnCode_IdRejected
value Client ID is rejected.
Definition: common.h:114
@ CC_Mqtt311ConnectReturnCode_Accepted
value Connection Accepted.
Definition: common.h:112
@ CC_Mqtt311ConnectReturnCode_BadAuth
value Bad authentication details.
Definition: common.h:116
@ CC_Mqtt311ConnectReturnCode_InvalidProtocolVersion
value Invalid Protocol Version.
Definition: common.h:113
struct CC_Mqtt311Disconnect * CC_Mqtt311DisconnectHandle
Handle for "disconnect" operation.
Definition: common.h:156
CC_Mqtt311ErrorCode
Error code returned by various API functions.
Definition: common.h:55
CC_Mqtt311BrokerDisconnectReason
Reason for reporting unsolicited broker disconnection.
Definition: common.h:101
CC_Mqtt311QoS
Quality of Service.
Definition: common.h:45
CC_Mqtt311AsyncOpStatus
Status of the asynchronous operation.
Definition: common.h:77
@ CC_Mqtt311ErrorCode_RetryLater
Retry in next event loop iteration.
Definition: common.h:67
@ CC_Mqtt311ErrorCode_BadParam
Bad parameter is passed to the function.
Definition: common.h:62
@ CC_Mqtt311ErrorCode_AlreadyConnected
The client library is already connected to the broker, cannot perform connection operation.
Definition: common.h:61
@ CC_Mqtt311ErrorCode_Success
The requested function executed successfully.
Definition: common.h:56
@ CC_Mqtt311ErrorCode_Busy
The client library is in the middle of previous operation(s), cannot start a new one.
Definition: common.h:59
@ CC_Mqtt311ErrorCode_ValuesLimit
Limit for the values.
Definition: common.h:71
@ CC_Mqtt311ErrorCode_BufferOverflow
Output buffer is too short.
Definition: common.h:65
@ CC_Mqtt311ErrorCode_PreparationLocked
Another operation is being prepared, cannot create a new one without performing "send" or "cancel".
Definition: common.h:70
@ CC_Mqtt311ErrorCode_NetworkDisconnected
When network is disconnected issueing new ops is not accepted.
Definition: common.h:69
@ CC_Mqtt311ErrorCode_NotIntitialized
The allocated client hasn't been initialized.
Definition: common.h:58
@ CC_Mqtt311ErrorCode_InternalError
Internal library error, please submit bug report
Definition: common.h:57
@ CC_Mqtt311ErrorCode_Disconnecting
The client is in "disconnecting" state, (re)connect is required in the next iteration loop.
Definition: common.h:68
@ CC_Mqtt311ErrorCode_NotConnected
The client library is not connected to the broker. Returned by operations that require connection to ...
Definition: common.h:60
@ CC_Mqtt311ErrorCode_OutOfMemory
Memory allocation failed.
Definition: common.h:64
@ CC_Mqtt311ErrorCode_InsufficientConfig
The required configuration hasn't been performed.
Definition: common.h:63
@ CC_Mqtt311ErrorCode_NotSupported
Feature is not supported.
Definition: common.h:66
@ CC_Mqtt311BrokerDisconnectReason_InternalError
The library encountered internal error and there is a need to close network connection.
Definition: common.h:103
@ CC_Mqtt311BrokerDisconnectReason_NoBrokerResponse
No messages from the broker and no response to PINGREQ.
Definition: common.h:102
@ CC_Mqtt311BrokerDisconnectReason_ProtocolError
Protocol error was detected.
Definition: common.h:104
@ CC_Mqtt311BrokerDisconnectReason_ValuesLimit
Limit for the values.
Definition: common.h:105
@ CC_Mqtt311QoS_ExactlyOnceDelivery
QoS=2. Exactly once delivery.
Definition: common.h:48
@ CC_Mqtt311QoS_AtMostOnceDelivery
QoS=0. At most once delivery.
Definition: common.h:46
@ CC_Mqtt311QoS_ValuesLimit
Limit for the values.
Definition: common.h:49
@ CC_Mqtt311QoS_AtLeastOnceDelivery
QoS=1. At least once delivery.
Definition: common.h:47
@ CC_Mqtt311AsyncOpStatus_BrokerDisconnected
The operation has been aborted before completion due to broker's disconnection.
Definition: common.h:83
@ CC_Mqtt311AsyncOpStatus_OutOfMemory
The client library wasn't able to allocate necessary memory.
Definition: common.h:84
@ CC_Mqtt311AsyncOpStatus_Complete
The requested operation has been completed, refer to reported extra details for information.
Definition: common.h:78
@ CC_Mqtt311AsyncOpStatus_Aborted
The operation has been aborted before completion due to client's side operation.
Definition: common.h:82
@ CC_Mqtt311AsyncOpStatus_ProtocolError
The broker's response doesn't comply with MQTT311 specification.
Definition: common.h:81
@ CC_Mqtt311AsyncOpStatus_Timeout
The required response from broker hasn't been received in time.
Definition: common.h:80
@ CC_Mqtt311AsyncOpStatus_InternalError
Internal library error, please submit bug report
Definition: common.h:79
@ CC_Mqtt311AsyncOpStatus_BadParam
Bad value has been returned from the relevant callback.
Definition: common.h:85
@ CC_Mqtt311AsyncOpStatus_ValuesLimit
Limit for the values.
Definition: common.h:86
struct CC_Mqtt311Publish * CC_Mqtt311PublishHandle
Handle for "publish" operation.
Definition: common.h:183
void(* CC_Mqtt311PublishCompleteCb)(void *data, CC_Mqtt311PublishHandle handle, CC_Mqtt311AsyncOpStatus status)
Callback used to report completion of the "publish" operation.
Definition: common.h:366
CC_Mqtt311PublishOrdering
Publish ordering configuration.
Definition: common.h:92
@ CC_Mqtt311PublishOrdering_ValuesLimit
Limit for the values.
Definition: common.h:95
@ CC_Mqtt311PublishOrdering_Full
Preserve strict order between all messages.
Definition: common.h:94
@ CC_Mqtt311PublishOrdering_SameQos
Preserve strict order only between same QoS messages.
Definition: common.h:93
CC_Mqtt311SubscribeReturnCode
"Subscribe Return Code" as defined in MQTT v3.1.1 specification
Definition: common.h:124
void(* CC_Mqtt311SubscribeCompleteCb)(void *data, CC_Mqtt311SubscribeHandle handle, CC_Mqtt311AsyncOpStatus status, const CC_Mqtt311SubscribeResponse *response)
Callback used to report completion of the "subscribe" operation.
Definition: common.h:344
struct CC_Mqtt311Subscribe * CC_Mqtt311SubscribeHandle
Handle for "subscribe" operation.
Definition: common.h:165
@ CC_Mqtt311SubscribeReturnCode_Failure
value Failure.
Definition: common.h:128
@ CC_Mqtt311SubscribeReturnCode_SuccessQos1
value Maximum QoS 1.
Definition: common.h:126
@ CC_Mqtt311SubscribeReturnCode_SuccessQos0
value Maximum QoS 0.
Definition: common.h:125
@ CC_Mqtt311SubscribeReturnCode_SuccessQos2
value Maximum QoS 2.
Definition: common.h:127
struct CC_Mqtt311Unsubscribe * CC_Mqtt311UnsubscribeHandle
Handle for "unsubscribe" operation.
Definition: common.h:174
void(* CC_Mqtt311UnsubscribeCompleteCb)(void *data, CC_Mqtt311UnsubscribeHandle handle, CC_Mqtt311AsyncOpStatus status)
Callback used to report completion of the "unsubscribe" operation.
Definition: common.h:355
Configuration structure to be passed to the cc_mqtt311_client_connect_config().
Definition: common.h:189
unsigned m_passwordLen
Number of password bytes. When 0 means no password value. Defaults to 0.
Definition: common.h:193
bool m_cleanSession
Clean session flag, defaults to false.
Definition: common.h:195
unsigned m_keepAlive
Keep alive seconds configuration, defaults to 60.
Definition: common.h:194
const char * m_username
Zero terminated Username string, can be NULL. When NULL means no username value. Defaults to NULL.
Definition: common.h:191
const unsigned char * m_password
Pointer to password buffer, can be NULL, defaults to NULL.
Definition: common.h:192
const char * m_clientId
Zero terminated Client ID string, can be NULL. When NULL means empty "Client ID". Defaults to NULL.
Definition: common.h:190
Response information from broker to "connect" request.
Definition: common.h:213
CC_Mqtt311ConnectReturnCode m_returnCode
"Connection Return Code" reported by the broker
Definition: common.h:214
bool m_sessionPresent
"Session Present" indication.
Definition: common.h:215
Configuration structure to be passed to the cc_mqtt311_client_connect_config_will().
Definition: common.h:202
bool m_retain
"Retain" flag, defaults to false.
Definition: common.h:207
const unsigned char * m_data
Will message data, can be NULL. Defaults to NULL.
Definition: common.h:204
unsigned m_dataLen
Number of will data bytes. When 0 means no data. Defaults to 0.
Definition: common.h:205
CC_Mqtt311QoS m_qos
QoS value of the will message, defaults to CC_Mqtt311QoS_AtMostOnceDelivery.
Definition: common.h:206
const char * m_topic
Will topic string, must NOT be NULL or empty. Defaults to NULL.
Definition: common.h:203
Received message information.
Definition: common.h:246
const char * m_topic
Topic used to publish the message.
Definition: common.h:247
unsigned m_dataLen
Amount of data bytes.
Definition: common.h:249
bool m_retained
Indication of whether the received message was "retained".
Definition: common.h:251
const unsigned char * m_data
Pointer to the temporary buffer containin message data.
Definition: common.h:248
CC_Mqtt311QoS m_qos
QoS value used by the broker to report the message.
Definition: common.h:250
Configuration structure to be passed to the cc_mqtt311_client_publish_config().
Definition: common.h:258
unsigned m_dataLen
Amount of bytes in the publish data buffer, defaults to 0.
Definition: common.h:261
const unsigned char * m_data
Pointer to publish data buffer, defaults to NULL.
Definition: common.h:260
CC_Mqtt311QoS m_qos
Publish QoS value, defaults to CC_Mqtt311QoS_AtMostOnceDelivery.
Definition: common.h:262
const char * m_topic
Publish topic, cannot be NULL.
Definition: common.h:259
bool m_retain
"Retain" flag, defaults to false.
Definition: common.h:263
Response information from broker to "subscribe" request.
Definition: common.h:230
unsigned m_returnCodesCount
Amount of return codes in the array.
Definition: common.h:232
const CC_Mqtt311SubscribeReturnCode * m_returnCodes
Pointer to array contianing per-topic subscription return codes.
Definition: common.h:231
Topic filter configuration structure of the "subscribe" operation.
Definition: common.h:222
CC_Mqtt311QoS m_maxQos
"Maximum QoS" value, defaults to CC_Mqtt311QoS_ExactlyOnceDelivery.
Definition: common.h:224
const char * m_topic
"Topic Filter" string, mustn't be NULL
Definition: common.h:223
Topic filter configuration structure of the "unsubscribe" operation.
Definition: common.h:239
const char * m_topic
"Topic Filter" string, mustn't be NULL
Definition: common.h:240