-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmqttmanager.h
77 lines (63 loc) · 1.7 KB
/
mqttmanager.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef MQTTMANAGER_H
#define MQTTMANAGER_H
#include <QObject>
#include <QMutex>
#include <QMqttTopicName>
class QMqttClient;
class QSettings;
class QTimer;
namespace Yate {
class MqttManager : public QObject
{
Q_OBJECT
public:
explicit MqttManager(QObject *parent = nullptr, QString key = "");
bool connectTo(QString lobby, QString &errMsg);
QString topic();
QString topicUrl();
const QString &getUserId() const;
public slots:
void start();
void sendMessageOnChannel1(QString msg);
void sendMessageOnChannel2(QString msg);
void sendMessageOnChannel3(QString msg);
void disconnectFromLobby();
void reconnect();
private slots:
void messageReceived(const QByteArray &message, const QMqttTopicName &topic);
void checkMessageBuffers();
void updateLogStateChange();
void brokerDisconnected();
void publishMessage(QString msg);
signals:
void onMessageFromChannel1(QString msg);
void onMessageFromChannel2(QString msg);
void onMessageFromChannel3(QString msg);
void onLobbyIdChange(QString id);
void connectionFailed(QString msg);
void connected();
void connecting();
void disconnected();
private:
void sendMessageOnChannel(QString msg, int ch);
bool running_;
bool initialized_;
QMqttClient *client_;
QTimer *messageBufferTimer_;
QSettings *settings_;
QString ch1Buffer_;
QString ch2Buffer_;
QString ch3Buffer_;
QMutex bufferMutex_;
QString username_;
QString password_;
QMqttTopicName peerTopic_;
QString peerId_;
QString userId_;
QString userPassword_;
int clientState_;
bool isSecure_;
QString stateToString_(int state);
};
}
#endif // MQTTMANAGER_H