-
Notifications
You must be signed in to change notification settings - Fork 13
/
mqttlistener.h
62 lines (50 loc) · 1.81 KB
/
mqttlistener.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef MQTTLISTENER_H
#define MQTTLISTENER_H
// Differentiate between three categories of compilers for this include:
// * MSVC 2017 x64 -> Use provided header & .lib files.
// * MinGW -> Compile the entire source for direct inclusion.
// * Other -> Use the globally installed libmosquitto(pp) files.
#ifdef __MINGW32__
#include "mosquitto/lib/cpp/mosquittopp.h"
#elif defined __MINGW64__
#include "mosquitto/lib/cpp/mosquittopp.h"
#elif defined _MSC_VER
#ifdef _WIN64
#include "mosquitto/mosquittopp.h"
//#pragma comment(linker, "/LIBPATH:"
#pragma comment(lib, "mosquitto.lib")
#pragma comment(lib, "mosquittopp.lib")
#endif
#else
#include <mosquittopp.h>
#endif
#include <string>
#include <QObject>
class MqttListener : public QObject, mosqpp::mosquittopp {
Q_OBJECT
QString host;
int port;
public:
explicit MqttListener(QObject *parent = 0, QString clientId = "CC-UI",
QString host = "localhost", int port = 1883);
~MqttListener();
public slots:
bool setTLS(std::string &ca, std::string &cert, std::string &key);
bool setPassword(std::string &username, std::string &password);
void on_connect(int rc);
void on_message(const struct mosquitto_message* message);
void on_subscribe(int mid, int qos_count, const int* granted_qos);
void on_log(int level, const char* str);
void publishMessage(std::string topic, std::string msg);
void addSubscription(std::string topic);
void removeSubscription(std::string topic);
signals:
void connected();
void failed(QString err);
void receivedMessage(std::string topic, std::string message);
void finished();
public slots:
void connectBroker();
void disconnectBroker();
};
#endif // MQTTLISTENER_H