-
Notifications
You must be signed in to change notification settings - Fork 0
/
connector.h
39 lines (29 loc) · 895 Bytes
/
connector.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
#ifndef CONNECTOR_H
#define CONNECTOR_H
#include <QObject>
#include <QWebSocket>
class QTimer;
class Connector : public QObject
{
Q_OBJECT
public:
explicit Connector(QObject *parent = nullptr);
~Connector();
void setConnectCallback(std::function<void (bool)> callback);
void setJsonParserCallback(std::function<void (const QString &message)> callback);
void setSendCallback(std::function<void ()> callback);
public slots:
void open();
void onSocketDisconnected();
void onSocketConnected();
void onSocketMessageReceived(const QString &message);
void sendSocketMessage(const QByteArray &data);
private:
QWebSocket *m_socket;
QUrl m_url;
QTimer *m_reconnectTimer;
std::function<void (bool)> m_callback;
std::function<void (const QString &)> m_jsonParser;
std::function<void ()> m_sendCallback;
};
#endif // CONNECTOR_H