LoboMQ
Loading...
Searching...
No Matches
PubSub.h
Go to the documentation of this file.
1
9#ifndef PUBSUB_H
10
11#define PUBSUB_H
12
13#include <stdint.h>
14
15#include "commons/Includes.h"
16
17#define MAXTOPICLENGTH 24
18#define MAXCONTENTSIZE 30
19
25typedef enum __attribute__((packed)) {
27 MSGTYPE_SUBSCRIBE = (uint8_t)0x00,
33
38typedef struct {
39 MessageType type;
41
47typedef struct : public MessageBase {
48 char topic[MAXTOPICLENGTH];
50
56typedef struct : public MessageBase{
57 char topic[MAXTOPICLENGTH];
59
65typedef struct : public MessageBase {
66 char topic[MAXTOPICLENGTH];
67 size_t contentSize;
68 void* content[MAXCONTENTSIZE];
70
87LMQErrType publish(uint8_t *mac, char *topic, void *payload, size_t payloadSize, Elog *_logger = disableLogger());
88
104LMQErrType subscribe(uint8_t *mac, char *topic, Elog *_logger = disableLogger());
105
122LMQErrType unsubscribe(uint8_t *mac, char *topic, Elog *_logger = disableLogger());
123
140bool isLMQMessage(const uint8_t *incomingData);
141
147typedef struct {
148 size_t contentSize;
149 void* content[MAXCONTENTSIZE];
151
167PayloadContent getLMQPayload(const uint8_t *incomingData);
168
169#endif
LMQErrType
Enumerates every error code that can be returned by the library functions.
Definition Includes.h:28
Elog * disableLogger()
Creates a logger without the ability to print messages.
Definition Logger.cpp:52
LMQErrType subscribe(uint8_t *mac, char *topic, Elog *_logger=disableLogger())
Subscribes to a topic on the broker.
Definition PubSub.cpp:133
LMQErrType unsubscribe(uint8_t *mac, char *topic, Elog *_logger=disableLogger())
Unsubscribes from a topic on the broker.
Definition PubSub.cpp:159
LMQErrType publish(uint8_t *mac, char *topic, void *payload, size_t payloadSize, Elog *_logger=disableLogger())
Publishes a message to the broker.
Definition PubSub.cpp:105
MessageType
Enumerates every type of message sent between the broker and the clients.
Definition PubSub.h:25
@ MSGTYPE_UNSUBSCRIBE
Unsubscribe message, sent from subscriber to broker.
Definition PubSub.h:29
@ MSGTYPE_PUBLISH
Publish message, sent from publisher to broker or from broker to subscriber.
Definition PubSub.h:31
@ MSGTYPE_SUBSCRIBE
Subscribe message, sent from subscriber to broker.
Definition PubSub.h:27
PayloadContent getLMQPayload(const uint8_t *incomingData)
Gets the payload content inside a published message This function extracts the payload from the bytes...
Definition PubSub.cpp:191
bool isLMQMessage(const uint8_t *incomingData)
Checks if the data received is a MQ message.
Definition PubSub.cpp:186
Structure that contains the fields used by every message.
Definition PubSub.h:38
Structure representing the content of a payload This structure holds properties of the content receiv...
Definition PubSub.h:147
size_t contentSize
Size of the content.
Definition PubSub.h:148
Structure that contains the fields used by a publish message, apart from those inherited from the Mes...
Definition PubSub.h:65
size_t contentSize
Size of the content.
Definition PubSub.h:67
Structure that contains the fields used by a subscribe message, apart from those inherited from the M...
Definition PubSub.h:47
Structure that contains the fields used by a unsubscribe message, apart from those inherited from the...
Definition PubSub.h:56