diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2019-06-17 12:02:55 +0200 |
---|---|---|
committer | Bernd Weimer <bernd.weimer@pelagicore.com> | 2019-08-01 13:20:57 +0200 |
commit | 1df51a44f4303410d255fa6b2aacc536fedd58ac (patch) | |
tree | 5f920282b23839f78e51abce692a5eca5bb04490 | |
parent | 4433649ed79b409ce59eafab143aff69dca546ed (diff) |
Only calculate the hardwareId once
If no other configuration was chosen appman calculates its hardwareId
using the available network interfaces.
Instead of iterating and sorting them every time the hardwareId is
now saved once calculated.
This is also a workaround for QTBUG-76408 on macOS which reports
a wrong intereface type on the second run and cause the appman to
stop without hardwareId.
Cherry-picked from dev: c82f080
Task-number: AUTOSUITE-1019
Change-Id: I521245987486b09fce5c410918d0a35be37b1e10
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r-- | src/main-lib/main.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/main-lib/main.cpp b/src/main-lib/main.cpp index 8a4c9788..84b48de7 100644 --- a/src/main-lib/main.cpp +++ b/src/main-lib/main.cpp @@ -1172,30 +1172,33 @@ QVector<AbstractApplicationInfo *> Main::scanForApplications(const QStringList & QString Main::hardwareId() const { + static QString hardwareId; + if (hardwareId.isEmpty()) { #if defined(AM_HARDWARE_ID) - return QString::fromLocal8Bit(AM_HARDWARE_ID); + hardwareId = QString::fromLocal8Bit(AM_HARDWARE_ID); #elif defined(AM_HARDWARE_ID_FROM_FILE) - QFile f(QString::fromLocal8Bit(AM_HARDWARE_ID_FROM_FILE)); - if (f.open(QFile::ReadOnly)) - return QString::fromLocal8Bit(f.readAll().trimmed()); + QFile f(QString::fromLocal8Bit(AM_HARDWARE_ID_FROM_FILE)); + if (f.open(QFile::ReadOnly)) + hardwareId = QString::fromLocal8Bit(f.readAll().trimmed()); #else - QVector<QNetworkInterface> candidateIfaces; - for (const QNetworkInterface &iface : QNetworkInterface::allInterfaces()) { - if (iface.isValid() - && !(iface.flags() & (QNetworkInterface::IsPointToPoint | QNetworkInterface::IsLoopBack)) - && iface.type() > QNetworkInterface::Virtual - && !iface.hardwareAddress().isEmpty()) { - candidateIfaces << iface; + QVector<QNetworkInterface> candidateIfaces; + for (const QNetworkInterface &iface : QNetworkInterface::allInterfaces()) { + if (iface.isValid() + && !(iface.flags() & (QNetworkInterface::IsPointToPoint | QNetworkInterface::IsLoopBack)) + && iface.type() > QNetworkInterface::Virtual + && !iface.hardwareAddress().isEmpty()) { + candidateIfaces << iface; + } + } + if (!candidateIfaces.isEmpty()) { + std::sort(candidateIfaces.begin(), candidateIfaces.end(), [](const QNetworkInterface &first, const QNetworkInterface &second) { + return first.name().compare(second.name()) < 0; + }); + hardwareId = candidateIfaces.constFirst().hardwareAddress().replace(qL1C(':'), qL1S("-")); } - } - if (!candidateIfaces.isEmpty()) { - std::sort(candidateIfaces.begin(), candidateIfaces.end(), [](const QNetworkInterface &first, const QNetworkInterface &second) { - return first.name().compare(second.name()) < 0; - }); - return candidateIfaces.constFirst().hardwareAddress().replace(qL1C(':'), qL1S("-")); - } #endif - return QString(); + } + return hardwareId; } QT_END_NAMESPACE_AM |