diff options
author | Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> | 2023-11-22 13:11:48 +0100 |
---|---|---|
committer | Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> | 2023-11-23 10:46:25 +0100 |
commit | 6a2c6e3166e36bbeafdddf9ca48e48b9aeeb212d (patch) | |
tree | 4dfa2366cca58b4b396203b572312aac0a377972 | |
parent | d9cdbda97ba0987f5b82bc3d52b0a76b76953606 (diff) |
PCSC: Make polling interval adjustable via environment
Allow overriding the default polling interval using
QT_NFC_POLL_INTERVAL_MS environment variable.
Reduce the default polling interval to 100 ms to make the
library more useful with readers that produce beeps when
new tags are detected. Long polling intervals may lead to
users removing tags from the reader before QtNfc is able
to read them.
[ChangeLog][QtNfc][PCSCLite backend] The polling interval
is now configurable using QT_NFC_POLL_INTERVAL_MS environment
variable. The default polling interval was reduced to 100ms.
Fixes: QTBUG-105526
Change-Id: I74c3f3bb88dafa5e389536d88b3837910e91d345
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/nfc/doc/src/nfc-pcsc.qdoc | 5 | ||||
-rw-r--r-- | src/nfc/pcsc/qpcscmanager.cpp | 14 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/nfc/doc/src/nfc-pcsc.qdoc b/src/nfc/doc/src/nfc-pcsc.qdoc index 439215e2..532f0311 100644 --- a/src/nfc/doc/src/nfc-pcsc.qdoc +++ b/src/nfc/doc/src/nfc-pcsc.qdoc @@ -25,5 +25,10 @@ can be used for accessing both wired and wireless smartcards and storage cards. a transaction that remains active until QNearFieldTarget::disconnect() is called. This transaction prevents other applications from accessing this target. + \li The backend is polling for new tags, that means that there + may be a delay up to the full polling interval before new tags are reported. + The default polling interval is 100 milliseconds. It can be adjusted + by setting environment valiable \c{QT_NFC_POLL_INTERVAL_MS} to an integer + value in milliseconds. \endlist */ diff --git a/src/nfc/pcsc/qpcscmanager.cpp b/src/nfc/pcsc/qpcscmanager.cpp index 1730d44c..f5b358a5 100644 --- a/src/nfc/pcsc/qpcscmanager.cpp +++ b/src/nfc/pcsc/qpcscmanager.cpp @@ -12,14 +12,24 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(QT_NFC_PCSC) -static constexpr int StateUpdateIntervalMs = 1000; +static constexpr auto PollIntervalEnvVar = "QT_NFC_POLL_INTERVAL_MS"; +static constexpr int DefaultPollIntervalMs = 100; QPcscManager::QPcscManager(QObject *parent) : QObject(parent) { qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO; + int pollInterval = DefaultPollIntervalMs; + QByteArray intervalEnv = qgetenv(PollIntervalEnvVar); + if (!intervalEnv.isEmpty()) { + if (int intervalFromEnv = intervalEnv.toInt(); intervalFromEnv > 0) + pollInterval = intervalFromEnv; + else + qCWarning(QT_NFC_PCSC) << PollIntervalEnvVar << "set to an invalid value"; + } + m_stateUpdateTimer = new QTimer(this); - m_stateUpdateTimer->setInterval(StateUpdateIntervalMs); + m_stateUpdateTimer->setInterval(pollInterval); connect(m_stateUpdateTimer, &QTimer::timeout, this, &QPcscManager::onStateUpdate); } |