Only start the reconnect timer once
This commit is contained in:
parent
608c02799c
commit
7455d9ba23
@ -70,6 +70,15 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent)
|
|||||||
});
|
});
|
||||||
|
|
||||||
updateActiveBearers();
|
updateActiveBearers();
|
||||||
|
|
||||||
|
m_reconnectTimer.setInterval(1000);
|
||||||
|
m_reconnectTimer.setSingleShot(true);
|
||||||
|
connect(&m_reconnectTimer, &QTimer::timeout, this, [this](){
|
||||||
|
if (m_currentHost) {
|
||||||
|
qCInfo(dcNymeaConnection()) << "Reconnecting...";
|
||||||
|
connectInternal(m_currentHost);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
NymeaConnection::BearerTypes NymeaConnection::availableBearerTypes() const
|
NymeaConnection::BearerTypes NymeaConnection::availableBearerTypes() const
|
||||||
@ -234,12 +243,7 @@ void NymeaConnection::onError(QAbstractSocket::SocketError error)
|
|||||||
emit connectionStatusChanged();
|
emit connectionStatusChanged();
|
||||||
|
|
||||||
if (m_connectionStatus != ConnectionStatusSslUntrusted) {
|
if (m_connectionStatus != ConnectionStatusSslUntrusted) {
|
||||||
QTimer::singleShot(1000, this, [this](){
|
m_reconnectTimer.start();
|
||||||
if (m_currentHost) {
|
|
||||||
qCInfo(dcNymeaConnection()) << "Reconnecting...";
|
|
||||||
connectInternal(m_currentHost);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@
|
|||||||
#include <QAbstractSocket>
|
#include <QAbstractSocket>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QNetworkConfigurationManager>
|
#include <QNetworkConfigurationManager>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "nymeahost.h"
|
#include "nymeahost.h"
|
||||||
|
|
||||||
@ -139,6 +139,8 @@ private:
|
|||||||
NymeaTransportInterface *m_currentTransport = nullptr;
|
NymeaTransportInterface *m_currentTransport = nullptr;
|
||||||
NymeaHost *m_currentHost = nullptr;
|
NymeaHost *m_currentHost = nullptr;
|
||||||
Connection *m_preferredConnection = nullptr;
|
Connection *m_preferredConnection = nullptr;
|
||||||
|
|
||||||
|
QTimer m_reconnectTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NYMEACONNECTION_H
|
#endif // NYMEACONNECTION_H
|
||||||
|
|||||||
@ -38,12 +38,15 @@ NymeaHost::NymeaHost(QObject *parent):
|
|||||||
{
|
{
|
||||||
connect(m_connections, &Connections::dataChanged, this, [this](const QModelIndex &, const QModelIndex &, const QVector<int>){
|
connect(m_connections, &Connections::dataChanged, this, [this](const QModelIndex &, const QModelIndex &, const QVector<int>){
|
||||||
emit connectionChanged();
|
emit connectionChanged();
|
||||||
|
syncOnlineState();
|
||||||
});
|
});
|
||||||
connect(m_connections, &Connections::connectionAdded, this, [this](Connection*){
|
connect(m_connections, &Connections::connectionAdded, this, [this](Connection*){
|
||||||
emit connectionChanged();
|
emit connectionChanged();
|
||||||
|
syncOnlineState();
|
||||||
});
|
});
|
||||||
connect(m_connections, &Connections::connectionRemoved, this, [this](Connection*){
|
connect(m_connections, &Connections::connectionRemoved, this, [this](Connection*){
|
||||||
emit connectionChanged();
|
emit connectionChanged();
|
||||||
|
syncOnlineState();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +96,28 @@ Connections* NymeaHost::connections() const
|
|||||||
return m_connections;
|
return m_connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NymeaHost::online() const
|
||||||
|
{
|
||||||
|
return m_online;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NymeaHost::syncOnlineState()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_connections->rowCount(); i++) {
|
||||||
|
if (m_connections->get(i)->online()) {
|
||||||
|
if (!m_online) {
|
||||||
|
m_online = true;
|
||||||
|
emit onlineChanged();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_online) {
|
||||||
|
m_online = false;
|
||||||
|
emit onlineChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections::Connections(QObject *parent):
|
Connections::Connections(QObject *parent):
|
||||||
QAbstractListModel(parent)
|
QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -137,6 +137,7 @@ class NymeaHost: public QObject
|
|||||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||||
Q_PROPERTY(QString version READ version NOTIFY versionChanged)
|
Q_PROPERTY(QString version READ version NOTIFY versionChanged)
|
||||||
Q_PROPERTY(Connections* connections READ connections CONSTANT)
|
Q_PROPERTY(Connections* connections READ connections CONSTANT)
|
||||||
|
Q_PROPERTY(bool online READ online NOTIFY onlineChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NymeaHost(QObject *parent = nullptr);
|
explicit NymeaHost(QObject *parent = nullptr);
|
||||||
@ -153,16 +154,23 @@ public:
|
|||||||
|
|
||||||
Connections *connections() const;
|
Connections *connections() const;
|
||||||
|
|
||||||
|
bool online() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void nameChanged();
|
void nameChanged();
|
||||||
void versionChanged();
|
void versionChanged();
|
||||||
void connectionChanged();
|
void connectionChanged();
|
||||||
|
void onlineChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void syncOnlineState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_uuid;
|
QUuid m_uuid;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QString m_version;
|
QString m_version;
|
||||||
Connections *m_connections = nullptr;
|
Connections *m_connections = nullptr;
|
||||||
|
bool m_online = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NYMEAHOST_H
|
#endif // NYMEAHOST_H
|
||||||
|
|||||||
Reference in New Issue
Block a user