NetBurner 3.5.6
PDF Version
mqtt_msg_reqs.h
1#ifndef __MQTT_MSG_REQS_H
2#define __MQTT_MSG_REQS_H
3#include <predef.h>
4#include <basictypes.h>
5#include <nbstring.h>
6#include <webclient/http_funcs.h>
7#include <mqtt/msg_types.h>
8
9namespace MQTT {
10
13namespace PacketInfo {
14struct ConnectAck {
15 uint8_t flags;
16 uint32_t remLen;
17 bool sessPresent;
18 uint32_t propsLen;
19 Pkt::eReasonCode_t reason;
20};
21
22struct Publish {
23 uint8_t flags;
24 uint32_t remLen;
25 NBString *topic;
26 uint16_t pktId;
27 uint32_t propsLen;
28 uint32_t payLen;
29};
30
31struct PublishAck{
32 uint8_t flags;
33 uint32_t remLen;
34 uint16_t pktId;
35 uint32_t propsLen;
36 Pkt::eReasonCode_t reason;
37};
38
39struct SubscribeAck {
40 uint8_t flags;
41 uint32_t remLen;
42 uint16_t pktId;
43 uint32_t propsLen;
44 Pkt::eReasonCode_t reason;
45 NBString *reasonStr;
46};
47
48struct UnsubscribeAck {
49 uint8_t flags;
50 uint32_t remLen;
51 uint16_t pktId;
52 uint32_t propsLen;
53 uint32_t paylLen;
54 Pkt::eReasonCode_t reason;
55 uint32_t subId;
56 NBString *reasonStr;
57};
58
59struct Disconnect {
60 uint8_t flags;
61 uint32_t remLen;
62 uint32_t propsLen;
63 Pkt::eReasonCode_t reason;
64 NBString *reasonStr;
65 NBString *serverRef;
66};
67
70struct Msg {
71 union {
72 struct {
73 uint8_t flags;
74 uint32_t remLen;
75 };
76 ConnectAck connack;
77 Publish publish;
78 PublishAck puback;
79 SubscribeAck suback;
80 UnsubscribeAck unsuback;
81 Disconnect disconn;
82 };
84 inline Pkt::eType_t GetType()
85 { return (Pkt::eType_t)(flags>>4); }
87 inline uint8_t GetFlags()
88 { return (flags & 0xF); }
90 Msg() {};
91 ~Msg() {};
92};
93
94
95}
96
97class Client;
98
99typedef int (*ConnAckCb_t) (Client *mConn, int mqttFd, void *ctx, PacketInfo::ConnectAck *connack);
100typedef bool(*TopicMatchCb_t)(Client *mConn, NBString *topicName, void *matchCtx);
101typedef int (*WrPropCb_t) (Client *mConn, int mqttFd, void *ctx, uint32_t propLen);
102typedef int (*WrPayloadCb_t) (Client *mClient, int mqttFd, void *ctx, uint32_t payloadLen);
103typedef int (*AckCb_t) (Client *mClient, void *ctx, PacketInfo::PublishAck *ack);
104typedef int (*DisconnCb_t) (Client *mClient, PacketInfo::Disconnect *disconn);
105
106struct TopicHandler;
107
108struct AckCbCtx {
109 AckCb_t cb;
110 void *ctx;
111};
112
113typedef enum {
114 ePropListType_PData,
115 ePropListType_PList,
116 ePropListType_Callback,
117 ePropListType_None
118} ePropertyListType;
119
120typedef enum {
121 ePayloadType_PData,
122 ePayloadType_PoolPtr,
123 ePayloadType_Callback,
124 ePayloadType_None
125} ePayloadType;
126
127typedef enum {
128 ePropValType_ValByte,
129 ePropValType_ValShort,
130 ePropValType_ValLong,
131 ePropValType_ValPStr,
132 ePropValType_ValPStrPair,
133 ePropValType_ValPData,
134 ePropValType_ValLocStr,
135 ePropValType_ValLocStrPair,
136 ePropValType_ValLocData,
137 ePropValType_Callback
138} ePropertyValueType;
139
140struct RequestProperty {
141 RequestProperty *pNext;
142 ePropertyValueType valType;
143 uint8_t prop;
144 union {
145 struct {
146 union {
147 uint8_t valByte;
148 uint16_t valShort;
149 uint32_t valLong;
150 uint16_t data_len;
151 uint16_t sLen[2];
152 };
153 union {
154 char * pStr[2];
155 uint8_t * pData;
156 struct {
157 WrPayloadCb_t cb;
158 void *ctx;
159 };
160 };
161 };
162 struct {
163 union {
164 uint8_t _val8;
165 uint16_t _val16;
166 uint32_t _val32;
167 uint16_t _data_len;
168 };
169 uint8_t data[];
170 };
171 };
172 uint32_t GetEncodedLength();
173 uint32_t ListGetEncodedLength();
174};
175
176struct PublishRequest;
177
182 ParsedURI brokerURI;
183 uint8_t flags;
184 uint16_t keepalive;
185 const char *clientId;
186 const char *username;
187 const char *password;
188
189 uint32_t propsType:4;
190 uint32_t propsLen:28;
191 union {
192 const uint8_t *propBuf;
193 RequestProperty *propList;
194 struct {
195 WrPropCb_t propWrCb;
196 void * propWrCtx;
197 };
198 };
199 PublishRequest *pLwtReq;
200 ConnAckCb_t connAckCb;
201 void *connAckCtx;
202};
203
208 PublishRequest *pNextReq;
209 PublishRequest *pPrevReq;
210 uint8_t flags;
211 const char *topicName;
212 uint32_t propsType : 4; // ePropertyValueType
213 uint32_t propsLen : 28;
214
215 union {
216 const uint8_t *propBuf;
217 RequestProperty *propList;
218 struct {
219 WrPropCb_t propWrCb;
220 void *propWrCtx;
221 };
222 };
223 uint32_t payloadType : 4;
224 uint32_t payloadLen : 28;
225 union {
226 const uint8_t *pBuf;
227// PoolPtr pp;
228 pool_buffer * pp;
229 struct {
230 WrPayloadCb_t payWrCb;
231 void *payWrCtx;
232 };
233 };
234 AckCbCtx *cbCtx;
235 void dump();
236};
237
238typedef enum {
239 eSubReq_Pay_cstr,
240 eSubReq_Pay_cstrList,
241 eSubReq_Pay_nbstr,
242 eSubReq_Pay_nbstrList,
243 eSubReq_Pay_cb,
244} eSubscribeRequestPayloadType;
245
246typedef enum {
247 eSubReq_UProp_None,
248 eSubReq_UProp_up,
249 eSubReq_UProp_ptrupList,
250 eSubReq_UProp_upList,
251 eSubReq_UProp_nbstr,
252 eSubReq_UProp_ptrnbstrList,
253 eSubReq_UProp_nbstrList,
254 eSubReq_UProp_cb,
255} eSubscribeRequestUserPropertyType;
256
257struct UserProperty {
258 const char *key;
259 const char *val;
260};
261
262struct UserProperty_NbStr {
263 const NBString *key;
264 const NBString *val;
265};
266
271 const char *filter;
272 uint8_t opts;
273};
274
279 const NBString *filter;
280 uint8_t opts;
281};
282
287 SubscribeRequest *pNextSubReq;
288 int subId;
289 uint8_t subType : 4;
290 uint8_t propsType: 4;
291 TopicHandler *pubHandler;
292 union {
293 SubscribeFilter_NbStr filterNB;
294 SubscribeFilter filter;
295 SubscribeFilter *filterList;
296 SubscribeFilter_NbStr *filterListNB;
297 struct {
298 uint32_t totalStrLen;
299 WrPayloadCb_t filtersCb;
300 void *filtersCtx;
301 };
302 };
303 union{
304 struct {
305 uint32_t listLen;
306 UserProperty *pUPropList;
307 };
308 UserProperty UProp; // optional, needs both key and val
309 UserProperty_NbStr nbUProp;
310 struct {
311 uint32_t _listLen0;
312 UserProperty_NbStr *pUPropNBList;
313 };
314 struct {
315 uint32_t _listLen1;
316 UserProperty UPropList[];
317 };
318 struct {
319 uint32_t _listLen2;
320 UserProperty_NbStr UPropNBList[];
321 };
322 struct {
323 uint32_t totalUserPropsLen;
324 WrPayloadCb_t UPropsCb;
325 void *UPropsCbCtx;
326 };
327 };
328};
329
330struct SubUnsubQueueMsg {
331 SubUnsubQueueMsg *pNextReq;
332 SubscribeRequest *req;
333 AckCbCtx *cb;
334 uint16_t handlerIdx;
335 bool unsub;
336};
337
338}
339
340
341#endif /* ----- #ifndef __MQTT_MSG_REQS_H ----- */
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
Parsed Uniform Resource Identifier Class (URI)
Definition http_funcs.h:62
MQTT Namespace.
Definition mqtt.h:81
Structure used to specify details for a Publish call.
Definition mqtt_msg_reqs.h:181
PacketInfo::Msg message data structure.
Definition mqtt_msg_reqs.h:70
Publish publish
Definition mqtt_msg_reqs.h:77
ConnectAck connack
Definition mqtt_msg_reqs.h:76
uint8_t GetFlags()
Definition mqtt_msg_reqs.h:87
Msg()
Definition mqtt_msg_reqs.h:90
PublishAck puback
Definition mqtt_msg_reqs.h:78
UnsubscribeAck unsuback
Definition mqtt_msg_reqs.h:80
Disconnect disconn
Definition mqtt_msg_reqs.h:81
uint8_t flags
Definition mqtt_msg_reqs.h:73
Pkt::eType_t GetType()
Definition mqtt_msg_reqs.h:84
uint32_t remLen
Definition mqtt_msg_reqs.h:74
SubscribeAck suback
Definition mqtt_msg_reqs.h:79
Structure used to specify details for a Publish call.
Definition mqtt_msg_reqs.h:207
Structure used to specify a topic filter for subscriptions.
Definition mqtt_msg_reqs.h:278
Structure used to specify a topic filter for subscriptions.
Definition mqtt_msg_reqs.h:270
Structure used to specify details for a Subscribe call.
Definition mqtt_msg_reqs.h:286
TopicHandler context definition.
Definition mqtt.h:155
Main buffer structure for network and serial communication.
Definition buffers.h:90