Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
SMQ.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 ****************************************************************************
10 * HEADER
11 *
12 * $Id: SMQ.h 6686 2026-10-29 23:59:57Z wini $
13 *
14 * COPYRIGHT: Real Time Logic LLC, 2014 - 2026
15 *
16 * This software is copyrighted by and is the sole property of Real
17 * Time Logic LLC. All rights, title, ownership, or other interests in
18 * the software remain the property of Real Time Logic LLC. This
19 * software may only be used in accordance with the terms and
20 * conditions stipulated in the corresponding license agreement under
21 * which the software has been supplied. Any unauthorized use,
22 * duplication, transmission, distribution, or disclosure of this
23 * software is expressly forbidden.
24 *
25 * This Copyright notice may not be removed or modified without prior
26 * written consent of Real Time Logic LLC.
27 *
28 * Real Time Logic LLC. reserves the right to modify this software
29 * without notice.
30 *
31 * https://realtimelogic.com
32 ****************************************************************************
33 * SMQ C library:
34 * https://realtimelogic.com/ba/doc/en/C/reference/html/group__SMQClient.html
35 */
36
37#ifndef __SMQClient_h
38#define __SMQClient_h
39
40#define SMQ_NONSEC
41
42#include "selib.h"
43
44#ifndef ISDIGIT
45#define ISDIGIT isdigit
46#endif
47
48#ifndef TRUE
49#define TRUE 1
50#define FALSE 0
51#endif
52
65#define SMQE_BUF_OVERFLOW -10000
66
69#define SMQE_INVALID_URL -10002
70
73#define SMQE_PROTOCOL_ERROR -10003
74
77#define SMQE_DISCONNECT -10004
78
79
82#define SMQE_PONGTIMEOUT -10005
83 /* end SMQClientErrorCodes */
85
86
100#define SMQ_SUBACK -20000
101
110#define SMQ_CREATEACK -20001
111
117#define SMQ_CREATESUBACK -20002
118
125#define SMQ_SUBCHANGE -20003
126
129#define SMQ_TIMEOUT -20004
130
131 /* end SMQClientRespCodes */
133
134
135#define SMQSTR(str) str, (sizeof(str)-1)
136
139typedef struct SMQ
140{
141 SOCKET sock;
142
144#ifdef SMQ_ENABLE_SENDBUF
145 U8* sBuf;
146#endif
147
151 S32 pingTmoCounter,pingTmo;
156 int status;
157 U16 bufLen;
158 U16 rBufIx;
159#ifdef SMQ_ENABLE_SENDBUF
160 U16 sBufIx;
161#endif
165 U8 inRecv; /* boolean set to true when thread blocked in SMQ_recv */
166 U8 recvPending; /* partial frame retained after timeout */
167#ifdef __cplusplus
168
174 SMQ(U8* buf, U16 bufLen);
175
176
183 int init(const char* url, U32* rnd);
184
195 int connect(const char* uid, int uidLen, const char* credentials,
196 U8 credLen, const char* info, int infoLen);
197
198
202 void disconnect();
203
204
208 ~SMQ();
209
210
216 int create(const char* topic);
217
218
224 int createsub(const char* subtopic);
225
226
233 int subscribe(const char* topic);
234
235
241 int unsubscribe(U32 tid);
242
243
254 int publish(const void* data, int len, U32 tid, U32 subtid);
255
256
263 int wrtstr(const char* str);
264
272 int write( const void* data, int len);
273
281 int pubflush(U32 tid, U32 subtid);
282
283
291 int observe(U32 tid);
292
293
299 int unobserve(U32 tid);
300
301
307 int getMessage(U8** msg);
308
309
314 int getMsgSize();
315
316#endif
318
319#ifdef __cplusplus
320extern "C" {
321#endif
322
337void SMQ_constructor(SMQ* o, U8* buf, U16 bufLen);
338
339
345#define SMQ_setCtx(o, ctx) SOCKET_constructor(&(o)->sock, ctx)
346
347
360int SMQ_init(SMQ* o, const char* url, U32* rnd);
361
392int SMQ_connect(SMQ* o, const char* uid, int uidLen, const char* credentials,
393 U8 credLen, const char* info, int infoLen);
394
395
401
402
407
408
421int SMQ_create(SMQ* o, const char* topic);
422
423
433int SMQ_createsub(SMQ* o, const char* subtopic);
434
435
445int SMQ_subscribe(SMQ* o, const char* topic);
446
447
454
455
466int SMQ_publish(SMQ* o, const void* data, int len, U32 tid, U32 subtid);
467
468
481int SMQ_wrtstr(SMQ* o, const char* str);
482
497int SMQ_write(SMQ* o, const void* data, int len);
498
516int SMQ_pubflush(SMQ* o, U32 tid, U32 subtid);
517
518
537int SMQ_observe(SMQ* o, U32 tid);
538
539
545int SMQ_unobserve(SMQ* o, U32 tid);
546
547
577int SMQ_getMessage(SMQ* o, U8** msg);
578
579
583#define SMQ_getMsgSize(o) ((o)->frameLen-15)
584 /* end group SMQClient_C */
586
587#ifdef __cplusplus
588}
589inline SMQ::SMQ(U8* buf, U16 bufLen) {
590 SMQ_constructor(this,buf, bufLen);
591}
592
593inline int SMQ::init(const char* url, U32* rnd) {
594 return SMQ_init(this, url, rnd);
595}
596
597inline int SMQ::connect(const char* uid, int uidLen, const char* credentials,
598 U8 credLen, const char* info, int infoLen) {
599 return SMQ_connect(this, uid, uidLen, credentials, credLen, info, infoLen);
600}
601
602inline void SMQ::disconnect() {
603 return SMQ_disconnect(this);
604}
605
606inline SMQ::~SMQ() {
607 SMQ_destructor(this);
608}
609
610inline int SMQ::create(const char* topic) {
611 return SMQ_create(this, topic);
612}
613
614inline int SMQ::createsub(const char* subtopic) {
615 return SMQ_createsub(this, subtopic);
616}
617
618inline int SMQ::subscribe(const char* topic) {
619 return SMQ_subscribe(this, topic);
620}
621
622inline int SMQ::unsubscribe(U32 _tid) {
623 return SMQ_unsubscribe(this, _tid);
624}
625
626inline int SMQ::publish(const void* data, int len, U32 _tid, U32 _subtid) {
627 return SMQ_publish(this, data, len, _tid, _subtid);
628}
629
630inline int SMQ::wrtstr(const char* str) {
631 return SMQ_wrtstr(this, str);
632}
633
634inline int SMQ::write( const void* data, int len) {
635 return SMQ_write(this, data, len);
636}
637
638inline int SMQ::pubflush(U32 _tid, U32 _subtid) {
639 return SMQ_pubflush(this, _tid, _subtid);
640}
641
642inline int SMQ::observe(U32 _tid) {
643 return SMQ_observe(this, _tid);
644}
645
646inline int SMQ::unobserve(U32 _tid) {
647 return SMQ_unobserve(this, _tid);
648}
649
650inline int SMQ::getMessage(U8** msg) {
651 return SMQ_getMessage(this, msg);
652}
653
654inline int SMQ::getMsgSize() {
655 return SMQ_getMsgSize(this);
656}
657
658#endif
659
660
661/*
662 The SharkMQ (secure SMQ) compatibility API makes it easy to write
663 code that can later be upgraded to a secure version, if needed.
664*/
665#ifndef SHARKMQ_COMPAT
666#define SHARKMQ_COMPAT 1
667#endif
668
669#if SHARKMQ_COMPAT
670#define SharkMQ SMQ
671#define SharkSslCon void
672#define SharkMQ_constructor(o, buf, bufLen) SMQ_constructor(o, buf, bufLen)
673#define SharkMQ_setCtx(o, ctx) SMQ_setCtx(o, ctx)
674#define SharkMQ_init(o, scon, url, rnd) SMQ_init(o, url, rnd)
675#define SharkMQ_connect(o, uid, uidLen, credentials, credLen, info, infoLen, NotApplicable) \
676 SMQ_connect(o, uid, uidLen, credentials, credLen, info, infoLen)
677#define SharkMQ_disconnect(o) SMQ_disconnect(o)
678#define SharkMQ_destructor(o) SMQ_destructor(o)
679#define SharkMQ_create(o, topic) SMQ_create(o, topic)
680#define SharkMQ_createsub(o, subtopic) SMQ_createsub(o, subtopic)
681#define SharkMQ_subscribe(o, topic) SMQ_subscribe(o, topic)
682#define SharkMQ_unsubscribe(o, tid) SMQ_unsubscribe(o, tid)
683#define SharkMQ_publish(o, data, len, tid, subtid) \
684 SMQ_publish(o, data, len, tid, subtid)
685#define SharkMQ_wrtstr(o, str) SMQ_wrtstr(o, str)
686#define SharkMQ_write(o, data, len) SMQ_write(o, data, len)
687#define SharkMQ_pubflush(o, tid, subtid) SMQ_pubflush(o, tid, subtid)
688#define SharkMQ_observe(o, tid) SMQ_observe(o, tid)
689#define SharkMQ_unobserve(o, tid) SMQ_unobserve(o, tid)
690#define SharkMQ_getMessage(o, msg) SMQ_getMessage(o, msg)
691#define SharkMQ_getMsgSize(o) SMQ_getMsgSize(o)
692#endif
693
694 /* end group selib */
696
697#endif
int SMQ_unobserve(SMQ *o, U32 tid)
Stop receiving change notifications for a topic ID or ephemeral topic ID.
int SMQ_connect(SMQ *o, const char *uid, int uidLen, const char *credentials, U8 credLen, const char *info, int infoLen)
Connect/establish a persistent SimpleMQ connection.
void SMQ_constructor(SMQ *o, U8 *buf, U16 bufLen)
Create a SimpleMQ client instance.
int SMQ_init(SMQ *o, const char *url, U32 *rnd)
Initiate the SMQ server connection.
int SMQ_getMessage(SMQ *o, U8 **msg)
Wait for messages sent from the broker.
void SMQ_destructor(SMQ *o)
Terminate a SimpleMQ instance.
int SMQ_subscribe(SMQ *o, const char *topic)
The response to SMQ_subscribe is asynchronous and returned as status SMQ_SUBACK via SMQ_getMessage.
int SMQ_unsubscribe(SMQ *o, U32 tid)
Requests the broker to unsubscribe the server from a topic.
int SMQ_observe(SMQ *o, U32 tid)
Request the broker to provide change notification events when the number of subscribers to a specific...
void SMQ_disconnect(SMQ *o)
Gracefully close the connection.
#define SMQ_getMsgSize(o)
Returns the message size, which is SMQ::frameLen - 15.
Definition: SMQ.h:583
int SMQ_pubflush(SMQ *o, U32 tid, U32 subtid)
Flush the internal buffer and request the broker to assemble all stored fragments as one message.
int SMQ_write(SMQ *o, const void *data, int len)
Publish a message in chunks and request the broker to assemble the message before publishing to the s...
int SMQ_wrtstr(SMQ *o, const char *str)
Publish a message in chunks and request the broker to assemble the message before publishing to the s...
int SMQ_createsub(SMQ *o, const char *subtopic)
Create a sub-topic and fetch the subtopic ID.
int SMQ_publish(SMQ *o, const void *data, int len, U32 tid, U32 subtid)
Publish messages to a topic and optionally to a sub-topic.
int SMQ_create(SMQ *o, const char *topic)
Create a topic an fetch the topic ID (tid).
int getMsgSize()
Returns the message size, which is SMQ::frameLen - 15.
Definition: SMQ.h:654
void disconnect()
Gracefully close the connection.
Definition: SMQ.h:602
int publish(const void *data, int len, U32 tid, U32 subtid)
Publish messages to a topic and optionally to a sub-topic.
Definition: SMQ.h:626
int pubflush(U32 tid, U32 subtid)
Flush the internal buffer and request the broker to assemble all stored fragments as one message.
Definition: SMQ.h:638
int createsub(const char *subtopic)
Create a sub-topic and fetch the subtopic ID.
Definition: SMQ.h:614
int observe(U32 tid)
Request the broker to provide change notification events when the number of subscribers to a specific...
Definition: SMQ.h:642
int getMessage(U8 **msg)
Wait for messages sent from the broker.
Definition: SMQ.h:650
int unsubscribe(U32 tid)
Requests the broker to unsubscribe the server from a topic.
Definition: SMQ.h:622
~SMQ()
Terminate a SimpleMQ instance.
Definition: SMQ.h:606
SMQ(U8 *buf, U16 bufLen)
Create a SimpleMQ client instance.
Definition: SMQ.h:589
struct SMQ SMQ
SimpleMQ structure.
int write(const void *data, int len)
Publish a message in chunks and request the broker to assemble the message before publishing to the s...
Definition: SMQ.h:634
int create(const char *topic)
Create a topic an fetch the topic ID (tid).
Definition: SMQ.h:610
int wrtstr(const char *str)
Publish a message in chunks and request the broker to assemble the message before publishing to the s...
Definition: SMQ.h:630
int init(const char *url, U32 *rnd)
Initiate the SMQ server connection.
Definition: SMQ.h:593
int unobserve(U32 tid)
Stop receiving change notifications for a topic ID or ephemeral topic ID.
Definition: SMQ.h:646
int subscribe(const char *topic)
The response to SMQ_subscribe is asynchronous and returned as status SMQ_SUBACK via SMQ_getMessage.
Definition: SMQ.h:618
int connect(const char *uid, int uidLen, const char *credentials, U8 credLen, const char *info, int infoLen)
Connect/establish a persistent SimpleMQ connection.
Definition: SMQ.h:597
uint16_t U16
Unsigned 16-bit integer.
Definition: GenPrimT.h:94
int32_t S32
Signed 32-bit integer.
Definition: GenPrimT.h:88
uint32_t U32
Unsigned 32-bit integer.
Definition: GenPrimT.h:96
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:92
#define SOCKET
The SOCKET object/handle is an 'int' when using a BSD compatible TCP/IP stack.
Definition: selib.h:135
SimpleMQ structure.
Definition: SMQ.h:140
U32 ptid
Publisher's tid: Set when receiving MSG_PUBLISH from broker.
Definition: SMQ.h:154
U16 frameLen
The SimpleMQ frame size for the incomming data.
Definition: SMQ.h:162
U32 tid
Topic: set when receiving MSG_PUBLISH from broker.
Definition: SMQ.h:153
U16 bytesRead
Read frame data using SMQ_getMessage until: frameLen - bytesRead = 0.
Definition: SMQ.h:164
U32 subtid
Sub-tid: set when receiving MSG_PUBLISH from broker.
Definition: SMQ.h:155
U32 timeout
Timeout in milliseconds to wait in functions waiting for server data.
Definition: SMQ.h:150
int status
Last known error code.
Definition: SMQ.h:156
U32 clientTid
Client's unique topic ID.
Definition: SMQ.h:152
U8 * buf
The buffer set via the constructor.
Definition: SMQ.h:143