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
177 int init(
const char* url, U32* rnd);
182 int connect(
const char* uid,
int uidLen,
const char* credentials,
183 U8 credLen,
const char* info,
int infoLen);
201 int create(
const char* topic);
235 int wrtstr(
const char* str);
241 int write(
const void* data,
int len);
304#define SMQ_setCtx(o, ctx) SOCKET_constructor(&(o)->sock, ctx)
352 U8 credLen,
const char* info,
int infoLen);
530#define SMQ_getMsgSize(o) ((o)->frameLen-15)
544inline int SMQ::connect(
const char* uid,
int uidLen,
const char* credentials,
545 U8 credLen,
const char* info,
int infoLen) {
546 return SMQ_connect(
this, uid, uidLen, credentials, credLen, info, infoLen);
573inline int SMQ::publish(
const void* data,
int len, U32 _tid, U32 _subtid) {
574 return SMQ_publish(
this, data, len, _tid, _subtid);
612#ifndef SHARKMQ_COMPAT
613#define SHARKMQ_COMPAT 1
618#define SharkSslCon void
619#define SharkMQ_constructor(o, buf, bufLen) SMQ_constructor(o, buf, bufLen)
620#define SharkMQ_setCtx(o, ctx) SMQ_setCtx(o, ctx)
621#define SharkMQ_init(o, scon, url, rnd) SMQ_init(o, url, rnd)
622#define SharkMQ_connect(o, uid, uidLen, credentials, credLen, info, infoLen, NotApplicable) \
623 SMQ_connect(o, uid, uidLen, credentials, credLen, info, infoLen)
624#define SharkMQ_disconnect(o) SMQ_disconnect(o)
625#define SharkMQ_destructor(o) SMQ_destructor(o)
626#define SharkMQ_create(o, topic) SMQ_create(o, topic)
627#define SharkMQ_createsub(o, subtopic) SMQ_createsub(o, subtopic)
628#define SharkMQ_subscribe(o, topic) SMQ_subscribe(o, topic)
629#define SharkMQ_unsubscribe(o, tid) SMQ_unsubscribe(o, tid)
630#define SharkMQ_publish(o, data, len, tid, subtid) \
631 SMQ_publish(o, data, len, tid, subtid)
632#define SharkMQ_wrtstr(o, str) SMQ_wrtstr(o, str)
633#define SharkMQ_write(o, data, len) SMQ_write(o, data, len)
634#define SharkMQ_pubflush(o, tid, subtid) SMQ_pubflush(o, tid, subtid)
635#define SharkMQ_observe(o, tid) SMQ_observe(o, tid)
636#define SharkMQ_unobserve(o, tid) SMQ_unobserve(o, tid)
637#define SharkMQ_getMessage(o, msg) SMQ_getMessage(o, msg)
638#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:530
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:601
void disconnect()
Gracefully close the connection.
Definition: SMQ.h:549
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:573
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:585
int createsub(const char *subtopic)
Create a sub-topic and fetch the subtopic ID.
Definition: SMQ.h:561
int observe(U32 tid)
Request the broker to provide change notification events when the number of subscribers to a specific...
Definition: SMQ.h:589
int getMessage(U8 **msg)
Wait for messages sent from the broker.
Definition: SMQ.h:597
int unsubscribe(U32 tid)
Requests the broker to unsubscribe the server from a topic.
Definition: SMQ.h:569
~SMQ()
Terminate a SimpleMQ instance.
Definition: SMQ.h:553
SMQ(U8 *buf, U16 bufLen)
Create a SimpleMQ client instance.
Definition: SMQ.h:536
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:581
int create(const char *topic)
Create a topic an fetch the topic ID (tid).
Definition: SMQ.h:557
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:577
int init(const char *url, U32 *rnd)
Initiate the SMQ server connection.
Definition: SMQ.h:540
int unobserve(U32 tid)
Stop receiving change notifications for a topic ID or ephemeral topic ID.
Definition: SMQ.h:593
int subscribe(const char *topic)
The response to SMQ_subscribe is asynchronous and returned as status SMQ_SUBACK via SMQ_getMessage.
Definition: SMQ.h:565
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:544
#define SOCKET
The SOCKET object/handle is an 'int' when using a BSD compatible TCP/IP stack.
Definition: selib.h:142
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