File indexing completed on 2024-05-12 05:39:52

0001 #ifndef HEARTBEATSENDER_H
0002 #define HEARTBEATSENDER_H
0003 
0004 #include <QObject>
0005 #include <QTimer>
0006 
0007 /**
0008  * @brief The heartBeatSender class is dedicated to send off heartbeat messages preventing
0009  * disconnection for some users.
0010  */
0011 class HeartBeatSender : public QObject
0012 {
0013     Q_OBJECT
0014     Q_PROPERTY(int timeOut READ timeOut WRITE setTimeOut NOTIFY timeOutChanged FINAL)
0015     Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged FINAL)
0016     Q_PROPERTY(QString localId READ localId WRITE setIdLocalUser NOTIFY localIdChanged FINAL)
0017 public:
0018     explicit HeartBeatSender( QObject* parent= nullptr);
0019 
0020     void setIdLocalUser(const QString& id);
0021     QString localId()const;
0022 
0023     int timeOut() const;
0024     void setTimeOut(int newTimeOut);
0025 
0026     bool active() const;
0027     void setActive(bool newActive);
0028 
0029 public slots:
0030     void sendHeartBeatMsg();
0031     void updateTimer();
0032 
0033 signals:
0034     void timeOutChanged();
0035     void localIdChanged();
0036     void activeChanged();
0037 
0038 private:
0039     QTimer m_timer;
0040     int m_timeOut{10000};
0041     QString m_localId{QStringLiteral("unknown")};
0042     bool m_active{false};
0043 };
0044 
0045 #endif // HEARTBEATSENDER_H