45#define ISDIGIT isdigit
65#define SMQE_BUF_OVERFLOW -10000
69#define SMQE_INVALID_URL -10002
73#define SMQE_PROTOCOL_ERROR -10003
77#define SMQE_DISCONNECT -10004
82#define SMQE_PONGTIMEOUT -10005
100#define SMQ_SUBACK -20000
110#define SMQ_CREATEACK -20001
117#define SMQ_CREATESUBACK -20002
125#define SMQ_SUBCHANGE -20003
129#define SMQ_TIMEOUT -20004
135#define SMQSTR(str) str, (sizeof(str)-1)
144#ifdef SMQ_ENABLE_SENDBUF
151 S32 pingTmoCounter,pingTmo;
159#ifdef SMQ_ENABLE_SENDBUF
183 int init(
const char* url,
U32* rnd);
195 int connect(
const char* uid,
int uidLen,
const char* credentials,
196 U8 credLen,
const char* info,
int infoLen);
216 int create(
const char* topic);
263 int wrtstr(
const char* str);
272 int write(
const void* data,
int len);
345#define SMQ_setCtx(o, ctx) SOCKET_constructor(&(o)->sock, ctx)
393 U8 credLen,
const char* info,
int infoLen);
583#define SMQ_getMsgSize(o) ((o)->frameLen-15)
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);
627 return SMQ_publish(
this, data, len, _tid, _subtid);
665#ifndef SHARKMQ_COMPAT
666#define SHARKMQ_COMPAT 1
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)
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