sMQTTBroker
sMQTTTopic.h
1#ifndef SMQTTTOPIC_FILE
2#define SMQTTTOPIC_FILE
3
4#define SINGLE_LEVEL_WILDCARD "+"
5#define TOPIC_LEVEL_SEPARATOR "/"
6#define MULTI_LEVEL_WILDCARD "#"
7
8#include<string>
9
11{
12public:
13 sMQTTTopic(const char *name,char QoS=0);
14 sMQTTTopic(const char *name, unsigned short nameLen, const char *payload, unsigned short payloadLen);
15 sMQTTTopic(std::string &name,std::string &payload, char QoS=0);
16 sMQTTTopic(sMQTTTopic *other);
17 virtual ~sMQTTTopic();
18 void update(sMQTTTopic *other)
19 {
20 if (_payload)
21 delete[] _payload;
22 _name = other->Name();
23
24 if (other->Payload())
25 {
26 _payload = new char[strlen(other->Payload()) + 1];
27 strcpy(_payload, other->Payload());
28 }
29 else
30 _payload = 0;
31 qos = other->QoS();
32 }
34 const char *Name() {
35 return _name.c_str();
36 }
38 const char *Payload() {
39 return _payload;
40 }
42 unsigned char QoS() {
43 return qos;
44 }
48 bool match(sMQTTTopic *other);
52 bool match(const std::string &other);
56 void subscribe(sMQTTClient *client);
57 bool unsubscribe(sMQTTClient *client) {
58 sMQTTClientList::iterator cli; for (cli = clients.begin(); cli != clients.end(); cli++)if (*cli == client) { clients.erase(cli); break; }
59 return clients.empty();
60 }
61 const sMQTTClientList getSubscribeList() {
62 return clients;
63 }
64protected:
65 std::string _name;
66 char *_payload;
67 unsigned char qos;
68 unsigned short _payloadLen;
69 // subscribe to topic
70 sMQTTClientList clients;
71};
72
73typedef std::vector<sMQTTTopic*> sMQTTTopicList;
74
76{
77public:
78 sMQTTTopicRetain(const char *name, const char *payload);
79};
80#endif
Main Client class.
Definition: sMQTTClient.h:22
Definition: sMQTTTopic.h:11
void subscribe(sMQTTClient *client)
Definition: sMQTTTopic.cpp:43
const char * Payload()
topic payload
Definition: sMQTTTopic.h:38
unsigned char QoS()
topic qos
Definition: sMQTTTopic.h:42
bool match(sMQTTTopic *other)
Definition: sMQTTTopic.cpp:49
const char * Name()
toppic name
Definition: sMQTTTopic.h:34
Definition: sMQTTTopic.h:76