summaryrefslogtreecommitdiffstats
path: root/src/nfc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nfc')
-rw-r--r--src/nfc/ApiChangesQt6.txt18
-rw-r--r--src/nfc/CMakeLists.txt125
-rw-r--r--src/nfc/android/androidjninfc.cpp94
-rw-r--r--src/nfc/android/androidjninfc_p.h73
-rw-r--r--src/nfc/android/androidmainnewintentlistener.cpp85
-rw-r--r--src/nfc/android/androidmainnewintentlistener_p.h69
-rw-r--r--src/nfc/configure.cmake12
-rw-r--r--src/nfc/doc/qtnfc.qdocconf25
-rw-r--r--src/nfc/doc/snippets/doc_src_qtnfc.cpp82
-rw-r--r--src/nfc/doc/snippets/doc_src_qtnfc.qml65
-rw-r--r--src/nfc/doc/snippets/foorecord.cpp124
-rw-r--r--src/nfc/doc/snippets/foorecord.h78
-rw-r--r--src/nfc/doc/snippets/main.cpp51
-rw-r--r--src/nfc/doc/snippets/nfc.cpp51
-rw-r--r--src/nfc/doc/snippets/snippets.pro13
-rw-r--r--src/nfc/doc/src/examples.qdoc42
-rw-r--r--src/nfc/doc/src/nfc-android.qdoc91
-rw-r--r--src/nfc/doc/src/nfc-cpp.qdoc45
-rw-r--r--src/nfc/doc/src/nfc-features.qdoc64
-rw-r--r--src/nfc/doc/src/nfc-index.qdoc122
-rw-r--r--src/nfc/doc/src/nfc-overview.qdoc166
-rw-r--r--src/nfc/doc/src/nfc-pcsc.qdoc34
-rw-r--r--src/nfc/doc/src/nfc-qml.qdoc43
-rw-r--r--src/nfc/doc/src/qt6-changes.qdoc149
-rw-r--r--src/nfc/ios/qiosndefnotifier.cpp11
-rw-r--r--src/nfc/ios/qiosndefnotifier_p.h56
-rw-r--r--src/nfc/ios/qiosnfcndefsessiondelegate.mm298
-rw-r--r--src/nfc/ios/qiosnfcndefsessiondelegate_p.h88
-rw-r--r--src/nfc/ios/qiostagreaderdelegate.mm110
-rw-r--r--src/nfc/ios/qiostagreaderdelegate_p.h48
-rw-r--r--src/nfc/ndef/qndefaccessfsm_p.h103
-rw-r--r--src/nfc/ndef/qnfctagtype4ndeffsm.cpp374
-rw-r--r--src/nfc/ndef/qnfctagtype4ndeffsm_p.h82
-rw-r--r--src/nfc/neard/adapter.cpp25
-rw-r--r--src/nfc/neard/adapter_p.h60
-rw-r--r--src/nfc/neard/agent.cpp38
-rw-r--r--src/nfc/neard/agent_p.h100
-rw-r--r--src/nfc/neard/dbusobjectmanager.cpp26
-rw-r--r--src/nfc/neard/dbusobjectmanager_p.h58
-rw-r--r--src/nfc/neard/dbusproperties.cpp26
-rw-r--r--src/nfc/neard/dbusproperties_p.h71
-rw-r--r--src/nfc/neard/manager.cpp25
-rw-r--r--src/nfc/neard/manager_p.h91
-rw-r--r--src/nfc/neard/neard.pri22
-rw-r--r--src/nfc/neard/neard_dbus_types_p.h28
-rw-r--r--src/nfc/neard/neard_helper.cpp44
-rw-r--r--src/nfc/neard/neard_helper_p.h51
-rw-r--r--src/nfc/neard/org.freedesktop.dbus.objectmanager.xml2
-rw-r--r--src/nfc/neard/org.freedesktop.dbus.properties.xml2
-rw-r--r--src/nfc/neard/org.neard.Agent.xml26
-rw-r--r--src/nfc/neard/org.neard.Manager.xml38
-rw-r--r--src/nfc/neard/tag.cpp25
-rw-r--r--src/nfc/neard/tag_p.h60
-rw-r--r--src/nfc/nfc.pro134
-rw-r--r--src/nfc/pcsc/qpcsc.cpp32
-rw-r--r--src/nfc/pcsc/qpcsc_p.h72
-rw-r--r--src/nfc/pcsc/qpcsccard.cpp419
-rw-r--r--src/nfc/pcsc/qpcsccard_p.h96
-rw-r--r--src/nfc/pcsc/qpcscmanager.cpp357
-rw-r--r--src/nfc/pcsc/qpcscmanager_p.h65
-rw-r--r--src/nfc/pcsc/qpcscslot.cpp57
-rw-r--r--src/nfc/pcsc/qpcscslot_p.h46
-rw-r--r--src/nfc/qapduutils.cpp81
-rw-r--r--src/nfc/qapduutils_p.h53
-rw-r--r--src/nfc/qllcpserver.cpp200
-rw-r--r--src/nfc/qllcpserver_android_p.cpp131
-rw-r--r--src/nfc/qllcpserver_android_p.h93
-rw-r--r--src/nfc/qllcpserver_p.cpp94
-rw-r--r--src/nfc/qllcpserver_p.h94
-rw-r--r--src/nfc/qllcpserver_p_p.h87
-rw-r--r--src/nfc/qllcpsocket.cpp400
-rw-r--r--src/nfc/qllcpsocket_android_p.cpp324
-rw-r--r--src/nfc/qllcpsocket_android_p.h134
-rw-r--r--src/nfc/qllcpsocket_p.cpp192
-rw-r--r--src/nfc/qllcpsocket_p.h142
-rw-r--r--src/nfc/qllcpsocket_p_p.h106
-rw-r--r--src/nfc/qndeffilter.cpp404
-rw-r--r--src/nfc/qndeffilter.h58
-rw-r--r--src/nfc/qndefmessage.cpp170
-rw-r--r--src/nfc/qndefmessage.h75
-rw-r--r--src/nfc/qndefnfcsmartposterrecord.cpp233
-rw-r--r--src/nfc/qndefnfcsmartposterrecord.h54
-rw-r--r--src/nfc/qndefnfcsmartposterrecord_p.h54
-rw-r--r--src/nfc/qndefnfctextrecord.cpp67
-rw-r--r--src/nfc/qndefnfctextrecord.h40
-rw-r--r--src/nfc/qndefnfcurirecord.cpp46
-rw-r--r--src/nfc/qndefnfcurirecord.h40
-rw-r--r--src/nfc/qndefrecord.cpp74
-rw-r--r--src/nfc/qndefrecord.h44
-rw-r--r--src/nfc/qndefrecord_p.h40
-rw-r--r--src/nfc/qnearfieldmanager.cpp331
-rw-r--r--src/nfc/qnearfieldmanager.h76
-rw-r--r--src/nfc/qnearfieldmanager_android.cpp331
-rw-r--r--src/nfc/qnearfieldmanager_android_p.h99
-rw-r--r--src/nfc/qnearfieldmanager_emulator.cpp101
-rw-r--r--src/nfc/qnearfieldmanager_emulator_p.h89
-rw-r--r--src/nfc/qnearfieldmanager_generic.cpp24
-rw-r--r--src/nfc/qnearfieldmanager_generic_p.h31
-rw-r--r--src/nfc/qnearfieldmanager_ios.mm278
-rw-r--r--src/nfc/qnearfieldmanager_ios_p.h84
-rw-r--r--src/nfc/qnearfieldmanager_neard.cpp100
-rw-r--r--src/nfc/qnearfieldmanager_neard_p.h61
-rw-r--r--src/nfc/qnearfieldmanager_p.h86
-rw-r--r--src/nfc/qnearfieldmanager_pcsc.cpp140
-rw-r--r--src/nfc/qnearfieldmanager_pcsc_p.h55
-rw-r--r--src/nfc/qnearfieldmanagerimpl_p.cpp60
-rw-r--r--src/nfc/qnearfieldmanagerimpl_p.h67
-rw-r--r--src/nfc/qnearfieldmanagervirtualbase.cpp214
-rw-r--r--src/nfc/qnearfieldmanagervirtualbase_p.h99
-rw-r--r--src/nfc/qnearfieldsharemanager.cpp181
-rw-r--r--src/nfc/qnearfieldsharemanager.h104
-rw-r--r--src/nfc/qnearfieldsharemanager_p.h91
-rw-r--r--src/nfc/qnearfieldsharemanagerimpl_p.cpp58
-rw-r--r--src/nfc/qnearfieldsharemanagerimpl_p.h69
-rw-r--r--src/nfc/qnearfieldsharetarget.cpp148
-rw-r--r--src/nfc/qnearfieldsharetarget.h84
-rw-r--r--src/nfc/qnearfieldsharetarget_p.h108
-rw-r--r--src/nfc/qnearfieldsharetargetimpl_p.cpp53
-rw-r--r--src/nfc/qnearfieldsharetargetimpl_p.h68
-rw-r--r--src/nfc/qnearfieldtagtype1.cpp738
-rw-r--r--src/nfc/qnearfieldtagtype1_p.h108
-rw-r--r--src/nfc/qnearfieldtagtype2.cpp325
-rw-r--r--src/nfc/qnearfieldtagtype2_p.h94
-rw-r--r--src/nfc/qnearfieldtagtype3.cpp185
-rw-r--r--src/nfc/qnearfieldtagtype3_p.h86
-rw-r--r--src/nfc/qnearfieldtagtype4.cpp161
-rw-r--r--src/nfc/qnearfieldtagtype4_p.h82
-rw-r--r--src/nfc/qnearfieldtarget.cpp328
-rw-r--r--src/nfc/qnearfieldtarget.h103
-rw-r--r--src/nfc/qnearfieldtarget_android.cpp419
-rw-r--r--src/nfc/qnearfieldtarget_android_p.cpp71
-rw-r--r--src/nfc/qnearfieldtarget_android_p.h109
-rw-r--r--src/nfc/qnearfieldtarget_emulator.cpp297
-rw-r--r--src/nfc/qnearfieldtarget_emulator_p.h127
-rw-r--r--src/nfc/qnearfieldtarget_ios.mm467
-rw-r--r--src/nfc/qnearfieldtarget_ios_p.h119
-rw-r--r--src/nfc/qnearfieldtarget_neard_p.cpp361
-rw-r--r--src/nfc/qnearfieldtarget_neard_p.h386
-rw-r--r--src/nfc/qnearfieldtarget_p.cpp160
-rw-r--r--src/nfc/qnearfieldtarget_p.h96
-rw-r--r--src/nfc/qnearfieldtarget_pcsc.cpp161
-rw-r--r--src/nfc/qnearfieldtarget_pcsc_p.h67
-rw-r--r--src/nfc/qnfc.cpp47
-rw-r--r--src/nfc/qqmlndefrecord.cpp356
-rw-r--r--src/nfc/qqmlndefrecord.h112
-rw-r--r--src/nfc/qtlv.cpp532
-rw-r--r--src/nfc/qtlv_p.h133
-rw-r--r--src/nfc/qtnfcglobal.h55
-rw-r--r--src/nfc/qtnfcglobal_p.h40
-rw-r--r--src/nfc/targetemulator.cpp389
-rw-r--r--src/nfc/targetemulator_p.h121
151 files changed, 6320 insertions, 12322 deletions
diff --git a/src/nfc/ApiChangesQt6.txt b/src/nfc/ApiChangesQt6.txt
new file mode 100644
index 00000000..10a50014
--- /dev/null
+++ b/src/nfc/ApiChangesQt6.txt
@@ -0,0 +1,18 @@
+This document lists the API changed done to QtNFC between Qt 5.15 and Qt 6.
+
+- Removed function QNearFieldTarget::url(). No replacement available as the function was never implemented.
+- Removed function QNearFieldTarget::sendCommands(...). No replacement available as the function needs to be implemented by the API user.
+- Renamed function QNearFieldManager::isAvailable() to QNearFieldManager::isEnabled().
+- Removed functions QNearFieldTarget::keepConnection() and QNearFieldTarget::setKeepConnection(...). Keeping the connection is the default behavior now.
+- Removed QML API. No replacement available because the support has been discontinued.
+- Removed functions QNearFieldTarget::(un)registerNdefMessageHandler(...). No replacement available.
+- Removed QNearFieldShareManager/QNearFieldShareTarget. No replacement available.
+- Removed function QNearFieldTarget::isProcessingCommand(). No replacement available as the function is not implemented.
+- Removed functions setResponseForRequest, handleResponse and reportError from QNearFieldTarget. No replacement available as this is for internal use only.
+- Added NfcTagType4A and NfcTagType4B to QNearFieldTarget::Type.
+- Changed the type of typeInfo in QNdefNfcSmartPosterRecord from QByteArray to QString.
+- Removed TargetAccessModes, setTargetAccessModes and targetAccessModes from QNearFieldManager. No replacement available.
+- Removed ndefMessagesWritten signal. A requestCompleted signal is used instead.
+- Added QNdefRecord::clear() method.
+- QNdefFilter::appendRecord now returns bool to indicate if the record is added or not.
+- Added QNdefFilter::match() to check if a message matches the filter.
diff --git a/src/nfc/CMakeLists.txt b/src/nfc/CMakeLists.txt
new file mode 100644
index 00000000..de2b927f
--- /dev/null
+++ b/src/nfc/CMakeLists.txt
@@ -0,0 +1,125 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## Nfc Module:
+#####################################################################
+
+qt_internal_add_module(Nfc
+ SOURCES
+ qndeffilter.cpp qndeffilter.h
+ qndefmessage.cpp qndefmessage.h
+ qndefnfcsmartposterrecord.cpp qndefnfcsmartposterrecord.h qndefnfcsmartposterrecord_p.h
+ qndefnfctextrecord.cpp qndefnfctextrecord.h
+ qndefnfcurirecord.cpp qndefnfcurirecord.h
+ qndefrecord.cpp qndefrecord.h qndefrecord_p.h
+ qnearfieldmanager.cpp qnearfieldmanager.h qnearfieldmanager_p.h
+ qnearfieldtarget.cpp qnearfieldtarget.h qnearfieldtarget_p.cpp qnearfieldtarget_p.h
+ qtnfcglobal.h qtnfcglobal_p.h
+ DEFINES
+ QT_NO_CONTEXTLESS_CONNECT
+ PUBLIC_LIBRARIES
+ Qt::Core
+ GENERATE_CPP_EXPORTS
+)
+
+## Scopes:
+#####################################################################
+
+if(ANDROID AND (ANDROID AND NOT ANDROID_EMBEDDED))
+ set_property(TARGET Nfc APPEND PROPERTY QT_ANDROID_BUNDLED_JAR_DEPENDENCIES
+ jar/Qt${QtConnectivity_VERSION_MAJOR}AndroidNfc.jar:org.qtproject.qt.android.nfc.QtNfc
+ )
+ set_property(TARGET Nfc APPEND PROPERTY QT_ANDROID_PERMISSIONS
+ android.permission.NFC
+ )
+ set(NFC_BACKEND_AVAILABLE ON)
+endif()
+
+qt_internal_extend_target(Nfc CONDITION ANDROID AND NOT ANDROID_EMBEDDED
+ SOURCES
+ android/androidjninfc.cpp android/androidjninfc_p.h
+ android/androidmainnewintentlistener.cpp android/androidmainnewintentlistener_p.h
+ qnearfieldmanager_android.cpp qnearfieldmanager_android_p.h
+ qnearfieldtarget_android.cpp qnearfieldtarget_android_p.h
+ DEFINES
+ ANDROID_NFC
+ QT_ANDROID_NFC
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+)
+
+if(IOS)
+ # special case begin
+ set(NFC_BACKEND_AVAILABLE ON)
+ qt_disable_apple_app_extension_api_only(Nfc)
+ qt_internal_find_apple_system_framework(FWCoreNFC CoreNFC)
+ # special case end
+endif()
+
+qt_internal_extend_target(Nfc CONDITION IOS
+ SOURCES
+ ios/qiostagreaderdelegate.mm ios/qiostagreaderdelegate_p.h
+ ios/qiosnfcndefsessiondelegate.mm ios/qiosnfcndefsessiondelegate_p.h
+ ios/qiosndefnotifier.cpp ios/qiosndefnotifier_p.h
+ qnearfieldmanager_ios.mm qnearfieldmanager_ios_p.h
+ qnearfieldtarget_ios.mm qnearfieldtarget_ios_p.h
+ DEFINES
+ IOS_NFC
+ LIBRARIES
+ ${FWCoreNFC}
+ Qt::CorePrivate
+)
+
+if(QT_FEATURE_pcsclite)
+ set(NFC_BACKEND_AVAILABLE ON)
+endif()
+
+qt_internal_extend_target(Nfc CONDITION QT_FEATURE_pcsclite
+ SOURCES
+ qnearfieldmanager_pcsc.cpp qnearfieldmanager_pcsc_p.h
+ qnearfieldtarget_pcsc.cpp qnearfieldtarget_pcsc_p.h
+ qapduutils.cpp qapduutils_p.h
+ pcsc/qpcsc.cpp pcsc/qpcsc_p.h
+ pcsc/qpcscmanager.cpp pcsc/qpcscmanager_p.h
+ pcsc/qpcscslot.cpp pcsc/qpcscslot_p.h
+ pcsc/qpcsccard.cpp pcsc/qpcsccard_p.h
+ ndef/qndefaccessfsm_p.h
+ ndef/qnfctagtype4ndeffsm.cpp ndef/qnfctagtype4ndeffsm_p.h
+ DEFINES
+ PCSC_NFC
+ LIBRARIES
+ PkgConfig::PCSCLITE
+)
+
+if(QT_FEATURE_neard)
+ set(NFC_BACKEND_AVAILABLE ON)
+endif()
+
+qt_internal_extend_target(Nfc CONDITION QT_FEATURE_neard
+ SOURCES
+ qnearfieldmanager_neard.cpp qnearfieldmanager_neard_p.h
+ qnearfieldtarget_neard_p.cpp qnearfieldtarget_neard_p.h
+ neard/neard_helper.cpp neard/neard_helper_p.h
+ neard/neard_dbus_types_p.h
+ DBUS_INTERFACE_SOURCES
+ neard/org.freedesktop.dbus.objectmanager.xml
+ neard/org.freedesktop.dbus.properties.xml
+ neard/org.neard.Adapter.xml
+ neard/org.neard.Tag.xml
+ DBUS_INTERFACE_FLAGS
+ -i neard/neard_dbus_types_p.h
+ DEFINES
+ NEARD_NFC
+ LIBRARIES
+ Qt::DBus
+)
+
+qt_internal_extend_target(Nfc CONDITION NOT NFC_BACKEND_AVAILABLE
+ SOURCES
+ qnearfieldmanager_generic.cpp qnearfieldmanager_generic_p.h
+)
+qt_internal_add_docs(Nfc
+ doc/qtnfc.qdocconf
+)
diff --git a/src/nfc/android/androidjninfc.cpp b/src/nfc/android/androidjninfc.cpp
index 9a1c5227..3f226985 100644
--- a/src/nfc/android/androidjninfc.cpp
+++ b/src/nfc/android/androidjninfc.cpp
@@ -1,102 +1,52 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Centria research and development
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "androidjninfc_p.h"
-#include <android/log.h>
+QT_BEGIN_NAMESPACE
-#include "androidmainnewintentlistener_p.h"
-
-#include "qglobal.h"
-#include "qbytearray.h"
-#include "qdebug.h"
-
-static const char *nfcClassName = "org/qtproject/qt5/android/nfc/QtNfc";
-
-static AndroidNfc::MainNfcNewIntentListener mainListener;
-
-QT_BEGIN_ANDROIDNFC_NAMESPACE
+namespace QtNfc {
bool startDiscovery()
{
- return QAndroidJniObject::callStaticMethod<jboolean>(nfcClassName,"start");
+ return QJniObject::callStaticMethod<jboolean>(
+ QtJniTypes::Traits<QtJniTypes::QtNfc>::className(), "startDiscovery");
}
-bool isAvailable()
+bool isEnabled()
{
- return QAndroidJniObject::callStaticMethod<jboolean>(nfcClassName,"isAvailable");
+ return QJniObject::callStaticMethod<jboolean>(
+ QtJniTypes::Traits<QtJniTypes::QtNfc>::className(), "isEnabled");
}
bool isSupported()
{
- return QAndroidJniObject::callStaticMethod<jboolean>(nfcClassName,"isSupported");
+ return QJniObject::callStaticMethod<jboolean>(
+ QtJniTypes::Traits<QtJniTypes::QtNfc>::className(), "isSupported");
}
bool stopDiscovery()
{
- return QAndroidJniObject::callStaticMethod<jboolean>(nfcClassName,"stop");
+ return QJniObject::callStaticMethod<jboolean>(
+ QtJniTypes::Traits<QtJniTypes::QtNfc>::className(), "stopDiscovery");
}
-QAndroidJniObject getStartIntent()
+QJniObject getStartIntent()
{
- QAndroidJniObject ret = QAndroidJniObject::callStaticObjectMethod(nfcClassName, "getStartIntent", "()Landroid/content/Intent;");
- return ret;
+ return QJniObject::callStaticMethod<QtJniTypes::Intent>(
+ QtJniTypes::Traits<QtJniTypes::QtNfc>::className(), "getStartIntent");
}
-bool registerListener(AndroidNfcListenerInterface *listener)
+QJniObject getTag(const QJniObject &intent)
{
- return mainListener.registerListener(listener);
+ return QJniObject::callStaticMethod<QtJniTypes::Parcellable>(
+ QtJniTypes::Traits<QtJniTypes::QtNfc>::className(), "getTag",
+ intent.object<QtJniTypes::Intent>());
}
-bool unregisterListener(AndroidNfcListenerInterface *listener)
-{
- return mainListener.unregisterListener(listener);
-}
-
-QAndroidJniObject getTag(const QAndroidJniObject &intent)
-{
- QAndroidJniObject extraTag = QAndroidJniObject::getStaticObjectField("android/nfc/NfcAdapter", "EXTRA_TAG", "Ljava/lang/String;");
- QAndroidJniObject tag = intent.callObjectMethod("getParcelableExtra", "(Ljava/lang/String;)Landroid/os/Parcelable;", extraTag.object<jstring>());
- return tag;
-}
+} // namespace QtNfc
-QT_END_ANDROIDNFC_NAMESPACE
+QT_END_NAMESPACE
Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
{
diff --git a/src/nfc/android/androidjninfc_p.h b/src/nfc/android/androidjninfc_p.h
index 60e9a107..476e0519 100644
--- a/src/nfc/android/androidjninfc_p.h
+++ b/src/nfc/android/androidjninfc_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Centria research and development
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef ANDROIDJNINFC_H
#define ANDROIDJNINFC_H
@@ -52,30 +16,29 @@
#include "qglobal.h"
-#include <QtAndroidExtras/QAndroidJniObject>
+#include <QtCore/QJniObject>
+#include <QtCore/qjnitypes.h>
-#define QT_USE_ANDROIDNFC_NAMESPACE using namespace ::AndroidNfc;
-#define QT_BEGIN_ANDROIDNFC_NAMESPACE namespace AndroidNfc {
-#define QT_END_ANDROIDNFC_NAMESPACE }
+QT_BEGIN_NAMESPACE
-QT_BEGIN_ANDROIDNFC_NAMESPACE
+Q_DECLARE_JNI_CLASS(QtNfc, "org/qtproject/qt/android/nfc/QtNfc")
+Q_DECLARE_JNI_CLASS(QtNfcBroadcastReceiver, "org/qtproject/qt/android/nfc/QtNfcBroadcastReceiver")
-class AndroidNfcListenerInterface
-{
-public:
- virtual ~AndroidNfcListenerInterface(){}
- virtual void newIntent(QAndroidJniObject intent) = 0;
-};
+Q_DECLARE_JNI_TYPE(StringArray, "[Ljava/lang/String;")
+Q_DECLARE_JNI_CLASS(Intent, "android/content/Intent")
+Q_DECLARE_JNI_CLASS(Parcellable, "android/os/Parcelable")
+Q_DECLARE_JNI_CLASS(NdefMessage, "android/nfc/NdefMessage")
+
+namespace QtNfc {
bool startDiscovery();
bool stopDiscovery();
-QAndroidJniObject getStartIntent();
-bool isAvailable();
+QJniObject getStartIntent();
+bool isEnabled();
bool isSupported();
-bool registerListener(AndroidNfcListenerInterface *listener);
-bool unregisterListener(AndroidNfcListenerInterface *listener);
-QAndroidJniObject getTag(const QAndroidJniObject &intent);
+QJniObject getTag(const QJniObject &intent);
+} // namespace QtNfc
-QT_END_ANDROIDNFC_NAMESPACE
+QT_END_NAMESPACE
#endif
diff --git a/src/nfc/android/androidmainnewintentlistener.cpp b/src/nfc/android/androidmainnewintentlistener.cpp
index 2076453d..cebf92da 100644
--- a/src/nfc/android/androidmainnewintentlistener.cpp
+++ b/src/nfc/android/androidmainnewintentlistener.cpp
@@ -1,78 +1,45 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 BasysKom GmbH
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 BasysKom GmbH
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "androidmainnewintentlistener_p.h"
-#include "qdebug.h"
+#include "android/androidjninfc_p.h"
#include <QtGui/QGuiApplication>
-#include <QtAndroidExtras/QAndroidJniObject>
+#include <QtCore/QJniObject>
-QT_BEGIN_ANDROIDNFC_NAMESPACE
+QT_BEGIN_NAMESPACE
-MainNfcNewIntentListener::MainNfcNewIntentListener()
- : listeners(), listenersLock(), paused(true), receiving(false)
+QMainNfcNewIntentListener::QMainNfcNewIntentListener() : paused(true), receiving(false)
{
QtAndroidPrivate::registerNewIntentListener(this);
QtAndroidPrivate::registerResumePauseListener(this);
}
-MainNfcNewIntentListener::~MainNfcNewIntentListener()
+QMainNfcNewIntentListener::~QMainNfcNewIntentListener()
{
QtAndroidPrivate::unregisterNewIntentListener(this);
QtAndroidPrivate::unregisterResumePauseListener(this);
}
-bool MainNfcNewIntentListener::handleNewIntent(JNIEnv */*env*/, jobject intent)
+bool QMainNfcNewIntentListener::handleNewIntent(JNIEnv * /*env*/, jobject intent)
{
+ // Only intents with a tag are relevant
+ if (!QtNfc::getTag(intent).isValid())
+ return false;
+
listenersLock.lockForRead();
- for (AndroidNfc::AndroidNfcListenerInterface *listener : qAsConst(listeners)) {
- listener->newIntent(QAndroidJniObject(intent));
+ for (auto listener : std::as_const(listeners)) {
+ listener->newIntent(QJniObject(intent));
}
listenersLock.unlock();
return true;
}
-bool MainNfcNewIntentListener::registerListener(AndroidNfcListenerInterface *listener)
+bool QMainNfcNewIntentListener::registerListener(QAndroidNfcListenerInterface *listener)
{
static bool firstListener = true;
if (firstListener) {
- QAndroidJniObject intent = AndroidNfc::getStartIntent();
+ QJniObject intent = QtNfc::getStartIntent();
if (intent.isValid()) {
listener->newIntent(intent);
}
@@ -87,7 +54,7 @@ bool MainNfcNewIntentListener::registerListener(AndroidNfcListenerInterface *lis
return true;
}
-bool MainNfcNewIntentListener::unregisterListener(AndroidNfcListenerInterface *listener)
+bool QMainNfcNewIntentListener::unregisterListener(QAndroidNfcListenerInterface *listener)
{
listenersLock.lockForWrite();
listeners.removeOne(listener);
@@ -96,24 +63,24 @@ bool MainNfcNewIntentListener::unregisterListener(AndroidNfcListenerInterface *l
return true;
}
-void MainNfcNewIntentListener::handleResume()
+void QMainNfcNewIntentListener::handleResume()
{
paused = false;
updateReceiveState();
}
-void MainNfcNewIntentListener::handlePause()
+void QMainNfcNewIntentListener::handlePause()
{
paused = true;
updateReceiveState();
}
-void MainNfcNewIntentListener::updateReceiveState()
+void QMainNfcNewIntentListener::updateReceiveState()
{
if (paused) {
// We were paused while receiving, so we stop receiving.
if (receiving) {
- AndroidNfc::stopDiscovery();
+ QtNfc::stopDiscovery();
receiving = false;
}
return;
@@ -122,15 +89,15 @@ void MainNfcNewIntentListener::updateReceiveState()
// We reach here, so we are not paused.
listenersLock.lockForRead();
// We have nfc listeners and do not receive. Switch on.
- if (listeners.count() && !receiving)
- receiving = AndroidNfc::startDiscovery();
+ if (!listeners.isEmpty() && !receiving)
+ receiving = QtNfc::startDiscovery();
// we have no nfc listeners and do receive. Switch off.
- if (!listeners.count() && receiving) {
- AndroidNfc::stopDiscovery();
+ if (listeners.isEmpty() && receiving) {
+ QtNfc::stopDiscovery();
receiving = false;
}
listenersLock.unlock();
}
-QT_END_ANDROIDNFC_NAMESPACE
+QT_END_NAMESPACE
diff --git a/src/nfc/android/androidmainnewintentlistener_p.h b/src/nfc/android/androidmainnewintentlistener_p.h
index acdd01ac..eb3c5217 100644
--- a/src/nfc/android/androidmainnewintentlistener_p.h
+++ b/src/nfc/android/androidmainnewintentlistener_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 BasysKom GmbH
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 BasysKom GmbH
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef ANDROIDMAINNEWINTENTLISTENER_P_H_
#define ANDROIDMAINNEWINTENTLISTENER_P_H_
@@ -55,21 +19,30 @@
#include "qlist.h"
#include "qreadwritelock.h"
-#include "androidjninfc_p.h"
-QT_BEGIN_ANDROIDNFC_NAMESPACE
+QT_BEGIN_NAMESPACE
-class MainNfcNewIntentListener : public QtAndroidPrivate::NewIntentListener, QtAndroidPrivate::ResumePauseListener
+class QJniObject;
+
+class QAndroidNfcListenerInterface
+{
+public:
+ virtual ~QAndroidNfcListenerInterface() = default;
+ virtual void newIntent(QJniObject intent) = 0;
+};
+
+class QMainNfcNewIntentListener : public QtAndroidPrivate::NewIntentListener,
+ QtAndroidPrivate::ResumePauseListener
{
public:
- MainNfcNewIntentListener();
- ~MainNfcNewIntentListener();
+ QMainNfcNewIntentListener();
+ ~QMainNfcNewIntentListener();
//QtAndroidPrivate::NewIntentListener
bool handleNewIntent(JNIEnv *env, jobject intent);
- bool registerListener(AndroidNfcListenerInterface *listener);
- bool unregisterListener(AndroidNfcListenerInterface *listener);
+ bool registerListener(QAndroidNfcListenerInterface *listener);
+ bool unregisterListener(QAndroidNfcListenerInterface *listener);
//QtAndroidPrivate::ResumePauseListener
void handleResume();
@@ -77,13 +50,13 @@ public:
private:
void updateReceiveState();
-protected:
- QList<AndroidNfc::AndroidNfcListenerInterface*> listeners;
+
+ QList<QAndroidNfcListenerInterface *> listeners;
QReadWriteLock listenersLock;
bool paused;
bool receiving;
};
-QT_END_ANDROIDNFC_NAMESPACE
+QT_END_NAMESPACE
#endif /* ANDROIDMAINNEWINTENTLISTENER_P_H_ */
diff --git a/src/nfc/configure.cmake b/src/nfc/configure.cmake
new file mode 100644
index 00000000..08448333
--- /dev/null
+++ b/src/nfc/configure.cmake
@@ -0,0 +1,12 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_find_package(PCSCLITE PROVIDED_TARGETS PkgConfig::PCSCLITE)
+
+qt_feature("pcsclite" PUBLIC
+ LABEL "Use the PCSCLite library to access NFC devices"
+ CONDITION PCSCLITE_FOUND)
+
+qt_feature("neard" PUBLIC
+ LABEL "Use neard to access NFC devices"
+ CONDITION LINUX AND NOT QT_FEATURE_pcsclite)
diff --git a/src/nfc/doc/qtnfc.qdocconf b/src/nfc/doc/qtnfc.qdocconf
index e4f10f0e..10aede7f 100644
--- a/src/nfc/doc/qtnfc.qdocconf
+++ b/src/nfc/doc/qtnfc.qdocconf
@@ -15,18 +15,11 @@ qhp.QtNfc.virtualFolder = qtnfc
qhp.QtNfc.indexTitle = Qt NFC
qhp.QtNfc.indexRoot =
-qhp.QtNfc.filterAttributes = qtnfc $QT_VERSION qtrefdoc
-qhp.QtNfc.customFilters.Qt.name = QtNfc $QT_VERSION
-qhp.QtNfc.customFilters.Qt.filterAttributes = qtnfc $QT_VERSION
-qhp.QtNfc.subprojects = overviews classes qml examples
+qhp.QtNfc.subprojects = overviews classes examples
qhp.QtNfc.subprojects.classes.title = C++ Classes
qhp.QtNfc.subprojects.classes.indexTitle = Qt NFC C++ Classes
qhp.QtNfc.subprojects.classes.selectors = class fake:headerfile
qhp.QtNfc.subprojects.classes.sortPages = true
-qhp.QtNfc.subprojects.qml.title = QML Types
-qhp.QtNfc.subprojects.qml.indexTitle = Qt NFC QML Types
-qhp.QtNfc.subprojects.qml.selectors = fake:headerfile
-qhp.QtNfc.subprojects.qml.sortPages = true
qhp.QtNfc.subprojects.overviews.title = Overviews
qhp.QtNfc.subprojects.overviews.indexTitle = Qt NFC Overview
qhp.QtNfc.subprojects.overviews.selectors = fake:page,group,module
@@ -36,20 +29,22 @@ qhp.QtNfc.subprojects.examples.selectors = fake:example
tagfile = ../../../doc/qtnfc/qtnfc.tags
-depends += qtcore qtdoc
+depends += qtcore qtwidgets qtdoc qmake qtcmake
-headerdirs += .. \
- ../../imports/nfc
+headerdirs += ..
-sourcedirs += .. \
- ../../imports/nfc \
+sourcedirs += ..
exampledirs += ../../../examples/nfc \
snippets/
-
imagedirs += images
+manifestmeta.highlighted.names = \
+ "QtNfc/Annotated URL"
+
navigation.landingpage = "Qt NFC"
navigation.cppclassespage = "Qt NFC C++ Classes"
-navigation.qmltypespage = "Qt NFC QML Types"
+
+# Enforce zero documentation warnings
+warninglimit = 0
diff --git a/src/nfc/doc/snippets/doc_src_qtnfc.cpp b/src/nfc/doc/snippets/doc_src_qtnfc.cpp
deleted file mode 100644
index 760d65fd..00000000
--- a/src/nfc/doc/snippets/doc_src_qtnfc.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/QObject>
-//! [include]
-#include <QtNfc/QNearFieldManager>
-//! [include]
-#include <QtNfc/QNdefMessage>
-
-//! [namespace]
-QT_USE_NAMESPACE
-//! [namespace]
-
-class MyClass : public QObject
-{
- Q_OBJECT
-public:
- MyClass() : QObject()
- {
-//formatting adjusted to improve usage in docs
-//! [handleNdefMessage]
-QNearFieldManager *manager = new QNearFieldManager(this);
-manager->registerNdefMessageHandler(this,
- SLOT(handleNdefMessage(QNdefMessage,QNearFieldTarget*)));
-//! [handleNdefMessage]
- }
-
-public Q_SLOTS:
- void handleNdefMessage(QNdefMessage,QNearFieldTarget*)
- {
- }
-};
-
-#include "doc_src_qtnfc.moc"
-
diff --git a/src/nfc/doc/snippets/doc_src_qtnfc.qml b/src/nfc/doc/snippets/doc_src_qtnfc.qml
deleted file mode 100644
index e7a45e89..00000000
--- a/src/nfc/doc/snippets/doc_src_qtnfc.qml
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [import]
-import QtNfc 5.12
-//! [import]
-
-Item {
-//! [QML register for messages]
- NearField {
- filter: [ NdefFilter { type: "U"; typeNameFormat: NdefRecord.NfcRtd; minimum: 1; maximum: 1 } ]
- orderMatch: false
-
- onMessageRecordsChanged: displayMessage()
- }
-//! [QML register for messages]
-}
diff --git a/src/nfc/doc/snippets/foorecord.cpp b/src/nfc/doc/snippets/foorecord.cpp
deleted file mode 100644
index 4fecd712..00000000
--- a/src/nfc/doc/snippets/foorecord.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "foorecord.h"
-#include <qndefrecord.h>
-
-//! [Declare foo record]
-Q_DECLARE_NDEFRECORD(QQmlNdefFooRecord, QNdefRecord::ExternalRtd, "com.example:f")
-//! [Declare foo record]
-
-//! [createFooRecord]
-static inline QNdefRecord createFooRecord()
-{
- QNdefRecord foo;
- foo.setTypeNameFormat(QNdefRecord::ExternalRtd);
- foo.setType("com.example:f");
- foo.setPayload(QByteArray(sizeof(int), char(0)));
- return foo;
-}
-//! [createFooRecord]
-
-//! [copyFooRecord]
-static inline QNdefRecord copyFooRecord(const QNdefRecord &record)
-{
- if (record.typeNameFormat() != QNdefRecord::ExternalRtd)
- return createFooRecord();
- if (record.type() != "com.example:f")
- return createFooRecord();
-
- return record;
-}
-//! [copyFooRecord]
-
-//! [Constructors]
-QQmlNdefFooRecord::QQmlNdefFooRecord(QObject *parent)
-: QQmlNdefRecord(createFooRecord(), parent)
-{
-}
-
-QQmlNdefFooRecord::QQmlNdefFooRecord(const QNdefRecord &record, QObject *parent)
-: QQmlNdefRecord(copyFooRecord(record), parent)
-{
-}
-//! [Constructors]
-
-QQmlNdefFooRecord::~QQmlNdefFooRecord()
-{
-}
-
-int QQmlNdefFooRecord::foo() const
-{
- QByteArray payload = record().payload();
-
- int value = payload.at(0) << 24 |
- payload.at(1) << 16 |
- payload.at(2) << 8 |
- payload.at(3) << 0;
-
- return value;
-}
-
-void QQmlNdefFooRecord::setFoo(int value)
-{
- if (foo() == value)
- return;
-
- QByteArray payload;
- payload[0] = (value >> 24) & 0xff;
- payload[1] = (value >> 16) & 0xff;
- payload[2] = (value >> 8) & 0xff;
- payload[3] = (value >> 0) & 0xff;
-
- QNdefRecord r = record();
- r.setPayload(payload);
- setRecord(r);
- emit fooChanged();
-}
diff --git a/src/nfc/doc/snippets/foorecord.h b/src/nfc/doc/snippets/foorecord.h
deleted file mode 100644
index c2501287..00000000
--- a/src/nfc/doc/snippets/foorecord.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef FOORECORD_H
-#define FOORECORD_H
-
-#include <qqmlndefrecord.h>
-
-QT_USE_NAMESPACE
-
-//! [Foo declaration]
-class QQmlNdefFooRecord : public QQmlNdefRecord
-{
- Q_OBJECT
-
- Q_PROPERTY(int foo READ foo WRITE setFoo NOTIFY fooChanged)
-
-public:
- explicit QQmlNdefFooRecord(QObject *parent = 0);
- Q_INVOKABLE QQmlNdefFooRecord(const QNdefRecord &record, QObject *parent = 0);
- ~QQmlNdefFooRecord();
-
- int foo() const;
- void setFoo(int value);
-
-signals:
- void fooChanged();
-};
-//! [Foo declaration]
-
-#endif // FOORECORD_H
diff --git a/src/nfc/doc/snippets/main.cpp b/src/nfc/doc/snippets/main.cpp
index 6f2bb0d7..fb6724d5 100644
--- a/src/nfc/doc/snippets/main.cpp
+++ b/src/nfc/doc/snippets/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
int main(int /*argc*/, char ** /*argv*/)
{
diff --git a/src/nfc/doc/snippets/nfc.cpp b/src/nfc/doc/snippets/nfc.cpp
index 82297682..a1192bec 100644
--- a/src/nfc/doc/snippets/nfc.cpp
+++ b/src/nfc/doc/snippets/nfc.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtNfc/qndefrecord.h>
#include <QtNfc/qndefnfctextrecord.h>
diff --git a/src/nfc/doc/snippets/snippets.pro b/src/nfc/doc/snippets/snippets.pro
deleted file mode 100644
index 437782e4..00000000
--- a/src/nfc/doc/snippets/snippets.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-TEMPLATE = app
-TARGET = nfc_cppsnippet
-QT = core
-#! [project modification]
-QT += nfc
-#! [project modification]
-
-SOURCES += main.cpp \
- doc_src_qtnfc.cpp \
- nfc.cpp \
- foorecord.cpp
-
-HEADERS += foorecord.h
diff --git a/src/nfc/doc/src/examples.qdoc b/src/nfc/doc/src/examples.qdoc
index 1eb410e3..a126763e 100644
--- a/src/nfc/doc/src/examples.qdoc
+++ b/src/nfc/doc/src/examples.qdoc
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\ingroup all-examples
\page nfc-examples.html
\title Qt NFC Examples
\brief Examples for the Qt NFC module.
@@ -46,18 +21,5 @@ in their own documentation, but they are also accessible from here.
\li \l{ndefeditor}{NDEF Editor}
\li Create new or modify existing NDEF messages on NFC Forum Tags.
\endtable
-
-\section2 QML Examples
-\table 80%
- \header
- \li Example
- \li Description
- \row
- \li \l{corkboard} {CorkBoard}
- \li Displays NDEF text tags on a corkboard.
- \row
- \li \l{poster}{QML Poster}
- \li Displays URLs stored on NFC Forum Tags.
-\endtable
*/
diff --git a/src/nfc/doc/src/nfc-android.qdoc b/src/nfc/doc/src/nfc-android.qdoc
index d28f78ee..e2ca5401 100644
--- a/src/nfc/doc/src/nfc-android.qdoc
+++ b/src/nfc/doc/src/nfc-android.qdoc
@@ -1,29 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 BasysKom GmbH
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2015 BasysKom GmbH
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\ingroup connectivity-nfc
@@ -33,13 +10,18 @@
\title Qt NFC on Android
\brief Notes on Nfc for Android.
-\section1 Automatically launching NDEF message handlers on Android
-Android, the registration of NDEF message handlers is done via the
-\l{http://developer.android.com/guide/topics/manifest/manifest-intro.html}{Android manifest file}.
-This means the application has to provide an AndroidManifest.xml file with proper
-\l{http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#manifest}{NFC intent-filter.}
+\section1 Automatically Launching NDEF Message Handlers on Android
-\code
+Android provides the possibility to automatically launch the application when
+touching the NDEF tag.
+
+This can be achieved by providing an
+\l {https://developer.android.com/guide/topics/manifest/manifest-intro.html}
+{Android manifest file} (AndroidManifest.xml) with proper
+\l{https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#manifest}
+{NFC intent-filter}.
+
+\badcode
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
@@ -47,23 +29,36 @@ This means the application has to provide an AndroidManifest.xml file with prope
</intent-filter>
\endcode
-When the application is started it has to register an message handler with
-\l {QNearFieldManager::}{registerNdefMessageHandler()}
-The first NDEF message arriving in the handler is the message that started the application.
-See the \l {corkboard}{CorkBoard} application for an example.
+With this intent-filter enabled, the application will be automatically started
+once the NDEF NFC tag is touched.
+
+\note It's important to design your application in such a way that all the GUI
+is connected to the NFC classes before the target detection is actually started.
+Otherwise it will be impossible to show the information from the tag that caused
+application startup.
+
+\note It's important to touch the tag long enough for the application to start
+and read the information. If the tag is lost during application startup, no data
+will be available, and the tag needs to be touched again.
+
+See \l {annotatedurl}{Annotated URL} application as an example.
+
+\section2 Supported Tag Types
-\section2 Note:
Supported tag types in Android are
-\l{http://developer.android.com/reference/android/nfc/NfcAdapter.html#ACTION_NDEF_DISCOVERED}{NDEF_DISCOVERED}
-and
-\l{http://developer.android.com/reference/android/nfc/NfcAdapter.html#ACTION_TECH_DISCOVERED}{ACTION_TAG_DISCOVERED}
-with
-\l{http://developer.android.com/reference/android/nfc/tech/TagTechnology.html}{TagTechnology}
-NdefFormatable or Ndef.
-If the application register other types in the
-\l{http://developer.android.com/guide/topics/manifest/manifest-intro.html}{Android manifest file}
-the application will be started, but the tag will never get delivered to the handler.
-The handler should be registered as early as possible. If the application has not registered a handler, the application
-will be started every time a new tag is in range and the Android device end up running multiple instances of the application.
+\l {https://developer.android.com/reference/android/nfc/NfcAdapter.html#ACTION_NDEF_DISCOVERED}
+{ACTION_NDEF_DISCOVERED},
+\l {https://developer.android.com/reference/android/nfc/NfcAdapter.html#ACTION_TAG_DISCOVERED}
+{ACTION_TAG_DISCOVERED} and
+\l {https://developer.android.com/reference/android/nfc/NfcAdapter.html#ACTION_TECH_DISCOVERED}
+{ACTION_TECH_DISCOVERED} with
+\l {https://developer.android.com/reference/android/nfc/tech/TagTechnology.html}
+{TagTechnology} \e NdefFormatable or \e Ndef.
+
+If the application registers other types in the
+\l {https://developer.android.com/guide/topics/manifest/manifest-intro.html}
+{Android manifest file}, the application will be started, but the tag will never
+be processed.
+
*/
diff --git a/src/nfc/doc/src/nfc-cpp.qdoc b/src/nfc/doc/src/nfc-cpp.qdoc
index 00fb8aa5..0fef1d6b 100644
--- a/src/nfc/doc/src/nfc-cpp.qdoc
+++ b/src/nfc/doc/src/nfc-cpp.qdoc
@@ -1,33 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\module QtNfc
\ingroup modules
+\qtcmakepackage Nfc
\qtvariable nfc
\title Qt NFC C++ Classes
@@ -35,9 +13,18 @@
The \l{Qt NFC} C++ API enables an application to access NFC Forum Tags.
-To use the C++ library in your application, add the following configuration
-option to your \c .pro file:
+\include module-use.qdocinc using qt module
+
+\badcode
+find_package(Qt6 REQUIRED COMPONENTS Nfc)
+target_link_libraries(mytarget PRIVATE Qt::Nfc)
+\endcode
+
+\include module-use.qdocinc building with qmake
+
+\badcode
+QT += nfc
+\endcode
-\snippet snippets.pro project modification
*/
diff --git a/src/nfc/doc/src/nfc-features.qdoc b/src/nfc/doc/src/nfc-features.qdoc
new file mode 100644
index 00000000..65c31f04
--- /dev/null
+++ b/src/nfc/doc/src/nfc-features.qdoc
@@ -0,0 +1,64 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page qtnfc-features.html
+\title Supported NFC Features
+\ingroup connectivity-nfc
+\inmodule QtNfc
+\brief Summary of supported NFC features on different platforms.
+
+Qt NFC provides two options for reading and writing the data. These options are
+reflected in the \l {QNearFieldTarget::}{AccessMethod} enum.
+
+\list
+ \li \l {QNearFieldTarget::}{NdefAccess} - using NDEF messages via
+ \l {QNearFieldTarget::}{readNdefMessages()} and
+ \l {QNearFieldTarget::}{writeNdefMessages()}.
+ \li \l {QNearFieldTarget::}{TagTypeSpecificAccess} - sending custom commands
+ using \l {QNearFieldTarget::}{sendCommand()} and getting the results via
+ \l {QNearFieldTarget::}{requestResponse()}.
+\endlist
+
+\l {QNearFieldTarget::}{TagTypeSpecificAccess} implies that the
+user might need to send different data based on the NFC Tag Type. Tag types
+recognized by Qt NFC are defined in the \l {QNearFieldTarget::}{Type} enum.
+
+Qt NFC support for different access methods and tag types varies depending on
+the platform. The table below shows currently supported subsets of features
+for every platform.
+
+\table
+ \header
+ \li Platform
+ \li Recognized Tag Types
+ \li NDEF Support
+ \li Tag Specific Access
+ \row
+ \li \l {Qt NFC on Android}{Android}
+ \li All from the \l {QNearFieldTarget::}{Type} enum
+ \li Yes
+ \li Yes
+ \row
+ \li iOS
+ \li \list
+ \li \l {QNearFieldTarget::}{NfcTagType4}
+ \li \l {QNearFieldTarget::}{NfcTagType4A}
+ \li \l {QNearFieldTarget::}{NfcTagType4B}
+ \li \l {QNearFieldTarget::}{ProprietaryTag}
+ \endlist
+ \li No
+ \li Yes - for supported tag types
+ \row
+ \li Linux, Windows, macOS
+
+ (implemented using \l {PC/SC in Qt NFC}{PC/SC})
+ \li \list
+ \li \l {QNearFieldTarget::}{NfcTagType4}
+ \li \l {QNearFieldTarget::}{ProprietaryTag}
+ \endlist
+ \li Yes - for \l {QNearFieldTarget::}{NfcTagType4}
+ \li Yes - for \l {QNearFieldTarget::}{ProprietaryTag}
+\endtable
+
+*/
diff --git a/src/nfc/doc/src/nfc-index.qdoc b/src/nfc/doc/src/nfc-index.qdoc
index 21f775a6..662fea09 100644
--- a/src/nfc/doc/src/nfc-index.qdoc
+++ b/src/nfc/doc/src/nfc-index.qdoc
@@ -1,30 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qtnfc-index.html
@@ -34,55 +10,42 @@
The NFC API provides connectivity between NFC enabled devices.
-Currently the API is supported on \l{Qt for Android}{Android},
-and \l{Qt for Linux/X11}{Linux} using \l {https://01.org/linux-nfc}{Neard} v0.14 or later.
+Currently, the API is supported on \l{Qt for Android}{Android}, \l{Qt for
+iOS}{iOS} and \l{Qt for Linux}{Linux} using
+\l {https://github.com/linux-nfc/neard}{Neard} v0.14 or later.
+This module also provides limited access to readers supporting
+\l{PC/SC in Qt NFC}{PC/SC} specification on Linux, macOS, and Windows.
-\section1 Overview
+NFC is a short-range (less than 20 centimeters) wireless technology
+with a maximum transfer rate of 424 Kbps. NFC is ideal for transferring
+small packets of data when two devices are placed together.
-NFC is an extremely short-range (less than 20 centimeters) wireless technology and has a
-maximum transfer rate of 424 kbit/s. NFC is ideal for transferring small packets of data when two
-devices are touched together.
+The NFC module provides APIs for interacting with NFC Forum Tags and NFC Forum
+Devices. It can detect targets and losses, register NDEF message handlers, read
+and write NDEF messages on NFC Forum Tags, and send tag-specific commands.
-The NFC API provides APIs for interacting with NFC Forum Tags and NFC Forum Devices, including
-target detection and loss, registering NDEF message handlers, reading and writing NDEF messages
-on NFC Forum Tags and sending tag specific commands.
+\section1 Using the Module
+\include {module-use.qdocinc} {using the c++ api} {NFC}
-\section1 Getting Started
+\section2 Building with CMake
-To use the C++ library in your application, add the following configuration
-option to your \c .pro file:
+\include {module-use.qdocinc} {building with cmake} {Nfc}
-\snippet snippets.pro project modification
+\section2 Building with qmake
-To use the classes of the module in your application you need the following
-import statement in your \c .qml file:
+\include {module-use.qdocinc} {building_with_qmake} {nfc}
-\snippet doc_src_qtnfc.qml import
+\section1 Articles and Guides
-\section1 Licenses
-
-Qt NFC is available under commercial licenses from \l{The Qt Company}.
-In addition, it is available under free software licenses. Since Qt 5.4,
-these free software licenses are
-\l{GNU Lesser General Public License, version 3}, or
-the \l{GNU General Public License, version 2}.
-See \l{Qt Licensing} for further details.
-
-\section1 Related Information
-
-\section2 Guides
\list
\li \l {Qt NFC Overview}
+ \li \l {Supported NFC Features}
+ \li \l {Qt NFC on Android}
+ \li \l {PC/SC in Qt NFC}
\endlist
-\section2 Reference
-\list
- \li \l {Qt NFC QML Types}{QML Types}
- \li \l {Qt NFC C++ Classes}{C++ Classes}
-\endlist
-
-\section2 Logging Categories
+\section1 Logging Categories
The \l QtNfc module exports the following
\l {Configuring Categories}{logging categories}:
@@ -96,17 +59,30 @@ The \l QtNfc module exports the following
\li Enables logging of the Neard/Linux implementation
\endtable
-\section2 Examples
+\section1 Examples
+
\list
- \li QML
- \list
- \li \l {corkboard}{CorkBoard}
- \li \l {poster}{QML Poster}
- \endlist
- \li C++
- \list
- \li \l {annotatedurl}{Annotated URL}
- \li \l {ndefeditor}{NDEF Editor}
- \endlist
+ \li \l {annotatedurl}{Annotated URL}
+ \li \l {ndefeditor}{NDEF Editor}
\endlist
+
+\section1 Reference
+
+\list
+ \li \l {Qt NFC C++ Classes}{C++ Classes}
+\endlist
+
+\section1 Module Evolution
+
+\l {Changes to Qt NFC} lists important changes in the module API and
+functionality that were done for the Qt 6 series of Qt.
+
+\section1 Licenses
+
+Qt NFC is available under commercial licenses from \l{The Qt Company}.
+In addition, it is available under free software licenses. Since Qt 5.4,
+these free software licenses are
+\l{GNU Lesser General Public License, version 3}, or
+the \l{GNU General Public License, version 2}.
+See \l{Qt Licensing} for further details.
*/
diff --git a/src/nfc/doc/src/nfc-overview.qdoc b/src/nfc/doc/src/nfc-overview.qdoc
index 6ac5c1dc..81e7212c 100644
--- a/src/nfc/doc/src/nfc-overview.qdoc
+++ b/src/nfc/doc/src/nfc-overview.qdoc
@@ -1,36 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\ingroup technology-apis
\title Qt NFC Overview
\page qtnfc-overview.html
\brief Provides access to NFC enabled devices.
+\ingroup explanations-networkingandconnectivity
\tableofcontents
@@ -45,8 +22,19 @@ With the Qt NFC API typical use cases are:
The following sections describe how to use Qt NFC C++ classes and QML types for the above use cases.
-\note On Android, Qt Nfc only works in foreground applications. Android services are not supported which is due to
-API limitations on the Android side.
+\note On Android, the detection of new NFC tags only works in foreground applications. Android
+services do not support this because of API limitations on the Android side. The only way to use a
+\l{https://developer.android.com/reference/android/nfc/Tag}{Tag} in a service is to provide an
+\l{https://developer.android.com/guide/components/aidl}{AIDL} interface accepting the Tag and forward
+it to Qt as shown in the following example.
+
+\code
+ public void setTag(Tag pTag) {
+ Intent newIntent = new Intent();
+ newIntent.putExtra(NfcAdapter.EXTRA_TAG, pTag);
+ QtNative.onNewIntent(newIntent);
+ }
+\endcode
\section1 C++ Overview
@@ -62,29 +50,78 @@ a tag comes into or leaves the range. The passed \l QNearFieldTarget parameter a
as primary interaction point for each detected tag. The detection does not actually start though until
\l QNearFieldManager::startTargetDetection() has been called.
-\snippet ndefeditor/mainwindow.cpp QNearFieldManager init
-\snippet ndefeditor/mainwindow.cpp QNearFieldManager start detection
+\code
+m_manager = new QNearFieldManager(this);
+connect(m_manager, &QNearFieldManager::targetDetected,
+ this, &MainWindow::targetDetected);
+connect(m_manager, &QNearFieldManager::targetLost,
+ this, &MainWindow::targetLost);
+m_manager->startTargetDetection(QNearFieldTarget::NdefAccess);
+\endcode
Finally the detection can be stopped:
-\snippet ndefeditor/mainwindow.cpp QNearFieldManager stop detection
+\code
+m_manager->stopTargetDetection();
+\endcode
Although each \l QNearFieldTarget instance is owned by its related \l QNearFieldManager
instance it can be beneficial to manually delete each instance. Otherwise they would continue to
exist until the \l QNearFieldManager instance is deleted. The best way to do that would be in response
to the \l QNearFieldManager::targetLost() signal:
-\snippet ndefeditor/mainwindow.cpp QNearFieldTarget lost
+\code
+void MainWindow::targetLost(QNearFieldTarget *target)
+{
+ target->deleteLater();
+}
+\endcode
\note The target object should only be deleted via deleteLater() if it is deleted inside the slot.
+\section2 Connecting NFC Tags
+
+All functions of \l QNearFieldTarget that require a connection will create one by its own.
+An active connection will prevent other instances to create a connection because only one
+connection at the time is allowed.
+
+Qt 5 disconnected the tag at the end of the functions to allow other instances to connect.
+QNearFieldManager::setKeepConnection() allowed to change this behavior.
+
+Since Qt 6, \l QNearFieldTarget keeps the connection by default. The connection is only closed
+when the \l QNearFieldTarget is destroyed or \l QNearFieldManager::disconnect() is called.
+
\section2 Reading and Writing NDEF Messages
The \l QNearFieldTarget instance returned by \l QNearFieldManager::targetDetected() signal
is used to interact with the tag. Reading and writing a message is an asynchronous operation.
The \l QNearFieldTarget::RequestId class associates individual operations and their results.
-\snippet ndefeditor/mainwindow.cpp QNearFieldTarget detected
+\code
+void MainWindow::targetDetected(QNearFieldTarget *target)
+{
+ switch (m_touchAction) {
+ case NoAction:
+ break;
+ case ReadNdef:
+ connect(target, &QNearFieldTarget::ndefMessageRead, this, &MainWindow::ndefMessageRead);
+ connect(target, &QNearFieldTarget::error, this, &MainWindow::targetError);
+
+ m_request = target->readNdefMessages();
+ if (!m_request.isValid()) // cannot read messages
+ targetError(QNearFieldTarget::NdefReadError, m_request);
+ break;
+ case WriteNdef:
+ connect(target, &QNearFieldTarget::requestCompleted, this, &MainWindow::ndefMessageWritten);
+ connect(target, &QNearFieldTarget::error, this, &MainWindow::targetError);
+
+ m_request = target->writeNdefMessages(QList<QNdefMessage>() << ndefMessage());
+ if (!m_request.isValid()) // cannot write messages
+ targetError(QNearFieldTarget::NdefWriteError, m_request);
+ break;
+ }
+}
+\endcode
Once the \l QNearFieldTarget::readNdefMessages() request was successfully processed, the
\l QNearFieldTarget::ndefMessageRead() signal is emitted. Each returned \l QNdefMessage
@@ -92,62 +129,7 @@ may consist of zero or more \l QNdefRecord entries, which can be identified by t
For more information about processing of records, see the \l QNdefRecord class documentation.
As the above code demonstrates, writing of NDEF messages is triggered via
\l QNearFieldTarget::writeNdefMessages(). The successful completion of the write operation
-is indicated by the emission of the \l QNearFieldTarget::ndefMessagesWritten() signal. Any
-type of error during read or write is indicated via \l QNearFieldTarget::error().
-
-\section2 Registering NDEF Message Handlers
-
-The above described method (of reading NDEF messages) directly connects to the platform's NFC infrastructure.
-However on some platforms (in particular mobile platforms) this may not actually trigger the target slot
-if the application is currently running in the background. This is not desirable in cases where an
-application wants to be activated if the platform detects a tag of particular type.
-For this purpose the Qt NFC API provides the possibility to register an NDEF message handler. The handler
-is called by the operating system, when the detected NDEF message matches the given filter criteria.
-Depending on the platform it may even be possible to start the application that registered the handler.
-
-\note This feature is not available on all platforms and, in addition to the code snippets below,
-may require further platform specific setup.
-
-\snippet annotatedurl/annotatedurl.cpp QNearFieldManager register handler
-
-For comparison an application that uses an empty NDEF filter (match all behavior) in combination with
-\l QNearFieldManager::registerNdefMessageHandler() would behave similarly to another application that uses
-\l QNearFieldTarget::readNdefMessages() while being in the forground. For more information about
-registration details of NDEF message handlers, see the
-\l {QNearFieldManager#automatically-launching-ndef-message-handlers}{QNearFieldManager} class description.
-
-The content of \c handleMessage() may look like the snippet below. Any incoming NDEF message of type
-\c text or \c uri will be processed:
-
-\snippet annotatedurl/annotatedurl.cpp handleMessage 1
-\snippet annotatedurl/annotatedurl.cpp handleMessage 2
-\snippet annotatedurl/annotatedurl.cpp handleMessage 3
-\snippet annotatedurl/annotatedurl.cpp handleMessage 4
-
-\section2 Sharing Files and Messages
-
-Since Qt 5.3, Qt NFC provides a generic NFC share feature. If both devices support the same protocol,
-the feature can be used to share files or NDEF messages. The advantage is that the two involved partners
-can quickly establish a connection via NFC but transfer the data through, for example, Bluetooth or Wifi.
-Effectively, this combines the low configuration effort of NFC with high data rate communication bearers
-which usually require a much more complex setup.
-
-\note The API does not make any guarantees about the actual communication bearer used during the transfer.
-The bearer is chosen based on the device's capabilities and the properties of the to-be-shared data.
-
-\l QNearFieldShareManager and \l QNearFieldShareTarget are responsible for accessing the NFC share feature.
-
-\section1 QML Overview
-
-The QML API only supports a very small subset of the Qt NFC feature set. This section outlines the available QML features.
-
-\section2 Reading NDEF Messages
-
-The user can specify NDEF filters and use those filters to register for the automatic reception of NDEF
-messages which match those filters. The \l NearField::messageRecords property contains the list of NDEF records
-of the last NDEF message read matching the given filters.
-
-\snippet doc_src_qtnfc.qml QML register for messages
-
-If no filter is set, the message handler will match all incoming NDEF messages.
+is indicated by the emission of the \l QNearFieldTarget::requestCompleted() signal with the
+corresponding request id. Any type of error during read or write is indicated via
+\l QNearFieldTarget::error().
*/
diff --git a/src/nfc/doc/src/nfc-pcsc.qdoc b/src/nfc/doc/src/nfc-pcsc.qdoc
new file mode 100644
index 00000000..532f0311
--- /dev/null
+++ b/src/nfc/doc/src/nfc-pcsc.qdoc
@@ -0,0 +1,34 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page qtnfc-pcsc.html
+\title PC/SC in Qt NFC
+\ingroup connectivity-nfc
+\inmodule QtNfc
+\since 6.4
+\brief Notes on PC/SC support in Qt Nfc.
+
+PC/SC support is provided using native APIs on macOS and Windows, and using
+\l{https://pcsclite.apdu.fr/}{PCSCLite} library on other platforms. The API
+can be used for accessing both wired and wireless smartcards and storage cards.
+
+\section1 Limitations
+
+\list
+ \li The current API does not provide means to distinguish between separate
+ readers/slots.
+ \li NDEF access is only provided for NFC Type 4 tags.
+ \li Other applications starting transactions on cards may block Qt applications
+ from using Qt Nfc API.
+ \li QNearFieldTarget::sendCommand() used with a PC/SC target starts
+ 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/doc/src/nfc-qml.qdoc b/src/nfc/doc/src/nfc-qml.qdoc
deleted file mode 100644
index 48ae3bd2..00000000
--- a/src/nfc/doc/src/nfc-qml.qdoc
+++ /dev/null
@@ -1,43 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-/*!
-
-\qmlmodule QtNfc \QtVer
-\title Qt NFC QML Types
-\ingroup qmlmodules
-\brief Provides QML types for accessing NFC Forum Tags.
-
-To use the classes of the module in your application, you need the following
-import statement in your \c .qml file:
-
-\qml \QtVer
-import QtNfc \1
-\endqml
-*/
-
diff --git a/src/nfc/doc/src/qt6-changes.qdoc b/src/nfc/doc/src/qt6-changes.qdoc
new file mode 100644
index 00000000..5b25571e
--- /dev/null
+++ b/src/nfc/doc/src/qt6-changes.qdoc
@@ -0,0 +1,149 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qtnfc-changes-qt6.html
+ \title Changes to Qt NFC
+ \ingroup changes-qt-5-to-6
+ \brief Migrate Qt NFC to Qt 6.
+
+ Qt 6 is a result of the conscious effort to make the framework more
+ efficient and easy to use.
+
+ We try to maintain binary and source compatibility for all the public
+ APIs in each release. But some changes were inevitable in an effort to
+ make Qt a better framework.
+
+ In this topic we summarize those changes in Qt NFC, and provide guidance
+ to handle them.
+
+ \section1 New Features and Methods
+
+ \section2 Added \l QNdefRecord::clear()
+
+ Use this method to clear an NDEF record.
+
+ \section2 Added \l QNdefFilter::match()
+
+ Use this method to check if a \l QNdefMessage matches the given filter.
+ The method returns \c true in case of successful match and \c false
+ otherwise.
+
+ \section2 Extended \l QNearFieldTarget::Type
+
+ The enum was extended with two more types:
+ \list
+ \li \l QNearFieldTarget::NfcTagType4A
+ \li \l QNearFieldTarget::NfcTagType4B
+ \endlist
+
+ \section1 Changes in the Features and Methods
+
+ \section2 Renamed QNearFieldManager::isAvailable()
+
+ The \c QNearFieldManager::isAvailable() was renamed to
+ \l QNearFieldManager::isEnabled().
+
+ \section2 Added access method argument to \l QNearFieldManager::isSupported
+
+ The \c accessMethod argument allows to check if a specific feature is
+ supported. This is relevant because different platforms or versions of
+ operating systems can support different options.
+
+ \section2 Added access method argument to \l QNearFieldManager::startTargetDetection
+
+ The \c accessMethod argument allows to scan for NFC tags with the given
+ access method.
+
+ \section2 Changed \l QNdefNfcSmartPosterRecord::typeInfo from \l QByteArray to \l QString
+
+ According to NDEF Smart Poster specification, the type is a UTF-8 formatted
+ string.
+ This affects the \l QNdefNfcSmartPosterRecord::typeInfo() and
+ \l QNdefNfcSmartPosterRecord::setTypeInfo() methods.
+
+ \section2 Updated return type of \l QNdefFilter::appendRecord
+
+ \l QNdefFilter::appendRecord now performs a basic validation of input
+ parameters and returns a boolean value indicating if the record is appended
+ to the filter or not.
+
+ \section1 Removed Features and Methods
+
+ \section2 Removed QNearFieldTarget::url
+
+ The method was never implemented in the existing subclasses of
+ \l QNearFieldTarget.
+
+ \section2 Removed QNearFieldTarget::sendCommands
+
+ In Qt 5, the method was not very helpful because it didn't provide a way to
+ track the results of intermediate commands. Normally, an additional command
+ needs to be sent only when the previous command is successfully executed.
+
+ The correct approach would be to manually create a queue of commands,
+ use \l QNearFieldTarget::sendCommand to send a command and
+ \l QNearFieldTarget::requestCompleted or \l QNearFieldTarget::error to
+ handle the results of each command individually.
+
+ \section2 Removed QNearFieldTarget::keepConnection
+
+ The methods \c QNearFieldTarget::keepConnection() and
+ \c QNearFieldTarget::setKeepConnection() were removed. Keeping the
+ connection is the default behavior for now.
+
+ \section2 Removed QNearFieldTarget::isProcessingCommand
+
+ The method was never implemented and always returned \c false.
+
+ \section2 Made QNearFieldTarget::setResponseForRequest private API
+
+ The method should not be exposed as a public API. Use
+ \l QNearFieldTarget::ndefMessageRead or \l QNearFieldTarget::requestResponse
+ to read the data from an NFC tag.
+
+ \section2 Removed QNearFieldTarget::handleResponse
+
+ The method was removed as it just forwarded the call to
+ \c QNearFieldManager::setResponseForRequest, which became private API.
+
+ \section2 Made QNearFieldTarget::reportError private API
+
+ A \l QNearFieldTarget::error signal can be used instead.
+
+ \section2 Removed QNearFieldTarget::ndefMessagesWritten signal
+
+ The \l QNearFieldTarget::requestCompleted signal is used for both NDEF
+ messages and custom commands. The \c id parameter can be used to check which
+ request is actually completed.
+
+ \section2 Removed QNearFieldManager::(un)registerNdefMessageHandler
+
+ The methods \c QNearFieldTarget::registerNdefMessageHandler and
+ \c QNearFieldTarget::unregisterNdefMessageHandler were removed.
+
+ Use \l QNearFieldTarget::ndefMessageRead() and \l QNdefFilter::match() to
+ detect the NDEF messages and filter the required ones.
+
+ \note The application can still be automatically started once the NDEF Tag
+ is touched. The \l {annotatedurl}{Annotated URL} example shows how to
+ achieve it on Android.
+
+ \section2 Removed QNearFieldManager::TargetAccessModes
+
+ The \c TargetAccessModes enum was removed together with the getter and
+ setter methods (\c QNearFieldManager::setTargetAccessModes() and
+ \c {QNearFieldManager::targetAccessModes()}).
+
+ The feature is not supported on Android and iOS platforms.
+
+ \section2 Removed QNearFieldShareManager and QNearFieldShareTarget
+
+ File sharing via NFC is deprecated on Android in API 29. Other technologies
+ should be used instead.
+
+ \section2 Removed QML API
+
+ The support for QML API is discontinued.
+
+*/
diff --git a/src/nfc/ios/qiosndefnotifier.cpp b/src/nfc/ios/qiosndefnotifier.cpp
new file mode 100644
index 00000000..20e01f06
--- /dev/null
+++ b/src/nfc/ios/qiosndefnotifier.cpp
@@ -0,0 +1,11 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qiosndefnotifier_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(QT_IOS_NFC, "qt.nfc.ios")
+
+QT_END_NAMESPACE
+
diff --git a/src/nfc/ios/qiosndefnotifier_p.h b/src/nfc/ios/qiosndefnotifier_p.h
new file mode 100644
index 00000000..fadade42
--- /dev/null
+++ b/src/nfc/ios/qiosndefnotifier_p.h
@@ -0,0 +1,56 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QIOSNDEFNOTIFIER_P_H
+#define QIOSNDEFNOTIFIER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qobject.h>
+
+#include <QtCore/qloggingcategory.h>
+
+#include "qnearfieldmanager.h"
+#include "qnearfieldtarget.h"
+
+QT_BEGIN_NAMESPACE
+
+class QNdefMessage;
+class QString;
+
+class QNfcNdefNotifier : public QObject
+{
+ Q_OBJECT
+
+public:
+ QNfcNdefNotifier() = default;
+
+Q_SIGNALS:
+ void tagDetected(void *tag);
+ void invalidateWithError(bool restart);
+ void tagLost(void *tag);
+
+ void tagError(QNearFieldTarget::Error code, QNearFieldTarget::RequestId request);
+
+ void ndefMessageWritten(QNearFieldTarget::RequestId request);
+ void ndefMessageRead(const QNdefMessage &message, QNearFieldTarget::RequestId request);
+
+private:
+ Q_DISABLE_COPY_MOVE(QNfcNdefNotifier);
+};
+
+Q_DECLARE_LOGGING_CATEGORY(QT_IOS_NFC)
+
+QT_END_NAMESPACE
+
+#endif //QIOSNDEFNOTIFIER_P_H
diff --git a/src/nfc/ios/qiosnfcndefsessiondelegate.mm b/src/nfc/ios/qiosnfcndefsessiondelegate.mm
new file mode 100644
index 00000000..4db39edf
--- /dev/null
+++ b/src/nfc/ios/qiosnfcndefsessiondelegate.mm
@@ -0,0 +1,298 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qiosnfcndefsessiondelegate_p.h"
+#include "qiosndefnotifier_p.h"
+
+#include "qndefmessage.h"
+
+#include <QtCore/qscopeguard.h>
+#include <QtCore/qbytearray.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qdebug.h>
+
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+dispatch_queue_t qt_Nfc_Queue()
+{
+ static dispatch_queue_t nfcQueue = []{
+ auto queue = dispatch_queue_create("qt-NFC-queue", DISPATCH_QUEUE_SERIAL);
+ if (!queue)
+ qCWarning(QT_IOS_NFC, "Failed to create the QtNfc's dispatch queue");
+ return queue;
+ }();
+ static const auto queueGuard = qScopeGuard([]{
+ if (nfcQueue)
+ dispatch_release(nfcQueue);
+ });
+ return nfcQueue;
+}
+
+QT_END_NAMESPACE
+
+QT_USE_NAMESPACE
+
+@implementation QIosNfcNdefSessionDelegate
+{
+ std::unique_ptr<QNfcNdefNotifier> notifier;
+ QString alertMessage;
+ NFCNDEFStatus tagStatus;
+ NSUInteger capacity;
+ QNearFieldTarget::RequestId requestId;
+}
+
+-(instancetype)initWithNotifier:(QNfcNdefNotifier *)aNotifier
+{
+ Q_ASSERT(aNotifier);
+
+ if (self = [super init]) {
+ auto queue = qt_Nfc_Queue();
+ if (!queue)
+ return self;
+
+ tagStatus = NFCNDEFStatusNotSupported;
+ capacity = 0;
+ notifier.reset(aNotifier);
+ }
+
+ return self;
+}
+
+-(void)dealloc
+{
+ [self abort];
+ [super dealloc];
+}
+
+-(QNfcNdefNotifier *)ndefNotifier
+{
+ return notifier.get();
+}
+
+-(void)abort
+{
+ notifier.reset(nullptr);
+ [self reset];
+}
+
+-(bool)startSession
+{
+ if (self.session)
+ return true;
+
+ auto queue = qt_Nfc_Queue();
+ Q_ASSERT(queue);
+ self.session = [[NFCNDEFReaderSession alloc] initWithDelegate:self queue:queue invalidateAfterFirstRead:NO];
+ if (alertMessage.size())
+ self.session.alertMessage = alertMessage.toNSString();
+
+ if (!self.session)
+ return false;
+
+ qCDebug(QT_IOS_NFC, "Starting NFC NDEF reader session");
+ [self.session beginSession];
+ return true;
+}
+
+-(void)reset
+{
+ self.session = nil; // Strong property, releases.
+ self.ndefTag = nil; // Strong property, releases.
+ requestId = {};
+ tagStatus = NFCNDEFStatusNotSupported;
+ capacity = 0;
+}
+
+-(void)stopSession:(const QString &)message
+{
+ if (!self.session)
+ return;
+
+ if (self.ndefTag && notifier.get())
+ emit notifier->tagLost(self.ndefTag);
+
+ if (message.size())
+ [self.session invalidateSessionWithErrorMessage:message.toNSString()];
+ else
+ [self.session invalidateSession];
+
+ [self reset];
+}
+
+-(void)setAlertMessage:(const QString &)message
+{
+ alertMessage = message;
+}
+
+-(void)readerSession:(NFCNDEFReaderSession *)session
+ didInvalidateWithError:(NSError *)error
+{
+ if (session != self.session) // If we stopped the session, this maybe the case.
+ return;
+
+ if (!notifier.get()) // Aborted.
+ return;
+
+ NSLog(@"session did invalidate with error %@", error);
+
+ if (error.code != NFCReaderSessionInvalidationErrorUserCanceled && error.code != NFCReaderErrorUnsupportedFeature) {
+ if (self.ndefTag)
+ emit notifier->tagError(QNearFieldTarget::TimeoutError, {});
+
+ emit notifier->invalidateWithError(true);
+ [self reset];
+ }
+
+ // Native errors:
+ //
+ // NFCReaderErrorRadioDisabled
+ // NFCReaderErrorUnsupportedFeature
+ // NFCReaderErrorSecurityViolation
+ // NFCReaderErrorInvalidParameter
+ // NFCReaderErrorParameterOutOfBound
+ // NFCReaderErrorInvalidParameterLength
+ // NFCReaderTransceiveErrorTagConnectionLost
+ // NFCReaderTransceiveErrorRetryExceeded
+ // NFCReaderTransceiveErrorSessionInvalidated
+ // NFCReaderTransceiveErrorTagNotConnected
+ // NFCReaderTransceiveErrorPacketTooLong
+ // NFCReaderSessionInvalidationErrorUserCanceled
+ // NFCReaderSessionInvalidationErrorSessionTimeout
+ // NFCReaderSessionInvalidationErrorSessionTerminatedUnexpectedly
+ // NFCReaderSessionInvalidationErrorSystemIsBusy
+ // NFCReaderSessionInvalidationErrorFirstNDEFTagRead
+ // NFCTagCommandConfigurationErrorInvalidParameters
+ // NFCNdefReaderSessionErrorTagNotWritable
+ // NFCNdefReaderSessionErrorTagUpdateFailure
+ // NFCNdefReaderSessionErrorTagSizeTooSmall
+ //NFCNdefReaderSessionErrorZeroLengthMessage
+
+ // And these are what Qt has ...
+ /*
+ enum Error {
+ NoError,
+ UnknownError,
+ UnsupportedError,
+ TargetOutOfRangeError,
+ NoResponseError,
+ ChecksumMismatchError,
+ InvalidParametersError,
+ ConnectionError,
+ NdefReadError,
+ NdefWriteError,
+ CommandError,
+ TimeoutError
+ };
+ */
+ // TODO: try to map those native errors to Qt ones ...
+}
+
+-(void)readerSession:(NFCNDEFReaderSession *)session
+ didDetectNDEFs:(NSArray<NFCNDEFMessage *> *)messages
+{
+ Q_UNUSED(session);
+ Q_UNUSED(messages);
+ // It's intentionally a noop and should never be called, because
+ // we implement the other method, giving us access to a tag.
+ Q_UNREACHABLE();
+}
+
+-(void)restartPolling
+{
+ if (!self.session)
+ return;
+
+ auto queue = qt_Nfc_Queue();
+ Q_ASSERT(queue);
+
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
+ int64_t(100./1000. * NSEC_PER_SEC)),//100 ms
+ queue,
+ ^{
+ [self.session restartPolling];
+ });
+}
+
+-(void)tag:(id<NFCNDEFTag>)tag didUpdateNDEFStatus:(NFCNDEFStatus)status
+ capacity:(NSUInteger)aCapacity error:(NSError *)error
+{
+ if (!notifier.get()) // Aborted.
+ return;
+
+ if (tag != self.ndefTag)
+ return;
+
+ if (error) {
+ NSLog(@"Querying NDEF tag's status failed: %@, restarting polling ...", error);
+ self.ndefTag = nil;
+ return [self restartPolling];
+ }
+
+ tagStatus = status;
+ capacity = aCapacity;
+
+ if (status == NFCNDEFStatusNotSupported) {
+ qCDebug(QT_IOS_NFC, "The discovered tag does not support NDEF.");
+ return [self restartPolling];
+ }
+
+ if (status == NFCNDEFStatusReadWrite)
+ qCDebug(QT_IOS_NFC, "NDEF read/write capable tag found");
+
+ if (status == NFCNDEFStatusReadOnly)
+ qCDebug(QT_IOS_NFC, "The discovered tag is read only");
+
+ qCInfo(QT_IOS_NFC) << "The max message size for the tag is:" << capacity;
+
+ [self.session connectToTag:self.ndefTag completionHandler:^(NSError * _Nullable error) {
+ if (!error) {
+ if (notifier.get())
+ emit notifier->tagDetected(self.ndefTag);
+ } else {
+ NSLog(@"Failed to connect to NDEF-capable tag, error: %@", error);
+ [self restartPolling];
+ }
+ }];
+}
+
+
+-(void)readerSession:(NFCNDEFReaderSession *)session
+ didDetectTags:(NSArray<__kindof id<NFCNDEFTag>> *)tags
+{
+ if (!notifier.get())
+ return; // Aborted by Qt.
+
+ if (session != self.session) // We stopped _that_ session.
+ return;
+
+ if (tags.count != 1) {
+ qCWarning(QT_IOS_NFC, "Unexpected number of NDEF tags, restarting ...");
+ [self restartPolling];
+ return;
+ }
+
+ NSLog(@"detected a tag! %@", tags[0]);
+
+ id<NFCNDEFTag> tag = tags[0];
+ self.ndefTag = tag; // Strong reference, retains.
+ tagStatus = NFCNDEFStatusNotSupported;
+ capacity = 0;
+
+ [self.ndefTag queryNDEFStatusWithCompletionHandler:
+ ^(NFCNDEFStatus status, NSUInteger aCapacity, NSError * _Nullable error) {
+ [self tag:tag didUpdateNDEFStatus:status capacity:aCapacity error:error];
+ }];
+}
+
+-(void)readerSessionDidBecomeActive:(NFCNDEFReaderSession *)session
+{
+ if (session != self.session)
+ return [session invalidateSession];
+
+ qCInfo(QT_IOS_NFC, "session is active now");
+}
+
+@end
+
diff --git a/src/nfc/ios/qiosnfcndefsessiondelegate_p.h b/src/nfc/ios/qiosnfcndefsessiondelegate_p.h
new file mode 100644
index 00000000..5ec1c12b
--- /dev/null
+++ b/src/nfc/ios/qiosnfcndefsessiondelegate_p.h
@@ -0,0 +1,88 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QIOSNFCNDEFSESSIONDELEFATE_P_H
+#define QIOSNFCNDEFSESSIONDELEFATE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
+#include <QtCore/private/qcore_mac_p.h>
+
+#include "qnearfieldmanager.h"
+#include "qnearfieldtarget.h"
+
+#include <Foundation/Foundation.h>
+#include <CoreNFC/CoreNFC.h>
+
+QT_BEGIN_NAMESPACE
+
+class QNearFieldManagerPrivateImpl;
+class QNfcNdefNotifier;
+class QNearFieldTarget;
+class QNdefMessage;
+class QString;
+
+dispatch_queue_t qt_Nfc_Queue();
+
+QT_END_NAMESPACE
+
+QT_USE_NAMESPACE
+
+@interface QT_MANGLE_NAMESPACE(QIosNfcNdefSessionDelegate) : NSObject<NFCNDEFReaderSessionDelegate>
+
+@property (strong, nonatomic) NFCNDEFReaderSession *session;
+@property (strong, nonatomic) id<NFCNDEFTag> ndefTag;
+
+
+-(instancetype)initWithNotifier:(QNfcNdefNotifier *)aNotifier;
+-(void)dealloc;
+
+-(QNfcNdefNotifier *)ndefNotifier;
+
+-(void)setAlertMessage:(const QString &)message;
+
+// Those methods to be called on the session.sessionQueue:
+-(bool)startSession;
+-(void)stopSession:(const QString &)message;
+-(void)abort;
+
+// Delegate's methods, implementing the protocol NFCNDEFReaderSessionDelegate.
+// Those methods not to be called by the Qt.
+
+// "Gets called when a session becomes invalid. At this point the client is expected to
+// discard the returned session object."
+-(void)readerSession:(NFCNDEFReaderSession *)session
+ didInvalidateWithError:(NSError *)error;
+
+// "Gets called when the reader detects NFC tag(s) with NDEF messages in the polling sequence.
+// Polling is automatically restarted once the detected tag is removed from the reader's read
+// range. This method is only get call if the optional -readerSession:didDetectTags: method
+// is not implemented."
+-(void)readerSession:(NFCNDEFReaderSession *)session
+ didDetectNDEFs:(NSArray<NFCNDEFMessage *> *)messages;
+
+// "Gets called when the reader detects NDEF tag(s) in the RF field. Presence of this method
+// overrides -readerSession:didDetectNDEFs: and enables read-write capability for the session."
+-(void)readerSession:(NFCNDEFReaderSession *)session
+ didDetectTags:(NSArray<__kindof id<NFCNDEFTag>> *)tags;
+
+// "Gets called when the NFC reader session has become active. RF is enabled and reader is
+// scanning for tags."
+-(void)readerSessionDidBecomeActive:(NFCNDEFReaderSession *)session;
+
+@end
+
+QT_NAMESPACE_ALIAS_OBJC_CLASS(QIosNfcNdefSessionDelegate);
+
+#endif // QIOSNFCNDEFSESSIONDELEFATE_P_H
diff --git a/src/nfc/ios/qiostagreaderdelegate.mm b/src/nfc/ios/qiostagreaderdelegate.mm
new file mode 100644
index 00000000..fd7db020
--- /dev/null
+++ b/src/nfc/ios/qiostagreaderdelegate.mm
@@ -0,0 +1,110 @@
+// Copyright (C) 2020 Governikus GmbH & Co. KG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qiostagreaderdelegate_p.h"
+
+#include "qnearfieldmanager_ios_p.h"
+
+#import <CoreNFC/NFCError.h>
+#import <CoreNFC/NFCTag.h>
+
+QT_USE_NAMESPACE
+
+@implementation QT_MANGLE_NAMESPACE(QIosTagReaderDelegate)
+
+- (instancetype)initWithListener:(QNearFieldManagerPrivateImpl *)listener
+{
+ self = [super init];
+ if (self) {
+ self.listener = listener;
+ self.sessionStoppedByApplication = false;
+ self.message = nil;
+ self.session = nil;
+ }
+
+ return self;
+}
+
+- (void)startSession
+{
+ if (self.session && !self.sessionStoppedByApplication) {
+ [self.session invalidateSession];
+ self.sessionStoppedByApplication = true;
+ }
+
+ if (self.sessionStoppedByApplication) {
+ Q_EMIT self.listener->didInvalidateWithError(true);
+ return;
+ }
+
+ self.session = [[[NFCTagReaderSession alloc] initWithPollingOption:NFCPollingISO14443 delegate:self queue:nil] autorelease];
+ if (self.session) {
+ if (self.message)
+ self.session.alertMessage = self.message;
+ [self.session beginSession];
+ } else {
+ Q_EMIT self.listener->didInvalidateWithError(true);
+ }
+}
+
+- (void)stopSession:(QString)message
+{
+ if (self.session && !self.sessionStoppedByApplication) {
+ if (message.isNull())
+ [self.session invalidateSession];
+ else
+ [self.session invalidateSessionWithErrorMessage:message.toNSString()];
+ self.sessionStoppedByApplication = true;
+ }
+}
+
+- (void)alertMessage:(QString)message
+{
+ if (self.session && !self.sessionStoppedByApplication)
+ self.session.alertMessage = message.toNSString();
+ else
+ self.message = message.toNSString();
+}
+
+- (void)tagReaderSessionDidBecomeActive:(NFCTagReaderSession*)session
+{
+ if (session != self.session)
+ [session invalidateSession];
+}
+
+- (void)tagReaderSession:(NFCTagReaderSession*)session didInvalidateWithError:(NSError*)error
+{
+ if (session != self.session)
+ return;
+
+ self.session = nil;
+ if (self.sessionStoppedByApplication) {
+ self.sessionStoppedByApplication = false;
+ return;
+ }
+
+ const bool doRestart =
+ !(error.code == NFCReaderError::NFCReaderSessionInvalidationErrorUserCanceled
+ || error.code == NFCReaderError::NFCReaderErrorUnsupportedFeature);
+ Q_EMIT self.listener->didInvalidateWithError(doRestart);
+}
+
+- (void)tagReaderSession:(NFCTagReaderSession*)session didDetectTags:(NSArray<__kindof id<NFCTag>>*)tags
+{
+ if (session != self.session)
+ return;
+
+ bool foundTag = false;
+ for (id<NFCTag> tag in tags) {
+ if (tag.type == NFCTagTypeISO7816Compatible) {
+ foundTag = true;
+ [tag retain];
+ Q_EMIT self.listener->tagDiscovered(tag);
+ }
+ }
+
+ if (!foundTag)
+ [session restartPolling];
+}
+
+@end
diff --git a/src/nfc/ios/qiostagreaderdelegate_p.h b/src/nfc/ios/qiostagreaderdelegate_p.h
new file mode 100644
index 00000000..7defcd44
--- /dev/null
+++ b/src/nfc/ios/qiostagreaderdelegate_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2020 Governikus GmbH & Co. KG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QIOSTAGREADERDELEGATE_P_H
+#define QIOSTAGREADERDELEGATE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QString>
+
+#import <CoreNFC/NFCReaderSession.h>
+#import <CoreNFC/NFCTagReaderSession.h>
+#import <Foundation/Foundation.h>
+
+QT_BEGIN_NAMESPACE
+
+class QNearFieldManagerPrivateImpl;
+
+QT_END_NAMESPACE
+
+API_AVAILABLE(ios(13.0))
+@interface QT_MANGLE_NAMESPACE(QIosTagReaderDelegate)
+ : NSObject<NFCTagReaderSessionDelegate>
+
+@property QNearFieldManagerPrivateImpl *listener;
+@property bool sessionStoppedByApplication;
+@property (nonatomic, strong) NSString *message;
+@property (nonatomic, strong) NFCTagReaderSession *session;
+
+- (instancetype)initWithListener:(QNearFieldManagerPrivateImpl *)listener;
+
+- (void)startSession;
+- (void)stopSession:(QString)message;
+
+- (void)alertMessage:(QString)message;
+
+@end
+
+#endif // QIOSTAGREADERDELEGATE_P_H
diff --git a/src/nfc/ndef/qndefaccessfsm_p.h b/src/nfc/ndef/qndefaccessfsm_p.h
new file mode 100644
index 00000000..2a175bcc
--- /dev/null
+++ b/src/nfc/ndef/qndefaccessfsm_p.h
@@ -0,0 +1,103 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNDEFACCESSFSM_P_H
+#define QNDEFACCESSFSM_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qndefmessage.h"
+
+QT_BEGIN_NAMESPACE
+
+/*
+ Base class for FSMs that can be used to exchange NDEF messages with cards.
+
+ The user may call one of these methods to start a task:
+
+ - detectNdefSupport()
+ - readMessages()
+ - writeMessages()
+
+ The user is then expected to perform actions indicated by Action type.
+*/
+class QNdefAccessFsm
+{
+ Q_DISABLE_COPY_MOVE(QNdefAccessFsm)
+public:
+ QNdefAccessFsm() = default;
+ virtual ~QNdefAccessFsm() = default;
+
+ enum Action {
+ // The requested task has successfully completed. New tasks can be started.
+ Done,
+ // The requested task has failed. New tasks can be started.
+ Failed,
+ // An NDEF message was successfully read. The user must call getMessage().
+ GetMessage,
+ // The user's call was unexpected. The FSM may be in an invalid state.
+ Unexpected,
+ // The user must call getCommand() and then send the returned command to the card.
+ SendCommand,
+ // The user must call provideResponse() with the result of the last sent command.
+ ProvideResponse
+ };
+
+ /*
+ Returns a command to send to the card.
+
+ This method must be called if the FMS has requested SendCommand action.
+
+ Next action will be ProvideResponse or Unexpected.
+ */
+ virtual QByteArray getCommand(Action &nextAction) = 0;
+
+ /*
+ This method must be called by the user to provide response for
+ a completed command.
+
+ An empty QByteArray can be provided to indicate that the command
+ has failed.
+ */
+ virtual Action provideResponse(const QByteArray &response) = 0;
+
+ /*
+ Returns an NDEF message that was read from the card.
+
+ This method must be called if the FSM has requested GetMessage action.
+ */
+ virtual QNdefMessage getMessage(Action &nextAction) = 0;
+
+ /*
+ Start NDEF support detection.
+ */
+ virtual Action detectNdefSupport() = 0;
+
+ /*
+ Start reading NDEF messages.
+
+ This call also performs NDEF support detection if it was not performed
+ earlier.
+ */
+ virtual Action readMessages() = 0;
+
+ /*
+ Start writing the given messages to the card.
+
+ This call also performs NDEF detection if is was not performed earlier.
+ */
+ virtual Action writeMessages(const QList<QNdefMessage> &messages) = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif // QNDEFACCESSFSM_P_H
diff --git a/src/nfc/ndef/qnfctagtype4ndeffsm.cpp b/src/nfc/ndef/qnfctagtype4ndeffsm.cpp
new file mode 100644
index 00000000..c21608e4
--- /dev/null
+++ b/src/nfc/ndef/qnfctagtype4ndeffsm.cpp
@@ -0,0 +1,374 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qnfctagtype4ndeffsm_p.h"
+#include <QtCore/QtEndian>
+#include <QtCore/QLoggingCategory>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(QT_NFC_T4T, "qt.nfc.t4t")
+
+/*
+ NDEF support for NFC Type 4 tags.
+
+ Based on Type 4 Tag Operation Specification, Version 2.0 (T4TOP 2.0).
+*/
+
+QByteArray QNfcTagType4NdefFsm::getCommand(QNdefAccessFsm::Action &nextAction)
+{
+ // ID of the NDEF Tag Application
+ static constexpr uint8_t NtagApplicationIdV2[] { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 };
+ // Capability container file ID.
+ static constexpr uint8_t CapabilityContainerId[] { 0xE1, 0x03 };
+ // Shortcut for specifying zero length of NDEF message data.
+ static constexpr uint8_t ZeroLength[] { 0x00, 0x00 };
+
+ nextAction = ProvideResponse;
+
+ switch (m_currentState) {
+ case SelectApplicationForProbe:
+ case SelectApplicationForRead:
+ case SelectApplicationForWrite:
+ return QCommandApdu::build(0x00, QCommandApdu::Select, 0x04, 0x00,
+ QByteArrayView::fromArray(NtagApplicationIdV2), 256);
+ case SelectCCFile:
+ return QCommandApdu::build(0x00, QCommandApdu::Select, 0x00, 0x0C,
+ QByteArrayView::fromArray(CapabilityContainerId));
+ case ReadCCFile:
+ return QCommandApdu::build(0x00, QCommandApdu::ReadBinary, 0x00, 0x00, {}, 15);
+ case SelectNdefFileForRead:
+ case SelectNdefFileForWrite:
+ return QCommandApdu::build(0x00, QCommandApdu::Select, 0x00, 0x0C, m_ndefFileId);
+ case ReadNdefMessageLength:
+ return QCommandApdu::build(0x00, QCommandApdu::ReadBinary, 0x00, 0x00, {}, 2);
+ case ReadNdefMessage: {
+ uint16_t readSize = qMin(m_fileSize, m_maxReadSize);
+
+ return QCommandApdu::build(0x00, QCommandApdu::ReadBinary, m_fileOffset >> 8,
+ m_fileOffset & 0xFF, {}, readSize);
+ }
+ case ClearNdefLength:
+ m_fileOffset = 2;
+ m_fileSize = m_ndefData.size();
+ return QCommandApdu::build(0x00, QCommandApdu::UpdateBinary, 0x00, 0x00,
+ QByteArrayView::fromArray(ZeroLength));
+ case WriteNdefFile: {
+ uint16_t updateSize = qMin(m_fileSize, m_maxUpdateSize);
+ uint16_t fileOffset = m_fileOffset;
+
+ m_fileOffset += updateSize;
+ m_fileSize -= updateSize;
+
+ return QCommandApdu::build(0x00, QCommandApdu::UpdateBinary, fileOffset >> 8,
+ fileOffset & 0xFF, m_ndefData.mid(fileOffset - 2, updateSize));
+ }
+ case WriteNdefLength: {
+ QByteArray data(2, Qt::Uninitialized);
+ qToUnaligned(qToBigEndian<uint16_t>(m_ndefData.size()), data.data());
+
+ return QCommandApdu::build(0x00, QCommandApdu::UpdateBinary, 0x00, 0x00, data);
+ }
+ default:
+ nextAction = Unexpected;
+ return {};
+ }
+}
+
+QNdefMessage QNfcTagType4NdefFsm::getMessage(QNdefAccessFsm::Action &nextAction)
+{
+ if (m_currentState == NdefMessageRead) {
+ auto message = QNdefMessage::fromByteArray(m_ndefData);
+ m_ndefData.clear();
+ m_currentState = NdefSupportDetected;
+ nextAction = Done;
+ return message;
+ }
+
+ nextAction = Unexpected;
+ return {};
+}
+
+QNdefAccessFsm::Action QNfcTagType4NdefFsm::detectNdefSupport()
+{
+ switch (m_currentState) {
+ case SelectApplicationForProbe:
+ m_targetState = NdefSupportDetected;
+ return SendCommand;
+ case NdefSupportDetected:
+ return Done;
+ case NdefNotSupported:
+ return Failed;
+ default:
+ return Unexpected;
+ }
+}
+
+QNdefAccessFsm::Action QNfcTagType4NdefFsm::readMessages()
+{
+ switch (m_currentState) {
+ case SelectApplicationForProbe:
+ m_targetState = NdefMessageRead;
+ return SendCommand;
+ case NdefSupportDetected:
+ m_currentState = SelectApplicationForRead;
+ m_targetState = NdefMessageRead;
+ return SendCommand;
+ case NdefNotSupported:
+ return Failed;
+ default:
+ return Unexpected;
+ }
+}
+
+QNdefAccessFsm::Action QNfcTagType4NdefFsm::writeMessages(const QList<QNdefMessage> &messages)
+{
+ // Only one message per tag is supported
+ if (messages.isEmpty() || messages.size() > 1)
+ return Failed;
+
+ auto messageData = messages.first().toByteArray();
+ if (messageData.size() > m_maxNdefSize - 2)
+ return Failed;
+
+ m_ndefData = messageData;
+
+ m_targetState = NdefMessageWritten;
+
+ switch (m_currentState) {
+ case SelectApplicationForProbe:
+ return SendCommand;
+
+ case NdefNotSupported:
+ return Failed;
+
+ case NdefSupportDetected:
+ if (!m_writable)
+ return Failed;
+
+ m_currentState = SelectApplicationForWrite;
+ return SendCommand;
+
+ default:
+ return Unexpected;
+ };
+}
+
+QNdefAccessFsm::Action QNfcTagType4NdefFsm::provideResponse(const QByteArray &response)
+{
+ QResponseApdu apdu(response);
+
+ switch (m_currentState) {
+ case SelectApplicationForProbe:
+ return handleSimpleResponse(apdu, SelectCCFile, NdefNotSupported);
+ case SelectCCFile:
+ return handleSimpleResponse(apdu, ReadCCFile, NdefNotSupported);
+ case ReadCCFile:
+ return handleReadCCResponse(apdu);
+
+ case SelectApplicationForRead:
+ return handleSimpleResponse(apdu, SelectNdefFileForRead, NdefSupportDetected);
+ case SelectNdefFileForRead:
+ return handleSimpleResponse(apdu, ReadNdefMessageLength, NdefSupportDetected);
+ case ReadNdefMessageLength:
+ return handleReadFileLengthResponse(apdu);
+ case ReadNdefMessage:
+ return handleReadFileResponse(apdu);
+
+ case SelectApplicationForWrite:
+ return handleSimpleResponse(apdu, SelectNdefFileForWrite, NdefSupportDetected);
+ case SelectNdefFileForWrite:
+ return handleSimpleResponse(apdu, ClearNdefLength, NdefSupportDetected);
+ case ClearNdefLength:
+ return handleSimpleResponse(apdu, WriteNdefFile, NdefSupportDetected);
+ case WriteNdefFile:
+ return handleWriteNdefFileResponse(apdu);
+ case WriteNdefLength:
+ return handleSimpleResponse(apdu, NdefSupportDetected, NdefSupportDetected, Done);
+
+ default:
+ return Unexpected;
+ }
+}
+
+QNdefAccessFsm::Action QNfcTagType4NdefFsm::handleSimpleResponse(
+ const QResponseApdu &response, QNfcTagType4NdefFsm::State okState,
+ QNfcTagType4NdefFsm::State failedState, QNdefAccessFsm::Action okAction)
+{
+ if (!response.isOk()) {
+ m_currentState = failedState;
+ return Failed;
+ }
+
+ m_currentState = okState;
+ return okAction;
+}
+
+QNdefAccessFsm::Action QNfcTagType4NdefFsm::handleReadCCResponse(const QResponseApdu &response)
+{
+ m_currentState = NdefNotSupported;
+
+ if (!response.isOk())
+ return Failed;
+
+ if (response.data().size() < 15) {
+ qCDebug(QT_NFC_T4T) << "Invalid response size";
+ return Failed;
+ }
+
+ qsizetype idx = 0;
+ auto readU8 = [&data = response.data(), &idx]() {
+ return static_cast<uint8_t>(data.at(idx++));
+ };
+ auto readU16 = [&data = response.data(), &idx]() {
+ Q_ASSERT(idx >= 0 && idx <= data.size() - 2);
+ uint16_t res = qFromBigEndian(qFromUnaligned<uint16_t>(data.constData() + idx));
+ idx += 2;
+ return res;
+ };
+ auto readBytes = [&data = response.data(), &idx](qsizetype count) {
+ auto res = data.sliced(idx, count);
+ idx += count;
+ return res;
+ };
+ auto ccLen = readU16();
+ if (ccLen < 15) {
+ qCDebug(QT_NFC_T4T) << "CC length is too small";
+ return Failed;
+ }
+ auto mapping = readU8();
+ if ((mapping & 0xF0) != 0x20) {
+ qCDebug(QT_NFC_T4T) << "Unsupported mapping:" << Qt::hex << mapping;
+ return Failed;
+ }
+ m_maxReadSize = readU16();
+ if (m_maxReadSize < 0xF) {
+ qCDebug(QT_NFC_T4T) << "Invalid maxReadSize" << m_maxReadSize;
+ return Failed;
+ }
+
+ m_maxUpdateSize = readU16();
+ auto tlvTag = readU8();
+ if (tlvTag != 0x04) {
+ qCDebug(QT_NFC_T4T) << "Invalid TLV tag";
+ return Failed;
+ }
+ auto tlvSize = readU8();
+ if (tlvSize == 0xFF || tlvSize < 6) {
+ qCDebug(QT_NFC_T4T) << "Invalid TLV size";
+ return Failed;
+ }
+ m_ndefFileId = readBytes(2);
+
+ m_maxNdefSize = readU16();
+ if (m_maxNdefSize < 2) {
+ qCDebug(QT_NFC_T4T) << "No space for NDEF file length";
+ return Failed;
+ }
+
+ /*
+ The specification defined value 0 for read access and write access
+ fields to mean that access is granted without any security, all
+ other values are either reserved, proprietary, or indicate than no
+ access is granted at all. Here all non-zero value are handled as
+ no access is granted.
+ */
+ auto readAccess = readU8();
+ if (readAccess != 0) {
+ qCDebug(QT_NFC_T4T) << "No read access";
+ return Failed;
+ }
+ auto writeAccess = readU8();
+ // It's not possible to atomically clear the length field if update
+ // size is < 2, so handle such tags as read-only. This also simplifies
+ // the update logic (no need to ever split ClearNdefLength/WriteNdefLength
+ // states)
+ m_writable = writeAccess == 0 && m_maxUpdateSize >= 2;
+
+ m_currentState = NdefSupportDetected;
+
+ if (m_targetState == NdefSupportDetected) {
+ return Done;
+ } else if (m_targetState == NdefMessageRead) {
+ // Skip extra application select
+ m_currentState = SelectNdefFileForRead;
+ return SendCommand;
+ } else if (m_targetState == NdefMessageWritten) {
+ if (m_writable) {
+ if (m_ndefData.size() > m_maxNdefSize - 2) {
+ qCDebug(QT_NFC_T4T) << "Message is too large";
+ return Failed;
+ }
+
+ // Skip extra application select
+ m_currentState = SelectNdefFileForWrite;
+ return SendCommand;
+ } else {
+ return Failed;
+ }
+ }
+
+ return Unexpected;
+}
+
+QNdefAccessFsm::Action
+QNfcTagType4NdefFsm::handleReadFileLengthResponse(const QResponseApdu &response)
+{
+ if (!response.isOk() || response.data().size() < 2) {
+ m_currentState = NdefSupportDetected;
+ return Failed;
+ }
+
+ m_fileSize = qFromBigEndian(qFromUnaligned<uint16_t>(response.data().constData()));
+ if (m_fileSize > m_maxNdefSize - 2) {
+ m_currentState = NdefSupportDetected;
+ return Failed;
+ }
+
+ m_fileOffset = 2;
+ m_ndefData.clear();
+
+ if (m_fileSize == 0) {
+ m_currentState = NdefMessageRead;
+ return GetMessage;
+ }
+
+ m_currentState = ReadNdefMessage;
+ return SendCommand;
+}
+
+QNdefAccessFsm::Action QNfcTagType4NdefFsm::handleReadFileResponse(const QResponseApdu &response)
+{
+ if (!response.isOk() || response.data().size() == 0) {
+ m_currentState = NdefSupportDetected;
+ return Failed;
+ }
+
+ auto readSize = qMin<qsizetype>(m_fileSize, response.data().size());
+ m_ndefData.append(response.data().first(readSize));
+ m_fileOffset += readSize;
+ m_fileSize -= readSize;
+
+ if (m_fileSize == 0) {
+ m_currentState = NdefMessageRead;
+ return GetMessage;
+ }
+
+ return SendCommand;
+}
+
+QNdefAccessFsm::Action
+QNfcTagType4NdefFsm::handleWriteNdefFileResponse(const QResponseApdu &response)
+{
+ if (!response.isOk()) {
+ m_currentState = NdefSupportDetected;
+ return Failed;
+ }
+
+ if (m_fileSize == 0)
+ m_currentState = WriteNdefLength;
+
+ return SendCommand;
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/ndef/qnfctagtype4ndeffsm_p.h b/src/nfc/ndef/qnfctagtype4ndeffsm_p.h
new file mode 100644
index 00000000..0ec8c378
--- /dev/null
+++ b/src/nfc/ndef/qnfctagtype4ndeffsm_p.h
@@ -0,0 +1,82 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNFCTAGTYPE4NDEFFSM_P_H
+#define QNFCTAGTYPE4NDEFFSM_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qndefaccessfsm_p.h"
+#include "qapduutils_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QNfcTagType4NdefFsm : public QNdefAccessFsm
+{
+public:
+ QByteArray getCommand(Action &nextAction) override;
+ QNdefMessage getMessage(Action &nextAction) override;
+ Action provideResponse(const QByteArray &response) override;
+
+ Action detectNdefSupport() override;
+ Action readMessages() override;
+ Action writeMessages(const QList<QNdefMessage> &messages) override;
+
+private:
+ enum State {
+ SelectApplicationForProbe,
+ SelectCCFile,
+ ReadCCFile,
+ NdefSupportDetected,
+ NdefNotSupported,
+
+ SelectApplicationForRead,
+ SelectNdefFileForRead,
+ ReadNdefMessageLength,
+ ReadNdefMessage,
+ NdefMessageRead,
+
+ SelectApplicationForWrite,
+ SelectNdefFileForWrite,
+ ClearNdefLength,
+ WriteNdefFile,
+ WriteNdefLength,
+ NdefMessageWritten // Only for target state, it is never actually reached
+ };
+
+ State m_currentState = SelectApplicationForProbe;
+ State m_targetState = SelectApplicationForProbe;
+
+ // Initialized during the detection phase
+ uint16_t m_maxReadSize;
+ uint16_t m_maxUpdateSize;
+ QByteArray m_ndefFileId;
+ uint16_t m_maxNdefSize = 0xFFFF;
+ bool m_writable;
+
+ // Used during the read and write operations
+ uint16_t m_fileSize;
+ uint16_t m_fileOffset;
+ QByteArray m_ndefData;
+
+ Action handleSimpleResponse(const QResponseApdu &response, State okState, State failedState,
+ Action okAction = SendCommand);
+
+ Action handleReadCCResponse(const QResponseApdu &response);
+ Action handleReadFileLengthResponse(const QResponseApdu &response);
+ Action handleReadFileResponse(const QResponseApdu &response);
+ Action handleWriteNdefFileResponse(const QResponseApdu &response);
+};
+
+QT_END_NAMESPACE
+
+#endif // QNFCTAGTYPE4NDEFFSM_P_H
diff --git a/src/nfc/neard/adapter.cpp b/src/nfc/neard/adapter.cpp
deleted file mode 100644
index d626678a..00000000
--- a/src/nfc/neard/adapter.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.neard.Adapter.xml -p adapter_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * This file may have been hand-edited. Look for HAND-EDIT comments
- * before re-generating it.
- */
-
-#include "adapter_p.h"
-
-/*
- * Implementation of interface class OrgNeardAdapterInterface
- */
-
-OrgNeardAdapterInterface::OrgNeardAdapterInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
- : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
-{
-}
-
-OrgNeardAdapterInterface::~OrgNeardAdapterInterface()
-{
-}
diff --git a/src/nfc/neard/adapter_p.h b/src/nfc/neard/adapter_p.h
deleted file mode 100644
index 76817705..00000000
--- a/src/nfc/neard/adapter_p.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.neard.Adapter.xml -p adapter_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * Do not edit! All changes made to it will be lost.
- */
-
-#ifndef ADAPTER_P_H_1410940487
-#define ADAPTER_P_H_1410940487
-
-#include <QtCore/QObject>
-#include <QtCore/QByteArray>
-#include <QtCore/QList>
-#include <QtCore/QMap>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtCore/QVariant>
-#include <QtDBus/QtDBus>
-
-/*
- * Proxy class for interface org.neard.Adapter
- */
-class OrgNeardAdapterInterface: public QDBusAbstractInterface
-{
- Q_OBJECT
-public:
- static inline const char *staticInterfaceName()
- { return "org.neard.Adapter"; }
-
-public:
- OrgNeardAdapterInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
-
- ~OrgNeardAdapterInterface();
-
-public Q_SLOTS: // METHODS
- inline QDBusPendingReply<> StartPollLoop(const QString &name)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(name);
- return asyncCallWithArgumentList(QStringLiteral("StartPollLoop"), argumentList);
- }
-
- inline QDBusPendingReply<> StopPollLoop()
- {
- QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QStringLiteral("StopPollLoop"), argumentList);
- }
-
-Q_SIGNALS: // SIGNALS
-};
-
-namespace org {
- namespace neard {
- typedef ::OrgNeardAdapterInterface Adapter;
- }
-}
-#endif
diff --git a/src/nfc/neard/agent.cpp b/src/nfc/neard/agent.cpp
deleted file mode 100644
index faa48043..00000000
--- a/src/nfc/neard/agent.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.neard.Agent.xml -p agent_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * This file may have been hand-edited. Look for HAND-EDIT comments
- * before re-generating it.
- */
-
-#include "agent_p.h"
-
-/*
- * Implementation of interface class OrgNeardHandoverAgentInterface
- */
-
-OrgNeardHandoverAgentInterface::OrgNeardHandoverAgentInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
- : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
-{
-}
-
-OrgNeardHandoverAgentInterface::~OrgNeardHandoverAgentInterface()
-{
-}
-
-/*
- * Implementation of interface class OrgNeardNDEFAgentInterface
- */
-
-OrgNeardNDEFAgentInterface::OrgNeardNDEFAgentInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
- : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
-{
-}
-
-OrgNeardNDEFAgentInterface::~OrgNeardNDEFAgentInterface()
-{
-}
diff --git a/src/nfc/neard/agent_p.h b/src/nfc/neard/agent_p.h
deleted file mode 100644
index 7e40ffaf..00000000
--- a/src/nfc/neard/agent_p.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.neard.Agent.xml -p agent_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * Do not edit! All changes made to it will be lost.
- */
-
-#ifndef AGENT_P_H_1410442485
-#define AGENT_P_H_1410442485
-
-#include <QtCore/QObject>
-#include <QtCore/QByteArray>
-#include <QtCore/QList>
-#include <QtCore/QMap>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtCore/QVariant>
-#include <QtDBus/QtDBus>
-
-/*
- * Proxy class for interface org.neard.HandoverAgent
- */
-class OrgNeardHandoverAgentInterface: public QDBusAbstractInterface
-{
- Q_OBJECT
-public:
- static inline const char *staticInterfaceName()
- { return "org.neard.HandoverAgent"; }
-
-public:
- OrgNeardHandoverAgentInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
-
- ~OrgNeardHandoverAgentInterface();
-
-public Q_SLOTS: // METHODS
- inline QDBusPendingReply<> PushOOB(const QVariantMap &values)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(values);
- return asyncCallWithArgumentList(QStringLiteral("PushOOB"), argumentList);
- }
-
- inline QDBusPendingReply<> Release()
- {
- QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QStringLiteral("Release"), argumentList);
- }
-
- inline QDBusPendingReply<QVariantMap> RequestOOB(const QVariantMap &values)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(values);
- return asyncCallWithArgumentList(QStringLiteral("RequestOOB"), argumentList);
- }
-
-Q_SIGNALS: // SIGNALS
-};
-
-/*
- * Proxy class for interface org.neard.NDEFAgent
- */
-class OrgNeardNDEFAgentInterface: public QDBusAbstractInterface
-{
- Q_OBJECT
-public:
- static inline const char *staticInterfaceName()
- { return "org.neard.NDEFAgent"; }
-
-public:
- OrgNeardNDEFAgentInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
-
- ~OrgNeardNDEFAgentInterface();
-
-public Q_SLOTS: // METHODS
- inline QDBusPendingReply<> GetNDEF(const QVariantMap &values)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(values);
- return asyncCallWithArgumentList(QStringLiteral("GetNDEF"), argumentList);
- }
-
- inline QDBusPendingReply<> Release()
- {
- QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QStringLiteral("Release"), argumentList);
- }
-
-Q_SIGNALS: // SIGNALS
-};
-
-namespace org {
- namespace neard {
- typedef ::OrgNeardHandoverAgentInterface HandoverAgent;
- typedef ::OrgNeardNDEFAgentInterface NDEFAgent;
- }
-}
-#endif
diff --git a/src/nfc/neard/dbusobjectmanager.cpp b/src/nfc/neard/dbusobjectmanager.cpp
deleted file mode 100644
index 7b3f8356..00000000
--- a/src/nfc/neard/dbusobjectmanager.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v dbus-object-manager.xml -p dbusobjectmanager -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * This file may have been hand-edited. Look for HAND-EDIT comments
- * before re-generating it.
- */
-
-#include "dbusobjectmanager_p.h"
-
-/*
- * Implementation of interface class OrgFreedesktopDBusObjectManagerInterface
- */
-
-OrgFreedesktopDBusObjectManagerInterface::OrgFreedesktopDBusObjectManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
- : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
-{
-}
-
-OrgFreedesktopDBusObjectManagerInterface::~OrgFreedesktopDBusObjectManagerInterface()
-{
-}
-
diff --git a/src/nfc/neard/dbusobjectmanager_p.h b/src/nfc/neard/dbusobjectmanager_p.h
deleted file mode 100644
index 64d11449..00000000
--- a/src/nfc/neard/dbusobjectmanager_p.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v -i neard_helper_p.h org.freedesktop.dbus.objectmanager.xml -p dbusobjectmanager_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * Do not edit! All changes made to it will be lost.
- */
-
-#ifndef DBUSOBJECTMANAGER_H_1409928664
-#define DBUSOBJECTMANAGER_H_1409928664
-
-#include <QtCore/QObject>
-#include <QtCore/QByteArray>
-#include <QtCore/QList>
-#include <QtCore/QMap>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtCore/QVariant>
-#include <QtDBus/QtDBus>
-#include "neard_helper_p.h"
-
-/*
- * Proxy class for interface org.freedesktop.DBus.ObjectManager
- */
-class OrgFreedesktopDBusObjectManagerInterface: public QDBusAbstractInterface
-{
- Q_OBJECT
-public:
- static inline const char *staticInterfaceName()
- { return "org.freedesktop.DBus.ObjectManager"; }
-
-public:
- OrgFreedesktopDBusObjectManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
-
- ~OrgFreedesktopDBusObjectManagerInterface();
-
-public Q_SLOTS: // METHODS
- inline QDBusPendingReply<ManagedObjectList> GetManagedObjects()
- {
- QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QStringLiteral("GetManagedObjects"), argumentList);
- }
-
-Q_SIGNALS: // SIGNALS
- void InterfacesAdded(const QDBusObjectPath &object, InterfaceList interfaces);
- void InterfacesRemoved(const QDBusObjectPath &object, const QStringList &interfaces);
-};
-
-namespace org {
- namespace freedesktop {
- namespace DBus {
- typedef ::OrgFreedesktopDBusObjectManagerInterface ObjectManager;
- }
- }
-}
-#endif
diff --git a/src/nfc/neard/dbusproperties.cpp b/src/nfc/neard/dbusproperties.cpp
deleted file mode 100644
index 554b83d6..00000000
--- a/src/nfc/neard/dbusproperties.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v dbus-properties.xml -p dbusproperties -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * This file may have been hand-edited. Look for HAND-EDIT comments
- * before re-generating it.
- */
-
-#include "dbusproperties_p.h" // HAND_EDIT
-
-/*
- * Implementation of interface class OrgFreedesktopDBusPropertiesInterface
- */
-
-OrgFreedesktopDBusPropertiesInterface::OrgFreedesktopDBusPropertiesInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
- : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
-{
-}
-
-OrgFreedesktopDBusPropertiesInterface::~OrgFreedesktopDBusPropertiesInterface()
-{
-}
-
diff --git a/src/nfc/neard/dbusproperties_p.h b/src/nfc/neard/dbusproperties_p.h
deleted file mode 100644
index ebca6278..00000000
--- a/src/nfc/neard/dbusproperties_p.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.freedesktop.dbus.properties.xml -p dbusproperties_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * Do not edit! All changes made to it will be lost.
- */
-
-#ifndef DBUSPROPERTIES_H_1409915780
-#define DBUSPROPERTIES_H_1409915780
-
-#include <QtCore/QObject>
-#include <QtCore/QByteArray>
-#include <QtCore/QList>
-#include <QtCore/QMap>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtCore/QVariant>
-#include <QtDBus/QtDBus>
-
-/*
- * Proxy class for interface org.freedesktop.DBus.Properties
- */
-class OrgFreedesktopDBusPropertiesInterface: public QDBusAbstractInterface
-{
- Q_OBJECT
-public:
- static inline const char *staticInterfaceName()
- { return "org.freedesktop.DBus.Properties"; }
-
-public:
- OrgFreedesktopDBusPropertiesInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
-
- ~OrgFreedesktopDBusPropertiesInterface();
-
-public Q_SLOTS: // METHODS
- inline QDBusPendingReply<QDBusVariant> Get(const QString &interface, const QString &name)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(interface) << QVariant::fromValue(name);
- return asyncCallWithArgumentList(QStringLiteral("Get"), argumentList);
- }
-
- inline QDBusPendingReply<QVariantMap> GetAll(const QString &interface)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(interface);
- return asyncCallWithArgumentList(QStringLiteral("GetAll"), argumentList);
- }
-
- inline QDBusPendingReply<> Set(const QString &interface, const QString &name, const QDBusVariant &value)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(interface) << QVariant::fromValue(name) << QVariant::fromValue(value);
- return asyncCallWithArgumentList(QStringLiteral("Set"), argumentList);
- }
-
-Q_SIGNALS: // SIGNALS
- void PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties);
-};
-
-namespace org {
- namespace freedesktop {
- namespace DBus {
- typedef ::OrgFreedesktopDBusPropertiesInterface Properties;
- }
- }
-}
-#endif
diff --git a/src/nfc/neard/manager.cpp b/src/nfc/neard/manager.cpp
deleted file mode 100644
index e1d72c6e..00000000
--- a/src/nfc/neard/manager.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.neard.Manager.xml -p manager_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * This file may have been hand-edited. Look for HAND-EDIT comments
- * before re-generating it.
- */
-
-#include "manager_p.h"
-
-/*
- * Implementation of interface class OrgNeardManagerInterface
- */
-
-OrgNeardManagerInterface::OrgNeardManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
- : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
-{
-}
-
-OrgNeardManagerInterface::~OrgNeardManagerInterface()
-{
-}
diff --git a/src/nfc/neard/manager_p.h b/src/nfc/neard/manager_p.h
deleted file mode 100644
index 921c177b..00000000
--- a/src/nfc/neard/manager_p.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.neard.Manager.xml -p manager_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * Do not edit! All changes made to it will be lost.
- */
-
-#ifndef MANAGER_P_H_1410442485
-#define MANAGER_P_H_1410442485
-
-#include <QtCore/QObject>
-#include <QtCore/QByteArray>
-#include <QtCore/QList>
-#include <QtCore/QMap>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtCore/QVariant>
-#include <QtDBus/QtDBus>
-
-/*
- * Proxy class for interface org.neard.Manager
- */
-class OrgNeardManagerInterface: public QDBusAbstractInterface
-{
- Q_OBJECT
-public:
- static inline const char *staticInterfaceName()
- { return "org.neard.Manager"; }
-
-public:
- OrgNeardManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
-
- ~OrgNeardManagerInterface();
-
-public Q_SLOTS: // METHODS
- inline QDBusPendingReply<QVariantMap> GetProperties()
- {
- QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QStringLiteral("GetProperties"), argumentList);
- }
-
- inline QDBusPendingReply<> RegisterHandoverAgent(const QDBusObjectPath &path)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(path);
- return asyncCallWithArgumentList(QStringLiteral("RegisterHandoverAgent"), argumentList);
- }
-
- inline QDBusPendingReply<> RegisterNDEFAgent(const QDBusObjectPath &path, const QString &type)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(path) << QVariant::fromValue(type);
- return asyncCallWithArgumentList(QStringLiteral("RegisterNDEFAgent"), argumentList);
- }
-
- inline QDBusPendingReply<> SetProperty(const QString &name, const QDBusVariant &value)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(name) << QVariant::fromValue(value);
- return asyncCallWithArgumentList(QStringLiteral("SetProperty"), argumentList);
- }
-
- inline QDBusPendingReply<> UnregisterHandoverAgent(const QDBusObjectPath &path)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(path);
- return asyncCallWithArgumentList(QStringLiteral("UnregisterHandoverAgent"), argumentList);
- }
-
- inline QDBusPendingReply<> UnregisterNDEFAgent(const QDBusObjectPath &path, const QString &type)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(path) << QVariant::fromValue(type);
- return asyncCallWithArgumentList(QStringLiteral("UnregisterNDEFAgent"), argumentList);
- }
-
-Q_SIGNALS: // SIGNALS
- void AdapterAdded(const QDBusObjectPath &adapter);
- void AdapterRemoved(const QDBusObjectPath &adapter);
- void PropertyChanged(const QString &name, const QDBusVariant &value);
-};
-
-namespace org {
- namespace neard {
- typedef ::OrgNeardManagerInterface Manager;
- }
-}
-#endif
diff --git a/src/nfc/neard/neard.pri b/src/nfc/neard/neard.pri
deleted file mode 100644
index 8120a784..00000000
--- a/src/nfc/neard/neard.pri
+++ /dev/null
@@ -1,22 +0,0 @@
-HEADERS += neard/adapter_p.h \
- neard/manager_p.h \
- neard/tag_p.h \
- neard/agent_p.h \
- neard/dbusproperties_p.h \
- neard/dbusobjectmanager_p.h \
- neard/neard_helper_p.h
-
-SOURCES += neard/adapter.cpp \
- neard/manager.cpp \
- neard/tag.cpp \
- neard/agent.cpp \
- neard/dbusproperties.cpp \
- neard/dbusobjectmanager.cpp \
- neard/neard_helper.cpp
-
-OTHER_FILES += neard/org.freedesktop.dbus.objectmanager.xml \
- neard/org.freedesktop.dbus.properties.xml \
- neard/org.neard.Adapter.xml \
- neard/org.neard.Agent.xml \
- neard/org.neard.Manager.xml \
- neard/org.neard.Tag.xml
diff --git a/src/nfc/neard/neard_dbus_types_p.h b/src/nfc/neard/neard_dbus_types_p.h
new file mode 100644
index 00000000..b85b3252
--- /dev/null
+++ b/src/nfc/neard/neard_dbus_types_p.h
@@ -0,0 +1,28 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 BasysKom GmbH.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef NEARD_DBUS_TYPES_P_H
+#define NEARD_DBUS_TYPES_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QMetaType>
+#include <QDBusObjectPath>
+
+typedef QMap<QString, QVariantMap> InterfaceList;
+typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList;
+
+Q_DECLARE_METATYPE(InterfaceList)
+Q_DECLARE_METATYPE(ManagedObjectList)
+
+#endif // NEARD_DBUS_TYPES_P_H
diff --git a/src/nfc/neard/neard_helper.cpp b/src/nfc/neard/neard_helper.cpp
index 90781a5b..3cd65bab 100644
--- a/src/nfc/neard/neard_helper.cpp
+++ b/src/nfc/neard/neard_helper.cpp
@@ -1,46 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 BasysKom GmbH.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 BasysKom GmbH.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QDBusMetaType>
#include "neard_helper_p.h"
-#include "dbusobjectmanager_p.h"
+#include "objectmanager_interface.h"
QT_BEGIN_NAMESPACE
diff --git a/src/nfc/neard/neard_helper_p.h b/src/nfc/neard/neard_helper_p.h
index e3258d5d..9964e547 100644
--- a/src/nfc/neard/neard_helper_p.h
+++ b/src/nfc/neard/neard_helper_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 BasysKom GmbH.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 BasysKom GmbH.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef NEARD_HELPER_P_H
#define NEARD_HELPER_P_H
@@ -52,14 +16,7 @@
// We mean it.
//
-#include <QMetaType>
-#include <QDBusObjectPath>
-
-typedef QMap<QString, QVariantMap> InterfaceList;
-typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList;
-
-Q_DECLARE_METATYPE(InterfaceList)
-Q_DECLARE_METATYPE(ManagedObjectList)
+#include "neard_dbus_types_p.h"
class OrgFreedesktopDBusObjectManagerInterface;
diff --git a/src/nfc/neard/org.freedesktop.dbus.objectmanager.xml b/src/nfc/neard/org.freedesktop.dbus.objectmanager.xml
index ae16f410..43427725 100644
--- a/src/nfc/neard/org.freedesktop.dbus.objectmanager.xml
+++ b/src/nfc/neard/org.freedesktop.dbus.objectmanager.xml
@@ -9,7 +9,7 @@
<signal name="InterfacesAdded">
<arg name="object" type="o"/>
<arg name="interfaces" type="a{sa{sv}}"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="InterfaceList"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="InterfaceList"/>
</signal>
<signal name="InterfacesRemoved">
<arg name="object" type="o"/>
diff --git a/src/nfc/neard/org.freedesktop.dbus.properties.xml b/src/nfc/neard/org.freedesktop.dbus.properties.xml
index 1449d567..6e22c586 100644
--- a/src/nfc/neard/org.freedesktop.dbus.properties.xml
+++ b/src/nfc/neard/org.freedesktop.dbus.properties.xml
@@ -20,7 +20,7 @@
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
diff --git a/src/nfc/neard/org.neard.Agent.xml b/src/nfc/neard/org.neard.Agent.xml
deleted file mode 100644
index 5ec0e487..00000000
--- a/src/nfc/neard/org.neard.Agent.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
-"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
-<node>
- <interface name="org.neard.NDEFAgent">
- <method name="GetNDEF">
- <arg name="values" type="a{sv}" direction="in"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
- </method>
- <method name="Release">
- </method>
- </interface>
- <interface name="org.neard.HandoverAgent">
- <method name="RequestOOB">
- <arg name="values" type="a{sv}" direction="in"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
- <arg name="result" type="a{sv}" direction="out"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
- </method>
- <method name="PushOOB">
- <arg name="values" type="a{sv}" direction="in"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
- </method>
- <method name="Release">
- </method>
- </interface>
-</node>
diff --git a/src/nfc/neard/org.neard.Manager.xml b/src/nfc/neard/org.neard.Manager.xml
deleted file mode 100644
index 1ed92378..00000000
--- a/src/nfc/neard/org.neard.Manager.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
-"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
-<node>
- <interface name="org.neard.Manager">
- <method name="GetProperties">
- <arg name="properties" type="a{sv}" direction="out"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
- </method>
- <method name="SetProperty">
- <arg name="name" type="s" direction="in"/>
- <arg name="value" type="v" direction="in"/>
- </method>
- <method name="RegisterHandoverAgent">
- <arg name="path" type="o" direction="in"/>
- </method>
- <method name="UnregisterHandoverAgent">
- <arg name="path" type="o" direction="in"/>
- </method>
- <method name="RegisterNDEFAgent">
- <arg name="path" type="o" direction="in"/>
- <arg name="type" type="s" direction="in"/>
- </method>
- <method name="UnregisterNDEFAgent">
- <arg name="path" type="o" direction="in"/>
- <arg name="type" type="s" direction="in"/>
- </method>
- <signal name="PropertyChanged">
- <arg name="name" type="s"/>
- <arg name="value" type="v"/>
- </signal>
- <signal name="AdapterAdded">
- <arg name="adapter" type="o"/>
- </signal>
- <signal name="AdapterRemoved">
- <arg name="adapter" type="o"/>
- </signal>
- </interface>
-</node>
diff --git a/src/nfc/neard/tag.cpp b/src/nfc/neard/tag.cpp
deleted file mode 100644
index 918f7f2d..00000000
--- a/src/nfc/neard/tag.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.neard.Tag.xml -p tag_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * This file may have been hand-edited. Look for HAND-EDIT comments
- * before re-generating it.
- */
-
-#include "tag_p.h"
-
-/*
- * Implementation of interface class OrgNeardTagInterface
- */
-
-OrgNeardTagInterface::OrgNeardTagInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
- : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
-{
-}
-
-OrgNeardTagInterface::~OrgNeardTagInterface()
-{
-}
diff --git a/src/nfc/neard/tag_p.h b/src/nfc/neard/tag_p.h
deleted file mode 100644
index c9a3aad3..00000000
--- a/src/nfc/neard/tag_p.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -v org.neard.Tag.xml -p tag_p -v
- *
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
- *
- * This is an auto-generated file.
- * Do not edit! All changes made to it will be lost.
- */
-
-#ifndef TAG_P_H_1410941369
-#define TAG_P_H_1410941369
-
-#include <QtCore/QObject>
-#include <QtCore/QByteArray>
-#include <QtCore/QList>
-#include <QtCore/QMap>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtCore/QVariant>
-#include <QtDBus/QtDBus>
-
-/*
- * Proxy class for interface org.neard.Tag
- */
-class OrgNeardTagInterface: public QDBusAbstractInterface
-{
- Q_OBJECT
-public:
- static inline const char *staticInterfaceName()
- { return "org.neard.Tag"; }
-
-public:
- OrgNeardTagInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
-
- ~OrgNeardTagInterface();
-
-public Q_SLOTS: // METHODS
- inline QDBusPendingReply<QByteArray> GetRawNDEF()
- {
- QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QStringLiteral("GetRawNDEF"), argumentList);
- }
-
- inline QDBusPendingReply<> Write(const QVariantMap &attributes)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(attributes);
- return asyncCallWithArgumentList(QStringLiteral("Write"), argumentList);
- }
-
-Q_SIGNALS: // SIGNALS
-};
-
-namespace org {
- namespace neard {
- typedef ::OrgNeardTagInterface Tag;
- }
-}
-#endif
diff --git a/src/nfc/nfc.pro b/src/nfc/nfc.pro
deleted file mode 100644
index c6ae147d..00000000
--- a/src/nfc/nfc.pro
+++ /dev/null
@@ -1,134 +0,0 @@
-TARGET = QtNfc
-QT = core
-DEFINES += QT_NO_FOREACH
-
-QMAKE_DOCS = $$PWD/doc/qtnfc.qdocconf
-OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator
-
-HEADERS += \
- qtnfcglobal.h \
- qnearfieldmanager.h \
- qnearfieldtarget.h \
- qndefrecord.h \
- qndefnfctextrecord.h \
- qndefmessage.h \
- qndeffilter.h \
- qndefnfcurirecord.h \
- qqmlndefrecord.h \
- qndefnfcsmartposterrecord.h \
- qnearfieldsharemanager.h \
- qnearfieldsharetarget.h \
- qtnfcglobal_p.h \
- qllcpsocket_p.h \
- qllcpserver_p.h \
- qndefrecord_p.h \
- qnearfieldtarget_p.h \
- qnearfieldmanager_p.h \
- qnearfieldtagtype1_p.h \
- qnearfieldtagtype2_p.h \
- qnearfieldtagtype3_p.h \
- qnearfieldtagtype4_p.h \
- qtlv_p.h \
- qndefnfcsmartposterrecord_p.h \
- qnearfieldsharemanager_p.h \
- qnearfieldsharetarget_p.h
-
-SOURCES += \
- qnearfieldmanager.cpp \
- qnearfieldtarget.cpp \
- qndefrecord.cpp \
- qndefnfctextrecord.cpp \
- qndefmessage.cpp \
- qndeffilter.cpp \
- qndefnfcurirecord.cpp \
- qnearfieldtagtype1.cpp \
- qnearfieldtagtype2.cpp \
- qnearfieldtagtype3.cpp \
- qllcpsocket.cpp \
- qnearfieldtagtype4.cpp \
- qtlv.cpp \
- qllcpserver.cpp \
- qqmlndefrecord.cpp \
- qndefnfcsmartposterrecord.cpp \
- qnearfieldsharemanager.cpp \
- qnearfieldsharetarget.cpp \
- qnfc.cpp
-
-linux:!android:qtHaveModule(dbus) {
- NFC_BACKEND_AVAILABLE = yes
-
- QT_PRIVATE += dbus
-
- DEFINES += NEARD_NFC
-
- HEADERS += \
- qllcpsocket_p_p.h \
- qllcpserver_p_p.h \
- qnearfieldmanager_neard_p.h \
- qnearfieldsharemanagerimpl_p.h \
- qnearfieldsharetargetimpl_p.h \
- qnearfieldtarget_neard_p.h
-
- SOURCES += \
- qllcpsocket_p.cpp \
- qllcpserver_p.cpp \
- qnearfieldsharemanagerimpl_p.cpp \
- qnearfieldsharetargetimpl_p.cpp \
- qnearfieldmanager_neard.cpp \
- qnearfieldtarget_neard_p.cpp
-
- include(neard/neard.pri)
-
-} else:android:!android-embedded {
- NFC_BACKEND_AVAILABLE = yes
- DEFINES += QT_ANDROID_NFC
- ANDROID_PERMISSIONS = \
- android.permission.NFC
- ANDROID_BUNDLED_JAR_DEPENDENCIES = \
- jar/QtNfc.jar:org.qtproject.qt5.android.nfc.QtNfc
- DEFINES += ANDROID_NFC
- QT_PRIVATE += core-private gui androidextras
-
- HEADERS += \
- qllcpserver_android_p.h \
- qllcpsocket_android_p.h \
- android/androidjninfc_p.h \
- qnearfieldmanager_android_p.h \
- qnearfieldtarget_android_p.h \
- qnearfieldsharemanagerimpl_p.h \
- qnearfieldsharetargetimpl_p.h \
- android/androidmainnewintentlistener_p.h
-
-
- SOURCES += \
- qllcpserver_android_p.cpp \
- qllcpsocket_android_p.cpp \
- android/androidjninfc.cpp \
- qnearfieldmanager_android.cpp \
- qnearfieldtarget_android.cpp \
- qnearfieldtarget_android_p.cpp \
- qnearfieldsharemanagerimpl_p.cpp \
- qnearfieldsharetargetimpl_p.cpp \
- android/androidmainnewintentlistener.cpp
-}
-
-isEmpty(NFC_BACKEND_AVAILABLE) {
- message("Unsupported NFC platform, will not build a working QtNfc library.")
-
- HEADERS += \
- qllcpsocket_p_p.h \
- qllcpserver_p_p.h \
- qnearfieldmanagerimpl_p.h \
- qnearfieldsharemanagerimpl_p.h \
- qnearfieldsharetargetimpl_p.h
-
- SOURCES += \
- qllcpsocket_p.cpp \
- qllcpserver_p.cpp \
- qnearfieldmanagerimpl_p.cpp \
- qnearfieldsharemanagerimpl_p.cpp \
- qnearfieldsharetargetimpl_p.cpp \
- qnearfieldtarget_p.cpp
-}
-
-load(qt_module)
diff --git a/src/nfc/pcsc/qpcsc.cpp b/src/nfc/pcsc/qpcsc.cpp
new file mode 100644
index 00000000..ec8bdd23
--- /dev/null
+++ b/src/nfc/pcsc/qpcsc.cpp
@@ -0,0 +1,32 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qpcsc_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt::StringLiterals;
+
+namespace QPcsc {
+
+QString errorMessage(LONG error)
+{
+#ifdef Q_OS_WIN
+ return (u"0x%1"_s).arg(error, 8, 16, QLatin1Char('0'));
+#else
+ return QString::fromUtf8(pcsc_stringify_error(error));
+#endif
+}
+
+} // namespace QPcsc
+
+qsizetype QPcscSlotName::nameSize(QPcscSlotName::CPtr p)
+{
+#ifdef Q_OS_WIN
+ return wcslen(p);
+#else
+ return strlen(p);
+#endif
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/pcsc/qpcsc_p.h b/src/nfc/pcsc/qpcsc_p.h
new file mode 100644
index 00000000..fba1085f
--- /dev/null
+++ b/src/nfc/pcsc/qpcsc_p.h
@@ -0,0 +1,72 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPCSC_P_H
+#define QPCSC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifdef Q_OS_WIN
+# include <qt_windows.h>
+#endif
+#include <QtCore/QtGlobal>
+#ifdef Q_OS_DARWIN
+# include <PCSC/winscard.h>
+# include <PCSC/wintypes.h>
+#else
+# include <winscard.h>
+#endif
+#include <QtCore/QByteArray>
+#include <QtCore/QString>
+
+QT_BEGIN_NAMESPACE
+
+namespace QPcsc {
+struct RawCommandResult
+{
+ LONG ret = SCARD_E_READER_UNAVAILABLE;
+ QByteArray response;
+
+ bool isOk() const { return ret == SCARD_S_SUCCESS; }
+};
+
+QString errorMessage(LONG error);
+
+} // namespace QPcsc
+
+class QPcscSlotName : public
+#ifdef Q_OS_WIN
+ QString
+#else
+ QByteArray
+#endif
+{
+public:
+#ifdef Q_OS_WIN
+ using CPtr = LPCWSTR;
+ using Ptr = LPWSTR;
+ explicit QPcscSlotName(CPtr p) : QString(reinterpret_cast<const QChar *>(p)) { }
+#else
+ using CPtr = LPCSTR;
+ using Ptr = LPSTR;
+ explicit QPcscSlotName(CPtr p) : QByteArray(p) { }
+#endif
+
+ CPtr ptr() const noexcept { return reinterpret_cast<CPtr>(constData()); }
+ Ptr ptr() { return reinterpret_cast<Ptr>(data()); }
+
+ static qsizetype nameSize(CPtr p);
+};
+
+QT_END_NAMESPACE
+
+#endif // QPCSC_P_H
diff --git a/src/nfc/pcsc/qpcsccard.cpp b/src/nfc/pcsc/qpcsccard.cpp
new file mode 100644
index 00000000..e06ac6f0
--- /dev/null
+++ b/src/nfc/pcsc/qpcsccard.cpp
@@ -0,0 +1,419 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qpcsccard_p.h"
+#include "ndef/qnfctagtype4ndeffsm_p.h"
+#include "qapduutils_p.h"
+#include <QtCore/QLoggingCategory>
+#include <QtCore/QTimer>
+
+#if defined(Q_OS_DARWIN)
+# define SCARD_ATTR_MAXINPUT 0x0007A007
+#elif !defined(Q_OS_WIN)
+# include <reader.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_NFC_PCSC)
+
+/*
+ Windows SCardBeginTransaction() documentation says the following:
+
+ If a transaction is held on the card for more than five seconds with no
+ operations happening on that card, then the card is reset. Calling any
+ of the Smart Card and Reader Access Functions or Direct Card Access
+ Functions on the card that is transacted results in the timer being
+ reset to continue allowing the transaction to be used.
+
+ We use a timer to ensure that transactions do not timeout unexpectedly.
+*/
+static constexpr int KeepAliveIntervalMs = 2500;
+
+/*
+ Start a temporary transaction if a persistent transaction was not already
+ started due to call to onSendCommandRequest().
+
+ If a temporary transaction was initiated, it is ended when this object is
+ destroyed.
+*/
+QPcscCard::Transaction::Transaction(QPcscCard *card) : m_card(card)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ if (!m_card->isValid() || m_card->m_inAutoTransaction)
+ return;
+
+ auto ret = SCardBeginTransaction(m_card->m_handle);
+ if (ret != SCARD_S_SUCCESS) {
+ qCWarning(QT_NFC_PCSC) << "SCardBeginTransaction failed:" << QPcsc::errorMessage(ret);
+ m_card->invalidate();
+ return;
+ }
+
+ m_initiated = true;
+}
+
+QPcscCard::Transaction::~Transaction()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ if (!m_initiated || !m_card->isValid())
+ return;
+
+ auto ret = SCardEndTransaction(m_card->m_handle, SCARD_LEAVE_CARD);
+
+ if (ret != SCARD_S_SUCCESS) {
+ qCWarning(QT_NFC_PCSC) << "SCardEndTransaction failed:" << QPcsc::errorMessage(ret);
+ m_card->invalidate();
+ }
+}
+
+QPcscCard::QPcscCard(SCARDHANDLE handle, DWORD protocol, QObject *parent)
+ : QObject(parent), m_handle(handle)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ m_keepAliveTimer = new QTimer(this);
+ m_keepAliveTimer->setInterval(KeepAliveIntervalMs);
+ connect(m_keepAliveTimer, &QTimer::timeout, this, &QPcscCard::onKeepAliveTimeout);
+
+ m_ioPci.dwProtocol = protocol;
+ m_ioPci.cbPciLength = sizeof(m_ioPci);
+
+ // Assume that everything is NFC Tag Type 4 for now
+ m_tagDetectionFsm = std::make_unique<QNfcTagType4NdefFsm>();
+
+ performNdefDetection();
+}
+
+QPcscCard::~QPcscCard()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ invalidate();
+}
+
+void QPcscCard::performNdefDetection()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid)
+ return;
+
+ Transaction transaction(this);
+
+ auto action = m_tagDetectionFsm->detectNdefSupport();
+
+ while (action == QNdefAccessFsm::SendCommand) {
+ auto command = m_tagDetectionFsm->getCommand(action);
+
+ if (action == QNdefAccessFsm::ProvideResponse) {
+ auto result = sendCommand(command, NoAutoTransaction);
+ action = m_tagDetectionFsm->provideResponse(result.response);
+ }
+ }
+
+ qCDebug(QT_NFC_PCSC) << "NDEF detection result" << action;
+
+ m_supportsNdef = action == QNdefAccessFsm::Done;
+ qCDebug(QT_NFC_PCSC) << "NDEF supported:" << m_supportsNdef;
+}
+
+/*
+ Release the resource associated with the card and notify the NFC target
+ about disconnection. The card is deleted when automatic deletion is enabled.
+*/
+void QPcscCard::invalidate()
+{
+ if (!m_isValid)
+ return;
+
+ SCardDisconnect(m_handle, m_inAutoTransaction ? SCARD_RESET_CARD : SCARD_LEAVE_CARD);
+
+ m_isValid = false;
+ m_inAutoTransaction = false;
+
+ Q_EMIT disconnected();
+ Q_EMIT invalidated();
+
+ if (m_autodelete)
+ deleteLater();
+}
+
+/*
+ Send the given command to the card.
+
+ Start an automatic transaction if autoTransaction is StartAutoTransaction
+ and it is not already started. This automatic transaction lasts until the
+ invalidate() or onDisconnectRequest() is called.
+
+ The automatic transaction is used to ensure that other applications do not
+ interfere with commands sent by the user application.
+
+ If autoTransaction is NoAutoTransaction, then the calling code should ensure
+ that either the command is atomic or that a temporary transaction is started
+ using Transaction object.
+*/
+QPcsc::RawCommandResult QPcscCard::sendCommand(const QByteArray &command,
+ QPcscCard::AutoTransaction autoTransaction)
+{
+ if (!m_isValid)
+ return {};
+
+ if (!m_inAutoTransaction && autoTransaction == StartAutoTransaction) {
+ qCDebug(QT_NFC_PCSC) << "Starting transaction";
+
+ // FIXME: Is there a timeout on this?
+ auto ret = SCardBeginTransaction(m_handle);
+ if (ret != SCARD_S_SUCCESS) {
+ qCWarning(QT_NFC_PCSC) << "SCardBeginTransaction failed:" << QPcsc::errorMessage(ret);
+ invalidate();
+ return {};
+ }
+ m_inAutoTransaction = true;
+ m_keepAliveTimer->start();
+ }
+
+ QPcsc::RawCommandResult result;
+ result.response.resize(0xFFFF + 2);
+ DWORD recvLength = result.response.size();
+
+ qCDebug(QT_NFC_PCSC) << "TX:" << command.toHex(':');
+
+ result.ret = SCardTransmit(m_handle, &m_ioPci, reinterpret_cast<LPCBYTE>(command.constData()),
+ command.size(), nullptr,
+ reinterpret_cast<LPBYTE>(result.response.data()), &recvLength);
+ if (result.ret != SCARD_S_SUCCESS) {
+ qCWarning(QT_NFC_PCSC) << "SCardTransmit failed:" << QPcsc::errorMessage(result.ret);
+ result.response.clear();
+ invalidate();
+ } else {
+ result.response.resize(recvLength);
+ qCDebug(QT_NFC_PCSC) << "RX:" << result.response.toHex(':');
+ }
+
+ return result;
+}
+
+void QPcscCard::onKeepAliveTimeout()
+{
+ if (!m_isValid || !m_inAutoTransaction) {
+ m_keepAliveTimer->stop();
+ return;
+ }
+
+ checkCardPresent();
+}
+
+QByteArray QPcscCard::readUid()
+{
+ QByteArray command = QCommandApdu::build(0xFF, QCommandApdu::GetData, 0x00, 0x00, {}, 256);
+
+ // Atomic command, no need for transaction.
+ QResponseApdu res(sendCommand(command, NoAutoTransaction).response);
+ if (!res.isOk())
+ return {};
+ return res.data();
+}
+
+void QPcscCard::onReadNdefMessagesRequest(const QNearFieldTarget::RequestId &request)
+{
+ if (!m_isValid) {
+ Q_EMIT requestCompleted(request, QNearFieldTarget::ConnectionError, {});
+ return;
+ }
+
+ if (!m_supportsNdef) {
+ Q_EMIT requestCompleted(request, QNearFieldTarget::UnsupportedError, {});
+ return;
+ }
+
+ Transaction transaction(this);
+
+ QList<QNdefMessage> messages;
+
+ auto nextState = m_tagDetectionFsm->readMessages();
+
+ while (true) {
+ if (nextState == QNdefAccessFsm::SendCommand) {
+ auto command = m_tagDetectionFsm->getCommand(nextState);
+
+ if (nextState == QNdefAccessFsm::ProvideResponse) {
+ auto result = sendCommand(command, NoAutoTransaction);
+ nextState = m_tagDetectionFsm->provideResponse(result.response);
+ }
+ } else if (nextState == QNdefAccessFsm::GetMessage) {
+ auto message = m_tagDetectionFsm->getMessage(nextState);
+ Q_EMIT ndefMessageRead(message);
+ } else {
+ break;
+ }
+ }
+
+ qCDebug(QT_NFC_PCSC) << "Final state:" << nextState;
+ auto errorCode = (nextState == QNdefAccessFsm::Done) ? QNearFieldTarget::NoError
+ : QNearFieldTarget::NdefReadError;
+ Q_EMIT requestCompleted(request, errorCode, {});
+}
+
+/*
+ Ends the persistent transaction and resets the card if sendCommand() was
+ used by user.
+
+ Resetting the card ensures that the current state of the card does not get
+ shared with other processes.
+*/
+void QPcscCard::onDisconnectRequest()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid)
+ return;
+
+ LONG ret;
+ if (m_inAutoTransaction) {
+ // NOTE: PCSCLite does not automatically release transaction in
+ // SCardReconnect(): https://salsa.debian.org/rousseau/PCSC/-/issues/11
+ ret = SCardEndTransaction(m_handle, SCARD_RESET_CARD);
+ if (ret != SCARD_S_SUCCESS) {
+ qCWarning(QT_NFC_PCSC) << "SCardEndTransaction failed:" << QPcsc::errorMessage(ret);
+ invalidate();
+ return;
+ }
+
+ m_inAutoTransaction = false;
+ }
+
+ DWORD activeProtocol;
+ ret = SCardReconnect(m_handle, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
+ SCARD_LEAVE_CARD, &activeProtocol);
+ if (ret != SCARD_S_SUCCESS) {
+ qCWarning(QT_NFC_PCSC) << "SCardReconnect failed:" << QPcsc::errorMessage(ret);
+ invalidate();
+ return;
+ }
+
+ Q_EMIT disconnected();
+}
+
+void QPcscCard::onTargetDestroyed()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ invalidate();
+}
+
+void QPcscCard::onSendCommandRequest(const QNearFieldTarget::RequestId &request,
+ const QByteArray &command)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid) {
+ Q_EMIT requestCompleted(request, QNearFieldTarget::ConnectionError, {});
+ return;
+ }
+
+ auto result = sendCommand(command, StartAutoTransaction);
+ if (result.isOk())
+ Q_EMIT requestCompleted(request, QNearFieldTarget::NoError, result.response);
+ else
+ Q_EMIT requestCompleted(request, QNearFieldTarget::CommandError, {});
+}
+
+void QPcscCard::onWriteNdefMessagesRequest(const QNearFieldTarget::RequestId &request,
+ const QList<QNdefMessage> &messages)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid) {
+ Q_EMIT requestCompleted(request, QNearFieldTarget::ConnectionError, {});
+ return;
+ }
+
+ if (!m_supportsNdef) {
+ Q_EMIT requestCompleted(request, QNearFieldTarget::UnsupportedError, {});
+ return;
+ }
+
+ Transaction transaction(this);
+
+ auto nextState = m_tagDetectionFsm->writeMessages(messages);
+
+ while (nextState == QNdefAccessFsm::SendCommand) {
+ auto command = m_tagDetectionFsm->getCommand(nextState);
+ if (nextState == QNdefAccessFsm::ProvideResponse) {
+ auto result = sendCommand(command, NoAutoTransaction);
+ nextState = m_tagDetectionFsm->provideResponse(result.response);
+ }
+ }
+
+ auto errorCode = (nextState == QNdefAccessFsm::Done) ? QNearFieldTarget::NoError
+ : QNearFieldTarget::NdefWriteError;
+ Q_EMIT requestCompleted(request, errorCode, {});
+}
+
+/*
+ Enable automatic card deletion when the connection is closed by the user
+ or the card otherwise becomes unavailable.
+
+ The automatic deletion is prevented initially so that
+ QNearFieldManagerPrivate can safely establish connections between this
+ object and a QNearFieldTargetPrivate proxy.
+*/
+void QPcscCard::enableAutodelete()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ m_autodelete = true;
+ if (!m_isValid)
+ deleteLater();
+}
+
+/*
+ Check if the card is still present in the reader.
+
+ Invalidates the object if card is not present.
+*/
+bool QPcscCard::checkCardPresent()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid)
+ return false;
+
+ DWORD state;
+ auto ret = SCardStatus(m_handle, nullptr, nullptr, &state, nullptr, nullptr, nullptr);
+ if (ret != SCARD_S_SUCCESS) {
+ qCWarning(QT_NFC_PCSC) << "SCardStatus failed:" << QPcsc::errorMessage(ret);
+ invalidate();
+ return false;
+ }
+
+ qCDebug(QT_NFC_PCSC) << "State:" << Qt::hex << state;
+
+ return (state & SCARD_PRESENT) != 0;
+}
+
+int QPcscCard::readMaxInputLength()
+{
+ if (!m_isValid)
+ return 0;
+
+ // Maximum standard APDU length
+ static constexpr int DefaultMaxInputLength = 261;
+
+ uint32_t maxInput;
+ DWORD attrSize = sizeof(maxInput);
+ auto ret = SCardGetAttrib(m_handle, SCARD_ATTR_MAXINPUT, reinterpret_cast<LPBYTE>(&maxInput),
+ &attrSize);
+ if (ret != SCARD_S_SUCCESS) {
+ qCDebug(QT_NFC_PCSC) << "SCardGetAttrib failed:" << QPcsc::errorMessage(ret);
+ return DefaultMaxInputLength;
+ }
+
+ if (attrSize != sizeof(maxInput)) {
+ qCWarning(QT_NFC_PCSC) << "Unexpected attribute size for SCARD_ATTR_MAXINPUT:" << attrSize;
+ return DefaultMaxInputLength;
+ }
+
+ return static_cast<int>(maxInput);
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/pcsc/qpcsccard_p.h b/src/nfc/pcsc/qpcsccard_p.h
new file mode 100644
index 00000000..0fe580e2
--- /dev/null
+++ b/src/nfc/pcsc/qpcsccard_p.h
@@ -0,0 +1,96 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPCSCCARD_P_H
+#define QPCSCCARD_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qpcsc_p.h"
+#include "qndefmessage.h"
+#include "qnearfieldtarget.h"
+#include "ndef/qndefaccessfsm_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTimer;
+
+class QPcscCard : public QObject
+{
+ Q_OBJECT
+public:
+ QPcscCard(SCARDHANDLE handle, DWORD protocol, QObject *parent = nullptr);
+ ~QPcscCard();
+
+ bool isValid() const { return m_isValid; }
+ void invalidate();
+
+ bool checkCardPresent();
+ Q_INVOKABLE void enableAutodelete();
+
+ QByteArray readUid();
+ int readMaxInputLength();
+
+ bool supportsNdef() const { return m_supportsNdef; }
+
+private:
+ SCARDHANDLE m_handle;
+ SCARD_IO_REQUEST m_ioPci;
+ bool m_isValid = true;
+ bool m_supportsNdef;
+ bool m_autodelete = false;
+ // Indicates that an _automatic_ transaction was started
+ bool m_inAutoTransaction = false;
+ QTimer *m_keepAliveTimer;
+
+ std::unique_ptr<QNdefAccessFsm> m_tagDetectionFsm;
+
+ enum AutoTransaction { NoAutoTransaction, StartAutoTransaction };
+
+ QPcsc::RawCommandResult sendCommand(const QByteArray &command, AutoTransaction autoTransaction);
+ void performNdefDetection();
+
+ class Transaction
+ {
+ public:
+ Transaction(QPcscCard *card);
+ ~Transaction();
+
+ private:
+ QPcscCard *m_card;
+ bool m_initiated = false;
+ };
+
+public Q_SLOTS:
+ void onDisconnectRequest();
+ void onTargetDestroyed();
+ void onSendCommandRequest(const QNearFieldTarget::RequestId &request,
+ const QByteArray &command);
+ void onReadNdefMessagesRequest(const QNearFieldTarget::RequestId &request);
+ void onWriteNdefMessagesRequest(const QNearFieldTarget::RequestId &request,
+ const QList<QNdefMessage> &messages);
+
+private Q_SLOTS:
+ void onKeepAliveTimeout();
+
+Q_SIGNALS:
+ void disconnected();
+ void invalidated();
+
+ void requestCompleted(const QNearFieldTarget::RequestId &request,
+ QNearFieldTarget::Error reason, const QVariant &result);
+ void ndefMessageRead(const QNdefMessage &message);
+};
+
+QT_END_NAMESPACE
+
+#endif // QPCSCCARD_P_H
diff --git a/src/nfc/pcsc/qpcscmanager.cpp b/src/nfc/pcsc/qpcscmanager.cpp
new file mode 100644
index 00000000..f5b358a5
--- /dev/null
+++ b/src/nfc/pcsc/qpcscmanager.cpp
@@ -0,0 +1,357 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qpcscmanager_p.h"
+#include "qpcscslot_p.h"
+#include "qpcsccard_p.h"
+#include <QtCore/QLoggingCategory>
+#include <QtCore/QThread>
+#include <QtCore/QTimer>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_NFC_PCSC)
+
+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(pollInterval);
+ connect(m_stateUpdateTimer, &QTimer::timeout, this, &QPcscManager::onStateUpdate);
+}
+
+QPcscManager::~QPcscManager()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ if (m_hasContext) {
+ // Destroy all card handles before destroying the PCSC context.
+ for (auto slot : std::as_const(m_slots))
+ slot->invalidateInsertedCard();
+ SCardReleaseContext(m_context);
+ }
+
+ // Stop the worker thread.
+ thread()->quit();
+}
+
+void QPcscManager::processSlotUpdates()
+{
+ for (auto &state : m_slotStates) {
+ auto slot = static_cast<QPcscSlot *>(state.pvUserData);
+ Q_ASSERT(slot != nullptr);
+
+ if ((state.dwEventState & SCARD_STATE_UNKNOWN) != 0)
+ continue;
+
+ if (state.dwEventState == state.dwCurrentState)
+ continue;
+
+ qCDebug(QT_NFC_PCSC) << Qt::hex << state.dwCurrentState << "=>" << state.dwEventState << ":"
+ << slot->name();
+
+ state.dwCurrentState = state.dwEventState;
+ slot->processStateChange(state.dwEventState, m_targetDetectionRunning);
+ }
+}
+
+/*
+ Remove slots that no longer need to be tracked.
+*/
+void QPcscManager::removeSlots()
+{
+ for (auto &state : m_slotStates) {
+ auto slot = static_cast<QPcscSlot *>(state.pvUserData);
+ Q_ASSERT(slot != nullptr);
+
+ // Remove slots that no longer exist, or all slots without cards if
+ // target detection is stopped.
+ if ((state.dwEventState & SCARD_STATE_UNKNOWN) != 0
+ || !(m_targetDetectionRunning || slot->hasCard())) {
+ qCDebug(QT_NFC_PCSC) << "Removing slot:" << slot;
+ state.dwEventState = SCARD_STATE_UNKNOWN;
+ slot->invalidateInsertedCard();
+ m_slots.remove(slot->name());
+ slot->deleteLater();
+ state.pvUserData = nullptr;
+ }
+ }
+
+ // Remove state tracking entries for slots that no longer exist.
+ m_slotStates.removeIf(
+ [](const auto &state) { return (state.dwEventState & SCARD_STATE_UNKNOWN) != 0; });
+}
+
+/*
+ Reads the system slot lists and marks slots that no longer exists, also
+ creates new slot entries if target detection is currently running.
+*/
+void QPcscManager::updateSlotList()
+{
+ Q_ASSERT(m_hasContext);
+
+#ifndef SCARD_AUTOALLOCATE
+ // macOS does not support automatic allocation. Try using a fixed-size
+ // buffer first, extending it if it is not sufficient.
+#define LIST_READER_BUFFER_EXTRA 1024
+ QPcscSlotName buf(nullptr);
+ DWORD listSize = LIST_READER_BUFFER_EXTRA;
+ buf.resize(listSize);
+ QPcscSlotName::Ptr list = buf.ptr();
+
+ auto ret = SCardListReaders(m_context, nullptr, list, &listSize);
+#else
+ QPcscSlotName::Ptr list;
+ DWORD listSize = SCARD_AUTOALLOCATE;
+ auto ret = SCardListReaders(m_context, nullptr, reinterpret_cast<QPcscSlotName::Ptr>(&list),
+ &listSize);
+#endif
+
+ if (ret == LONG(SCARD_E_NO_READERS_AVAILABLE)) {
+ list = nullptr;
+ ret = SCARD_S_SUCCESS;
+ }
+#ifndef SCARD_AUTOALLOCATE
+ else if (ret == LONG(SCARD_E_INSUFFICIENT_BUFFER)) {
+ // SCardListReaders() has set listSize to the required size. We add
+ // extra space to reduce possibility of failure if the reader list has
+ // changed since the last call.
+ listSize += LIST_READER_BUFFER_EXTRA;
+ buf.resize(listSize);
+ list = buf.ptr();
+
+ ret = SCardListReaders(m_context, nullptr, list, &listSize);
+ if (ret == LONG(SCARD_E_NO_READERS_AVAILABLE)) {
+ list = nullptr;
+ ret = SCARD_S_SUCCESS;
+ }
+ }
+#undef LIST_READER_BUFFER_EXTRA
+#endif
+
+ if (ret != SCARD_S_SUCCESS) {
+ qCDebug(QT_NFC_PCSC) << "Failed to list readers:" << QPcsc::errorMessage(ret);
+ return;
+ }
+
+#ifdef SCARD_AUTOALLOCATE
+ auto freeList = qScopeGuard([this, list] {
+ if (list) {
+ Q_ASSERT(m_hasContext);
+ SCardFreeMemory(m_context, list);
+ }
+ });
+#endif
+
+ QSet<QPcscSlotName> presentSlots;
+
+ if (list != nullptr) {
+ for (const auto *p = list; *p; p += QPcscSlotName::nameSize(p) + 1)
+ presentSlots.insert(QPcscSlotName(p));
+ }
+
+ // Check current state list and mark slots that are not present anymore to
+ // be removed later.
+ for (auto &state : m_slotStates) {
+ auto slot = static_cast<QPcscSlot *>(state.pvUserData);
+ Q_ASSERT(slot != nullptr);
+
+ if (presentSlots.contains(slot->name()))
+ presentSlots.remove(slot->name());
+ else
+ state.dwEventState = SCARD_STATE_UNKNOWN;
+ }
+
+ if (!m_targetDetectionRunning)
+ return;
+
+ // Add new slots
+ for (auto &&slotName : std::as_const(presentSlots)) {
+ QPcscSlot *slot = new QPcscSlot(slotName, this);
+ qCDebug(QT_NFC_PCSC) << "New slot:" << slot;
+
+ m_slots[slotName] = slot;
+
+ SCARD_READERSTATE state {};
+ state.pvUserData = slot;
+ state.szReader = slot->name().ptr();
+ state.dwCurrentState = SCARD_STATE_UNAWARE;
+
+ m_slotStates.append(state);
+ }
+}
+
+bool QPcscManager::establishContext()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ Q_ASSERT(!m_hasContext);
+
+ LONG ret = SCardEstablishContext(SCARD_SCOPE_USER, nullptr, nullptr, &m_context);
+ if (ret != SCARD_S_SUCCESS) {
+ qCWarning(QT_NFC_PCSC) << "Failed to establish context:" << QPcsc::errorMessage(ret);
+ return false;
+ }
+ m_hasContext = true;
+
+ return true;
+}
+
+void QPcscManager::onStateUpdate()
+{
+ if (!m_hasContext) {
+ if (!m_targetDetectionRunning) {
+ m_stateUpdateTimer->stop();
+ return;
+ }
+
+ if (!establishContext())
+ return;
+ }
+
+ updateSlotList();
+ removeSlots();
+
+ if (m_slotStates.isEmpty()) {
+ if (!m_targetDetectionRunning) {
+ // Free the context if it is no longer needed to card tracking.
+ SCardReleaseContext(m_context);
+ m_hasContext = false;
+
+ m_stateUpdateTimer->stop();
+ }
+ return;
+ }
+
+ // Both Windows and PCSCLite support interruptable continuos state detection
+ // where SCardCancel() can be used to abort it from another thread.
+ // But that introduces a problem of reliable cancelling of the status change
+ // call and no other. Reliable use of SCardCancel() would probably require
+ // some form of synchronization and polling, and would make the code much
+ // more complicated.
+ // Alternatively, the state detection code could run in a yet another thread
+ // that will not need to be cancelled too often.
+ // For simplicity, the current code just checks for status changes every
+ // second.
+ LONG ret = SCardGetStatusChange(m_context, 0, m_slotStates.data(), m_slotStates.size());
+
+ if (ret == SCARD_S_SUCCESS || ret == LONG(SCARD_E_UNKNOWN_READER)) {
+ processSlotUpdates();
+ removeSlots();
+ } else if (ret == LONG(SCARD_E_CANCELLED) || ret == LONG(SCARD_E_UNKNOWN_READER)
+ || ret == LONG(SCARD_E_TIMEOUT)) {
+ /* ignore */
+ } else {
+ qCWarning(QT_NFC_PCSC) << "SCardGetStatusChange failed:" << QPcsc::errorMessage(ret);
+
+ // Unknown failure. It is likely that the current context will not
+ // recover from it, so destroy it and try to create a new context at the
+ // next iteration.
+ Q_ASSERT(m_hasContext);
+ m_hasContext = false;
+ for (auto slot : std::as_const(m_slots)) {
+ slot->invalidateInsertedCard();
+ slot->deleteLater();
+ }
+ SCardReleaseContext(m_context);
+ m_slots.clear();
+ m_slotStates.clear();
+ }
+}
+
+void QPcscManager::onStartTargetDetectionRequest(QNearFieldTarget::AccessMethod accessMethod)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ m_requestedMethod = accessMethod;
+
+ if (m_targetDetectionRunning)
+ return;
+
+ m_targetDetectionRunning = true;
+ m_stateUpdateTimer->start();
+}
+
+void QPcscManager::onStopTargetDetectionRequest()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ m_targetDetectionRunning = false;
+}
+
+QPcscCard *QPcscManager::connectToCard(QPcscSlot *slot)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ Q_ASSERT(slot != nullptr);
+ Q_ASSERT(m_hasContext);
+
+ SCARDHANDLE cardHandle;
+ DWORD activeProtocol;
+
+ LONG ret = SCardConnect(m_context, slot->name().ptr(), SCARD_SHARE_SHARED,
+ SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &cardHandle, &activeProtocol);
+ if (ret != SCARD_S_SUCCESS) {
+ qCDebug(QT_NFC_PCSC) << "Failed to connect to card:" << QPcsc::errorMessage(ret);
+ retryCardDetection(slot);
+ return nullptr;
+ }
+
+ auto card = new QPcscCard(cardHandle, activeProtocol, this);
+ auto uid = card->readUid();
+ auto maxInputLength = card->readMaxInputLength();
+
+ QNearFieldTarget::AccessMethods accessMethods = QNearFieldTarget::TagTypeSpecificAccess;
+ if (card->supportsNdef())
+ accessMethods |= QNearFieldTarget::NdefAccess;
+
+ if (m_requestedMethod != QNearFieldTarget::UnknownAccess
+ && (accessMethods & m_requestedMethod) == 0) {
+ qCDebug(QT_NFC_PCSC) << "Dropping card without required access support";
+ card->deleteLater();
+ return nullptr;
+ }
+
+ if (!card->isValid()) {
+ qCDebug(QT_NFC_PCSC) << "Card became invalid";
+ card->deleteLater();
+
+ retryCardDetection(slot);
+
+ return nullptr;
+ }
+
+ Q_EMIT cardInserted(card, uid, accessMethods, maxInputLength);
+
+ return card;
+}
+
+/*
+ Setup states list so that the card detection for the given slot will
+ be retried on the next iteration.
+
+ This is useful to try to get cards working after reset.
+*/
+void QPcscManager::retryCardDetection(const QPcscSlot *slot)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ for (auto &state : m_slotStates) {
+ if (state.pvUserData == slot) {
+ state.dwCurrentState = SCARD_STATE_UNAWARE;
+ break;
+ }
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/pcsc/qpcscmanager_p.h b/src/nfc/pcsc/qpcscmanager_p.h
new file mode 100644
index 00000000..d35edf57
--- /dev/null
+++ b/src/nfc/pcsc/qpcscmanager_p.h
@@ -0,0 +1,65 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPCSCMANAGER_P_H
+#define QPCSCMANAGER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qpcsc_p.h"
+#include "qnearfieldtarget.h"
+
+QT_BEGIN_NAMESPACE
+
+class QPcscSlot;
+class QPcscCard;
+class QTimer;
+
+class QPcscManager : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QPcscManager(QObject *parent = nullptr);
+ ~QPcscManager() override;
+
+ QPcscCard *connectToCard(QPcscSlot *slot);
+
+private:
+ QTimer *m_stateUpdateTimer;
+ bool m_targetDetectionRunning = false;
+ bool m_hasContext = false;
+ SCARDCONTEXT m_context;
+ QMap<QPcscSlotName, QPcscSlot *> m_slots;
+ QList<SCARD_READERSTATE> m_slotStates;
+ QNearFieldTarget::AccessMethod m_requestedMethod;
+
+ [[nodiscard]] bool establishContext();
+ void processSlotUpdates();
+ void updateSlotList();
+ void removeSlots();
+ void retryCardDetection(const QPcscSlot *slot);
+
+public Q_SLOTS:
+ void onStartTargetDetectionRequest(QNearFieldTarget::AccessMethod accessMethod);
+ void onStopTargetDetectionRequest();
+
+private Q_SLOTS:
+ void onStateUpdate();
+
+Q_SIGNALS:
+ void cardInserted(QPcscCard *card, const QByteArray &uid,
+ QNearFieldTarget::AccessMethods accessMethods, int maxInputLength);
+};
+
+QT_END_NAMESPACE
+
+#endif // QPCSCMANAGER_P_H
diff --git a/src/nfc/pcsc/qpcscslot.cpp b/src/nfc/pcsc/qpcscslot.cpp
new file mode 100644
index 00000000..cf55cf7b
--- /dev/null
+++ b/src/nfc/pcsc/qpcscslot.cpp
@@ -0,0 +1,57 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qpcscslot_p.h"
+#include "qpcscmanager_p.h"
+#include "qpcsccard_p.h"
+#include <QtCore/QLoggingCategory>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_NFC_PCSC)
+
+QPcscSlot::QPcscSlot(const QPcscSlotName &name, QPcscManager *manager)
+ : QObject(manager), m_name(name)
+{
+}
+
+QPcscSlot::~QPcscSlot()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO << this;
+ if (m_insertedCard)
+ m_insertedCard->invalidate();
+}
+
+void QPcscSlot::processStateChange(DWORD eventId, bool createCards)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ // Check if the currently inserted card is still valid
+ if (!m_insertedCard.isNull()) {
+ if (m_insertedCard->checkCardPresent())
+ return;
+ qCDebug(QT_NFC_PCSC) << "Removing card from slot" << m_name;
+ m_insertedCard->invalidate();
+ m_insertedCard.clear();
+ }
+
+ auto manager = qobject_cast<QPcscManager *>(parent());
+
+ if (manager != nullptr && createCards
+ && (eventId
+ & (SCARD_STATE_PRESENT | SCARD_STATE_MUTE | SCARD_STATE_UNPOWERED
+ | SCARD_STATE_EXCLUSIVE))
+ == SCARD_STATE_PRESENT) {
+ qCDebug(QT_NFC_PCSC) << "New card in slot" << m_name;
+
+ m_insertedCard = manager->connectToCard(this);
+ }
+}
+
+void QPcscSlot::invalidateInsertedCard()
+{
+ if (m_insertedCard)
+ m_insertedCard->invalidate();
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/pcsc/qpcscslot_p.h b/src/nfc/pcsc/qpcscslot_p.h
new file mode 100644
index 00000000..c335b47a
--- /dev/null
+++ b/src/nfc/pcsc/qpcscslot_p.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPCSCSLOT_P_H
+#define QPCSCSLOT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qpcsc_p.h"
+#include <QtCore/QObject>
+#include <QtCore/QPointer>
+
+QT_BEGIN_NAMESPACE
+
+class QPcscManager;
+class QPcscCard;
+
+class QPcscSlot : public QObject
+{
+ Q_OBJECT
+public:
+ QPcscSlot(const QPcscSlotName &name, QPcscManager *manager);
+ ~QPcscSlot() override;
+
+ const QPcscSlotName &name() const { return m_name; }
+ void processStateChange(DWORD eventId, bool createCards);
+ bool hasCard() const { return !m_insertedCard.isNull(); }
+ void invalidateInsertedCard();
+
+private:
+ const QPcscSlotName m_name;
+ QPointer<QPcscCard> m_insertedCard;
+};
+
+QT_END_NAMESPACE
+
+#endif // QPCSCSLOT_P_H
diff --git a/src/nfc/qapduutils.cpp b/src/nfc/qapduutils.cpp
new file mode 100644
index 00000000..057e4346
--- /dev/null
+++ b/src/nfc/qapduutils.cpp
@@ -0,0 +1,81 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qapduutils_p.h"
+#include <QtCore/QtEndian>
+
+QT_BEGIN_NAMESPACE
+
+/*
+ Utilities for handling smart card application protocol data units (APDU).
+
+ The structure of APDUs is defined by ISO/IEC 7816-4 Organization, security
+ and commands for interchange. The summary can be found on Wikipedia:
+
+ https://en.wikipedia.org/wiki/Smart_card_application_protocol_data_unit
+*/
+
+/*
+ Parses a response APDU from the raw data.
+
+ If the data is too short to contain SW bytes, the returned responses SW
+ is set to QResponseApdu::Empty.
+*/
+QResponseApdu::QResponseApdu(const QByteArray &response)
+{
+ if (response.size() < 2) {
+ m_status = Empty;
+ m_data = response;
+ } else {
+ const auto dataSize = response.size() - 2;
+ m_status = qFromBigEndian(qFromUnaligned<uint16_t>(response.constData() + dataSize));
+ m_data = response.left(dataSize);
+ }
+}
+
+/*
+ Builds a command APDU from components according to ISO/IEC 7816.
+*/
+QByteArray QCommandApdu::build(uint8_t cla, uint8_t ins, uint8_t p1, uint8_t p2,
+ QByteArrayView data, uint16_t ne)
+{
+ Q_ASSERT(data.size() <= 0xFFFF);
+
+ QByteArray apdu;
+ apdu.append(static_cast<char>(cla));
+ apdu.append(static_cast<char>(ins));
+ apdu.append(static_cast<char>(p1));
+ apdu.append(static_cast<char>(p2));
+
+ bool extendedLc = false;
+ uint16_t nc = data.size();
+
+ if (nc > 0) {
+ if (nc < 256) {
+ apdu.append(static_cast<char>(nc));
+ } else {
+ extendedLc = true;
+ apdu.append('\0');
+ apdu.append(static_cast<char>(nc >> 8));
+ apdu.append(static_cast<char>(nc & 0xFF));
+ }
+ apdu.append(data);
+ }
+
+ if (ne) {
+ if (ne < 256) {
+ apdu.append(static_cast<char>(ne));
+ } else if (ne == 256) {
+ apdu.append(static_cast<char>('\0'));
+ } else {
+ if (!extendedLc)
+ apdu.append('\0');
+ apdu.append(static_cast<char>(ne >> 8));
+ apdu.append(static_cast<char>(ne & 0xFF));
+ }
+ }
+
+ return apdu;
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/qapduutils_p.h b/src/nfc/qapduutils_p.h
new file mode 100644
index 00000000..dd777b03
--- /dev/null
+++ b/src/nfc/qapduutils_p.h
@@ -0,0 +1,53 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAPDUUTILS_P_H
+#define QAPDUUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QByteArray>
+
+QT_BEGIN_NAMESPACE
+
+class QResponseApdu
+{
+public:
+ static constexpr uint16_t Empty = 0x0000;
+ static constexpr uint16_t Success = 0x9000;
+
+ explicit QResponseApdu(const QByteArray &response = {});
+
+ const QByteArray &data() const { return m_data; }
+ uint16_t status() const { return m_status; }
+ bool isOk() const { return m_status == Success; }
+
+private:
+ QByteArray m_data;
+ uint16_t m_status;
+};
+
+namespace QCommandApdu {
+
+// INS byte values for command APDUs
+constexpr uint8_t Select = 0xA4;
+constexpr uint8_t ReadBinary = 0xB0;
+constexpr uint8_t GetData = 0xCA;
+constexpr uint8_t UpdateBinary = 0xD6;
+
+QByteArray build(uint8_t cla, uint8_t ins, uint8_t p1, uint8_t p2, QByteArrayView data,
+ uint16_t ne = 0);
+};
+
+QT_END_NAMESPACE
+
+#endif // QAPDUUTILS_P_H
diff --git a/src/nfc/qllcpserver.cpp b/src/nfc/qllcpserver.cpp
deleted file mode 100644
index 66831b9f..00000000
--- a/src/nfc/qllcpserver.cpp
+++ /dev/null
@@ -1,200 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qllcpserver_p.h"
-
-#if defined(QT_SIMULATOR)
-#include "qllcpserver_simulator_p.h"
-#elif defined(QT_ANDROID_NFC)
-#include "qllcpserver_android_p.h"
-#else
-#include "qllcpserver_p_p.h"
-#endif
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QLlcpServer
- \brief The QLlcpServer class provides an NFC LLCP socket based server.
- \internal
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
-
- This class makes it possible to accept incoming LLCP socket connections.
-
- Call listen() to have the server start listening for incoming connections on a specified port.
- The newConnection() signal is then emitted each time a client connects to the server.
-
- Call nextPendingConnection() to accept the pending connection as a connected QLlcpSocket. The
- function returns a pointer to a QLlcpSocket that can be used for communicating with the client.
-
- If an error occurs, serverError() returns the type of error, and errorString() can be called to
- get a human readable description of what happened.
-
- When listening for connections, the port which the server is listening on is available through
- serverPort().
-
- Calling close() makes QLlcpServer stop listening for incoming connections.
-*/
-
-/*!
- \fn QLlcpServer::newConnection()
-
- This signal is emitted every time a new connection is available.
-
- \sa hasPendingConnections(), nextPendingConnection()
-*/
-
-/*!
- Constructs a new NFC LLCP server with \a parent.
-*/
-QLlcpServer::QLlcpServer(QObject *parent)
-: QObject(parent), d_ptr(new QLlcpServerPrivate(this))
-{
-}
-
-/*!
- Destroys the NFC LLCP server.
-*/
-QLlcpServer::~QLlcpServer()
-{
- delete d_ptr;
-}
-
-/*!
- Tells the server to listen for incoming connections on \a serviceUri. If the server is
- currently listening then it will return false. Returns true on success; otherwise returns
- false.
-
- serviceUri() will return the \a serviceUri that is passed into listen.
-
- serverPort() will return the port that is assigned to the server.
-
- \sa serverPort(), isListening(), close()
-*/
-bool QLlcpServer::listen(const QString &serviceUri)
-{
- Q_D(QLlcpServer);
-
- return d->listen(serviceUri);
-}
-
-/*!
- Returns true if the server is listening for incoming connections; otherwise returns false.
-*/
-bool QLlcpServer::isListening() const
-{
- Q_D(const QLlcpServer);
-
- return d->isListening();
-}
-
-/*!
- Stops listening for incoming connections.
-*/
-void QLlcpServer::close()
-{
- Q_D(QLlcpServer);
-
- d->close();
-}
-
-/*!
- Returns the LLCP service URI that the server is listening on.
-*/
-QString QLlcpServer::serviceUri() const
-{
- Q_D(const QLlcpServer);
-
- return d->serviceUri();
-}
-
-/*!
- Returns the LLCP port associated with the service URI that the server is listening on.
- This call is not supported on all platforms and will return 0 on these platforms.
-*/
-quint8 QLlcpServer::serverPort() const
-{
- Q_D(const QLlcpServer);
-
- return d->serverPort();
-}
-
-/*!
- Returns true if the server has a pending connection; otherwise returns false.
-
- \sa nextPendingConnection()
-*/
-bool QLlcpServer::hasPendingConnections() const
-{
- Q_D(const QLlcpServer);
-
- return d->hasPendingConnections();
-}
-
-/*!
- Returns the next pending connection as a connected QLlcpSocket object.
-
- The socket is created as a child of the server, which means that it is automatically deleted
- when the QLlcpServer object is destroyed. It is still a good idea to delete the object
- explicitly when you are done with it, to avoid wasting memory.
-
- 0 is returned if this function is called when there are no pending connections.
-
- \sa hasPendingConnections(), newConnection()
-*/
-QLlcpSocket *QLlcpServer::nextPendingConnection()
-{
- Q_D(QLlcpServer);
-
- return d->nextPendingConnection();
-}
-
-/*!
- Returns the last error that occurred.
-*/
-QLlcpSocket::SocketError QLlcpServer::serverError() const
-{
- Q_D(const QLlcpServer);
-
- return d->serverError();
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qllcpserver_android_p.cpp b/src/nfc/qllcpserver_android_p.cpp
deleted file mode 100644
index eb0306a0..00000000
--- a/src/nfc/qllcpserver_android_p.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qllcpserver_android_p.h"
-//#include "qnx/qnxnfcmanager_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QLlcpServerPrivate::QLlcpServerPrivate(QLlcpServer *q)
- : q_ptr(q), m_llcpSocket(0), m_connected(false)
-{
-}
-
-QLlcpServerPrivate::~QLlcpServerPrivate()
-{
-}
-
-bool QLlcpServerPrivate::listen(const QString &/*serviceUri*/)
-{
- /*//The server is already listening
- if (isListening())
- return false;
-
- nfc_result_t result = nfc_llcp_register_connection_listener(NFC_LLCP_SERVER, 0, serviceUri.toStdString().c_str(), &m_conListener);
- m_connected = true;
- if (result == NFC_RESULT_SUCCESS) {
- m_serviceUri = serviceUri;
- qQNXNFCDebug() << "LLCP server registered" << serviceUri;
- } else {
- qWarning() << Q_FUNC_INFO << "Could not register for llcp connection listener";
- return false;
- }
- QNXNFCManager::instance()->registerLLCPConnection(m_conListener, this);*/
- return true;
-}
-
-bool QLlcpServerPrivate::isListening() const
-{
- return m_connected;
-}
-
-void QLlcpServerPrivate::close()
-{
- /*nfc_llcp_unregister_connection_listener(m_conListener);
- QNXNFCManager::instance()->unregisterLLCPConnection(m_conListener);
- m_serviceUri = QString();
- m_connected = false;*/
-}
-
-QString QLlcpServerPrivate::serviceUri() const
-{
- return m_serviceUri;
-}
-
-quint8 QLlcpServerPrivate::serverPort() const
-{
- /*unsigned int sap;
- if (nfc_llcp_get_local_sap(m_target, &sap) == NFC_RESULT_SUCCESS) {
- return sap;
- }*/
- return -1;
-}
-
-bool QLlcpServerPrivate::hasPendingConnections() const
-{
- return m_llcpSocket != 0;
-}
-
-QLlcpSocket *QLlcpServerPrivate::nextPendingConnection()
-{
- /*QLlcpSocket *socket = m_llcpSocket;
- m_llcpSocket = 0;
- return socket;*/
- return 0;
-}
-
-QLlcpSocket::SocketError QLlcpServerPrivate::serverError() const
-{
- return QLlcpSocket::UnknownSocketError;
-}
-
-/*void QLlcpServerPrivate::connected(nfc_target_t *target)
-{
- m_target = target;
- if (m_llcpSocket != 0) {
- qWarning() << Q_FUNC_INFO << "LLCP socket not cloesed properly";
- return;
- }
- m_llcpSocket = new QLlcpSocket();
- m_llcpSocket->bind(serverPort());
-}*/
-
-QT_END_NAMESPACE
-
-
diff --git a/src/nfc/qllcpserver_android_p.h b/src/nfc/qllcpserver_android_p.h
deleted file mode 100644
index 5d5e2aea..00000000
--- a/src/nfc/qllcpserver_android_p.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLLCPSERVER_ANDROID_P_H
-#define QLLCPSERVER_ANDROID_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qllcpserver_p.h"
-//#include "nfc/nfc.h"
-
-QT_BEGIN_NAMESPACE
-
-class QLlcpServerPrivate : public QObject
-{
- Q_OBJECT
-public:
- QLlcpServerPrivate(QLlcpServer *q);
- ~QLlcpServerPrivate();
-
- bool listen(const QString &serviceUri);
- bool isListening() const;
-
- void close();
-
- QString serviceUri() const;
- quint8 serverPort() const;
-
- bool hasPendingConnections() const;
- QLlcpSocket *nextPendingConnection();
-
- QLlcpSocket::SocketError serverError() const;
-
- //Q_INVOKABLE void connected(nfc_target_t *);
-
-private:
- QLlcpServer *q_ptr;
- QLlcpSocket *m_llcpSocket;
- //We can not use m_conListener for the connection state
- bool m_connected;
- //nfc_llcp_connection_listener_t m_conListener;
- QString m_serviceUri;
- //nfc_target_t *m_target;
-};
-
-QT_END_NAMESPACE
-
-#endif // QLLCPSERVER_ANDROID_P_H
diff --git a/src/nfc/qllcpserver_p.cpp b/src/nfc/qllcpserver_p.cpp
deleted file mode 100644
index a3cf95bd..00000000
--- a/src/nfc/qllcpserver_p.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qllcpserver_p_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QLlcpServerPrivate::QLlcpServerPrivate(QLlcpServer *q)
-: q_ptr(q)
-{
-}
-
-QLlcpServerPrivate::~QLlcpServerPrivate()
-{
-}
-
-bool QLlcpServerPrivate::listen(const QString &serviceUri)
-{
- Q_UNUSED(serviceUri);
-
- return false;
-}
-
-bool QLlcpServerPrivate::isListening() const
-{
- return false;
-}
-
-void QLlcpServerPrivate::close()
-{
-}
-
-QString QLlcpServerPrivate::serviceUri() const
-{
- return QString();
-}
-
-quint8 QLlcpServerPrivate::serverPort() const
-{
- return 0;
-}
-
-bool QLlcpServerPrivate::hasPendingConnections() const
-{
- return false;
-}
-
-QLlcpSocket *QLlcpServerPrivate::nextPendingConnection()
-{
- return 0;
-}
-
-QLlcpSocket::SocketError QLlcpServerPrivate::serverError() const
-{
- return QLlcpSocket::UnknownSocketError;
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qllcpserver_p.h b/src/nfc/qllcpserver_p.h
deleted file mode 100644
index 33ab6f1b..00000000
--- a/src/nfc/qllcpserver_p.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLLCPSERVER_H
-#define QLLCPSERVER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/QObject>
-#include <QtNfc/qtnfcglobal.h>
-#include "qllcpsocket_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QLlcpServerPrivate;
-
-class Q_NFC_EXPORT QLlcpServer : public QObject
-{
- Q_OBJECT
-
- Q_DECLARE_PRIVATE(QLlcpServer)
-
-public:
- explicit QLlcpServer(QObject *parent = 0);
- virtual ~QLlcpServer();
-
- bool listen(const QString &serviceUri);
- bool isListening() const;
-
- void close();
-
- QString serviceUri() const;
- quint8 serverPort() const;
-
- virtual bool hasPendingConnections() const;
- virtual QLlcpSocket *nextPendingConnection();
-
- QLlcpSocket::SocketError serverError() const;
-
-signals:
- void newConnection();
-
-private:
- QLlcpServerPrivate *d_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QLLCPSERVER_H
diff --git a/src/nfc/qllcpserver_p_p.h b/src/nfc/qllcpserver_p_p.h
deleted file mode 100644
index 62cfa953..00000000
--- a/src/nfc/qllcpserver_p_p.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLLCPSERVER_P_H
-#define QLLCPSERVER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qtnfcglobal.h"
-
-#include "qllcpserver_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QLlcpServerPrivate
-{
- Q_DECLARE_PUBLIC(QLlcpServer)
-
-public:
- QLlcpServerPrivate(QLlcpServer *q);
- ~QLlcpServerPrivate();
-
- bool listen(const QString &serviceUri);
- bool isListening() const;
-
- void close();
-
- QString serviceUri() const;
- quint8 serverPort() const;
-
- bool hasPendingConnections() const;
- QLlcpSocket *nextPendingConnection();
-
- QLlcpSocket::SocketError serverError() const;
-
-private:
- QLlcpServer *q_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QLLCPSERVER_P_H
diff --git a/src/nfc/qllcpsocket.cpp b/src/nfc/qllcpsocket.cpp
deleted file mode 100644
index a3785a60..00000000
--- a/src/nfc/qllcpsocket.cpp
+++ /dev/null
@@ -1,400 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qllcpsocket_p.h"
-
-#if defined(QT_SIMULATOR)
-#include "qllcpsocket_simulator_p.h"
-#else
-#include "qllcpsocket_p_p.h"
-#endif
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QLlcpSocket
- \brief The QLlcpSocket class provides an NFC LLCP socket.
- \internal
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
-
- NFC LLCP protocol is a peer-to-peer communication protocol between two NFC compliant devices.
-*/
-
-/*!
- \enum QLlcpSocket::SocketError
-
- This enum describes the errors that can occur. The most recent error can be retrieved through a
- call to error().
-
- \value UnknownSocketError An unidentified error has occurred.
- \value RemoteHostClosedError The remote host closed the connection.
- \value SocketAccessError The socket operation failed because the application lacked the
- required privileges.
- \value SocketResourceError The local system ran out of resources (e.g., too many sockets).
-*/
-
-/*!
- \enum QLlcpSocket::SocketState
-
- This enum describes the different state in which a socket can be.
-
- \value UnconnectedState The socket is not connected.
- \value ConnectingState The socket has started establishing a connection.
- \value ConnectedState A connection is established.
- \value ClosingState The socket is about to close.
- \value BoundState The socket is bound to a local port (for servers).
- \value ListeningState The socket is listening for incoming connections (for internal use).
-*/
-
-/*!
- \fn QLlcpSocket::connected()
-
- This signal is emitted after connectToService() has been called and a connection has been
- successfully established.
-
- \sa connectToService(), disconnected()
-*/
-
-/*!
- \fn QLlcpSocket::disconnected()
-
- This signal is emitted when the socket has been disconnected.
-
- \sa disconnectFromService(),
-*/
-
-/*!
- \fn QLlcpSocket::error(QLlcpSocket::SocketError socketError)
-
- This signal is emitted when an error occurs. The \a socketError parameter describes the error.
-*/
-
-/*!
- \fn QLlcpSocket::stateChanged(QLlcpSocket::SocketState socketState)
-
- This signal is emitted when the state of the socket changes. The \a socketState parameter
- describes the new state.
-*/
-
-/*!
- Construct a new unconnected LLCP socket with \a parent.
-*/
-QLlcpSocket::QLlcpSocket(QObject *parent)
-: QIODevice(parent), d_ptr(new QLlcpSocketPrivate(this))
-{
- setOpenMode(QIODevice::NotOpen);
-}
-
-/*!
- \internal
-*/
-QLlcpSocket::QLlcpSocket(QLlcpSocketPrivate *d, QObject *parent)
-: QIODevice(parent), d_ptr(d)
-{
- setOpenMode(QIODevice::ReadWrite);
- d_ptr->q_ptr = this;
-}
-
-/*!
- Destroys the LLCP socket.
-*/
-QLlcpSocket::~QLlcpSocket()
-{
- delete d_ptr;
-}
-
-/*!
- Connects to the service identified by the URI \a serviceUri on \a target.
-*/
-void QLlcpSocket::connectToService(QNearFieldTarget *target, const QString &serviceUri)
-{
- Q_D(QLlcpSocket);
-
- d->connectToService(target, serviceUri);
-}
-
-/*!
- Disconnects the socket.
-*/
-void QLlcpSocket::disconnectFromService()
-{
- Q_D(QLlcpSocket);
-
- d->disconnectFromService();
-}
-
-/*!
- Disconnects the socket.
-*/
-void QLlcpSocket::close()
-{
- Q_D(QLlcpSocket);
-
- QIODevice::close();
-
- d->disconnectFromService();
-}
-
-/*!
- Binds the LLCP socket to local \a port. Returns true on success; otherwise returns false.
-*/
-bool QLlcpSocket::bind(quint8 port)
-{
- Q_D(QLlcpSocket);
-
- return d->bind(port);
-}
-
-/*!
- Returns true if at least one datagram (service data units) is waiting to be read; otherwise
- returns false.
-
- \sa pendingDatagramSize(), readDatagram()
-*/
-bool QLlcpSocket::hasPendingDatagrams() const
-{
- Q_D(const QLlcpSocket);
-
- return d->hasPendingDatagrams();
-}
-
-/*!
- Returns the size of the first pending datagram (service data unit). If there is no datagram
- available, this function returns -1.
-
- \sa hasPendingDatagrams(), readDatagram()
-*/
-qint64 QLlcpSocket::pendingDatagramSize() const
-{
- Q_D(const QLlcpSocket);
-
- return d->pendingDatagramSize();
-}
-
-/*!
- Sends the datagram at \a data of size \a size to the service that this socket is connected to.
- Returns the number of bytes sent on success; otherwise return -1;
-*/
-qint64 QLlcpSocket::writeDatagram(const char *data, qint64 size)
-{
- Q_D(QLlcpSocket);
-
- return d->writeDatagram(data, size);
-}
-
-/*!
- \reimp
-
- Always returns true.
-*/
-bool QLlcpSocket::isSequential() const
-{
- return true;
-}
-
-/*!
- \overload
-
- Sends the datagram \a datagram to the service that this socket is connected to.
-*/
-qint64 QLlcpSocket::writeDatagram(const QByteArray &datagram)
-{
- Q_D(QLlcpSocket);
-
- return d->writeDatagram(datagram);
-}
-
-/*!
- Receives a datagram no larger than \a maxSize bytes and stores it in \a data. The sender's
- details are stored in \a target and \a port (unless the pointers are 0).
-
- Returns the size of the datagram on success; otherwise returns -1.
-
- If maxSize is too small, the rest of the datagram will be lost. To avoid loss of data, call
- pendingDatagramSize() to determine the size of the pending datagram before attempting to read
- it. If maxSize is 0, the datagram will be discarded.
-
- \sa writeDatagram(), hasPendingDatagrams(), pendingDatagramSize()
-*/
-qint64 QLlcpSocket::readDatagram(char *data, qint64 maxSize, QNearFieldTarget **target,
- quint8 *port)
-{
- Q_D(QLlcpSocket);
-
- return d->readDatagram(data, maxSize, target, port);
-}
-
-/*!
- Sends the datagram at \a data of size \a size to the service identified by the URI
- \a port on \a target. Returns the number of bytes sent on success; otherwise returns -1.
-
- \sa readDatagram()
-*/
-qint64 QLlcpSocket::writeDatagram(const char *data, qint64 size, QNearFieldTarget *target,
- quint8 port)
-{
- Q_D(QLlcpSocket);
-
- return d->writeDatagram(data, size, target, port);
-}
-
-/*!
- \overload
-
- Sends the datagram \a datagram to the service identified by the URI \a port on \a target.
-*/
-qint64 QLlcpSocket::writeDatagram(const QByteArray &datagram, QNearFieldTarget *target,
- quint8 port)
-{
- Q_D(QLlcpSocket);
-
- return d->writeDatagram(datagram, target, port);
-}
-
-/*!
- Returns the type of error that last occurred.
-*/
-QLlcpSocket::SocketError QLlcpSocket::error() const
-{
- Q_D(const QLlcpSocket);
-
- return d->error();
-}
-
-/*!
- Returns the state of the socket.
-*/
-QLlcpSocket::SocketState QLlcpSocket::state() const
-{
- Q_D(const QLlcpSocket);
-
- return d->state();
-}
-
-/*!
- \reimp
-*/
-qint64 QLlcpSocket::bytesAvailable() const
-{
- Q_D(const QLlcpSocket);
-
- return d->bytesAvailable() + QIODevice::bytesAvailable();
-}
-
-/*!
- \reimp
-*/
-bool QLlcpSocket::canReadLine() const
-{
- Q_D(const QLlcpSocket);
-
- return d->canReadLine() || QIODevice::canReadLine();
-}
-
-/*!
- \reimp
-*/
-bool QLlcpSocket::waitForReadyRead(int msecs)
-{
- Q_D(QLlcpSocket);
-
- return d->waitForReadyRead(msecs);
-}
-
-/*!
- \reimp
-*/
-bool QLlcpSocket::waitForBytesWritten(int msecs)
-{
- Q_D(QLlcpSocket);
-
- return d->waitForBytesWritten(msecs);
-}
-
-/*!
- Waits until the socket is connected, up to \a msecs milliseconds. If the connection has been
- established, this function returns true; otherwise it returns false. In the case where it
- returns false, you can call error() to determine the cause of the error.
-
- If msecs is -1, this function will not time out.
-*/
-bool QLlcpSocket::waitForConnected(int msecs)
-{
- Q_D(QLlcpSocket);
-
- return d->waitForConnected(msecs);
-}
-
-/*!
- Waits until the socket is disconnected, up to \a msecs milliseconds. If the connection has been
- disconnected, this function returns true; otherwise it returns false. In the case where it
- returns false, you can call error() to determine the cause of the error.
-
- If msecs is -1, this function will not time out.
-*/
-bool QLlcpSocket::waitForDisconnected(int msecs)
-{
- Q_D(QLlcpSocket);
-
- return d->waitForDisconnected(msecs);
-}
-
-/*!
- \internal
-*/
-qint64 QLlcpSocket::readData(char *data, qint64 maxlen)
-{
- Q_D(QLlcpSocket);
-
- return d->readData(data, maxlen);
-}
-
-/*!
- \internal
-*/
-qint64 QLlcpSocket::writeData(const char *data, qint64 len)
-{
- Q_D(QLlcpSocket);
-
- return d->writeData(data, len);
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qllcpsocket_android_p.cpp b/src/nfc/qllcpsocket_android_p.cpp
deleted file mode 100644
index 97b8db16..00000000
--- a/src/nfc/qllcpsocket_android_p.cpp
+++ /dev/null
@@ -1,324 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qllcpsocket_android_p.h"
-#include <unistd.h>
-
-QT_BEGIN_NAMESPACE
-
-QLlcpSocketPrivate::QLlcpSocketPrivate(QLlcpSocket *q)
- : q_ptr(q), m_state(QLlcpSocket::UnconnectedState), m_server(false)
-{
-}
-
-QLlcpSocketPrivate::~QLlcpSocketPrivate()
-{
- disconnectFromService();
-}
-
-void QLlcpSocketPrivate::connectToService(QNearFieldTarget *target, const QString &serviceUri)
-{
- Q_UNUSED(target)
- Q_UNUSED(serviceUri)
- /*if (m_state != QLlcpSocket::UnconnectedState) {
- qWarning() << Q_FUNC_INFO << "socket is already connected";
- return;
- }
-
- m_state = QLlcpSocket::ConnectingState;
- if (nfc_llcp_register_connection_listener(NFC_LLCP_CLIENT, 0, serviceUri.toLocal8Bit().constData(),
- &m_conListener) != NFC_RESULT_SUCCESS) {
- qWarning() << Q_FUNC_INFO << "could not register for connection listener";
- return;
- }
-
- QNXNFCManager::instance()->registerLLCPConnection(m_conListener, this);
-
- qQNXNFCDebug() << "Connecting client socket" << serviceUri << m_conListener;
- connect(QNXNFCManager::instance(), &QNXNFCManager::llcpDisconnected, this, &QLlcpSocketPrivate::disconnectFromService);*/
-}
-
-void QLlcpSocketPrivate::disconnectFromService()
-{
- /*Q_Q(QLlcpSocket);
- QNXNFCManager::instance()->unregisterTargetLost(this);
- qQNXNFCDebug() << "Shutting down LLCP socket";
- if (!m_server && nfc_llcp_unregister_connection_listener(m_conListener) != NFC_RESULT_SUCCESS) {
- qWarning() << Q_FUNC_INFO << "Error when trying to close LLCP socket";
- }
- QNXNFCManager::instance()->unregisterLLCPConnection(m_conListener);
- disconnect(QNXNFCManager::instance(), &QNXNFCManager::llcpDisconnected, this, &QLlcpSocketPrivate::disconnectFromService);
-
- q->disconnected();
- m_conListener = 0;
- m_state = QLlcpSocket::UnconnectedState;*/
-}
-
-bool QLlcpSocketPrivate::bind(quint8 port)
-{
- Q_UNUSED(port);
-
- /*m_state = QLlcpSocket::ConnectedState;
- m_server = true;
- connect(QNXNFCManager::instance(), &QNXNFCManager::llcpDisconnected, this, &QLlcpSocketPrivate::disconnectFromService);
- connected(QNXNFCManager::instance()->getLastTarget());*/
-
- return true;
-}
-
-bool QLlcpSocketPrivate::hasPendingDatagrams() const
-{
- return !m_receivedDatagrams.isEmpty();
-}
-
-qint64 QLlcpSocketPrivate::pendingDatagramSize() const
-{
- if (m_receivedDatagrams.isEmpty())
- return -1;
-
- return m_receivedDatagrams.first().length();
-}
-
-qint64 QLlcpSocketPrivate::writeDatagram(const char *data, qint64 size)
-{
- if (m_state == QLlcpSocket::ConnectedState)
- return writeData(data, size);
-
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::writeDatagram(const QByteArray &datagram)
-{
- return writeDatagram(datagram.constData(), datagram.size());
-}
-
-qint64 QLlcpSocketPrivate::readDatagram(char *data, qint64 maxSize,
- QNearFieldTarget **target, quint8 *port)
-{
- Q_UNUSED(target);
- Q_UNUSED(port);
-
- if (m_state == QLlcpSocket::ConnectedState)
- return readData(data, maxSize);
-
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::writeDatagram(const char *data, qint64 size,
- QNearFieldTarget *target, quint8 port)
-{
- Q_UNUSED(target);
- Q_UNUSED(port);
-
- return writeDatagram(data, size);
-}
-
-qint64 QLlcpSocketPrivate::writeDatagram(const QByteArray &datagram,
- QNearFieldTarget *target, quint8 port)
-{
- Q_UNUSED(datagram);
- Q_UNUSED(target);
- Q_UNUSED(port);
-
- return writeDatagram(datagram.constData(), datagram.size()-1);
-}
-
-QLlcpSocket::SocketError QLlcpSocketPrivate::error() const
-{
- return QLlcpSocket::UnknownSocketError;
-}
-
-QLlcpSocket::SocketState QLlcpSocketPrivate::state() const
-{
- return m_state;
-}
-
-qint64 QLlcpSocketPrivate::readData(char *data, qint64 maxlen)
-{
- Q_UNUSED(data);
- Q_UNUSED(maxlen);
- if (m_receivedDatagrams.isEmpty())
- return 0;
-
- /*const QByteArray datagram = m_receivedDatagrams.takeFirst();
- qint64 size = qMin(maxlen, qint64(datagram.length()));
- memcpy(data, datagram.constData(), size);
- return size;*/
- return 0;
-}
-
-qint64 QLlcpSocketPrivate::writeData(const char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
- /*if (socketState != Idle) {
- m_writeQueue.append(QByteArray(data, len));
- return len;
- } else {
- socketState = Writing;
- qQNXNFCDebug() << "LLCP write";
- nfc_result_t res = nfc_llcp_write(m_target, (uchar_t*)data, (size_t)len);
- if (res == NFC_RESULT_SUCCESS) {
- return len;
- } else {
- qWarning() << Q_FUNC_INFO << "Error writing to LLCP socket. Error" << res;
- enteringIdle();
- return -1;
- }
- }*/
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::bytesAvailable() const
-{
- /*qint64 available = 0;
- for (const QByteArray &datagram : qAsConst(m_receivedDatagrams))
- available += datagram.length();
-
- return available;*/
- return 0;
-}
-
-bool QLlcpSocketPrivate::canReadLine() const
-{
- /*for (const QByteArray &datagram : qAsConst(m_receivedDatagrams)) {
- if (datagram.contains('\n'))
- return true;
- }*/
-
- return false;
-}
-
-bool QLlcpSocketPrivate::waitForReadyRead(int msecs)
-{
- Q_UNUSED(msecs);
-
- return false;
-}
-
-bool QLlcpSocketPrivate::waitForBytesWritten(int msecs)
-{
- Q_UNUSED(msecs);
-
- return false;
-}
-
-bool QLlcpSocketPrivate::waitForConnected(int msecs)
-{
- Q_UNUSED(msecs);
-
- return false;
-}
-
-bool QLlcpSocketPrivate::waitForDisconnected(int msecs)
-{
- Q_UNUSED(msecs);
-
- return false;
-}
-
-/*void QLlcpSocketPrivate::connected(nfc_target_t *target)
-{
- Q_Q(QLlcpSocket);
- m_target = target;
-
- m_state = QLlcpSocket::ConnectedState;
- emit q->connected();
- qQNXNFCDebug() << "Socket connected";
-
- unsigned int targetId;
- nfc_get_target_connection_id(target, &targetId);
- QNXNFCManager::instance()->requestTargetLost(this, targetId);
- enteringIdle();
-}*/
-
-void QLlcpSocketPrivate::targetLost()
-{
- disconnectFromService();
- //qQNXNFCDebug() << "LLCP target lost...socket disconnected";
-}
-
-void QLlcpSocketPrivate::dataRead(QByteArray& data)
-{
- Q_UNUSED(data);
- /*Q_Q(QLlcpSocket);
- if (!data.isEmpty()) {
- m_receivedDatagrams.append(data);
- emit q->readyRead();
- }
- socketState = Idle;
- enteringIdle();*/
-}
-
-void QLlcpSocketPrivate::dataWritten()
-{
- //enteringIdle();
-}
-
-void QLlcpSocketPrivate::read()
-{
- /*if (socketState != Idle) {
- qQNXNFCDebug() << "Trying to read but socket state not in idle..abort";
- return;
- }
- socketState = Reading;
- qQNXNFCDebug() << "LLCP read";
- if (nfc_llcp_read(m_target, 128) != NFC_RESULT_SUCCESS) {
- qWarning() << Q_FUNC_INFO << "Could not register for reading";
- socketState = Idle;
- }*/
-}
-
-void QLlcpSocketPrivate::enteringIdle()
-{
- /*qQNXNFCDebug() << "entering idle; Socket state:" << socketState;
- socketState = Idle;
- if (m_state == QLlcpSocket::ConnectedState) {
- if (m_writeQueue.isEmpty()) {
- qQNXNFCDebug() << "Write queue empty, reading in 50ms";
- QTimer::singleShot(50, this, SLOT(read()));
- } else {
- qQNXNFCDebug() << "Write first package in queue";
- writeDatagram(m_writeQueue.takeFirst());
- }
- }*/
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/nfc/qllcpsocket_android_p.h b/src/nfc/qllcpsocket_android_p.h
deleted file mode 100644
index 6109d7dd..00000000
--- a/src/nfc/qllcpsocket_android_p.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLLCPSOCKET_ANDROID_P_H
-#define QLLCPSOCKET_ANDROID_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qllcpsocket_p.h"
-
-//#include "qnearfieldtarget_ANDROID_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QLlcpSocketPrivate : public QObject
-{
- Q_OBJECT
- Q_DECLARE_PUBLIC(QLlcpSocket)
-
-public:
- QLlcpSocketPrivate(QLlcpSocket *q);
-
- ~QLlcpSocketPrivate();
-
- void connectToService(QNearFieldTarget *target, const QString &serviceUri);
-
- bool bind(quint8 port);
-
- bool hasPendingDatagrams() const;
- qint64 pendingDatagramSize() const;
-
- qint64 writeDatagram(const char *data, qint64 size);
- qint64 writeDatagram(const QByteArray &datagram);
-
- qint64 readDatagram(char *data, qint64 maxSize,
- QNearFieldTarget **target = 0, quint8 *port = 0);
- qint64 writeDatagram(const char *data, qint64 size,
- QNearFieldTarget *target, quint8 port);
- qint64 writeDatagram(const QByteArray &datagram, QNearFieldTarget *target, quint8 port);
-
- QLlcpSocket::SocketError error() const;
- QLlcpSocket::SocketState state() const;
-
- qint64 readData(char *data, qint64 maxlen);
- qint64 writeData(const char *data, qint64 len);
-
- qint64 bytesAvailable() const;
- bool canReadLine() const;
-
- bool waitForReadyRead(int msecs);
- bool waitForBytesWritten(int msecs);
- bool waitForConnected(int msecs);
- bool waitForDisconnected(int msecs);
-
- //Q_INVOKABLE void connected(nfc_target_t *);
- Q_INVOKABLE void targetLost();
-
- void dataRead(QByteArray&);
- void dataWritten();
-
-public Q_SLOTS:
- void disconnectFromService();
-
-private:
- QLlcpSocket *q_ptr;
- unsigned int m_sap;
- //nfc_llcp_connection_listener_t m_conListener;
- //NearFieldTarget *m_target;
- //nfc_target_t *m_target;
-
- QLlcpSocket::SocketState m_state;
-
- QList<QByteArray> m_receivedDatagrams;
- QList<QByteArray> m_writeQueue;
-
- bool m_server;
-
- enum llcpState {
- Idle, Reading, Writing
- } socketState;
-
-private Q_SLOTS:
- void read();
- void enteringIdle();
-};
-
-QT_END_NAMESPACE
-
-#endif // QLLCPSOCKET_ANDROID_P_H
diff --git a/src/nfc/qllcpsocket_p.cpp b/src/nfc/qllcpsocket_p.cpp
deleted file mode 100644
index f604d551..00000000
--- a/src/nfc/qllcpsocket_p.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qllcpsocket_p_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QLlcpSocketPrivate::QLlcpSocketPrivate(QLlcpSocket *q)
-: q_ptr(q)
-{
-}
-
-QLlcpSocketPrivate::~QLlcpSocketPrivate()
-{
-
-}
-
-void QLlcpSocketPrivate::connectToService(QNearFieldTarget *target, const QString &serviceUri)
-{
- Q_UNUSED(target);
- Q_UNUSED(serviceUri);
-}
-
-void QLlcpSocketPrivate::disconnectFromService()
-{
-}
-
-bool QLlcpSocketPrivate::bind(quint8 port)
-{
- Q_UNUSED(port);
-
- return false;
-}
-
-bool QLlcpSocketPrivate::hasPendingDatagrams() const
-{
- return false;
-}
-
-qint64 QLlcpSocketPrivate::pendingDatagramSize() const
-{
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::writeDatagram(const char *data, qint64 size)
-{
- Q_UNUSED(data);
- Q_UNUSED(size);
-
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::writeDatagram(const QByteArray &datagram)
-{
- Q_UNUSED(datagram);
-
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::readDatagram(char *data, qint64 maxSize,
- QNearFieldTarget **target, quint8 *port)
-{
- Q_UNUSED(data);
- Q_UNUSED(maxSize);
- Q_UNUSED(target);
- Q_UNUSED(port);
-
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::writeDatagram(const char *data, qint64 size,
- QNearFieldTarget *target, quint8 port)
-{
- Q_UNUSED(data);
- Q_UNUSED(size);
- Q_UNUSED(target);
- Q_UNUSED(port);
-
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::writeDatagram(const QByteArray &datagram,
- QNearFieldTarget *target, quint8 port)
-{
- Q_UNUSED(datagram);
- Q_UNUSED(target);
- Q_UNUSED(port);
-
- return -1;
-}
-
-QLlcpSocket::SocketError QLlcpSocketPrivate::error() const
-{
- return QLlcpSocket::UnknownSocketError;
-}
-
-QLlcpSocket::SocketState QLlcpSocketPrivate::state() const
-{
- return QLlcpSocket::UnconnectedState;
-}
-
-qint64 QLlcpSocketPrivate::readData(char *data, qint64 maxlen)
-{
- Q_UNUSED(data);
- Q_UNUSED(maxlen);
-
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::writeData(const char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
-
- return -1;
-}
-
-qint64 QLlcpSocketPrivate::bytesAvailable() const
-{
- return 0;
-}
-
-bool QLlcpSocketPrivate::canReadLine() const
-{
- return false;
-}
-
-bool QLlcpSocketPrivate::waitForReadyRead(int msecs)
-{
- Q_UNUSED(msecs);
-
- return false;
-}
-
-bool QLlcpSocketPrivate::waitForBytesWritten(int msecs)
-{
- Q_UNUSED(msecs);
-
- return false;
-}
-
-bool QLlcpSocketPrivate::waitForConnected(int msecs)
-{
- Q_UNUSED(msecs);
-
- return false;
-}
-
-bool QLlcpSocketPrivate::waitForDisconnected(int msecs)
-{
- Q_UNUSED(msecs);
-
- return false;
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qllcpsocket_p.h b/src/nfc/qllcpsocket_p.h
deleted file mode 100644
index 442367c6..00000000
--- a/src/nfc/qllcpsocket_p.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLLCPSOCKET_H
-#define QLLCPSOCKET_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/QIODevice>
-#include <QtNetwork/QAbstractSocket>
-#include <QtNfc/qtnfcglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldTarget;
-class QLlcpSocketPrivate;
-
-class Q_NFC_EXPORT QLlcpSocket : public QIODevice
-{
- Q_OBJECT
-
- Q_DECLARE_PRIVATE(QLlcpSocket)
-
- friend class QLlcpServerPrivate;
-
-public:
- enum SocketState {
- UnconnectedState = QAbstractSocket::UnconnectedState,
- ConnectingState = QAbstractSocket::ConnectingState,
- ConnectedState = QAbstractSocket::ConnectedState,
- ClosingState = QAbstractSocket::ClosingState,
- BoundState = QAbstractSocket::BoundState,
- ListeningState = QAbstractSocket::ListeningState
- };
- Q_ENUM(SocketState)
-
- enum SocketError {
- UnknownSocketError = QAbstractSocket::UnknownSocketError,
- RemoteHostClosedError = QAbstractSocket::RemoteHostClosedError,
- SocketAccessError = QAbstractSocket::SocketAccessError,
- SocketResourceError = QAbstractSocket::SocketResourceError
- };
- Q_ENUM(SocketError)
-
- explicit QLlcpSocket(QObject *parent = 0);
- ~QLlcpSocket();
-
- void connectToService(QNearFieldTarget *target, const QString &serviceUri);
- void disconnectFromService();
-
- void close();
-
- bool bind(quint8 port);
-
- bool hasPendingDatagrams() const;
- qint64 pendingDatagramSize() const;
-
- qint64 writeDatagram(const char *data, qint64 size);
- qint64 writeDatagram(const QByteArray &datagram);
-
- qint64 readDatagram(char *data, qint64 maxSize,
- QNearFieldTarget **target = 0, quint8 *port = 0);
- qint64 writeDatagram(const char *data, qint64 size,
- QNearFieldTarget *target, quint8 port);
- qint64 writeDatagram(const QByteArray &datagram, QNearFieldTarget *target, quint8 port);
-
- SocketError error() const;
- SocketState state() const;
-
- qint64 bytesAvailable() const;
- bool canReadLine() const;
-
- bool waitForReadyRead(int msecs = 30000);
- bool waitForBytesWritten(int msecs = 30000);
- virtual bool waitForConnected(int msecs = 30000);
- virtual bool waitForDisconnected(int msecs = 30000);
- bool isSequential() const;
-
-signals:
- void connected();
- void disconnected();
- void error(QLlcpSocket::SocketError socketError);
- void stateChanged(QLlcpSocket::SocketState socketState);
-
-protected:
- qint64 readData(char *data, qint64 maxlen);
- qint64 writeData(const char *data, qint64 len);
-
-private:
- QLlcpSocket(QLlcpSocketPrivate *d, QObject *parent);
-
- QLlcpSocketPrivate *d_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QLLCPSOCKET_H
diff --git a/src/nfc/qllcpsocket_p_p.h b/src/nfc/qllcpsocket_p_p.h
deleted file mode 100644
index 9a747502..00000000
--- a/src/nfc/qllcpsocket_p_p.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLLCPSOCKET_P_H
-#define QLLCPSOCKET_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qtnfcglobal.h"
-
-#include "qllcpsocket_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QLlcpSocketPrivate
-{
- Q_DECLARE_PUBLIC(QLlcpSocket)
-
-public:
- QLlcpSocketPrivate(QLlcpSocket *q);
-
- ~QLlcpSocketPrivate();
-
- void connectToService(QNearFieldTarget *target, const QString &serviceUri);
- void disconnectFromService();
-
- bool bind(quint8 port);
-
- bool hasPendingDatagrams() const;
- qint64 pendingDatagramSize() const;
-
- qint64 writeDatagram(const char *data, qint64 size);
- qint64 writeDatagram(const QByteArray &datagram);
-
- qint64 readDatagram(char *data, qint64 maxSize,
- QNearFieldTarget **target = 0, quint8 *port = 0);
- qint64 writeDatagram(const char *data, qint64 size,
- QNearFieldTarget *target, quint8 port);
- qint64 writeDatagram(const QByteArray &datagram, QNearFieldTarget *target, quint8 port);
-
- QLlcpSocket::SocketError error() const;
- QLlcpSocket::SocketState state() const;
-
- qint64 readData(char *data, qint64 maxlen);
- qint64 writeData(const char *data, qint64 len);
-
- qint64 bytesAvailable() const;
- bool canReadLine() const;
-
- bool waitForReadyRead(int msecs);
- bool waitForBytesWritten(int msecs);
- bool waitForConnected(int msecs);
- bool waitForDisconnected(int msecs);
-
-private:
- QLlcpSocket *q_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QLLCPSOCKET_P_H
diff --git a/src/nfc/qndeffilter.cpp b/src/nfc/qndeffilter.cpp
index 486ac633..4bbd0ef7 100644
--- a/src/nfc/qndeffilter.cpp
+++ b/src/nfc/qndeffilter.cpp
@@ -1,45 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qndeffilter.h"
+#include "qndefmessage.h"
#include <QtCore/QList>
+#include <QtCore/QMap>
QT_BEGIN_NAMESPACE
@@ -51,9 +17,8 @@ QT_BEGIN_NAMESPACE
\inmodule QtNfc
\since 5.2
- The QNdefFilter encapsulates the structure of an NDEF message and is used by
- QNearFieldManager::registerNdefMessageHandler() to match NDEF message that have a particular
- structure.
+ The QNdefFilter encapsulates the structure of an NDEF message and is used for
+ matching messages that have a particular structure.
The following filter matches NDEF messages that contain a single smart poster record:
@@ -72,13 +37,185 @@ QT_BEGIN_NAMESPACE
filter.appendRecord<QNdefNfcTextRecord>();
filter.appendRecord(QNdefRecord::Mime, "image/jpeg", 0, 1);
\endcode
+
+ The \l match() method can be used to check if a message matches the filter.
+
+ \section1 Matching Algorithms
+
+ The filter behavior depends on the value of \l orderMatch() parameter.
+
+ \note In the discussion below we will consider the filter records to be
+ equal if their \c typeNameFormat and \c type parameters match. Joining
+ two records means adding their \c minimum and \c maximum values,
+ respectively.
+
+ \section2 Unordered Matching
+
+ If the record order is not taken into account, all the equal records in the
+ filter can be joined. The resulting filter will contain only unique records,
+ each with the updated \c minimum and \c maximum value.
+
+ Consider the following example:
+
+ \code
+ QNdefFilter filter;
+ filter.appendRecord<QNdefNfcTextRecord>(0, 1);
+ filter.appendRecord<QNdefNfcTextRecord>(0, 1);
+ filter.appendRecord(QNdefRecord::Mime, "", 1, 1);
+ filter.appendRecord<QNdefNfcTextRecord>(1, 1);
+ filter.setOrderMatch(false);
+ \endcode
+
+ With the unordered matching, the filter will be simplified to the following:
+
+ \code
+ QNdefFilter filter;
+ filter.appendRecord<QNdefNfcTextRecord>(1, 3);
+ filter.appendRecord(QNdefRecord::Mime, "", 1, 1);
+ filter.setOrderMatch(false);
+ \endcode
+
+ Once the filter contains only the unique records, the matching algorithm
+ iterates through the message and calculates the actual amount of records of
+ each type. If all the actual amounts fit in the corresponding
+ [minimum, maximum] ranges, the matching algorithm returns \c true.
+
+ \section2 Ordered Matching
+
+ If the record order is important, a different approach is applied. In this
+ case the equal records can't be simply joined together. However, the
+ consecutive equal records can still be joined. Then, the matching
+ algorithm iterates through the message, this time also taking the positions
+ of the records into account.
+
+ \section2 Handling Empty Type in Filter Record
+
+ It's possible to add a filter record with an empty \c type. In this case
+ the empty type will act as a wildcard for any type.
+
+ For example, the filter can be defined as follows:
+
+ \code
+ QNdefFilter filter;
+ filter.addRecord(QNdefRecord::Mime, "", 1, 1);
+ \endcode
+
+ This filter specifies that the message must contain exactly one NDEF record
+ with \l {QNdefRecord::}{Mime} \l {QNdefRecord::}{typeNameFormat}(), and any
+ \l {QNdefRecord::}{type}().
+
+ \section2 Handling Extra Records in the Message
+
+ If the message contains some records that do not match \e any record in the
+ filter, the matching algorithm will return \c false.
+
+ \section2 Filter Examples
+
+ In the table below, each filter record is specified by the following
+ parameters (in the given order):
+
+ \list
+ \li \c typeNameFormat - contains the \l {QNdefRecord::}{typeNameFormat}() of
+ the record.
+ \li \c type - contains the \l {QNdefRecord::}{type}() of the record.
+ \li \c minimum - contains the minimum amount of occurrences of the record
+ in the message.
+ \li \c maximum - contains the maximum amount of occurrences of the record
+ in the message.
+ \endlist
+
+ The filter contains multiple records.
+
+ The message consists of multiple \l {QNdefRecord}s. In the table below, only
+ the \l {QNdefRecord::}{typeNameFormat}() and \l {QNdefRecord::}{type}() of
+ each record will be shown, because the other parameters do not matter for
+ filtering.
+
+ \table
+ \header
+ \li Filter
+ \li Message
+ \li Match Result
+ \li Comment
+ \row
+ \li Empty filter
+ \li Empty message
+ \li Match
+ \li
+ \row
+ \li Empty filter
+ \li Non-empty message
+ \li No match
+ \li
+ \row
+ \li Non-empty filter
+ \li Empty message
+ \li No match
+ \li
+ \row
+ \li {1, 2}[(QNdefRecord::NfcRtd, "T", 1, 2),
+ (QNdefRecord::Mime, "", 1, 1), (QNdefRecord::Empty, "", 0, 100)]
+ \li {1, 2}[(QNdefRecord::Mime, "image/jpeg"), (QNdefRecord::Empty, ""),
+ (QNdefRecord::NfcRtd, "T"), (QNdefRecord::Empty, ""),
+ (QNdefRecord::NfcRtd, "T")]
+ \li Unordered: match
+ \li {1, 2} Ordered filter does not match because the message must start
+ with a QNdefRecord::NfcRtd record, but it starts with
+ QNdefRecord::Mime.
+ \row
+ \li Ordered: no match
+ \row
+ \li {1, 2}[(QNdefRecord::NfcRtd, "T", 0, 2),
+ (QNdefRecord::Mime, "", 1, 1), (QNdefRecord::NfcRtd, "T", 1, 1)]
+ \li {1, 2}[(QNdefRecord::NfcRtd, "T"), (QNdefRecord::NfcRtd, "T"),
+ (QNdefRecord::Mime, "image/jpeg")]
+ \li Unordered: match
+ \li {1, 2} Ordered filter does not match because an QNdefRecord::NfcRtd
+ record is expected after QNdefRecord::Mime, but the message does not
+ have it.
+ \row
+ \li Ordered: no match
+ \row
+ \li {1, 2}[(QNdefRecord::NfcRtd, "T", 0, 2),
+ (QNdefRecord::NfcRtd, "T", 1, 1), (QNdefRecord::Mime, "", 1, 1)]
+ \li {1, 2}[(QNdefRecord::NfcRtd, "T"),
+ (QNdefRecord::Mime, "image/jpeg")]
+ \li Unordered: match
+ \li {1, 2} Both cases match because the message contains the required
+ minimum of records in the correct order.
+ \row
+ \li Ordered: match
+ \endtable
+
*/
/*!
- \fn void QNdefFilter::appendRecord(unsigned int min, unsigned int max)
+ \class QNdefFilter::Record
+ \brief The QNdefFilter::Record struct contains the information about a
+ filter record.
- Appends a record matching the template parameter to the NDEF filter. The record must occur
- between \a min and \a max times in the NDEF message.
+ \ingroup connectivity-nfc
+ \inmodule QtNfc
+ \since 5.2
+
+ The QNdefFilter::Record struct is used to populate the QNdefFilter object.
+ Each record contains the following information:
+ \list
+ \li \l {QNdefRecord::TypeNameFormat} of the corresponding \l QNdefRecord.
+ \li Type of the \l QNdefRecord.
+ \li Minimum and maximum amount of the records with such parameters in the
+ filter.
+ \endlist
+*/
+
+/*!
+ \fn template<typename T> bool QNdefFilter::appendRecord(unsigned int min, unsigned int max)
+
+ Appends a record matching the template parameter to the NDEF filter.
+ The record must occur between \a min and \a max times in the NDEF message.
+
+ Returns \c true if the record was appended successfully. Otherwise returns
+ \c false.
*/
class QNdefFilterPrivate : public QSharedData
@@ -104,7 +241,7 @@ QNdefFilter::QNdefFilter()
}
/*!
- constructs a new NDEF filter that is a copy of \a other.
+ Constructs a new NDEF filter that is a copy of \a other.
*/
QNdefFilter::QNdefFilter(const QNdefFilter &other)
: d(other.d)
@@ -130,6 +267,132 @@ QNdefFilter &QNdefFilter::operator=(const QNdefFilter &other)
}
/*!
+ \since 6.2
+
+ Returns \c true if the \a message matches the given filter.
+ Otherwise returns \c false.
+
+ See \l {Matching Algorithms} for more detailed explanation of matching.
+*/
+bool QNdefFilter::match(const QNdefMessage &message) const
+{
+ // empty filter matches only empty message
+ if (d->filterRecords.isEmpty())
+ return message.isEmpty();
+
+ bool matched = true;
+ int totalCount = 0;
+
+ if (!d->orderMatching) {
+ // Order is not important. The most reliable way is to merge all the
+ // similar records, and then simply check the amount of occurrences.
+ using MapKey = QPair<QNdefRecord::TypeNameFormat, QByteArray>;
+
+ // Creating a map from the list of filter records.
+ QMap<MapKey, Record> joinedFilterRecords;
+ for (const auto &rec : d->filterRecords) {
+ const auto key = qMakePair(rec.typeNameFormat, rec.type);
+ if (joinedFilterRecords.contains(key)) {
+ joinedFilterRecords[key].minimum += rec.minimum;
+ joinedFilterRecords[key].maximum += rec.maximum;
+ } else {
+ joinedFilterRecords.insert(key, rec);
+ }
+ }
+ // Checking the message, calculate occurrences.
+ QMap<MapKey, unsigned int> counts; // current number of occurrences
+ for (const auto &record : message) {
+ const auto key = qMakePair(record.typeNameFormat(), record.type());
+ // Do not forget that we handle an empty type as "any type".
+ const auto emptyTypeKey = qMakePair(record.typeNameFormat(), QByteArray());
+
+ if (joinedFilterRecords.contains(key))
+ counts[key] += 1;
+ else if (joinedFilterRecords.contains(emptyTypeKey))
+ counts[emptyTypeKey] += 1;
+ }
+ // Check that the occurrences match [min; max] range.
+ for (auto it = joinedFilterRecords.cbegin(); it != joinedFilterRecords.cend(); ++it) {
+ const auto count = counts.value(it.key(), 0);
+ totalCount += count;
+ if (count < it.value().minimum || count > it.value().maximum) {
+ matched = false;
+ break;
+ }
+ }
+ } else {
+ // Order *is* important. Need to iterate the list.
+
+ // Here we need to merge consecutive records with the same parameters.
+ QList<Record> mergedRecords;
+ // we know that filer is not empty here
+ Record currentRecord = d->filterRecords.first();
+ for (qsizetype i = 1; i < d->filterRecords.size(); ++i) {
+ const auto &rec = d->filterRecords.at(i);
+ if (rec.typeNameFormat == currentRecord.typeNameFormat
+ && rec.type == currentRecord.type) {
+ currentRecord.minimum += rec.minimum;
+ currentRecord.maximum += rec.maximum;
+ } else {
+ mergedRecords.push_back(currentRecord);
+ currentRecord = rec;
+ }
+ }
+ mergedRecords.push_back(currentRecord);
+
+ // The list contains the current number of occurrences of each record.
+ QList<unsigned int> counts(mergedRecords.size(), 0);
+
+ // Iterate through the messages and calculate the number of occurrences.
+ qsizetype filterIndex = 0;
+ for (qsizetype messageIndex = 0; matched && messageIndex < message.size(); ++messageIndex) {
+ const auto &messageRec = message.at(messageIndex);
+ // Try to find a filter record that matches the message record.
+ // We start from the last processed filter record, not from the very
+ // beginning (because the order matters).
+ qsizetype idx = filterIndex;
+ for (; idx < mergedRecords.size(); ++idx) {
+ const auto &filterRec = mergedRecords.at(idx);
+ if (filterRec.typeNameFormat == messageRec.typeNameFormat()
+ && (filterRec.type == messageRec.type() || filterRec.type.isEmpty())) {
+ counts[idx] += 1;
+ break;
+ } else if (counts[idx] < filterRec.minimum || counts[idx] > filterRec.maximum) {
+ // The current message record does not match the current
+ // filter record, but we didn't get enough records to
+ // fulfill the filter => that's an error.
+ matched = false;
+ break;
+ }
+ }
+ filterIndex = idx;
+ }
+
+ if (matched) {
+ // Check that the occurrences match [min; max] range.
+ for (qsizetype i = 0; i < mergedRecords.size(); ++i) {
+ const auto &rec = mergedRecords.at(i);
+ totalCount += counts[i];
+ if (counts[i] < rec.minimum || counts[i] > rec.maximum) {
+ matched = false;
+ break;
+ }
+ }
+ }
+ }
+
+ // Check if the message has records that do not match any record from the
+ // filter. To do it we just need to compare the total count of records,
+ // detected by filter, with the full message size. If they do not match,
+ // we have some records, that are not covered by the filter.
+ if (matched && (totalCount != message.size())) {
+ matched = false;
+ }
+
+ return matched;
+}
+
+/*!
Clears the filter.
*/
void QNdefFilter::clear()
@@ -139,9 +402,10 @@ void QNdefFilter::clear()
}
/*!
- Sets the ording requirements of the filter. If \a on is true the filter will only match if the
- order of records in the filter matches the order of the records in the NDEF message. If \a on
- is false the order of the records is not taken into account when matching.
+ Sets the ordering requirements of the filter. If \a on is \c {true}, the
+ filter will only match if the order of records in the filter matches the
+ order of the records in the NDEF message. If \a on is \c {false}, the order
+ of the records is not taken into account when matching.
By default record order is not taken into account.
*/
@@ -151,8 +415,8 @@ void QNdefFilter::setOrderMatch(bool on)
}
/*!
- Returns true if the filter takes NDEF record order into account when matching; otherwise
- returns false.
+ Returns \c true if the filter takes NDEF record order into account when
+ matching. Otherwise returns \c false.
*/
bool QNdefFilter::orderMatch() const
{
@@ -160,10 +424,14 @@ bool QNdefFilter::orderMatch() const
}
/*!
- Appends a record with type name format \a typeNameFormat and type \a type to the NDEF filter.
- The record must occur between \a min and \a max times in the NDEF message.
+ Appends a record with type name format \a typeNameFormat and type \a type
+ to the NDEF filter. The record must occur between \a min and \a max times
+ in the NDEF message.
+
+ Returns \c true if the record was appended successfully. Otherwise returns
+ \c false.
*/
-void QNdefFilter::appendRecord(QNdefRecord::TypeNameFormat typeNameFormat, const QByteArray &type,
+bool QNdefFilter::appendRecord(QNdefRecord::TypeNameFormat typeNameFormat, const QByteArray &type,
unsigned int min, unsigned int max)
{
QNdefFilter::Record record;
@@ -173,21 +441,37 @@ void QNdefFilter::appendRecord(QNdefRecord::TypeNameFormat typeNameFormat, const
record.minimum = min;
record.maximum = max;
- d->filterRecords.append(record);
+ return appendRecord(record);
+}
+
+static bool verifyRecord(const QNdefFilter::Record &record)
+{
+ return record.minimum <= record.maximum;
}
/*!
- Appends \a record to the NDEF filter.
+ Verifies the \a record and appends it to the NDEF filter.
+
+ Returns \c true if the record was appended successfully. Otherwise returns
+ \c false.
*/
-void QNdefFilter::appendRecord(const Record &record)
+bool QNdefFilter::appendRecord(const Record &record)
{
- d->filterRecords.append(record);
+ if (verifyRecord(record)) {
+ d->filterRecords.append(record);
+ return true;
+ }
+ return false;
}
/*!
Returns the NDEF record at index \a i.
+
+ \a i must be a valid index (i.e. 0 <= i < \l recordCount()).
+
+ \sa recordCount()
*/
-QNdefFilter::Record QNdefFilter::recordAt(int i) const
+QNdefFilter::Record QNdefFilter::recordAt(qsizetype i) const
{
return d->filterRecords.at(i);
}
@@ -195,9 +479,9 @@ QNdefFilter::Record QNdefFilter::recordAt(int i) const
/*!
Returns the number of NDEF records in the filter.
*/
-int QNdefFilter::recordCount() const
+qsizetype QNdefFilter::recordCount() const
{
- return d->filterRecords.count();
+ return d->filterRecords.size();
}
QT_END_NAMESPACE
diff --git a/src/nfc/qndeffilter.h b/src/nfc/qndeffilter.h
index 26327067..693342e6 100644
--- a/src/nfc/qndeffilter.h
+++ b/src/nfc/qndeffilter.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNDEFFILTER_H
#define QNDEFFILTER_H
@@ -46,6 +10,8 @@
QT_BEGIN_NAMESPACE
+class QNdefMessage;
+
class QNdefFilterPrivate;
class Q_NFC_EXPORT QNdefFilter
{
@@ -67,26 +33,28 @@ public:
};
template<typename T>
- void appendRecord(unsigned int min = 1, unsigned int max = 1);
- void appendRecord(QNdefRecord::TypeNameFormat typeNameFormat, const QByteArray &type,
+ bool appendRecord(unsigned int min = 1, unsigned int max = 1);
+ bool appendRecord(QNdefRecord::TypeNameFormat typeNameFormat, const QByteArray &type,
unsigned int min = 1, unsigned int max = 1);
- void appendRecord(const Record &record);
+ bool appendRecord(const Record &record);
- int recordCount() const;
- Record recordAt(int i) const;
+ qsizetype recordCount() const;
+ Record recordAt(qsizetype i) const;
QNdefFilter &operator=(const QNdefFilter &other);
+ bool match(const QNdefMessage &message) const;
+
private:
QSharedDataPointer<QNdefFilterPrivate> d;
};
template <typename T>
-void QNdefFilter::appendRecord(unsigned int min, unsigned int max)
+bool QNdefFilter::appendRecord(unsigned int min, unsigned int max)
{
T record;
- appendRecord(record.typeNameFormat(), record.type(), min, max);
+ return appendRecord(record.typeNameFormat(), record.type(), min, max);
}
QT_END_NAMESPACE
diff --git a/src/nfc/qndefmessage.cpp b/src/nfc/qndefmessage.cpp
index 58a572c8..443d43e6 100644
--- a/src/nfc/qndefmessage.cpp
+++ b/src/nfc/qndefmessage.cpp
@@ -1,47 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qndefmessage.h"
#include "qndefrecord_p.h"
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN(QNdefMessage)
+
/*!
\class QNdefMessage
\brief The QNdefMessage class provides an NFC NDEF message.
@@ -101,17 +67,17 @@ QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)
QByteArray partialChunk;
QNdefRecord record;
- QByteArray::const_iterator i = message.begin();
- while (i < message.constEnd()) {
- quint8 flags = *i;
+ qsizetype idx = 0;
+ while (idx < message.size()) {
+ quint8 flags = message.at(idx);
- bool messageBegin = flags & 0x80;
- bool messageEnd = flags & 0x40;
+ const bool messageBegin = flags & 0x80;
+ const bool messageEnd = flags & 0x40;
- bool cf = flags & 0x20;
- bool sr = flags & 0x10;
- bool il = flags & 0x08;
- quint8 typeNameFormat = flags & 0x07;
+ const bool cf = flags & 0x20;
+ const bool sr = flags & 0x10;
+ const bool il = flags & 0x08;
+ const quint8 typeNameFormat = flags & 0x07;
if (messageBegin && seenMessageBegin) {
qWarning("Got message begin but already parsed some records");
@@ -128,8 +94,9 @@ QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)
} else if (messageEnd && !seenMessageEnd) {
seenMessageEnd = true;
}
- if (cf && (typeNameFormat != 0x06) && !partialChunk.isEmpty()) {
- qWarning("partial chunk not empty or typeNameFormat not 0x06 as expected");
+ // TNF must be 0x06 even for the last chunk, when cf == 0.
+ if ((typeNameFormat != 0x06) && !partialChunk.isEmpty()) {
+ qWarning("Partial chunk not empty, but TNF not 0x06 as expected");
return QNdefMessage();
}
@@ -137,12 +104,12 @@ QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)
headerLength += (sr) ? 1 : 4;
headerLength += (il) ? 1 : 0;
- if (i + headerLength >= message.constEnd()) {
+ if (idx + headerLength >= message.size()) {
qWarning("Unexpected end of message");
return QNdefMessage();
}
- quint8 typeLength = *(++i);
+ const quint8 typeLength = message.at(++idx);
if ((typeNameFormat == 0x06) && (typeLength != 0)) {
qWarning("Invalid chunked data, TYPE_LENGTH != 0");
@@ -151,27 +118,40 @@ QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)
quint32 payloadLength;
if (sr)
- payloadLength = quint8(*(++i));
+ payloadLength = quint8(message.at(++idx));
else {
- payloadLength = quint8(*(++i)) << 24;
- payloadLength |= quint8(*(++i)) << 16;
- payloadLength |= quint8(*(++i)) << 8;
- payloadLength |= quint8(*(++i)) << 0;
+ payloadLength = quint8(message.at(++idx)) << 24;
+ payloadLength |= quint8(message.at(++idx)) << 16;
+ payloadLength |= quint8(message.at(++idx)) << 8;
+ payloadLength |= quint8(message.at(++idx)) << 0;
}
quint8 idLength;
if (il)
- idLength = *(++i);
+ idLength = message.at(++idx);
else
idLength = 0;
- int contentLength = typeLength + payloadLength + idLength;
- if (i + contentLength >= message.constEnd()) {
+ // On 32-bit systems this can overflow
+ const qsizetype convertedPayloadLength = static_cast<qsizetype>(payloadLength);
+ const qsizetype contentLength = convertedPayloadLength + typeLength + idLength;
+
+ // On a 32 bit platform the payload can theoretically exceed the max.
+ // size of a QByteArray. This will never happen in practice with correct
+ // data because there are no NFC tags that can store such data sizes,
+ // but still can be possible if the data is corrupted.
+ if ((contentLength < 0) || (convertedPayloadLength < 0)
+ || ((std::numeric_limits<qsizetype>::max() - idx) < contentLength)) {
+ qWarning("Payload can't fit into QByteArray");
+ return QNdefMessage();
+ }
+
+ if (idx + contentLength >= message.size()) {
qWarning("Unexpected end of message");
return QNdefMessage();
}
- if ((typeNameFormat == 0x06) && (idLength != 0)) {
+ if ((typeNameFormat == 0x06) && il) {
qWarning("Invalid chunked data, IL != 0");
return QNdefMessage();
}
@@ -180,20 +160,19 @@ QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)
record.setTypeNameFormat(QNdefRecord::TypeNameFormat(typeNameFormat));
if (typeLength > 0) {
- QByteArray type(++i, typeLength);
+ QByteArray type(&message.constData()[++idx], typeLength);
record.setType(type);
- i += typeLength - 1;
+ idx += typeLength - 1;
}
if (idLength > 0) {
- QByteArray id(++i, idLength);
+ QByteArray id(&message.constData()[++idx], idLength);
record.setId(id);
- i += idLength - 1;
+ idx += idLength - 1;
}
if (payloadLength > 0) {
- QByteArray payload(++i, payloadLength);
-
+ QByteArray payload(&message.constData()[++idx], payloadLength);
if (cf) {
// chunked payload, except last
@@ -207,7 +186,7 @@ QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)
record.setPayload(payload);
}
- i += payloadLength - 1;
+ idx += payloadLength - 1;
}
if (!cf) {
@@ -219,11 +198,11 @@ QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)
break;
// move to start of next record
- ++i;
+ ++idx;
}
- if (!seenMessageBegin && !seenMessageEnd) {
- qWarning("Malformed NDEF Message, missing begin or end.");
+ if (!seenMessageBegin || !seenMessageEnd) {
+ qWarning("Malformed NDEF Message, missing begin or end");
return QNdefMessage();
}
@@ -231,10 +210,33 @@ QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)
}
/*!
- Returns true if this NDEF message is equivalent to \a other; otherwise returns false.
+ \fn QNdefMessage &QNdefMessage::operator=(const QNdefMessage &other)
+ \overload
+ \since 6.2
+
+ Copy assignment operator from QList<QNdefRecord>. Assigns the
+ \a other list of NDEF records to this NDEF record list.
+
+ After the operation, \a other and \c *this will be equal.
+*/
+
+/*!
+ \fn QNdefMessage &QNdefMessage::operator=(QNdefMessage &&other)
+ \overload
+ \since 6.2
+
+ Move assignment operator from QList<QNdefRecord>. Moves the
+ \a other list of NDEF records to this NDEF record list.
+
+ After the operation, \a other will be empty.
+*/
+
+/*!
+ Returns \c true if this NDEF message is equivalent to \a other; otherwise
+ returns \c false.
- An empty message (i.e. isEmpty() returns true) is equivalent to a NDEF message containing a
- single record of type QNdefRecord::Empty.
+ An empty message (i.e. isEmpty() returns \c true) is equivalent to a NDEF
+ message containing a single record of type \l QNdefRecord::Empty.
*/
bool QNdefMessage::operator==(const QNdefMessage &other) const
{
@@ -243,15 +245,15 @@ bool QNdefMessage::operator==(const QNdefMessage &other) const
return true;
// compare empty to really empty
- if (isEmpty() && other.count() == 1 && other.first().typeNameFormat() == QNdefRecord::Empty)
+ if (isEmpty() && other.size() == 1 && other.first().typeNameFormat() == QNdefRecord::Empty)
return true;
- if (other.isEmpty() && count() == 1 && first().typeNameFormat() == QNdefRecord::Empty)
+ if (other.isEmpty() && size() == 1 && first().typeNameFormat() == QNdefRecord::Empty)
return true;
- if (count() != other.count())
+ if (size() != other.size())
return false;
- for (int i = 0; i < count(); ++i) {
+ for (qsizetype i = 0; i < size(); ++i) {
if (at(i) != other.at(i))
return false;
}
@@ -273,31 +275,31 @@ QByteArray QNdefMessage::toByteArray() const
QByteArray m;
- for (int i = 0; i < count(); ++i) {
+ for (qsizetype i = 0; i < size(); ++i) {
const QNdefRecord &record = at(i);
quint8 flags = record.typeNameFormat();
if (i == 0)
flags |= 0x80;
- if (i == count() - 1)
+ if (i == size() - 1)
flags |= 0x40;
// cf (chunked records) not supported yet
- if (record.payload().length() < 255)
+ if (record.payload().size() < 255)
flags |= 0x10;
if (!record.id().isEmpty())
flags |= 0x08;
m.append(flags);
- m.append(record.type().length());
+ m.append(record.type().size());
if (flags & 0x10) {
- m.append(quint8(record.payload().length()));
+ m.append(quint8(record.payload().size()));
} else {
- quint32 length = record.payload().length();
+ quint32 length = record.payload().size();
m.append(length >> 24);
m.append(length >> 16);
m.append(length >> 8);
@@ -305,7 +307,7 @@ QByteArray QNdefMessage::toByteArray() const
}
if (flags & 0x08)
- m.append(record.id().length());
+ m.append(record.id().size());
if (!record.type().isEmpty())
m.append(record.type());
diff --git a/src/nfc/qndefmessage.h b/src/nfc/qndefmessage.h
index 59dedaa8..ba840d10 100644
--- a/src/nfc/qndefmessage.h
+++ b/src/nfc/qndefmessage.h
@@ -1,46 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNDEFMESSAGE_H
#define QNDEFMESSAGE_H
-#include <QtCore/QVector>
#include <QtCore/QSet>
#include <QtCore/QList>
#include <QtCore/QMetaType>
@@ -49,23 +12,39 @@
QT_BEGIN_NAMESPACE
-class Q_NFC_EXPORT QNdefMessage : public QList<QNdefRecord>
+// This class used to be exported exposing QList methods, see QTBUG-102367.
+#if defined(QT_BUILD_NFC_LIB)
+# define Q_NFC_EXPORT_COMPAT QT6_ONLY(Q_NFC_EXPORT)
+#else
+# define Q_NFC_EXPORT_COMPAT
+#endif
+
+class QNdefMessage : public QList<QNdefRecord>
{
public:
- inline QNdefMessage() { }
- inline explicit QNdefMessage(const QNdefRecord &record) { append(record); }
- inline QNdefMessage(const QNdefMessage &message) : QList<QNdefRecord>(message) { }
- inline QNdefMessage(const QList<QNdefRecord> &records) : QList<QNdefRecord>(records) { }
+ Q_NFC_EXPORT_COMPAT
+ QNdefMessage() = default;
+ Q_NFC_EXPORT_COMPAT
+ explicit QNdefMessage(const QNdefRecord &record) { append(record); }
+ Q_NFC_EXPORT_COMPAT
+ QNdefMessage(const QNdefMessage &message) = default;
+ Q_NFC_EXPORT_COMPAT
+ QNdefMessage(const QList<QNdefRecord> &records) : QList<QNdefRecord>(records) { }
+
+ Q_NFC_EXPORT_COMPAT
+ QNdefMessage &operator=(const QNdefMessage &other) = default;
+ Q_NFC_EXPORT_COMPAT
+ QNdefMessage &operator=(QNdefMessage &&other) noexcept = default;
- bool operator==(const QNdefMessage &other) const;
+ Q_NFC_EXPORT bool operator==(const QNdefMessage &other) const;
- QByteArray toByteArray() const;
+ Q_NFC_EXPORT QByteArray toByteArray() const;
- static QNdefMessage fromByteArray(const QByteArray &message);
+ Q_NFC_EXPORT static QNdefMessage fromByteArray(const QByteArray &message);
};
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QNdefMessage)
+QT_DECL_METATYPE_EXTERN(QNdefMessage, Q_NFC_EXPORT)
#endif // QNDEFMESSAGE_H
diff --git a/src/nfc/qndefnfcsmartposterrecord.cpp b/src/nfc/qndefnfcsmartposterrecord.cpp
index bc7acfab..866abeed 100644
--- a/src/nfc/qndefnfcsmartposterrecord.cpp
+++ b/src/nfc/qndefnfcsmartposterrecord.cpp
@@ -1,41 +1,5 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 - 2012 Research In Motion
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
+// Copyright (C) 2016 - 2012 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qndefnfcsmartposterrecord.h>
#include "qndefnfcsmartposterrecord_p.h"
@@ -48,6 +12,32 @@
QT_BEGIN_NAMESPACE
/*!
+ \class QNdefNfcIconRecord
+ \brief The QNdefNfcIconRecord class provides an NFC MIME record to hold an
+ icon.
+
+ \ingroup connectivity-nfc
+ \inmodule QtNfc
+ \since Qt 5.2
+
+ This class wraps the image data into an NDEF message.
+ It provides an NDEF record of type \l QNdefRecord::Mime.
+ The \l {QNdefRecord::}{payload}() contains the raw image data.
+*/
+
+/*!
+ \fn QNdefNfcIconRecord::QNdefNfcIconRecord()
+
+ Constructs an empty NDEF record of type \l QNdefRecord::Mime.
+*/
+
+/*!
+ \fn QNdefNfcIconRecord::QNdefNfcIconRecord(const QNdefRecord &other)
+
+ Constructs an NDEF icon record that is a copy of \a other.
+*/
+
+/*!
\class QNdefNfcSmartPosterRecord
\brief The QNdefNfcSmartPosterRecord class provides an NFC RTD-SmartPoster.
@@ -183,7 +173,7 @@ void QNdefNfcSmartPosterRecord::convertToPayload()
QNdefMessage message;
// Title
- for (int t=0; t<titleCount(); t++)
+ for (qsizetype t = 0; t < titleCount(); t++)
message.append(titleRecord(t));
// URI
@@ -195,7 +185,7 @@ void QNdefNfcSmartPosterRecord::convertToPayload()
message.append(*(d->m_action));
// Icon
- for (int i=0; i<iconCount(); i++)
+ for (qsizetype i = 0; i < iconCount(); i++)
message.append(iconRecord(i));
// Size
@@ -210,13 +200,14 @@ void QNdefNfcSmartPosterRecord::convertToPayload()
}
/*!
- Returns true if the smart poster contains a title record using locale \a locale. If \a locale
- is empty then true is returned if the smart poster contains at least one title record. In all
- cases false is returned.
+ Returns \c true if the smart poster contains a title record using the locale
+ \a locale. If \a locale is empty, then \c true is returned if the smart
+ poster contains at least one title record. In all other cases, \c false is
+ returned.
*/
bool QNdefNfcSmartPosterRecord::hasTitle(const QString &locale) const
{
- for (int i = 0; i < d->m_titleList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
const QNdefNfcTextRecord &text = d->m_titleList[i];
if (locale.isEmpty() || text.locale() == locale)
@@ -227,21 +218,23 @@ bool QNdefNfcSmartPosterRecord::hasTitle(const QString &locale) const
}
/*!
- Returns true if the smart poster contains an action record, otherwise false.
+ Returns \c true if the smart poster contains an action record, otherwise
+ returns \c false.
*/
bool QNdefNfcSmartPosterRecord::hasAction() const
{
- return d->m_action != 0;
+ return d->m_action != nullptr;
}
/*!
- Returns true if the smart poster contains an icon record using type \a mimetype.
- If \a mimetype is empty then true is returned if the smart poster contains at least one icon record.
- In all other cases false is returned.
+ Returns \c true if the smart poster contains an icon record using the type
+ \a mimetype. If \a mimetype is empty, then \c true is returned if the smart
+ poster contains at least one icon record.
+ In all other cases, \c false is returned.
*/
bool QNdefNfcSmartPosterRecord::hasIcon(const QByteArray &mimetype) const
{
- for (int i = 0; i < d->m_iconList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
const QNdefNfcIconRecord &icon = d->m_iconList[i];
if (mimetype.isEmpty() || icon.type() == mimetype)
@@ -252,35 +245,39 @@ bool QNdefNfcSmartPosterRecord::hasIcon(const QByteArray &mimetype) const
}
/*!
- Returns true if the smart poster contains a size record, otherwise false.
+ Returns \c true if the smart poster contains a size record, otherwise
+ returns \c false.
*/
bool QNdefNfcSmartPosterRecord::hasSize() const
{
- return d->m_size != 0;
+ return d->m_size != nullptr;
}
/*!
- Returns true if the smart poster contains a type record, otherwise false.
+ Returns \c true if the smart poster contains a type record, otherwise
+ returns \c false.
*/
bool QNdefNfcSmartPosterRecord::hasTypeInfo() const
{
- return d->m_type != 0;
+ return d->m_type != nullptr;
}
/*!
Returns the number of title records contained inside the smart poster.
*/
-int QNdefNfcSmartPosterRecord::titleCount() const
+qsizetype QNdefNfcSmartPosterRecord::titleCount() const
{
- return d->m_titleList.length();
+ return d->m_titleList.size();
}
/*!
- Returns the title record corresponding to the index \a index inside the smart poster, where \a index is a value between 0 and titleCount() - 1. Values outside of this range return an empty record.
+ Returns the title record corresponding to the index \a index inside the
+ smart poster, where \a index is a value between 0 and titleCount() - 1.
+ Values outside of this range return an empty record.
*/
-QNdefNfcTextRecord QNdefNfcSmartPosterRecord::titleRecord(const int index) const
+QNdefNfcTextRecord QNdefNfcSmartPosterRecord::titleRecord(qsizetype index) const
{
- if (index >= 0 && index < d->m_titleList.length())
+ if (index >= 0 && index < d->m_titleList.size())
return d->m_titleList[index];
return QNdefNfcTextRecord();
@@ -293,7 +290,7 @@ QNdefNfcTextRecord QNdefNfcSmartPosterRecord::titleRecord(const int index) const
*/
QString QNdefNfcSmartPosterRecord::title(const QString &locale) const
{
- for (int i = 0; i < d->m_titleList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
const QNdefNfcTextRecord &text = d->m_titleList[i];
if (locale.isEmpty() || text.locale() == locale)
@@ -314,21 +311,22 @@ QList<QNdefNfcTextRecord> QNdefNfcSmartPosterRecord::titleRecords() const
/*!
Attempts to add a title record \a text to the smart poster. If the smart poster does not already
contain a title record with the same locale as title record \a text, then the title record is added
- and the function returns true. Otherwise false is returned.
+ and the function returns \c true. Otherwise \c false is returned.
*/
bool QNdefNfcSmartPosterRecord::addTitle(const QNdefNfcTextRecord &text)
{
- bool status = addTitleInternal(text);
+ const bool status = addTitleInternal(text);
- // Convert to payload
- convertToPayload();
+ // Convert to payload if the title is added
+ if (status)
+ convertToPayload();
return status;
}
bool QNdefNfcSmartPosterRecord::addTitleInternal(const QNdefNfcTextRecord &text)
{
- for (int i = 0; i < d->m_titleList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
const QNdefNfcTextRecord &rec = d->m_titleList[i];
if (rec.locale() == text.locale())
@@ -342,7 +340,7 @@ bool QNdefNfcSmartPosterRecord::addTitleInternal(const QNdefNfcTextRecord &text)
/*!
Attempts to add a new title record with title \a text, locale \a locale and encoding \a encoding.
If the smart poster does not already contain a title record with locale \a locale, then the title record
- is added and the function returns true. Otherwise false is returned.
+ is added and the function returns \c true. Otherwise \c false is returned.
*/
bool QNdefNfcSmartPosterRecord::addTitle(const QString &text, const QString &locale, QNdefNfcTextRecord::Encoding encoding)
{
@@ -355,14 +353,15 @@ bool QNdefNfcSmartPosterRecord::addTitle(const QString &text, const QString &loc
}
/*!
- Attempts to remove the title record \a text from the smart poster. Removes the record and returns true
- if the smart poster contains a matching record, otherwise false.
+ Attempts to remove the title record \a text from the smart poster. Removes
+ the record and returns \c true if the smart poster contains a matching
+ record, otherwise \c false is returned.
*/
bool QNdefNfcSmartPosterRecord::removeTitle(const QNdefNfcTextRecord &text)
{
bool status = false;
- for (int i = 0; i < d->m_titleList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
const QNdefNfcTextRecord &rec = d->m_titleList[i];
if (rec.text() == text.text() && rec.locale() == text.locale() && rec.encoding() == text.encoding()) {
@@ -372,21 +371,23 @@ bool QNdefNfcSmartPosterRecord::removeTitle(const QNdefNfcTextRecord &text)
}
}
- // Convert to payload
- convertToPayload();
+ // Convert to payload if the title list has changed
+ if (status)
+ convertToPayload();
return status;
}
/*!
- Attempts to remove a title record with locale \a locale from the smart poster. Removes the record and returns true
- if the smart poster contains a matching record, otherwise false.
+ Attempts to remove a title record with the locale \a locale from the smart
+ poster. Removes the record and returns \c true if the smart poster contains
+ a matching record, otherwise \c false is returned.
*/
bool QNdefNfcSmartPosterRecord::removeTitle(const QString &locale)
{
bool status = false;
- for (int i = 0; i < d->m_titleList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
const QNdefNfcTextRecord &rec = d->m_titleList[i];
if (rec.locale() == locale) {
@@ -396,8 +397,9 @@ bool QNdefNfcSmartPosterRecord::removeTitle(const QString &locale)
}
}
- // Convert to payload
- convertToPayload();
+ // Convert to payload if the title list has changed
+ if (status)
+ convertToPayload();
return status;
}
@@ -409,7 +411,7 @@ void QNdefNfcSmartPosterRecord::setTitles(const QList<QNdefNfcTextRecord> &title
{
d->m_titleList.clear();
- for (int i = 0; i < titles.length(); ++i) {
+ for (qsizetype i = 0; i < titles.size(); ++i) {
d->m_titleList.append(titles[i]);
}
@@ -492,17 +494,19 @@ void QNdefNfcSmartPosterRecord::setAction(Action act)
/*!
Returns the number of icon records contained inside the smart poster.
*/
-int QNdefNfcSmartPosterRecord::iconCount() const
+qsizetype QNdefNfcSmartPosterRecord::iconCount() const
{
- return d->m_iconList.length();
+ return d->m_iconList.size();
}
/*!
- Returns the icon record corresponding to the index \a index inside the smart poster, where \a index is a value between 0 and \l iconCount() - 1. Values outside of this range return an empty record.
+ Returns the icon record corresponding to the index \a index inside the smart
+ poster, where \a index is a value between 0 and \l iconCount() - 1.
+ Values outside of this range return an empty record.
*/
-QNdefNfcIconRecord QNdefNfcSmartPosterRecord::iconRecord(const int index) const
+QNdefNfcIconRecord QNdefNfcSmartPosterRecord::iconRecord(qsizetype index) const
{
- if (index >= 0 && index < d->m_iconList.length())
+ if (index >= 0 && index < d->m_iconList.size())
return d->m_iconList[index];
return QNdefNfcIconRecord();
@@ -514,7 +518,7 @@ QNdefNfcIconRecord QNdefNfcSmartPosterRecord::iconRecord(const int index) const
*/
QByteArray QNdefNfcSmartPosterRecord::icon(const QByteArray& mimetype) const
{
- for (int i = 0; i < d->m_iconList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
const QNdefNfcIconRecord &icon = d->m_iconList[i];
if (mimetype.isEmpty() || icon.type() == mimetype)
@@ -546,7 +550,7 @@ void QNdefNfcSmartPosterRecord::addIcon(const QNdefNfcIconRecord &icon)
void QNdefNfcSmartPosterRecord::addIconInternal(const QNdefNfcIconRecord &icon)
{
- for (int i = 0; i < d->m_iconList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
const QNdefNfcIconRecord &rec = d->m_iconList[i];
if (rec.type() == icon.type())
@@ -570,14 +574,15 @@ void QNdefNfcSmartPosterRecord::addIcon(const QByteArray &type, const QByteArray
}
/*!
- Attempts to remove the icon record \a icon from the smart poster. Removes the record and returns true
- if the smart poster contains a matching record, otherwise false.
+ Attempts to remove the icon record \a icon from the smart poster.
+ Removes the record and returns \c true if the smart poster contains
+ a matching record, otherwise \c false is returned.
*/
bool QNdefNfcSmartPosterRecord::removeIcon(const QNdefNfcIconRecord &icon)
{
bool status = false;
- for (int i = 0; i < d->m_iconList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
const QNdefNfcIconRecord &rec = d->m_iconList[i];
if (rec.type() == icon.type() && rec.data() == icon.data()) {
@@ -587,21 +592,23 @@ bool QNdefNfcSmartPosterRecord::removeIcon(const QNdefNfcIconRecord &icon)
}
}
- // Convert to payload
- convertToPayload();
+ // Convert to payload if the icon list has changed
+ if (status)
+ convertToPayload();
return status;
}
/*!
- Attempts to remove the icon record with type \a type from the smart poster. Removes the record
- and returns true if the smart poster contains a matching record, otherwise false.
+ Attempts to remove the icon record with the type \a type from the smart
+ poster. Removes the record and returns \c true if the smart poster contains
+ a matching record, otherwise \c false is returned.
*/
bool QNdefNfcSmartPosterRecord::removeIcon(const QByteArray &type)
{
bool status = false;
- for (int i = 0; i < d->m_iconList.length(); ++i) {
+ for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
const QNdefNfcIconRecord &rec = d->m_iconList[i];
if (rec.type() == type) {
@@ -611,8 +618,9 @@ bool QNdefNfcSmartPosterRecord::removeIcon(const QByteArray &type)
}
}
- // Convert to payload
- convertToPayload();
+ // Convert to payload if the icon list has changed
+ if (status)
+ convertToPayload();
return status;
}
@@ -627,7 +635,7 @@ void QNdefNfcSmartPosterRecord::setIcons(const QList<QNdefNfcIconRecord> &icons)
{
d->m_iconList.clear();
- for (int i = 0; i < icons.length(); ++i) {
+ for (qsizetype i = 0; i < icons.size(); ++i) {
d->m_iconList.append(icons[i]);
}
@@ -670,28 +678,28 @@ void QNdefNfcSmartPosterRecord::setSize(quint32 size)
}
/*!
- Returns the UTF-8 encoded MIME type that describes the type of the objects
- that can be reached via uri().
+ Returns the MIME type that describes the type of the objects that can be
+ reached via uri().
- If the type is not known the return QByteArray is empty.
+ If the type is not known, the returned QString is empty.
\sa setTypeInfo(), hasTypeInfo()
*/
-QByteArray QNdefNfcSmartPosterRecord::typeInfo() const
+QString QNdefNfcSmartPosterRecord::typeInfo() const
{
if (d->m_type)
return d->m_type->typeInfo();
- return QByteArray();
+ return QString();
}
/*!
- Sets the type record to \a type. \a type must be UTF-8 encoded
- and describes the type of the object referenced by uri()
+ Sets the type record to \a type. \a type describes the type of the object
+ referenced by uri().
\sa typeInfo()
*/
-void QNdefNfcSmartPosterRecord::setTypeInfo(const QByteArray &type)
+void QNdefNfcSmartPosterRecord::setTypeInfo(const QString &type)
{
if (d->m_type)
delete d->m_type;
@@ -705,8 +713,7 @@ void QNdefNfcSmartPosterRecord::setTypeInfo(const QByteArray &type)
void QNdefNfcActRecord::setAction(QNdefNfcSmartPosterRecord::Action action)
{
- QByteArray data;
- data[0] = action;
+ QByteArray data(1, action);
setPayload(data);
}
@@ -723,11 +730,17 @@ QNdefNfcSmartPosterRecord::Action QNdefNfcActRecord::action() const
return value;
}
+/*!
+ Sets the contents of the icon record to \a data.
+*/
void QNdefNfcIconRecord::setData(const QByteArray &data)
{
setPayload(data);
}
+/*!
+ Returns the icon data as \l QByteArray.
+*/
QByteArray QNdefNfcIconRecord::data() const
{
return payload();
@@ -735,7 +748,7 @@ QByteArray QNdefNfcIconRecord::data() const
void QNdefNfcSizeRecord::setSize(quint32 size)
{
- QByteArray data;
+ QByteArray data(4, 0);
data[0] = (int) ((size & 0xFF000000) >> 24);
data[1] = (int) ((size & 0x00FF0000) >> 16);
@@ -756,14 +769,14 @@ quint32 QNdefNfcSizeRecord::size() const
+ ((p[2] << 8) & 0x0000FF00) + (p[3] & 0x000000FF);
}
-void QNdefNfcTypeRecord::setTypeInfo(const QByteArray &type)
+void QNdefNfcTypeRecord::setTypeInfo(const QString &type)
{
- setPayload(type);
+ setPayload(type.toUtf8());
}
-QByteArray QNdefNfcTypeRecord::typeInfo() const
+QString QNdefNfcTypeRecord::typeInfo() const
{
- return payload();
+ return QString::fromUtf8(payload());
}
QT_END_NAMESPACE
diff --git a/src/nfc/qndefnfcsmartposterrecord.h b/src/nfc/qndefnfcsmartposterrecord.h
index 9b714d5d..0424e05c 100644
--- a/src/nfc/qndefnfcsmartposterrecord.h
+++ b/src/nfc/qndefnfcsmartposterrecord.h
@@ -1,46 +1,11 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 - 2012 Research In Motion
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
+// Copyright (C) 2016 - 2012 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNDEFNFCSMARTPOSTERRECORD_H
#define QNDEFNFCSMARTPOSTERRECORD_H
#include <QtCore/QList>
+#include <QtCore/QString>
#include <QtNfc/qtnfcglobal.h>
#include <QtNfc/QNdefRecord>
#include <QtNfc/qndefnfctextrecord.h>
@@ -97,8 +62,8 @@ public:
bool hasSize() const;
bool hasTypeInfo() const;
- int titleCount() const;
- QNdefNfcTextRecord titleRecord(const int index) const;
+ qsizetype titleCount() const;
+ QNdefNfcTextRecord titleRecord(qsizetype index) const;
QString title(const QString &locale = QString()) const;
QList<QNdefNfcTextRecord> titleRecords() const;
@@ -116,8 +81,8 @@ public:
Action action() const;
void setAction(Action act);
- int iconCount() const;
- QNdefNfcIconRecord iconRecord(const int index) const;
+ qsizetype iconCount() const;
+ QNdefNfcIconRecord iconRecord(qsizetype index) const;
QByteArray icon(const QByteArray& mimetype = QByteArray()) const;
QList<QNdefNfcIconRecord> iconRecords() const;
@@ -131,9 +96,8 @@ public:
quint32 size() const;
void setSize(quint32 size);
- //TODO Qt 6 the mimetype should be QString as it is UTF-8
- QByteArray typeInfo() const;
- void setTypeInfo(const QByteArray &type);
+ QString typeInfo() const;
+ void setTypeInfo(const QString &type);
private:
QSharedDataPointer<QNdefNfcSmartPosterRecordPrivate> d;
diff --git a/src/nfc/qndefnfcsmartposterrecord_p.h b/src/nfc/qndefnfcsmartposterrecord_p.h
index f2042be8..cab85756 100644
--- a/src/nfc/qndefnfcsmartposterrecord_p.h
+++ b/src/nfc/qndefnfcsmartposterrecord_p.h
@@ -1,41 +1,5 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 - 2012 Research In Motion
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
+// Copyright (C) 2016 - 2012 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNDEFNFCSMARTPOSTERRECORD_P_H
#define QNDEFNFCSMARTPOSTERRECORD_P_H
@@ -76,22 +40,22 @@ class QNdefNfcTypeRecord : public QNdefRecord
public:
Q_DECLARE_NDEF_RECORD(QNdefNfcTypeRecord, QNdefRecord::NfcRtd, "t", QByteArray(0, char(0)))
- void setTypeInfo(const QByteArray &type);
- QByteArray typeInfo() const;
+ void setTypeInfo(const QString &type);
+ QString typeInfo() const;
};
class QNdefNfcSmartPosterRecordPrivate : public QSharedData
{
public:
- QNdefNfcSmartPosterRecordPrivate() : m_uri(0), m_action(0), m_size(0), m_type(0) {}
+ QNdefNfcSmartPosterRecordPrivate() {}
public:
QList<QNdefNfcTextRecord> m_titleList;
- QNdefNfcUriRecord *m_uri;
- QNdefNfcActRecord *m_action;
+ QNdefNfcUriRecord *m_uri = nullptr;
+ QNdefNfcActRecord *m_action = nullptr;
QList<QNdefNfcIconRecord> m_iconList;
- QNdefNfcSizeRecord *m_size;
- QNdefNfcTypeRecord *m_type;
+ QNdefNfcSizeRecord *m_size = nullptr;
+ QNdefNfcTypeRecord *m_type = nullptr;
};
QT_END_NAMESPACE
diff --git a/src/nfc/qndefnfctextrecord.cpp b/src/nfc/qndefnfctextrecord.cpp
index 95fb4c66..a8d9b091 100644
--- a/src/nfc/qndefnfctextrecord.cpp
+++ b/src/nfc/qndefnfctextrecord.cpp
@@ -1,45 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qndefnfctextrecord.h>
-#include <QtCore/QTextCodec>
+#include <QtCore/QStringConverter>
#include <QtCore/QLocale>
QT_BEGIN_NAMESPACE
@@ -104,7 +68,7 @@ void QNdefNfcTextRecord::setLocale(const QString &locale)
quint8 codeLength = status & 0x3f;
- quint8 newStatus = (status & 0xd0) | locale.length();
+ quint8 newStatus = (status & 0xd0) | locale.size();
p[0] = newStatus;
p.replace(1, codeLength, locale.toLatin1());
@@ -122,19 +86,15 @@ QString QNdefNfcTextRecord::text() const
if (p.isEmpty())
return QString();
-#if QT_CONFIG(textcodec)
quint8 status = p.at(0);
-
bool utf16 = status & 0x80;
quint8 codeLength = status & 0x3f;
- QTextCodec *codec = QTextCodec::codecForName(utf16 ? "UTF-16BE" : "UTF-8");
+ auto toUnicode = QStringDecoder(
+ utf16 ? QStringDecoder::Encoding::Utf16BE : QStringDecoder::Encoding::Utf8,
+ QStringDecoder::Flag::Stateless);
- return codec ? codec->toUnicode(p.constData() + 1 + codeLength, p.length() - 1 - codeLength) : QString();
-#else
- qWarning("Cannot decode payload, Qt was built with -no-feature-textcodec!");
- return QString();
-#endif
+ return toUnicode(QByteArrayView(p.constData() + 1 + codeLength, p.size() - 1 - codeLength));
}
/*!
@@ -142,7 +102,6 @@ QString QNdefNfcTextRecord::text() const
*/
void QNdefNfcTextRecord::setText(const QString text)
{
-#if QT_CONFIG(textcodec)
if (payload().isEmpty())
setLocale(QLocale().name());
@@ -155,15 +114,13 @@ void QNdefNfcTextRecord::setText(const QString text)
p.truncate(1 + codeLength);
- QTextCodec *codec = QTextCodec::codecForName(utf16 ? "UTF-16BE" : "UTF-8");
+ auto fromUnicode = QStringEncoder(
+ utf16? QStringEncoder::Encoding::Utf16BE : QStringEncoder::Encoding::Utf8,
+ QStringEncoder::Flag::Stateless|QStringEncoder::Flag::WriteBom);
- p += codec->fromUnicode(text);
+ p += fromUnicode(text);
setPayload(p);
-#else
- qWarning("Cannot encode payload, Qt was built with -no-feature-textcodec!");
- Q_UNUSED(text);
-#endif
}
/*!
diff --git a/src/nfc/qndefnfctextrecord.h b/src/nfc/qndefnfctextrecord.h
index 72fc4878..103669b3 100644
--- a/src/nfc/qndefnfctextrecord.h
+++ b/src/nfc/qndefnfctextrecord.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNDEFNFCTEXTRECORD_H
#define QNDEFNFCTEXTRECORD_H
diff --git a/src/nfc/qndefnfcurirecord.cpp b/src/nfc/qndefnfcurirecord.cpp
index 3438d9f2..690e1848 100644
--- a/src/nfc/qndefnfcurirecord.cpp
+++ b/src/nfc/qndefnfcurirecord.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qndefnfcurirecord.h"
@@ -135,9 +99,8 @@ void QNdefNfcUriRecord::setUri(const QUrl &uri)
for (int i = 1; i < abbrevs; ++i) {
if (uri.toString().startsWith(QLatin1String(abbreviations[i]))) {
- QByteArray p;
+ QByteArray p(1, i);
- p[0] = i;
p += uri.toString().mid(qstrlen(abbreviations[i])).toUtf8();
setPayload(p);
@@ -146,8 +109,7 @@ void QNdefNfcUriRecord::setUri(const QUrl &uri)
}
}
- QByteArray p;
- p[0] = 0;
+ QByteArray p(1, 0);
p += uri.toString().toUtf8();
setPayload(p);
diff --git a/src/nfc/qndefnfcurirecord.h b/src/nfc/qndefnfcurirecord.h
index 90a199a3..9a59d8ee 100644
--- a/src/nfc/qndefnfcurirecord.h
+++ b/src/nfc/qndefnfcurirecord.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNDEFNFCURIRECORD_H
#define QNDEFNFCURIRECORD_H
diff --git a/src/nfc/qndefrecord.cpp b/src/nfc/qndefrecord.cpp
index a8436bdb..51df2ab6 100644
--- a/src/nfc/qndefrecord.cpp
+++ b/src/nfc/qndefrecord.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qndefrecord.h"
@@ -102,15 +66,17 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn bool QNdefRecord::isRecordType() const
+ \fn template <typename T> bool QNdefRecord::isRecordType() const
- Returns true if the NDEF record is of the specified record type; otherwise returns false.
+ Returns \c true if the NDEF record is of the specified record type;
+ otherwise returns \c false.
*/
/*!
\fn bool QNdefRecord::operator!=(const QNdefRecord &other) const
- Returns true if this NDEF record does not equal \a other; otherwise return false.
+ Returns \c true if this NDEF record does not equal \a other;
+ otherwise return \c false.
*/
/*!
@@ -148,7 +114,7 @@ QT_BEGIN_NAMESPACE
\sa Q_DECLARE_NDEF_RECORD()
*/
-uint qHash(const QNdefRecord &key)
+size_t qHash(const QNdefRecord &key)
{
return qHash(key.type() + key.id() + key.payload());
}
@@ -327,7 +293,8 @@ QByteArray QNdefRecord::payload() const
}
/*!
- Returns true if the NDEF record contains an empty payload; otherwise return false.
+ Returns \c true if the NDEF record contains an empty payload;
+ otherwise returns \c false.
This is equivalent to calling \c {payload().isEmpty()}.
*/
@@ -340,7 +307,8 @@ bool QNdefRecord::isEmpty() const
}
/*!
- Returns true if \a other and this NDEF record are the same.
+ Returns \c true if \a other and this NDEF record are the same.
+ Otherwise returns \c false.
*/
bool QNdefRecord::operator==(const QNdefRecord &other) const
{
@@ -365,4 +333,22 @@ bool QNdefRecord::operator==(const QNdefRecord &other) const
return true;
}
+/*!
+ \since 6.2
+
+ Clear the NDEF record.
+
+ An \l isEmpty() call returns \c true for a cleared record. The record
+ \l type() is set to \l {QNdefRecord::}{Empty}.
+*/
+void QNdefRecord::clear()
+{
+ if (d) {
+ d->typeNameFormat = 0;
+ d->type.clear();
+ d->id.clear();
+ d->payload.clear();
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/nfc/qndefrecord.h b/src/nfc/qndefrecord.h
index 6cb6ac8c..1d9c65ee 100644
--- a/src/nfc/qndefrecord.h
+++ b/src/nfc/qndefrecord.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNDEFRECORD_H
#define QNDEFRECORD_H
@@ -90,6 +54,8 @@ public:
bool operator==(const QNdefRecord &other) const;
inline bool operator!=(const QNdefRecord &other) const { return !operator==(other); }
+ void clear();
+
protected:
QNdefRecord(const QNdefRecord &other, TypeNameFormat typeNameFormat, const QByteArray &type);
QNdefRecord(const QNdefRecord &other, TypeNameFormat typeNameFormat);
@@ -111,7 +77,7 @@ private:
} \
QT_END_NAMESPACE
-Q_NFC_EXPORT uint qHash(const QNdefRecord &key);
+Q_NFC_EXPORT size_t qHash(const QNdefRecord &key);
QT_END_NAMESPACE
diff --git a/src/nfc/qndefrecord_p.h b/src/nfc/qndefrecord_p.h
index 89ce5d99..f9f64d9a 100644
--- a/src/nfc/qndefrecord_p.h
+++ b/src/nfc/qndefrecord_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNDEFRECORD_P_H
#define QNDEFRECORD_P_H
diff --git a/src/nfc/qnearfieldmanager.cpp b/src/nfc/qnearfieldmanager.cpp
index 02e4d918..ee1013f2 100644
--- a/src/nfc/qnearfieldmanager.cpp
+++ b/src/nfc/qnearfieldmanager.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qnearfieldmanager.h"
#include "qnearfieldmanager_p.h"
@@ -46,8 +10,12 @@
#include "qnearfieldmanager_neard_p.h"
#elif defined(ANDROID_NFC)
#include "qnearfieldmanager_android_p.h"
+#elif defined(IOS_NFC)
+#include "qnearfieldmanager_ios_p.h"
+#elif defined(PCSC_NFC)
+#include "qnearfieldmanager_pcsc_p.h"
#else
-#include "qnearfieldmanagerimpl_p.h"
+#include "qnearfieldmanager_generic_p.h"
#endif
#include <QtCore/QMetaType>
@@ -66,56 +34,27 @@ QT_BEGIN_NAMESPACE
NFC Forum devices support two modes of communications. The first mode, peer-to-peer
communications, is used to communicate between two NFC Forum devices. The second mode,
master/slave communications, is used to communicate between an NFC Forum device and an NFC
- Forum Tag or Contactless Card. The targetDetected() signal is emitted when a target device
- enters communications range. Communications can be initiated from the slot connected to this
+ Forum Tag or Contactless Card. The targetDetected() signal is emitted when a target device
+ enters communications range. Communications can be initiated from the slot connected to this
signal.
NFC Forum devices generally operate as the master in master/slave communications. Some devices
are also capable of operating as the slave, so called Card Emulation mode. In this mode the
local NFC device emulates a NFC Forum Tag or Contactless Card.
- NFC Forum Tags can contain one or more messages in a standardized format. These messages are
- encapsulated by the QNdefMessage class. Use the registerNdefMessageHandler() functions to
- register message handlers with particular criteria. Handlers can be unregistered with the
- unregisterNdefMessageHandler() function.
-
Applications can connect to the targetDetected() and targetLost() signals to get notified when
- an NFC Forum Tag enters or leaves proximity. Before these signals are
- emitted target detection must be started with the startTargetDetection() function.
- Target detection can be stopped with
- the stopTargetDetection() function. Before a detected target can be accessed it is necessary to
- request access rights. This must be done before the target device is touched. The
- setTargetAccessModes() function is used to set the types of access the application wants to
- perform on the detected target. When access is no longer required the target access modes
- should be set to NoTargetAccess as other applications may be blocked from accessing targets.
- The current target access modes can be retried with the targetAccessModes() function.
-
-
- \section2 Automatically launching NDEF message handlers
-
- On some platforms it is possible to pre-register an application to receive NDEF messages
- matching a given criteria. This is useful to get the system to automatically launch your
- application when a matching NDEF message is received. This removes the need to have the user
- manually launch NDEF handling applications, prior to touching a tag, or to have those
- applications always running and using system resources.
-
- The process of registering the handler is different for each platform. Please refer to the
- platform documentation on how such a registration may be done.
- If the application has been registered as an NDEF message handler, the application only needs
- to call the registerNdefMessageHandler() function:
-
- \snippet doc_src_qtnfc.cpp handleNdefMessage
-
- Automatically launching NDEF message handlers is supported on
- \l{nfc-android.html}{Android}.
+ an NFC Forum Tag enters or leaves proximity. Before these signals are emitted target detection
+ must be started with the startTargetDetection() function. Target detection can be stopped with
+ the stopTargetDetection() function. When the target is no longer required the target should be
+ deleted as other applications may be blocked from accessing the target.
\section3 NFC on Linux
- The \l{https://01.org/linux-nfc}{Linux NFC project} provides software to support NFC on Linux platforms.
- The neard daemon will allow access to the supported hardware via DBus interfaces. QtNfc requires neard
- version 0.14 which can be built from source or installed via the appropriate Linux package manager. Not
- all API features are currently supported.
- To allow QtNfc to access the DBus interfaces the neard daemon has to be running. In case of problems
- debug output can be enabled by enabling categorized logging for 'qt.nfc.neard'.
+ The \l{https://github.com/linux-nfc/neard}{Linux NFC project} provides software to support NFC
+ on Linux platforms. The neard daemon will allow access to the supported hardware via DBus
+ interfaces. QtNfc requires neard version 0.14 which can be built from source or installed via
+ the appropriate Linux package manager. Not all API features are currently supported.
+ To allow QtNfc to access the DBus interfaces the neard daemon has to be running. In case of
+ problems debug output can be enabled by enabling categorized logging for 'qt.nfc.neard'.
*/
/*!
@@ -132,27 +71,25 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \enum QNearFieldManager::TargetAccessMode
+ \fn void QNearFieldManager::adapterStateChanged(AdapterState state)
- This enum describes the different access modes an application can have.
+ \since 5.12
+
+ This signal is emitted whenever the \a state of the NFC adapter changed.
- \value NoTargetAccess The application cannot access NFC capabilities.
- \value NdefReadTargetAccess The application can read NDEF messages from targets by calling
- QNearFieldTarget::readNdefMessages().
- \value NdefWriteTargetAccess The application can write NDEF messages to targets by calling
- QNearFieldTarget::writeNdefMessages().
- \value TagTypeSpecificTargetAccess The application can access targets using raw commands by
- calling QNearFieldTarget::sendCommand().
+ \note Currently, this signal is only emitted on Android.
*/
/*!
- \fn void QNearFieldManager::adapterStateChanged(AdapterState state)
+ \fn void QNearFieldManager::targetDetectionStopped()
- \since 5.12
+ \since 6.2
- This signal is emitted whenever the state of the NFC adapter changed.
+ This signal is emitted whenever the target detection is stopped.
- \note Currently, this signal is only emitted on Android.
+ \note Mostly this signal is emitted when \l stopTargetDetection() has been called.
+ Additionally the user is able to stop the detection on iOS within a popup shown
+ by the system during the scan, which also leads to emitting this signal.
*/
/*!
@@ -196,6 +133,8 @@ QNearFieldManager::QNearFieldManager(QObject *parent)
connect(d_ptr, &QNearFieldManagerPrivate::adapterStateChanged,
this, &QNearFieldManager::adapterStateChanged);
+ connect(d_ptr, &QNearFieldManagerPrivate::targetDetectionStopped,
+ this, &QNearFieldManager::targetDetectionStopped);
connect(d_ptr, &QNearFieldManagerPrivate::targetDetected,
this, &QNearFieldManager::targetDetected);
connect(d_ptr, &QNearFieldManagerPrivate::targetLost,
@@ -217,6 +156,8 @@ QNearFieldManager::QNearFieldManager(QNearFieldManagerPrivate *backend, QObject
connect(d_ptr, &QNearFieldManagerPrivate::adapterStateChanged,
this, &QNearFieldManager::adapterStateChanged);
+ connect(d_ptr, &QNearFieldManagerPrivate::targetDetectionStopped,
+ this, &QNearFieldManager::targetDetectionStopped);
connect(d_ptr, &QNearFieldManagerPrivate::targetDetected,
this, &QNearFieldManager::targetDetected);
connect(d_ptr, &QNearFieldManagerPrivate::targetLost,
@@ -232,211 +173,109 @@ QNearFieldManager::~QNearFieldManager()
}
/*!
+ \since 6.2
+
Returns \c true if the device has a NFC adapter and
it is turned on; otherwise returns \c false.
\sa isSupported()
*/
-bool QNearFieldManager::isAvailable() const
+bool QNearFieldManager::isEnabled() const
{
Q_D(const QNearFieldManager);
- return d->isAvailable();
+ return d->isEnabled();
}
/*!
\since 5.12
- Returns \c true if the underlying device has a NFC adapter; otherwise returns \c false.
+ Returns \c true if the underlying device has a NFC adapter; otherwise
+ returns \c false. If an \a accessMethod is given, the function returns
+ \c true only if the NFC adapter supports the given \a accessMethod.
- \sa isAvailable()
+ \sa isEnabled()
*/
-bool QNearFieldManager::isSupported() const
+bool QNearFieldManager::isSupported(QNearFieldTarget::AccessMethod accessMethod) const
{
Q_D(const QNearFieldManager);
- return d->isSupported();
-}
-/*!
- \fn bool QNearFieldManager::startTargetDetection()
-
- Starts detecting targets and returns true if target detection is
- successfully started; otherwise returns false. Causes the targetDetected() signal to be emitted
- when a target is within proximity.
- \sa stopTargetDetection()
-
- \note For platforms using neard: target detection will stop as soon as a tag has been detected.
-*/
-bool QNearFieldManager::startTargetDetection()
-{
- Q_D(QNearFieldManager);
- return d->startTargetDetection();
+ return d->isSupported(accessMethod);
}
/*!
- Stops detecting targets. The targetDetected() signal will no longer be emitted until another
- call to startTargetDetection() is made.
-*/
-void QNearFieldManager::stopTargetDetection()
-{
- Q_D(QNearFieldManager);
+ \fn bool QNearFieldManager::startTargetDetection(QNearFieldTarget::AccessMethod accessMethod)
- d->stopTargetDetection();
-}
+ Starts detecting targets and returns \c true if target detection started successfully;
+ otherwise returns \c false. Causes the targetDetected() signal to be emitted
+ when a target is within proximity. Only tags with the given \a accessMethod will be reported.
+ Target detection continues until \l stopTargetDetection() is called.
-static QMetaMethod methodForSignature(QObject *object, const char *method)
-{
- QByteArray normalizedMethod = QMetaObject::normalizedSignature(method);
-
- if (!QMetaObject::checkConnectArgs(SIGNAL(targetDetected(QNdefMessage,QNearFieldTarget*)),
- normalizedMethod)) {
- qWarning("Signatures do not match: %s:%d\n", __FILE__, __LINE__);
- return QMetaMethod();
- }
-
- quint8 memcode = (normalizedMethod.at(0) - '0') & 0x03;
- normalizedMethod = normalizedMethod.mid(1);
-
- int index;
- switch (memcode) {
- case QSLOT_CODE:
- index = object->metaObject()->indexOfSlot(normalizedMethod.constData());
- break;
- case QSIGNAL_CODE:
- index = object->metaObject()->indexOfSignal(normalizedMethod.constData());
- break;
- case QMETHOD_CODE:
- index = object->metaObject()->indexOfMethod(normalizedMethod.constData());
- break;
- default:
- index = -1;
- }
-
- if (index == -1)
- return QMetaMethod();
-
- return object->metaObject()->method(index);
-}
+ To detect targets with a different \a accessMethod, stopTargetDetection() must be called first.
-/*!
- Registers \a object to receive notifications on \a method when a tag has been detected and has
- an NDEF record that matches \a typeNameFormat and \a type. The \a method on \a object should
- have the prototype
- 'void targetDetected(const QNdefMessage &message, QNearFieldTarget *target)'.
+ \note On iOS, it is impossible to start target detection for both NdefAccess and TagTypeSpecificAccess
+ at the same time. So if AnyAccess is selected, NdefAccess will be used instead.
- Returns an identifier, which can be used to unregister the handler, on success; otherwise
- returns -1.
+ \note On platforms using neard, target detection will stop as soon as a tag has been detected.
- \note The \e target parameter of \a method may not be available on all platforms, in which case
- \e target will be 0.
-
- \note On platforms using neard registering message handlers is not supported.
+ \sa stopTargetDetection()
*/
-
-int QNearFieldManager::registerNdefMessageHandler(QNdefRecord::TypeNameFormat typeNameFormat,
- const QByteArray &type,
- QObject *object, const char *method)
+bool QNearFieldManager::startTargetDetection(QNearFieldTarget::AccessMethod accessMethod)
{
- QMetaMethod metaMethod = methodForSignature(object, method);
- if (!metaMethod.enclosingMetaObject())
- return -1;
-
- QNdefFilter filter;
- filter.appendRecord(typeNameFormat, type);
-
Q_D(QNearFieldManager);
- return d->registerNdefMessageHandler(filter, object, metaMethod);
+ return d->startTargetDetection(accessMethod);
}
/*!
- \fn int QNearFieldManager::registerNdefMessageHandler(QObject *object, const char *method)
+ Stops detecting targets. The \l targetDetected() signal will no longer be emitted until another
+ call to \l startTargetDetection() is made. Targets detected before are still valid.
- Registers \a object to receive notifications on \a method when a tag has been detected and has
- an NDEF message that matches a pre-registered message format. The \a method on \a object should
- have the prototype
- 'void targetDetected(const QNdefMessage &message, QNearFieldTarget *target)'.
+ \note On iOS, detected targets become invalid after this call (e.g. an attempt to write or
+ read NDEF messages will result in an error).
- Returns an identifier, which can be used to unregister the handler, on success; otherwise
- returns -1.
+ If an \a errorMessage is provided, it is a hint to the system that the application's goal
+ was not achieved. The \a errorMessage and a matching error icon are shown to the user.
+ Calling this function with an empty \a errorMessage implies a successful end of operation;
+ otherwise, an \a errorMessage should be passed to this function.
- This function is used to register a QNearFieldManager instance to receive notifications when a
- NDEF message matching a pre-registered message format is received. See the section on
- \l {Automatically launching NDEF message handlers}.
+ \note Currently, \a errorMessage only has an effect on iOS because the system shows a popup
+ during the scan where the \a errorMessage is visible. Other platforms will ignore this
+ parameter.
- \note The \e target parameter of \a method may not be available on all platforms, in which case
- \e target will be 0.
+ \sa setUserInformation()
*/
-int QNearFieldManager::registerNdefMessageHandler(QObject *object, const char *method)
+void QNearFieldManager::stopTargetDetection(const QString &errorMessage)
{
- QMetaMethod metaMethod = methodForSignature(object, method);
- if (!metaMethod.enclosingMetaObject())
- return -1;
-
Q_D(QNearFieldManager);
- return d->registerNdefMessageHandler(object, metaMethod);
+ d->stopTargetDetection(errorMessage);
}
/*!
- Registers \a object to receive notifications on \a method when a tag has been detected and has
- an NDEF message that matches \a filter is detected. The \a method on \a object should have the
- prototype 'void targetDetected(const QNdefMessage &message, QNearFieldTarget *target)'.
+ \since 6.2
- Returns an identifier, which can be used to unregister the handler, on success; otherwise
- returns -1.
+ Sets the message that the system shows to the user. If target detection is running, the
+ \a message will be updated immediately and can be used as a progress message. The last message
+ set before a call to \l startTargetDetection() without an error message is used as a success
+ message. If target detection is not running, the \a message will be used as the initial
+ message when the next detection is started. By default, no message is shown to the user.
- \note The \e target parameter of \a method may not be available on all platforms, in which case
- \e target will be 0.
-*/
-int QNearFieldManager::registerNdefMessageHandler(const QNdefFilter &filter,
- QObject *object, const char *method)
-{
- QMetaMethod metaMethod = methodForSignature(object, method);
- if (!metaMethod.enclosingMetaObject())
- return -1;
+ \note Currently, this function only has an effect on iOS because the system shows a popup
+ during the scan. On iOS, this \a message is mapped to the alert message which is shown upon
+ successful completion of the scan. Other platforms will ignore \a message.
- Q_D(QNearFieldManager);
-
- return d->registerNdefMessageHandler(filter, object, metaMethod);
-}
-
-/*!
- Unregisters the target detect handler identified by \a handlerId.
-
- Returns true on success; otherwise returns false.
+ \sa startTargetDetection(), stopTargetDetection()
*/
-bool QNearFieldManager::unregisterNdefMessageHandler(int handlerId)
+void QNearFieldManager::setUserInformation(const QString &message)
{
Q_D(QNearFieldManager);
- return d->unregisterNdefMessageHandler(handlerId);
+ d->setUserInformation(message);
}
-/*!
- Sets the requested target access modes to \a accessModes.
-*/
-void QNearFieldManager::setTargetAccessModes(TargetAccessModes accessModes)
-{
- Q_D(QNearFieldManager);
-
- TargetAccessModes removedModes = ~accessModes & d->m_requestedModes;
- if (removedModes)
- d->releaseAccess(removedModes);
-
- TargetAccessModes newModes = accessModes & ~d->m_requestedModes;
- if (newModes)
- d->requestAccess(newModes);
-}
-
-/*!
- Returns current requested target access modes.
-*/
-QNearFieldManager::TargetAccessModes QNearFieldManager::targetAccessModes() const
-{
- Q_D(const QNearFieldManager);
+QT_END_NAMESPACE
- return d->m_requestedModes;
-}
+#include "moc_qnearfieldmanager_p.cpp"
-QT_END_NAMESPACE
+#include "moc_qnearfieldmanager.cpp"
diff --git a/src/nfc/qnearfieldmanager.h b/src/nfc/qnearfieldmanager.h
index 22506e7e..833245b0 100644
--- a/src/nfc/qnearfieldmanager.h
+++ b/src/nfc/qnearfieldmanager.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNEARFIELDMANAGER_H
#define QNEARFIELDMANAGER_H
@@ -63,43 +27,23 @@ public:
TurningOff = 4
};
Q_ENUM(AdapterState)
- enum TargetAccessMode {
- NoTargetAccess = 0x00,
- NdefReadTargetAccess = 0x01,
- NdefWriteTargetAccess = 0x02,
- TagTypeSpecificTargetAccess = 0x04
- };
- Q_ENUM(TargetAccessMode)
- Q_DECLARE_FLAGS(TargetAccessModes, TargetAccessMode)
explicit QNearFieldManager(QObject *parent = nullptr);
explicit QNearFieldManager(QNearFieldManagerPrivate *backend, QObject *parent = nullptr);
~QNearFieldManager();
- bool isAvailable() const;
- bool isSupported() const;
-
- void setTargetAccessModes(TargetAccessModes accessModes);
- TargetAccessModes targetAccessModes() const;
+ bool isEnabled() const;
+ bool isSupported(QNearFieldTarget::AccessMethod accessMethod
+ = QNearFieldTarget::AnyAccess) const;
- bool startTargetDetection();
- void stopTargetDetection();
+ bool startTargetDetection(QNearFieldTarget::AccessMethod accessMethod);
+ void stopTargetDetection(const QString &errorMessage = QString());
- //TODO Qt 6 Consider removal of this registration mechanism
- //None of the currently supported platforms supports the feature
- //or in fact the implementation (on Android) is not what the
- //function is supposed to do.
- int registerNdefMessageHandler(QObject *object, const char *method);
- int registerNdefMessageHandler(QNdefRecord::TypeNameFormat typeNameFormat,
- const QByteArray &type,
- QObject *object, const char *method);
- int registerNdefMessageHandler(const QNdefFilter &filter,
- QObject *object, const char *method);
-
- bool unregisterNdefMessageHandler(int handlerId);
+ void setUserInformation(const QString &message);
Q_SIGNALS:
void adapterStateChanged(QNearFieldManager::AdapterState state);
+ void targetDetectionStopped();
void targetDetected(QNearFieldTarget *target);
void targetLost(QNearFieldTarget *target);
@@ -107,8 +51,6 @@ private:
QNearFieldManagerPrivate *d_ptr;
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(QNearFieldManager::TargetAccessModes)
-
QT_END_NAMESPACE
#endif // QNEARFIELDMANAGER_H
diff --git a/src/nfc/qnearfieldmanager_android.cpp b/src/nfc/qnearfieldmanager_android.cpp
index 0b305501..63cc8472 100644
--- a/src/nfc/qnearfieldmanager_android.cpp
+++ b/src/nfc/qnearfieldmanager_android.cpp
@@ -1,340 +1,148 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Centria research and development
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qnearfieldmanager_android_p.h"
-#include "qnearfieldtarget_android_p.h"
-#include "qndeffilter.h"
#include "qndefmessage.h"
-#include "qndefrecord.h"
#include "qbytearray.h"
#include "qcoreapplication.h"
-#include "qdebug.h"
-#include "qlist.h"
-#include <QScopedPointer>
#include <QtCore/QMetaType>
-#include <QtCore/QMetaMethod>
-#include <QtCore/private/qjnihelpers_p.h>
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC(QAndroidJniObject, broadcastReceiver)
-Q_GLOBAL_STATIC(QList<QNearFieldManagerPrivateImpl *>, broadcastListener)
-
extern "C"
{
- JNIEXPORT void JNICALL Java_org_qtproject_qt5_android_nfc_QtNfcBroadcastReceiver_jniOnReceive(
- JNIEnv */*env*/, jobject /*javaObject*/, jint state)
+ JNIEXPORT void JNICALL Java_org_qtproject_qt_android_nfc_QtNfcBroadcastReceiver_jniOnReceive(
+ JNIEnv */*env*/, jobject /*javaObject*/, jlong qtObject, jint state)
{
- QNearFieldManager::AdapterState adapterState = static_cast<QNearFieldManager::AdapterState>((int) state);
-
- for (const auto listener : qAsConst(*broadcastListener)) {
- Q_EMIT listener->adapterStateChanged(adapterState);
- }
+ QNearFieldManager::AdapterState adapterState =
+ static_cast<QNearFieldManager::AdapterState>(state);
+ auto obj = reinterpret_cast<QNearFieldManagerPrivateImpl *>(qtObject);
+ Q_ASSERT(obj != nullptr);
+ obj->adapterStateChanged(adapterState);
}
}
+Q_GLOBAL_STATIC(QMainNfcNewIntentListener, newIntentListener)
+
QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl() :
- m_detecting(false), m_handlerID(0)
+ detecting(false)
{
- qRegisterMetaType<QAndroidJniObject>("QAndroidJniObject");
+ qRegisterMetaType<QJniObject>("QJniObject");
qRegisterMetaType<QNdefMessage>("QNdefMessage");
- if (!broadcastReceiver->isValid()) {
- *broadcastReceiver = QAndroidJniObject("org/qtproject/qt5/android/nfc/QtNfcBroadcastReceiver",
- "(Landroid/content/Context;)V", QtAndroidPrivate::context());
- }
- broadcastListener->append(this);
-
- connect(this, &QNearFieldManagerPrivateImpl::targetDetected, this, &QNearFieldManagerPrivateImpl::handlerTargetDetected);
- connect(this, &QNearFieldManagerPrivateImpl::targetLost, this, &QNearFieldManagerPrivateImpl::handlerTargetLost);
+ broadcastReceiver = QJniObject::construct<QtJniTypes::QtNfcBroadcastReceiver>(
+ reinterpret_cast<jlong>(this), QNativeInterface::QAndroidApplication::context());
}
QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl()
{
- broadcastListener->removeOne(this);
- if (broadcastListener->isEmpty()) {
- broadcastReceiver->callMethod<void>("unregisterReceiver");
- *broadcastReceiver = QAndroidJniObject();
- }
+ broadcastReceiver.callMethod<void>("unregisterReceiver");
}
-void QNearFieldManagerPrivateImpl::handlerTargetDetected(QNearFieldTarget *target)
+void QNearFieldManagerPrivateImpl::onTargetDetected(QNearFieldTargetPrivateImpl *target)
{
- if (ndefMessageHandlers.count() == 0 && ndefFilterHandlers.count() == 0) // if no handler is registered
+ if (target->q_ptr) {
+ Q_EMIT targetDetected(target->q_ptr);
return;
- if (target->hasNdefMessage()) {
- connect(reinterpret_cast<NearFieldTarget *>(target), &NearFieldTarget::ndefMessageRead,
- this, &QNearFieldManagerPrivateImpl::handlerNdefMessageRead);
- connect(target, &QNearFieldTarget::requestCompleted,
- this, &QNearFieldManagerPrivateImpl::handlerRequestCompleted);
- connect(target, &QNearFieldTarget::error,
- this, &QNearFieldManagerPrivateImpl::handlerError);
-
- QNearFieldTarget::RequestId id = target->readNdefMessages();
- m_idToTarget.insert(id, target);
- }
-}
-
-void QNearFieldManagerPrivateImpl::handlerTargetLost(QNearFieldTarget *target)
-{
- disconnect(reinterpret_cast<NearFieldTarget *>(target), &NearFieldTarget::ndefMessageRead,
- this, &QNearFieldManagerPrivateImpl::handlerNdefMessageRead);
- disconnect(target, &QNearFieldTarget::requestCompleted,
- this, &QNearFieldManagerPrivateImpl::handlerRequestCompleted);
- disconnect(target, &QNearFieldTarget::error,
- this, &QNearFieldManagerPrivateImpl::handlerError);
- m_idToTarget.remove(m_idToTarget.key(target));
-}
-
-struct VerifyRecord
-{
- QNdefFilter::Record filterRecord;
- unsigned int count;
-};
-
-void QNearFieldManagerPrivateImpl::handlerNdefMessageRead(const QNdefMessage &message, const QNearFieldTarget::RequestId &id)
-{
- QNearFieldTarget *target = m_idToTarget.value(id);
- //For message handlers without filters
- for (int i = 0; i < ndefMessageHandlers.count(); i++) {
- ndefMessageHandlers.at(i).second.invoke(ndefMessageHandlers.at(i).first.second, Q_ARG(QNdefMessage, message), Q_ARG(QNearFieldTarget*, target));
}
- //For message handlers that specified a filter
- for (int i = 0; i < ndefFilterHandlers.count(); ++i) {
- bool matched = true;
-
- QNdefFilter filter = ndefFilterHandlers.at(i).second.first;
-
- QList<VerifyRecord> filterRecords;
- for (int j = 0; j < filter.recordCount(); ++j) {
- VerifyRecord vr;
- vr.count = 0;
- vr.filterRecord = filter.recordAt(j);
-
- filterRecords.append(vr);
- }
-
- for (const QNdefRecord &record : message) {
- for (int j = 0; matched && (j < filterRecords.count()); ++j) {
- VerifyRecord &vr = filterRecords[j];
-
- if (vr.filterRecord.typeNameFormat == record.typeNameFormat() &&
- ( vr.filterRecord.type == record.type() ||
- vr.filterRecord.type.isEmpty()) ) {
- ++vr.count;
- break;
- } else {
- if (filter.orderMatch()) {
- if (vr.filterRecord.minimum <= vr.count &&
- vr.count <= vr.filterRecord.maximum) {
- continue;
- } else {
- matched = false;
- }
- }
- }
- }
- }
-
- for (int j = 0; matched && (j < filterRecords.count()); ++j) {
- const VerifyRecord &vr = filterRecords.at(j);
-
- if (vr.filterRecord.minimum <= vr.count && vr.count <= vr.filterRecord.maximum)
- continue;
- else
- matched = false;
- }
-
- if (matched) {
- ndefFilterHandlers.at(i).second.second.invoke(ndefFilterHandlers.at(i).first.second, Q_ARG(QNdefMessage, message), Q_ARG(QNearFieldTarget*, target));
- }
- }
+ Q_EMIT targetDetected(new QNearFieldTarget(target, this));
}
-void QNearFieldManagerPrivateImpl::handlerRequestCompleted(const QNearFieldTarget::RequestId &id)
+void QNearFieldManagerPrivateImpl::onTargetLost(QNearFieldTargetPrivateImpl *target)
{
- m_idToTarget.remove(id);
+ Q_EMIT targetLost(target->q_ptr);
}
-void QNearFieldManagerPrivateImpl::handlerError(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id)
+bool QNearFieldManagerPrivateImpl::isEnabled() const
{
- Q_UNUSED(error);
- m_idToTarget.remove(id);
+ return QtNfc::isEnabled();
}
-bool QNearFieldManagerPrivateImpl::isAvailable() const
+bool QNearFieldManagerPrivateImpl::isSupported(QNearFieldTarget::AccessMethod accessMethod) const
{
- return AndroidNfc::isAvailable();
-}
+ if (accessMethod == QNearFieldTarget::UnknownAccess)
+ return false;
-bool QNearFieldManagerPrivateImpl::isSupported() const
-{
- return AndroidNfc::isSupported();
+ return QtNfc::isSupported();
}
-bool QNearFieldManagerPrivateImpl::startTargetDetection()
+bool QNearFieldManagerPrivateImpl::startTargetDetection(QNearFieldTarget::AccessMethod accessMethod)
{
- if (m_detecting)
+ if (detecting)
return false; // Already detecting targets
- m_detecting = true;
- updateReceiveState();
- return true;
-}
+ if (newIntentListener.isDestroyed())
+ return false;
-void QNearFieldManagerPrivateImpl::stopTargetDetection()
-{
- m_detecting = false;
- updateReceiveState();
-}
-
-// FIXME This is supposed to be a platform registration. A message that
-// matches the given NDEF filter should restart the current application.
-// The implementation below only works as long as the current application
-// is running. It is not a platform wide registration on Android.
-int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(QObject *object, const QMetaMethod &method)
-{
- ndefMessageHandlers.append(QPair<QPair<int, QObject *>, QMetaMethod>(QPair<int, QObject *>(m_handlerID, object), method));
- updateReceiveState();
- //Returns the handler ID and increments it afterwards
- return m_handlerID++;
-}
-
-// FIXME see above
-int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(const QNdefFilter &filter,
- QObject *object, const QMetaMethod &method)
-{
- //If no record is set in the filter, we ignore the filter
- if (filter.recordCount()==0)
- return registerNdefMessageHandler(object, method);
-
- ndefFilterHandlers.append(QPair<QPair<int, QObject*>, QPair<QNdefFilter, QMetaMethod> >
- (QPair<int, QObject*>(m_handlerID, object), QPair<QNdefFilter, QMetaMethod>(filter, method)));
-
- updateReceiveState();
-
- return m_handlerID++;
-}
-
-bool QNearFieldManagerPrivateImpl::unregisterNdefMessageHandler(int handlerId)
-{
- for (int i=0; i<ndefMessageHandlers.count(); ++i) {
- if (ndefMessageHandlers.at(i).first.first == handlerId) {
- ndefMessageHandlers.removeAt(i);
- updateReceiveState();
- return true;
- }
- }
- for (int i=0; i<ndefFilterHandlers.count(); ++i) {
- if (ndefFilterHandlers.at(i).first.first == handlerId) {
- ndefFilterHandlers.removeAt(i);
- updateReceiveState();
- return true;
- }
- }
- return false;
-}
-
-void QNearFieldManagerPrivateImpl::requestAccess(QNearFieldManager::TargetAccessModes accessModes)
-{
- Q_UNUSED(accessModes);
- //Do nothing, because we dont have access modes for the target
+ detecting = true;
+ requestedMethod = accessMethod;
+ newIntentListener->registerListener(this);
+ return true;
}
-void QNearFieldManagerPrivateImpl::releaseAccess(QNearFieldManager::TargetAccessModes accessModes)
+void QNearFieldManagerPrivateImpl::stopTargetDetection(const QString &)
{
- Q_UNUSED(accessModes);
- //Do nothing, because we dont have access modes for the target
+ detecting = false;
+ if (newIntentListener.exists())
+ newIntentListener->unregisterListener(this);
+ Q_EMIT targetDetectionStopped();
}
-void QNearFieldManagerPrivateImpl::newIntent(QAndroidJniObject intent)
+void QNearFieldManagerPrivateImpl::newIntent(QJniObject intent)
{
// This function is called from different thread and is used to move intent to main thread.
- QMetaObject::invokeMethod(this, "onTargetDiscovered", Qt::QueuedConnection, Q_ARG(QAndroidJniObject, intent));
+ QMetaObject::invokeMethod(this, [this, intent] {
+ this->onTargetDiscovered(intent);
+ }, Qt::QueuedConnection);
}
-QByteArray QNearFieldManagerPrivateImpl::getUid(const QAndroidJniObject &intent)
+QByteArray QNearFieldManagerPrivateImpl::getUid(const QJniObject &intent)
{
if (!intent.isValid())
return QByteArray();
- QAndroidJniEnvironment env;
- QAndroidJniObject tag = AndroidNfc::getTag(intent);
+ QJniObject tag = QtNfc::getTag(intent);
return getUidforTag(tag);
}
-void QNearFieldManagerPrivateImpl::onTargetDiscovered(QAndroidJniObject intent)
+void QNearFieldManagerPrivateImpl::onTargetDiscovered(QJniObject intent)
{
- // Only intents with a tag are relevant
- if (!AndroidNfc::getTag(intent).isValid())
- return;
-
// Getting UID
QByteArray uid = getUid(intent);
// Accepting all targets but only sending signal of requested types.
- NearFieldTarget *&target = m_detectedTargets[uid];
+ QNearFieldTargetPrivateImpl *&target = detectedTargets[uid];
if (target) {
target->setIntent(intent); // Updating existing target
} else {
- target = new NearFieldTarget(intent, uid, this);
- connect(target, &NearFieldTarget::targetDestroyed, this, &QNearFieldManagerPrivateImpl::onTargetDestroyed);
- connect(target, &NearFieldTarget::targetLost, this, &QNearFieldManagerPrivateImpl::targetLost);
+ target = new QNearFieldTargetPrivateImpl(intent, uid);
+
+ if (target->accessMethods() & requestedMethod) {
+ connect(target, &QNearFieldTargetPrivateImpl::targetDestroyed, this, &QNearFieldManagerPrivateImpl::onTargetDestroyed);
+ connect(target, &QNearFieldTargetPrivateImpl::targetLost, this, &QNearFieldManagerPrivateImpl::onTargetLost);
+ onTargetDetected(target);
+ } else {
+ delete target;
+ detectedTargets.remove(uid);
+ }
}
- emit targetDetected(target);
}
void QNearFieldManagerPrivateImpl::onTargetDestroyed(const QByteArray &uid)
{
- m_detectedTargets.remove(uid);
+ detectedTargets.remove(uid);
}
-QByteArray QNearFieldManagerPrivateImpl::getUidforTag(const QAndroidJniObject &tag)
+QByteArray QNearFieldManagerPrivateImpl::getUidforTag(const QJniObject &tag)
{
if (!tag.isValid())
return QByteArray();
- QAndroidJniEnvironment env;
- QAndroidJniObject tagId = tag.callObjectMethod("getId", "()[B");
+ QJniEnvironment env;
+ QJniObject tagId = tag.callMethod<jbyteArray>("getId");
QByteArray uid;
jsize len = env->GetArrayLength(tagId.object<jbyteArray>());
uid.resize(len);
@@ -342,17 +150,4 @@ QByteArray QNearFieldManagerPrivateImpl::getUidforTag(const QAndroidJniObject &t
return uid;
}
-void QNearFieldManagerPrivateImpl::updateReceiveState()
-{
- if (m_detecting) {
- AndroidNfc::registerListener(this);
- } else {
- if (ndefMessageHandlers.count() || ndefFilterHandlers.count()) {
- AndroidNfc::registerListener(this);
- } else {
- AndroidNfc::unregisterListener(this);
- }
- }
-}
-
QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanager_android_p.h b/src/nfc/qnearfieldmanager_android_p.h
index 7bf444d9..76a5fd20 100644
--- a/src/nfc/qnearfieldmanager_android_p.h
+++ b/src/nfc/qnearfieldmanager_android_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Centria research and development
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNEARFIELDMANAGER_ANDROID_P_H
#define QNEARFIELDMANAGER_ANDROID_P_H
@@ -52,22 +16,18 @@
//
#include "qnearfieldmanager_p.h"
-#include "qnearfieldmanager.h"
-#include "qnearfieldtarget.h"
+#include "qnearfieldtarget_android_p.h"
#include "android/androidjninfc_p.h"
+#include "android/androidmainnewintentlistener_p.h"
#include <QHash>
-#include <QMap>
-#include <QtAndroidExtras/QAndroidJniObject>
-#include <QtAndroidExtras/QAndroidJniEnvironment>
+#include <QtCore/QJniObject>
QT_BEGIN_NAMESPACE
-typedef QList<QNdefMessage> QNdefMessageList;
-
-class NearFieldTarget;
class QByteArray;
-class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivate, public AndroidNfc::AndroidNfcListenerInterface
+class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivate,
+ public QAndroidNfcListenerInterface
{
Q_OBJECT
@@ -75,39 +35,28 @@ public:
QNearFieldManagerPrivateImpl();
~QNearFieldManagerPrivateImpl() override;
- bool isAvailable() const override;
- bool isSupported() const override;
- bool startTargetDetection() override;
- void stopTargetDetection() override;
- int registerNdefMessageHandler(QObject *object, const QMetaMethod &method) override;
- int registerNdefMessageHandler(const QNdefFilter &filter, QObject *object, const QMetaMethod &method) override;
- bool unregisterNdefMessageHandler(int handlerId) override;
- void requestAccess(QNearFieldManager::TargetAccessModes accessModes) override;
- void releaseAccess(QNearFieldManager::TargetAccessModes accessModes) override;
- void newIntent(QAndroidJniObject intent);
- QByteArray getUid(const QAndroidJniObject &intent);
-
-public slots:
- void onTargetDiscovered(QAndroidJniObject intent);
- void onTargetDestroyed(const QByteArray &uid);
- void handlerTargetDetected(QNearFieldTarget *target);
- void handlerTargetLost(QNearFieldTarget *target);
- void handlerNdefMessageRead(const QNdefMessage &message, const QNearFieldTarget::RequestId &id);
- void handlerRequestCompleted(const QNearFieldTarget::RequestId &id);
- void handlerError(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id);
+ bool isEnabled() const override;
+ bool isSupported(QNearFieldTarget::AccessMethod accessMethod) const override;
+ bool startTargetDetection(QNearFieldTarget::AccessMethod accessMethod) override;
+ void stopTargetDetection(const QString &errorMessage) override;
+ void newIntent(QJniObject intent) override;
+ QByteArray getUid(const QJniObject &intent);
protected:
- static QByteArray getUidforTag(const QAndroidJniObject &tag);
- void updateReceiveState();
+ static QByteArray getUidforTag(const QJniObject &tag);
private:
- bool m_detecting;
- QHash<QByteArray, NearFieldTarget*> m_detectedTargets;
- QMap<QNearFieldTarget::RequestId, QNearFieldTarget*> m_idToTarget;
+ bool detecting;
+ QNearFieldTarget::AccessMethod requestedMethod;
+ QHash<QByteArray, QNearFieldTargetPrivateImpl*> detectedTargets;
- int m_handlerID;
- QList< QPair<QPair<int, QObject *>, QMetaMethod> > ndefMessageHandlers;
- QList< QPair<QPair<int, QObject *>, QPair<QNdefFilter, QMetaMethod> > > ndefFilterHandlers;
+ QJniObject broadcastReceiver;
+
+private slots:
+ void onTargetDiscovered(QJniObject intent);
+ void onTargetDestroyed(const QByteArray &uid);
+ void onTargetDetected(QNearFieldTargetPrivateImpl *target);
+ void onTargetLost(QNearFieldTargetPrivateImpl *target);
};
QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanager_emulator.cpp b/src/nfc/qnearfieldmanager_emulator.cpp
deleted file mode 100644
index 4b5e5e0c..00000000
--- a/src/nfc/qnearfieldmanager_emulator.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnearfieldmanager_emulator_p.h"
-#include "qnearfieldtarget_emulator_p.h"
-
-#include "qndefmessage.h"
-#include "qtlv_p.h"
-
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl()
-{
- TagActivator *activator = TagActivator::instance();
- activator->initialize();
-
- connect(activator, &TagActivator::tagActivated, this, &QNearFieldManagerPrivateImpl::tagActivated);
- connect(activator, &TagActivator::tagDeactivated, this, &QNearFieldManagerPrivateImpl::tagDeactivated);
-}
-
-QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl()
-{
-}
-
-bool QNearFieldManagerPrivateImpl::isAvailable() const
-{
- return true;
-}
-
-void QNearFieldManagerPrivateImpl::reset()
-{
- TagActivator::instance()->reset();
-}
-
-void QNearFieldManagerPrivateImpl::tagActivated(TagBase *tag)
-{
- QNearFieldTarget *target = m_targets.value(tag).data();
- if (!target) {
- if (dynamic_cast<NfcTagType1 *>(tag))
- target = new TagType1(tag, this);
- else if (dynamic_cast<NfcTagType2 *>(tag))
- target = new TagType2(tag, this);
- else
- qFatal("Unknown emulator tag type");
-
- m_targets.insert(tag, target);
- }
-
- targetActivated(target);
-}
-
-void QNearFieldManagerPrivateImpl::tagDeactivated(TagBase *tag)
-{
- QNearFieldTarget *target = m_targets.value(tag).data();
- if (!target) {
- m_targets.remove(tag);
- return;
- }
-
- targetDeactivated(target);
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanager_emulator_p.h b/src/nfc/qnearfieldmanager_emulator_p.h
deleted file mode 100644
index 0416388a..00000000
--- a/src/nfc/qnearfieldmanager_emulator_p.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNEARFIELDMANAGER_EMULATOR_H
-#define QNEARFIELDMANAGER_EMULATOR_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qnearfieldmanagervirtualbase_p.h"
-#include "qnearfieldtarget.h"
-#include "qndeffilter.h"
-
-#include <QtCore/QObject>
-#include <QtCore/QPointer>
-
-QT_BEGIN_NAMESPACE
-
-class TagBase;
-class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivateVirtualBase
-{
- Q_OBJECT
-
-public:
- QNearFieldManagerPrivateImpl();
- ~QNearFieldManagerPrivateImpl() override;
-
- bool isAvailable() const override;
-
- void reset();
-
-private slots:
- void tagActivated(TagBase *tag);
- void tagDeactivated(TagBase *tag);
-
-private:
- void ndefReceived(const QNdefMessage &message, QNearFieldTarget *target);
-
- QMap<TagBase *, QPointer<QNearFieldTarget> > m_targets;
-
-};
-
-QT_END_NAMESPACE
-
-#endif // QNEARFIELDMANAGER_EMULATOR_H
diff --git a/src/nfc/qnearfieldmanager_generic.cpp b/src/nfc/qnearfieldmanager_generic.cpp
new file mode 100644
index 00000000..1a8df2ce
--- /dev/null
+++ b/src/nfc/qnearfieldmanager_generic.cpp
@@ -0,0 +1,24 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QCoreApplication>
+
+#include "qnearfieldmanager_generic_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*
+ Constructs a new near field manager private implementation.
+*/
+QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl()
+{
+}
+
+/*
+ Destroys the near field manager private implementation.
+*/
+QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl()
+{
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanager_generic_p.h b/src/nfc/qnearfieldmanager_generic_p.h
new file mode 100644
index 00000000..b01cd9ad
--- /dev/null
+++ b/src/nfc/qnearfieldmanager_generic_p.h
@@ -0,0 +1,31 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNEARFIELDMANAGERIMPL_P_H
+#define QNEARFIELDMANAGERIMPL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qnearfieldmanager_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivate
+{
+public:
+ QNearFieldManagerPrivateImpl();
+ ~QNearFieldManagerPrivateImpl() override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QNEARFIELDMANAGERIMPL_P_H
diff --git a/src/nfc/qnearfieldmanager_ios.mm b/src/nfc/qnearfieldmanager_ios.mm
new file mode 100644
index 00000000..4ab00a51
--- /dev/null
+++ b/src/nfc/qnearfieldmanager_ios.mm
@@ -0,0 +1,278 @@
+// Copyright (C) 2020 Governikus GmbH & Co. KG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qnearfieldmanager_ios_p.h"
+
+#include "ios/qiosnfcndefsessiondelegate_p.h"
+#include "ios/qiostagreaderdelegate_p.h"
+#include "ios/qiosndefnotifier_p.h"
+
+#include "qnearfieldtarget_ios_p.h"
+
+#include <QDateTime>
+
+#include <memory>
+
+#import <CoreNFC/NFCReaderSession.h>
+#import <CoreNFC/NFCNDEFReaderSession.h>
+#import <CoreNFC/NFCTagReaderSession.h>
+
+QT_BEGIN_NAMESPACE
+
+QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl()
+{
+ auto notifier = std::make_unique<QNfcNdefNotifier>();
+
+ if (@available(iOS 13, *))
+ delegate = [[QT_MANGLE_NAMESPACE(QIosTagReaderDelegate) alloc] initWithListener:this];
+
+ connect(this, &QNearFieldManagerPrivateImpl::tagDiscovered,
+ this, &QNearFieldManagerPrivateImpl::onTagDiscovered,
+ Qt::QueuedConnection);
+ connect(this, &QNearFieldManagerPrivateImpl::didInvalidateWithError,
+ this, &QNearFieldManagerPrivateImpl::onDidInvalidateWithError,
+ Qt::QueuedConnection);
+
+ ndefDelegate = [[QIosNfcNdefSessionDelegate alloc] initWithNotifier:notifier.get()];
+ if (ndefDelegate) {
+ auto watchDog = notifier.release(); // Delegate took the ownership.
+
+ connect(watchDog, &QNfcNdefNotifier::tagDetected,
+ this, &QNearFieldManagerPrivateImpl::onTagDiscovered,
+ Qt::QueuedConnection);
+ connect(watchDog, &QNfcNdefNotifier::invalidateWithError,
+ this, &QNearFieldManagerPrivateImpl::onDidInvalidateWithError,
+ Qt::QueuedConnection);
+ } else {
+ qCWarning(QT_IOS_NFC, "Failed to allocate NDEF reading session's delegate");
+ }
+
+ sessionTimer.setInterval(2000);
+ sessionTimer.setSingleShot(true);
+ connect(&sessionTimer, &QTimer::timeout, this, &QNearFieldManagerPrivateImpl::onSessionTimer);
+}
+
+QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl()
+{
+ if (@available(iOS 13, *))
+ [delegate release];
+
+ if (!ndefDelegate)
+ return;
+
+ if (auto queue = qt_Nfc_Queue()) {
+ dispatch_sync(queue, ^{
+ [ndefDelegate abort];
+ });
+ }
+
+ [ndefDelegate release];
+}
+
+bool QNearFieldManagerPrivateImpl::isSupported(QNearFieldTarget::AccessMethod accessMethod) const
+{
+ switch (accessMethod) {
+ case QNearFieldTarget::AnyAccess:
+ case QNearFieldTarget::NdefAccess:
+ return NFCNDEFReaderSession.readingAvailable;
+ case QNearFieldTarget::TagTypeSpecificAccess:
+ if (@available(iOS 13, *))
+ return NFCTagReaderSession.readingAvailable;
+ Q_FALLTHROUGH();
+ case QNearFieldTarget::UnknownAccess:
+ return false;
+ }
+}
+
+bool QNearFieldManagerPrivateImpl::startTargetDetection(QNearFieldTarget::AccessMethod accessMethod)
+{
+ if (detectionRunning)
+ return false;
+
+ activeAccessMethod = QNearFieldTarget::UnknownAccess;
+
+ switch (accessMethod) {
+ case QNearFieldTarget::UnknownAccess:
+ case QNearFieldTarget::AnyAccess:
+ return false;
+ case QNearFieldTarget::TagTypeSpecificAccess:
+ if (@available(iOS 13, *))
+ if (NFCTagReaderSession.readingAvailable) {
+ detectionRunning = scheduleSession(accessMethod);
+ if (detectionRunning)
+ activeAccessMethod = accessMethod;
+ return detectionRunning;
+ }
+ return false;
+ case QNearFieldTarget::NdefAccess:
+ if (NFCNDEFReaderSession.readingAvailable) {
+ detectionRunning = scheduleSession(accessMethod);
+ if (detectionRunning)
+ activeAccessMethod = accessMethod;
+ return detectionRunning;
+ }
+ return false;
+ }
+
+ return false;
+}
+
+void QNearFieldManagerPrivateImpl::stopTargetDetection(const QString &errorMessage)
+{
+ if (!detectionRunning)
+ return;
+
+ isSessionScheduled = false;
+
+ if (activeAccessMethod == QNearFieldTarget::TagTypeSpecificAccess) {
+ stopSession(errorMessage);
+ } else if (activeAccessMethod == QNearFieldTarget::NdefAccess) {
+ stopNdefSession(errorMessage);
+ } else {
+ qCWarning(QT_IOS_NFC, "Unknown access method, cannot stop target detection");
+ return;
+ }
+
+ detectionRunning = false;
+ Q_EMIT targetDetectionStopped();
+}
+
+bool QNearFieldManagerPrivateImpl::scheduleSession(QNearFieldTarget::AccessMethod accessMethod)
+{
+ if (sessionTimer.isActive()) {
+ isSessionScheduled = true;
+ return true;
+ }
+ isSessionScheduled = false;
+
+ if (accessMethod == QNearFieldTarget::TagTypeSpecificAccess) {
+ startSession();
+ return true;
+ } else if (accessMethod == QNearFieldTarget::NdefAccess) {
+ return startNdefSession();
+ }
+
+ return false;
+}
+
+void QNearFieldManagerPrivateImpl::startSession()
+{
+ if (@available(iOS 13, *)) {
+ [delegate startSession];
+ }
+}
+
+bool QNearFieldManagerPrivateImpl::startNdefSession()
+{
+ if (!ndefDelegate)
+ return false;
+
+ if (auto queue = qt_Nfc_Queue()) {
+ __block bool startSessionSucceded = false;
+ dispatch_sync(queue, ^{ startSessionSucceded = [ndefDelegate startSession]; });
+ return startSessionSucceded;
+ }
+
+ return false;
+}
+
+void QNearFieldManagerPrivateImpl::stopSession(const QString &error)
+{
+ Q_ASSERT(activeAccessMethod == QNearFieldTarget::TagTypeSpecificAccess);
+
+ clearTargets();
+
+ if (@available(iOS 13, *)) {
+ [delegate stopSession:error];
+ }
+}
+
+void QNearFieldManagerPrivateImpl::stopNdefSession(const QString &error)
+{
+ Q_ASSERT(activeAccessMethod == QNearFieldTarget::NdefAccess);
+
+ clearTargets();
+
+ if (auto queue = qt_Nfc_Queue()) {
+ dispatch_sync(queue, ^{
+ [ndefDelegate stopSession:error];
+ });
+ }
+}
+
+void QNearFieldManagerPrivateImpl::clearTargets()
+{
+ auto i = detectedTargets.begin();
+ while (i != detectedTargets.end()) {
+ (*i)->invalidate();
+ i = detectedTargets.erase(i);
+ }
+}
+
+
+void QNearFieldManagerPrivateImpl::setUserInformation(const QString &message)
+{
+ if (activeAccessMethod != QNearFieldTarget::NdefAccess)
+ [delegate alertMessage:message];
+
+ if (detectionRunning) {
+ // Too late!
+ qCWarning(QT_IOS_NFC,
+ "User information must be set prior before the target detection started");
+ return;
+ }
+
+ if (auto queue = qt_Nfc_Queue()) {
+ dispatch_sync(queue, ^{
+ [ndefDelegate setAlertMessage:message];
+ });
+ }
+}
+
+void QNearFieldManagerPrivateImpl::onTagDiscovered(void *tag)
+{
+ QNearFieldTargetPrivateImpl *target = nullptr;
+ if (activeAccessMethod == QNearFieldTarget::NdefAccess) {
+ [id(tag) retain];
+ target = new QNearFieldTargetPrivateImpl(ndefDelegate, tag);
+ } else {
+ target = new QNearFieldTargetPrivateImpl(tag);
+ }
+
+ detectedTargets += target;
+
+ connect(target, &QNearFieldTargetPrivateImpl::targetLost,
+ this, &QNearFieldManagerPrivateImpl::onTargetLost);
+ Q_EMIT targetDetected(new QNearFieldTarget(target, this));
+}
+
+void QNearFieldManagerPrivateImpl::onTargetLost(QNearFieldTargetPrivateImpl *target)
+{
+ detectedTargets.removeOne(target);
+ Q_EMIT targetLost(target->q_ptr);
+
+ if (detectionRunning && detectedTargets.isEmpty())
+ onDidInvalidateWithError(true);
+}
+
+void QNearFieldManagerPrivateImpl::onDidInvalidateWithError(bool doRestart)
+{
+ clearTargets();
+ sessionTimer.start();
+
+ if (detectionRunning && doRestart && scheduleSession(activeAccessMethod))
+ return;
+
+ detectionRunning = false;
+ Q_EMIT targetDetectionStopped();
+}
+
+void QNearFieldManagerPrivateImpl::onSessionTimer()
+{
+ if (isSessionScheduled && !scheduleSession(activeAccessMethod)) {
+ detectionRunning = false;
+ Q_EMIT targetDetectionStopped();
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanager_ios_p.h b/src/nfc/qnearfieldmanager_ios_p.h
new file mode 100644
index 00000000..ef638ecb
--- /dev/null
+++ b/src/nfc/qnearfieldmanager_ios_p.h
@@ -0,0 +1,84 @@
+// Copyright (C) 2020 Governikus GmbH & Co. KG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNEARFIELDMANAGER_IOS_P_H
+#define QNEARFIELDMANAGER_IOS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+#include <QtCore/private/qcore_mac_p.h>
+
+#include "qnearfieldmanager_p.h"
+
+#include <QTimer>
+
+#import <os/availability.h>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QIosTagReaderDelegate));
+
+Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QIosNfcNdefSessionDelegate));
+QT_NAMESPACE_ALIAS_OBJC_CLASS(QIosNfcNdefSessionDelegate);
+
+QT_BEGIN_NAMESPACE
+
+class QNearFieldTargetPrivateImpl;
+
+class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivate
+{
+ Q_OBJECT
+
+public:
+ QNearFieldManagerPrivateImpl();
+ ~QNearFieldManagerPrivateImpl();
+
+ bool isEnabled() const override
+ {
+ return true;
+ }
+
+ bool isSupported(QNearFieldTarget::AccessMethod accessMethod) const override;
+
+ bool startTargetDetection(QNearFieldTarget::AccessMethod accessMethod) override;
+ void stopTargetDetection(const QString &errorMessage) override;
+
+ void setUserInformation(const QString &message) override;
+
+Q_SIGNALS:
+ void tagDiscovered(void *tag);
+ void didInvalidateWithError(bool doRestart);
+
+private:
+ QT_MANGLE_NAMESPACE(QIosTagReaderDelegate) *delegate API_AVAILABLE(ios(13.0)) = nullptr;
+ QIosNfcNdefSessionDelegate *ndefDelegate = nullptr;
+ bool detectionRunning = false;
+ bool isSessionScheduled = false;
+ QTimer sessionTimer;
+ QList<QNearFieldTargetPrivateImpl *> detectedTargets;
+ QNearFieldTarget::AccessMethod activeAccessMethod = QNearFieldTarget::UnknownAccess;
+
+ bool scheduleSession(QNearFieldTarget::AccessMethod accessMethod);
+ void startSession();
+ bool startNdefSession();
+ void stopSession(const QString &error);
+ void stopNdefSession(const QString &error);
+ void clearTargets();
+
+private Q_SLOTS:
+ void onTagDiscovered(void *target);
+ void onTargetLost(QNearFieldTargetPrivateImpl *target);
+ void onDidInvalidateWithError(bool doRestart);
+ void onSessionTimer();
+};
+
+
+QT_END_NAMESPACE
+
+#endif // QNEARFIELDMANAGER_IOS_P_H
diff --git a/src/nfc/qnearfieldmanager_neard.cpp b/src/nfc/qnearfieldmanager_neard.cpp
index 4df1e0ef..4e942259 100644
--- a/src/nfc/qnearfieldmanager_neard.cpp
+++ b/src/nfc/qnearfieldmanager_neard.cpp
@@ -1,53 +1,17 @@
-/***************************************************************************
-**
-** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
-** Copyright (C) 2016 BasysKom GmbH.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 BlackBerry Limited, Copyright (C) 2016 BasysKom GmbH
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qnearfieldmanager_neard_p.h"
#include "qnearfieldtarget_neard_p.h"
-#include "neard/adapter_p.h"
-#include "neard/dbusproperties_p.h"
-#include "neard/dbusobjectmanager_p.h"
+#include "adapter_interface.h"
+#include "properties_interface.h"
+#include "objectmanager_interface.h"
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_NFC_NEARD)
+Q_LOGGING_CATEGORY(QT_NFC_NEARD, "qt.nfc.neard")
// TODO We need a constructor that lets us select an adapter
QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl()
@@ -94,7 +58,7 @@ QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl()
stopTargetDetection();
}
-bool QNearFieldManagerPrivateImpl::isAvailable() const
+bool QNearFieldManagerPrivateImpl::isEnabled() const
{
if (!m_neardHelper->dbusObjectManager()->isValid() || m_adapterPath.isNull()) {
qCWarning(QT_NFC_NEARD) << "dbus object manager invalid or adapter path invalid";
@@ -117,25 +81,25 @@ bool QNearFieldManagerPrivateImpl::isAvailable() const
return false;
}
-bool QNearFieldManagerPrivateImpl::isSupported() const
+bool QNearFieldManagerPrivateImpl::isSupported(QNearFieldTarget::AccessMethod accessMethod) const
{
if (m_adapterPath.isEmpty()) {
qCWarning(QT_NFC_NEARD) << "no adapter found, neard daemon running?";
return false;
}
- if (!m_neardHelper->dbusObjectManager()->isValid() || m_adapterPath.isNull()) {
+ if (!m_neardHelper->dbusObjectManager()->isValid()) {
qCWarning(QT_NFC_NEARD) << "dbus object manager invalid or adapter path invalid";
return false;
}
- return true;
+ return accessMethod == QNearFieldTarget::NdefAccess;
}
-bool QNearFieldManagerPrivateImpl::startTargetDetection()
+bool QNearFieldManagerPrivateImpl::startTargetDetection(QNearFieldTarget::AccessMethod accessMethod)
{
qCDebug(QT_NFC_NEARD) << "starting target detection";
- if (!isAvailable())
+ if (!isEnabled() || accessMethod != QNearFieldTarget::NdefAccess)
return false;
OrgFreedesktopDBusPropertiesInterface dbusProperties(QStringLiteral("org.neard"),
@@ -188,7 +152,7 @@ bool QNearFieldManagerPrivateImpl::startTargetDetection()
QDBusConnection::systemBus());
// possible modes: "Target", "Initiator", "Dual"
- QDBusPendingReply<> replyPollLoop = neardAdapter.StartPollLoop(QStringLiteral("Dual"));
+ QDBusPendingReply<> replyPollLoop = neardAdapter.StartPollLoop(QStringLiteral("Initiator"));
replyPollLoop.waitForFinished();
if (replyPollLoop.isError()) {
qCWarning(QT_NFC_NEARD) << "error when starting polling";
@@ -200,10 +164,10 @@ bool QNearFieldManagerPrivateImpl::startTargetDetection()
return true;
}
-void QNearFieldManagerPrivateImpl::stopTargetDetection()
+void QNearFieldManagerPrivateImpl::stopTargetDetection(const QString&)
{
qCDebug(QT_NFC_NEARD) << "stopping target detection";
- if (!isAvailable())
+ if (!isEnabled())
return;
OrgFreedesktopDBusPropertiesInterface dbusProperties(QStringLiteral("org.neard"),
@@ -240,40 +204,10 @@ void QNearFieldManagerPrivateImpl::stopTargetDetection()
}
}
-int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(QObject *object, const QMetaMethod &method)
-{
- Q_UNUSED(object);
- Q_UNUSED(method);
- return -1;
-}
-
-int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(const QNdefFilter &filter, QObject *object, const QMetaMethod &method)
-{
- Q_UNUSED(filter);
- Q_UNUSED(object);
- Q_UNUSED(method);
- return -1;
-}
-
-bool QNearFieldManagerPrivateImpl::unregisterNdefMessageHandler(int handlerId)
-{
- Q_UNUSED(handlerId);
- return false;
-}
-
-void QNearFieldManagerPrivateImpl::requestAccess(QNearFieldManager::TargetAccessModes accessModes)
-{
- Q_UNUSED(accessModes);
-}
-
-void QNearFieldManagerPrivateImpl::releaseAccess(QNearFieldManager::TargetAccessModes accessModes)
-{
- Q_UNUSED(accessModes);
-}
-
void QNearFieldManagerPrivateImpl::handleTagFound(const QDBusObjectPath &path)
{
- NearFieldTarget<QNearFieldTarget> *nfTag = new NearFieldTarget<QNearFieldTarget>(this, path);
+ auto priv = new QNearFieldTargetPrivateImpl(this, path);
+ auto nfTag = new QNearFieldTarget(priv, this);
m_activeTags.insert(path.path(), nfTag);
emit targetDetected(nfTag);
}
diff --git a/src/nfc/qnearfieldmanager_neard_p.h b/src/nfc/qnearfieldmanager_neard_p.h
index 88c45c1c..42cca80a 100644
--- a/src/nfc/qnearfieldmanager_neard_p.h
+++ b/src/nfc/qnearfieldmanager_neard_p.h
@@ -1,42 +1,5 @@
-/***************************************************************************
-**
-** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
-** Copyright (C) 2016 BasysKom GmbH.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 BlackBerry Limited, Copyright (C) 2016 BasysKom GmbH
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNEARFIELDMANAGER_NEARD_H
#define QNEARFIELDMANAGER_NEARD_H
@@ -73,25 +36,13 @@ public:
QNearFieldManagerPrivateImpl();
~QNearFieldManagerPrivateImpl() override;
- bool isAvailable() const override;
+ bool isEnabled() const override;
- bool isSupported() const override;
+ bool isSupported(QNearFieldTarget::AccessMethod) const override;
- bool startTargetDetection() override;
+ bool startTargetDetection(QNearFieldTarget::AccessMethod) override;
- void stopTargetDetection() override;
-
- // not implemented
- int registerNdefMessageHandler(QObject *object, const QMetaMethod &method) override;
-
- int registerNdefMessageHandler(const QNdefFilter &filter, QObject *object,
- const QMetaMethod &method) override;
-
- bool unregisterNdefMessageHandler(int handlerId) override;
-
- void requestAccess(QNearFieldManager::TargetAccessModes accessModes) override;
-
- void releaseAccess(QNearFieldManager::TargetAccessModes accessModes) override;
+ void stopTargetDetection(const QString& = QString()) override;
private Q_SLOTS:
void handleTagFound(const QDBusObjectPath&);
diff --git a/src/nfc/qnearfieldmanager_p.h b/src/nfc/qnearfieldmanager_p.h
index 351c844a..6ec8ff0e 100644
--- a/src/nfc/qnearfieldmanager_p.h
+++ b/src/nfc/qnearfieldmanager_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNEARFIELDMANAGER_P_H
#define QNEARFIELDMANAGER_P_H
@@ -68,73 +32,43 @@ class Q_AUTOTEST_EXPORT QNearFieldManagerPrivate : public QObject
Q_OBJECT
public:
- explicit QNearFieldManagerPrivate(QObject *parent = 0)
+ explicit QNearFieldManagerPrivate(QObject *parent = nullptr)
: QObject(parent)
{
}
- ~QNearFieldManagerPrivate()
+ virtual ~QNearFieldManagerPrivate()
{
}
- virtual bool isAvailable() const
+ virtual bool isEnabled() const
{
return false;
}
- virtual bool isSupported() const
+ virtual bool isSupported(QNearFieldTarget::AccessMethod) const
{
return false;
}
- virtual bool startTargetDetection()
+ virtual bool startTargetDetection(QNearFieldTarget::AccessMethod)
{
return false;
}
- virtual void stopTargetDetection()
+ virtual void stopTargetDetection(const QString &)
{
}
- virtual int registerNdefMessageHandler(QObject *object, const QMetaMethod &/*method*/)
+ virtual void setUserInformation(const QString &)
{
- Q_UNUSED(object);
-
- return -1;
- }
-
- virtual int registerNdefMessageHandler(const QNdefFilter &/*filter*/,
- QObject *object, const QMetaMethod &/*method*/)
- {
- Q_UNUSED(object);
-
- return -1;
- }
-
- virtual bool unregisterNdefMessageHandler(int handlerId)
- {
- Q_UNUSED(handlerId);
-
- return false;
- }
-
- virtual void requestAccess(QNearFieldManager::TargetAccessModes accessModes)
- {
- m_requestedModes |= accessModes;
- }
-
- virtual void releaseAccess(QNearFieldManager::TargetAccessModes accessModes)
- {
- m_requestedModes &= ~accessModes;
}
signals:
void adapterStateChanged(QNearFieldManager::AdapterState state);
+ void targetDetectionStopped();
void targetDetected(QNearFieldTarget *target);
void targetLost(QNearFieldTarget *target);
-
-public:
- QNearFieldManager::TargetAccessModes m_requestedModes;
};
QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanager_pcsc.cpp b/src/nfc/qnearfieldmanager_pcsc.cpp
new file mode 100644
index 00000000..2ce795d7
--- /dev/null
+++ b/src/nfc/qnearfieldmanager_pcsc.cpp
@@ -0,0 +1,140 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qnearfieldmanager_pcsc_p.h"
+#include "qnearfieldtarget_pcsc_p.h"
+#include "pcsc/qpcscmanager_p.h"
+#include "pcsc/qpcsccard_p.h"
+#include <QtCore/QLoggingCategory>
+#include <QtCore/QThread>
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt::StringLiterals;
+
+Q_DECLARE_LOGGING_CATEGORY(QT_NFC_PCSC)
+
+/*
+ Constructs a new near field manager private implementation.
+
+ This object creates a worker thread with an instance of QPcscManager in
+ it. All the communication with QPcscManager is done using signal-slot
+ mechanism.
+*/
+QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ m_worker = new QPcscManager;
+ m_workerThread = new QThread(this);
+ m_workerThread->setObjectName(u"QtNfcThread"_s);
+ m_worker->moveToThread(m_workerThread);
+
+ connect(m_worker, &QPcscManager::cardInserted, this,
+ &QNearFieldManagerPrivateImpl::onCardInserted);
+ connect(this, &QNearFieldManagerPrivateImpl::startTargetDetectionRequest, m_worker,
+ &QPcscManager::onStartTargetDetectionRequest);
+ connect(this, &QNearFieldManagerPrivateImpl::stopTargetDetectionRequest, m_worker,
+ &QPcscManager::onStopTargetDetectionRequest);
+
+ m_workerThread->start();
+}
+
+/*
+ Destroys the near field manager private implementation.
+*/
+QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ // Destroy the worker. It calls QThread::quit() on the working thread in
+ // its destructor.
+ QMetaObject::invokeMethod(m_worker, &QObject::deleteLater, Qt::QueuedConnection);
+ m_workerThread->wait();
+}
+
+bool QNearFieldManagerPrivateImpl::isEnabled() const
+{
+ return true;
+}
+
+bool QNearFieldManagerPrivateImpl::isSupported(QNearFieldTarget::AccessMethod accessMethod) const
+{
+ switch (accessMethod) {
+ case QNearFieldTarget::TagTypeSpecificAccess:
+ case QNearFieldTarget::NdefAccess:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool QNearFieldManagerPrivateImpl::startTargetDetection(QNearFieldTarget::AccessMethod accessMethod)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ Q_EMIT startTargetDetectionRequest(accessMethod);
+
+ return true;
+}
+
+void QNearFieldManagerPrivateImpl::stopTargetDetection(const QString &errorMessage)
+{
+ Q_UNUSED(errorMessage);
+
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ Q_EMIT stopTargetDetectionRequest();
+}
+
+/*
+ Invoked when the worker has detected a new card.
+
+ The worker will ensure that the card object remains valid until the manager
+ emits targetCreatedForCard() signal.
+*/
+void QNearFieldManagerPrivateImpl::onCardInserted(QPcscCard *card, const QByteArray &uid,
+ QNearFieldTarget::AccessMethods accessMethods,
+ int maxInputLength)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ auto priv = new QNearFieldTargetPrivateImpl(uid, accessMethods, maxInputLength, this);
+
+ connect(priv, &QNearFieldTargetPrivateImpl::disconnectRequest, card,
+ &QPcscCard::onDisconnectRequest);
+ connect(priv, &QNearFieldTargetPrivateImpl::destroyed, card, &QPcscCard::onTargetDestroyed);
+ connect(priv, &QNearFieldTargetPrivateImpl::sendCommandRequest, card,
+ &QPcscCard::onSendCommandRequest);
+ connect(priv, &QNearFieldTargetPrivateImpl::readNdefMessagesRequest, card,
+ &QPcscCard::onReadNdefMessagesRequest);
+ connect(priv, &QNearFieldTargetPrivateImpl::writeNdefMessagesRequest, card,
+ &QPcscCard::onWriteNdefMessagesRequest);
+
+ connect(priv, &QNearFieldTargetPrivateImpl::targetLost, this,
+ &QNearFieldManagerPrivateImpl::onTargetLost);
+
+ connect(card, &QPcscCard::disconnected, priv, &QNearFieldTargetPrivateImpl::onDisconnected);
+ connect(card, &QPcscCard::invalidated, priv, &QNearFieldTargetPrivateImpl::onInvalidated);
+ connect(card, &QPcscCard::requestCompleted, priv,
+ &QNearFieldTargetPrivateImpl::onRequestCompleted);
+ connect(card, &QPcscCard::ndefMessageRead, priv,
+ &QNearFieldTargetPrivateImpl::onNdefMessageRead);
+
+ auto target = new QNearFieldTarget(priv, this);
+
+ Q_EMIT targetDetected(target);
+
+ // Let the worker know that the card object can be deleted if it is no
+ // longer needed.
+ QMetaObject::invokeMethod(card, &QPcscCard::enableAutodelete, Qt::QueuedConnection);
+}
+
+void QNearFieldManagerPrivateImpl::onTargetLost(QNearFieldTargetPrivate *target)
+{
+ Q_EMIT targetLost(target->q_ptr);
+}
+
+Q_LOGGING_CATEGORY(QT_NFC_PCSC, "qt.nfc.pcsc")
+
+QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanager_pcsc_p.h b/src/nfc/qnearfieldmanager_pcsc_p.h
new file mode 100644
index 00000000..a74322af
--- /dev/null
+++ b/src/nfc/qnearfieldmanager_pcsc_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNEARFIELDMANAGER_PCSC_P_H
+#define QNEARFIELDMANAGER_PCSC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qnearfieldmanager_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QPcscManager;
+class QPcscCard;
+class QThread;
+
+class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivate
+{
+ Q_OBJECT
+public:
+ QNearFieldManagerPrivateImpl();
+ ~QNearFieldManagerPrivateImpl() override;
+
+ bool isEnabled() const override;
+ bool isSupported(QNearFieldTarget::AccessMethod accessMethod) const override;
+
+ bool startTargetDetection(QNearFieldTarget::AccessMethod accessMethod) override;
+ void stopTargetDetection(const QString &errorMessage) override;
+
+public Q_SLOTS:
+ void onCardInserted(QPcscCard *card, const QByteArray &uid,
+ QNearFieldTarget::AccessMethods accessMethods, int maxInputLength);
+ void onTargetLost(QNearFieldTargetPrivate *target);
+
+Q_SIGNALS:
+ void startTargetDetectionRequest(QNearFieldTarget::AccessMethod accessMethod);
+ void stopTargetDetectionRequest();
+
+private:
+ QThread *m_workerThread;
+ QPcscManager *m_worker;
+};
+
+QT_END_NAMESPACE
+
+#endif // QNEARFIELDMANAGER_PCSC_P_H
diff --git a/src/nfc/qnearfieldmanagerimpl_p.cpp b/src/nfc/qnearfieldmanagerimpl_p.cpp
deleted file mode 100644
index c8de0432..00000000
--- a/src/nfc/qnearfieldmanagerimpl_p.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QCoreApplication>
-
-#include "qnearfieldmanagerimpl_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*
- Constructs a new near field manager private implementation.
-*/
-QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl()
-{
-}
-
-/*
- Destroys the near field manager private implementation.
-*/
-QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl()
-{
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanagerimpl_p.h b/src/nfc/qnearfieldmanagerimpl_p.h
deleted file mode 100644
index 334d745b..00000000
--- a/src/nfc/qnearfieldmanagerimpl_p.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNEARFIELDMANAGERIMPL_P_H
-#define QNEARFIELDMANAGERIMPL_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qnearfieldmanager_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivate
-{
-public:
- QNearFieldManagerPrivateImpl();
- ~QNearFieldManagerPrivateImpl();
-};
-
-QT_END_NAMESPACE
-
-#endif // QNEARFIELDMANAGERIMPL_P_H
diff --git a/src/nfc/qnearfieldmanagervirtualbase.cpp b/src/nfc/qnearfieldmanagervirtualbase.cpp
deleted file mode 100644
index 82e272ce..00000000
--- a/src/nfc/qnearfieldmanagervirtualbase.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnearfieldmanagervirtualbase_p.h"
-#include "qndefmessage.h"
-#include "qtlv_p.h"
-
-QT_BEGIN_NAMESPACE
-
-//static inline bool matchesTarget(QNearFieldTarget::Type type,
-// const QList<QNearFieldTarget::Type> &types)
-//{
-// return types.contains(type) || types.contains(QNearFieldTarget::AnyTarget);
-//}
-
-QNearFieldManagerPrivateVirtualBase::QNearFieldManagerPrivateVirtualBase()
-{
-}
-
-QNearFieldManagerPrivateVirtualBase::~QNearFieldManagerPrivateVirtualBase()
-{
-}
-
-bool QNearFieldManagerPrivateVirtualBase::startTargetDetection()
-{
- return true;
-}
-
-void QNearFieldManagerPrivateVirtualBase::stopTargetDetection()
-{
-}
-
-int QNearFieldManagerPrivateVirtualBase::getFreeId()
-{
- if (!m_freeIds.isEmpty())
- return m_freeIds.takeFirst();
-
- m_registeredHandlers.append(Callback());
- return m_registeredHandlers.count() - 1;
-}
-
-int QNearFieldManagerPrivateVirtualBase::registerNdefMessageHandler(QObject *object,
- const QMetaMethod &method)
-{
- int id = getFreeId();
-
- Callback &callback = m_registeredHandlers[id];
-
- callback.filter = QNdefFilter();
- callback.object = object;
- callback.method = method;
-
- return id;
-}
-
-int QNearFieldManagerPrivateVirtualBase::registerNdefMessageHandler(const QNdefFilter &filter,
- QObject *object,
- const QMetaMethod &method)
-{
- int id = getFreeId();
-
- Callback &callback = m_registeredHandlers[id];
-
- callback.filter = filter;
- callback.object = object;
- callback.method = method;
-
- return id;
-}
-
-bool QNearFieldManagerPrivateVirtualBase::unregisterNdefMessageHandler(int id)
-{
- if (id < 0 || id >= m_registeredHandlers.count())
- return false;
-
- m_freeIds.append(id);
-
- while (m_freeIds.contains(m_registeredHandlers.count() - 1)) {
- m_freeIds.removeAll(m_registeredHandlers.count() - 1);
- m_registeredHandlers.removeLast();
- }
-
- return true;
-}
-
-void QNearFieldManagerPrivateVirtualBase::targetActivated(QNearFieldTarget *target)
-{
- //if (matchesTarget(target->type(), m_detectTargetTypes))
- emit targetDetected(target);
-
- if (target->hasNdefMessage()) {
- QTlvReader reader(target);
- while (!reader.atEnd()) {
- if (!reader.readNext()) {
- if (!target->waitForRequestCompleted(reader.requestId()))
- break;
- else
- continue;
- }
-
- // NDEF Message TLV
- if (reader.tag() == 0x03)
- ndefReceived(QNdefMessage::fromByteArray(reader.data()), target);
- }
- }
-}
-
-void QNearFieldManagerPrivateVirtualBase::targetDeactivated(QNearFieldTarget *target)
-{
- emit targetLost(target);
- QMetaObject::invokeMethod(target, "disconnected");
-}
-
-struct VerifyRecord
-{
- QNdefFilter::Record filterRecord;
- unsigned int count;
-};
-
-void QNearFieldManagerPrivateVirtualBase::ndefReceived(const QNdefMessage &message,
- QNearFieldTarget *target)
-{
- for (int i = 0; i < m_registeredHandlers.count(); ++i) {
- if (m_freeIds.contains(i))
- continue;
-
- Callback &callback = m_registeredHandlers[i];
-
- bool matched = true;
-
- QList<VerifyRecord> filterRecords;
- for (int j = 0; j < callback.filter.recordCount(); ++j) {
- VerifyRecord vr;
- vr.count = 0;
- vr.filterRecord = callback.filter.recordAt(j);
-
- filterRecords.append(vr);
- }
-
- for (const QNdefRecord &record : message) {
- for (int j = 0; matched && (j < filterRecords.count()); ++j) {
- VerifyRecord &vr = filterRecords[j];
-
- if (vr.filterRecord.typeNameFormat == record.typeNameFormat() &&
- ( vr.filterRecord.type == record.type() ||
- vr.filterRecord.type.isEmpty()) ) {
- ++vr.count;
- break;
- } else {
- if (callback.filter.orderMatch()) {
- if (vr.filterRecord.minimum <= vr.count &&
- vr.count <= vr.filterRecord.maximum) {
- continue;
- } else {
- matched = false;
- }
- }
- }
- }
- }
-
- for (int j = 0; matched && (j < filterRecords.count()); ++j) {
- const VerifyRecord &vr = filterRecords.at(j);
-
- if (vr.filterRecord.minimum <= vr.count && vr.count <= vr.filterRecord.maximum)
- continue;
- else
- matched = false;
- }
-
- if (matched) {
- callback.method.invoke(callback.object, Q_ARG(QNdefMessage, message),
- Q_ARG(QNearFieldTarget *, target));
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanagervirtualbase_p.h b/src/nfc/qnearfieldmanagervirtualbase_p.h
deleted file mode 100644
index 164edaf5..00000000
--- a/src/nfc/qnearfieldmanagervirtualbase_p.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNEARFIELDMANAGERVIRTUALBASE_P_H
-#define QNEARFIELDMANAGERVIRTUALBASE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qnearfieldmanager_p.h"
-
-#include <QtCore/QMetaMethod>
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldManagerPrivateVirtualBase : public QNearFieldManagerPrivate
-{
- Q_OBJECT
-
-public:
- QNearFieldManagerPrivateVirtualBase();
- ~QNearFieldManagerPrivateVirtualBase() override;
-
- bool startTargetDetection() override;
- void stopTargetDetection() override;
-
- int registerNdefMessageHandler(QObject *object, const QMetaMethod &method) override;
- int registerNdefMessageHandler(const QNdefFilter &filter,
- QObject *object, const QMetaMethod &method) override;
-
- bool unregisterNdefMessageHandler(int id) override;
-
-protected:
- struct Callback {
- QNdefFilter filter;
-
- QObject *object;
- QMetaMethod method;
- };
-
- void targetActivated(QNearFieldTarget *target);
- void targetDeactivated(QNearFieldTarget *target);
-
-private:
- int getFreeId();
- void ndefReceived(const QNdefMessage &message, QNearFieldTarget *target);
-
- QList<Callback> m_registeredHandlers;
- QList<int> m_freeIds;
- QList<QNearFieldTarget::Type> m_detectTargetTypes;
-};
-
-QT_END_NAMESPACE
-
-#endif // QNEARFIELDMANAGERVIRTUALBASE_P_H
diff --git a/src/nfc/qnearfieldsharemanager.cpp b/src/nfc/qnearfieldsharemanager.cpp
deleted file mode 100644
index 0709f60e..00000000
--- a/src/nfc/qnearfieldsharemanager.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#include "qnearfieldsharemanager.h"
-#include "qnearfieldsharemanager_p.h"
-
-#include "qnearfieldsharemanagerimpl_p.h"
-
-#include "qnearfieldsharetarget.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QNearFieldShareManager
- \brief The QNearFieldShareManager class manages all interactions related to sharing files and data over NFC.
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
- \since 5.3
-
- Applications can share NDEF data or file content using NFC technology by tapping two NFC-enabled devices
- together. The QNearFieldShareManager provides a high level entry point to access this functionality.
-
- The class allows both NDEF data and/or files to be shared between two devices by calling the setShareModes()
- method. This method specifies either an NDEF Data and/or a File transfer. The targetDetected() signal is emitted
- each time a share target is detected. A QNearFieldShareTarget pointer is passed with the signal, which can
- be used to share either an NDEF message or one or more files.
-
- The process of sharing files via NFC involves other underlying communication transports such as Bluetooth or Wi-Fi Direct.
- It is implementation specific how and what type of transports are used to perform file transfer. The overall time taken to
- transfer content depends on the maximum speed of the transport used. Note that the process of sharing NDEF message/data
- does not require the use of other transports outside NFC.
-
- If an error occurs, shareError() returns the error type.
-
- Platforms that do not support both NDEF data and file content sharing modes can return the supported subset in the
- supportedShareModes() method. Applications that call setShareModes() with an unsupported mode will receive an error
- signal with a UnsupportedShareModeError.
-
- Since sharing data over NFC is effectively a data pipe between two processes (one on the sender and one of
- the receiver), the application developer should only create a single instance of QNearFieldShareManager per
- application. This avoids the possibility that different parts of the same application attempt to all consume
- data transferred over NFC.
-*/
-
-/*!
- \enum QNearFieldShareManager::ShareError
-
- This enum specifies the share error type.
-
- \value NoError No error.
- \value UnknownError Unknown or internal error occurred.
- \value InvalidShareContentError Invalid content was provided for sharing.
- \value ShareCanceledError Data or file sharing is canceled on the local or remote device.
- \value ShareInterruptedError Data or file sharing is interrupted due to an I/O error.
- \value ShareRejectedError Data or file sharing is rejected by the remote device.
- \value UnsupportedShareModeError Data or file sharing is not supported by the share target.
- \value ShareAlreadyInProgressError Data or file sharing is already in progress.
- \value SharePermissionDeniedError File sharing is denied due to insufficient permission.
-*/
-
-/*!
- \enum QNearFieldShareManager::ShareMode
-
- This enum specifies the content type to be shared.
-
- \value NoShare No content is currently set to be shared.
- \value NdefShare Share NDEF message with target.
- \value FileShare Share file with target.
-*/
-
-/*!
- \fn void QNearFieldShareManager::targetDetected(QNearFieldShareTarget* shareTarget)
-
- This signal is emitted whenever a \a shareTarget is detected. The \a shareTarget
- instance is owned by QNearFieldShareManager and must not be deleted by the application.
-*/
-
-/*!
- \fn void QNearFieldShareManager::shareModesChanged(ShareModes modes)
-
- This signal is emitted whenever the share \a modes are changed.
-*/
-
-/*!
- \fn void QNearFieldShareManager::error(ShareError error)
-
- This signal is emitted whenever an \a error occurs related to a share request.
-*/
-
-/*!
- Constructs a new near field share manager with \a parent.
-*/
-QNearFieldShareManager::QNearFieldShareManager(QObject *parent)
-: QObject(parent), d_ptr(new QNearFieldShareManagerPrivateImpl(this))
-{
-}
-
-/*!
- Destroys the near field share manager.
-*/
-QNearFieldShareManager::~QNearFieldShareManager()
-{
-}
-
-/*!
- Initializes the NFC share \a mode to detect a QNearFieldShareTarget for data and/or file sharing.
- Calls to this method will overwrite previous share modes.
-
- A shareModesChanged() signal will be emitted when share modes are different from previous modes.
- A targetDetected() signal will be emitted if a share target is detected.
-*/
-void QNearFieldShareManager::setShareModes(ShareModes mode)
-{
- Q_D(QNearFieldShareManager);
- d->setShareModes(mode);
-}
-
-/*!
- Returns the shared modes supported by NFC.
-*/
-QNearFieldShareManager::ShareModes QNearFieldShareManager::supportedShareModes()
-{
- return QNearFieldShareManagerPrivateImpl::supportedShareModes();
-}
-
-/*!
- Returns which shared modes are set.
-*/
-QNearFieldShareManager::ShareModes QNearFieldShareManager::shareModes() const
-{
- Q_D(const QNearFieldShareManager);
- return d->shareModes();
-}
-
-/*!
- Returns the error code of the error that occurred.
- */
-QNearFieldShareManager::ShareError QNearFieldShareManager::shareError() const
-{
- Q_D(const QNearFieldShareManager);
- return d->shareError();
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldsharemanager.h b/src/nfc/qnearfieldsharemanager.h
deleted file mode 100644
index e34e9a64..00000000
--- a/src/nfc/qnearfieldsharemanager.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#ifndef QNEARFIELDSHAREMANAGER_H
-#define QNEARFIELDSHAREMANAGER_H
-
-#include <QtCore/QObject>
-#include <QtNfc/qtnfcglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldShareManagerPrivate;
-class QNearFieldShareTarget;
-
-class Q_NFC_EXPORT QNearFieldShareManager : public QObject
-{
- Q_OBJECT
-
-public:
- explicit QNearFieldShareManager(QObject *parent = nullptr);
- ~QNearFieldShareManager();
-
- enum ShareError {
- NoError,
- UnknownError,
- InvalidShareContentError,
- ShareCanceledError,
- ShareInterruptedError,
- ShareRejectedError,
- UnsupportedShareModeError,
- ShareAlreadyInProgressError,
- SharePermissionDeniedError
- };
- Q_ENUM(ShareError)
-
- enum ShareMode {
- NoShare = 0x00,
- NdefShare = 0x01,
- FileShare = 0x02
- };
- Q_ENUM(ShareMode)
- Q_DECLARE_FLAGS(ShareModes, ShareMode)
-
-public:
- static QNearFieldShareManager::ShareModes supportedShareModes();
- void setShareModes(ShareModes modes);
- QNearFieldShareManager::ShareModes shareModes() const;
- QNearFieldShareManager::ShareError shareError() const;
-
-Q_SIGNALS:
- void targetDetected(QNearFieldShareTarget* shareTarget);
- void shareModesChanged(QNearFieldShareManager::ShareModes modes);
- void error(QNearFieldShareManager::ShareError error);
-
-private:
- QScopedPointer<QNearFieldShareManagerPrivate> const d_ptr;
- Q_DECLARE_PRIVATE(QNearFieldShareManager)
- Q_DISABLE_COPY(QNearFieldShareManager)
-
- friend class QNearFieldShareManagerPrivateImpl;
- friend class QNearFieldShareTargetPrivateImpl;
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QNearFieldShareManager::ShareModes)
-
-QT_END_NAMESPACE
-
-#endif /* QNEARFIELDSHAREMANAGER_H */
diff --git a/src/nfc/qnearfieldsharemanager_p.h b/src/nfc/qnearfieldsharemanager_p.h
deleted file mode 100644
index fc802901..00000000
--- a/src/nfc/qnearfieldsharemanager_p.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#ifndef QNEARFIELDSHAREMANAGER_P_H_
-#define QNEARFIELDSHAREMANAGER_P_H_
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qnearfieldsharemanager.h"
-#include <QtCore/QObject>
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldShareManagerPrivate : public QObject
-{
- Q_OBJECT
-
-public:
- QNearFieldShareManagerPrivate(QNearFieldShareManager* q)
- : QObject(q)
- {
- }
-
- ~QNearFieldShareManagerPrivate()
- {
- }
-
- virtual void setShareModes(QNearFieldShareManager::ShareModes modes)
- {
- Q_UNUSED(modes)
- }
-
- virtual QNearFieldShareManager::ShareModes shareModes() const
- {
- return QNearFieldShareManager::NoShare;
- }
-
- virtual QNearFieldShareManager::ShareError shareError() const
- {
- return QNearFieldShareManager::NoError;
- }
-};
-
-QT_END_NAMESPACE
-
-#endif /* QNEARFIELDSHAREMANAGER_P_H_ */
diff --git a/src/nfc/qnearfieldsharemanagerimpl_p.cpp b/src/nfc/qnearfieldsharemanagerimpl_p.cpp
deleted file mode 100644
index 0187795c..00000000
--- a/src/nfc/qnearfieldsharemanagerimpl_p.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#include "qnearfieldsharemanagerimpl_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QNearFieldShareManagerPrivateImpl::QNearFieldShareManagerPrivateImpl(QNearFieldShareManager* q)
- : QNearFieldShareManagerPrivate(q)
-{
-}
-
-QNearFieldShareManagerPrivateImpl::~QNearFieldShareManagerPrivateImpl()
-{
-}
-
-QNearFieldShareManager::ShareModes QNearFieldShareManagerPrivateImpl::supportedShareModes()
-{
- return QNearFieldShareManager::NoShare;
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldsharemanagerimpl_p.h b/src/nfc/qnearfieldsharemanagerimpl_p.h
deleted file mode 100644
index c201f07b..00000000
--- a/src/nfc/qnearfieldsharemanagerimpl_p.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#ifndef QNEARFIELDSHAREMANAGERIMPL_P_H_
-#define QNEARFIELDSHAREMANAGERIMPL_P_H_
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qnearfieldsharemanager_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldShareManagerPrivateImpl : public QNearFieldShareManagerPrivate
-{
-public:
- QNearFieldShareManagerPrivateImpl(QNearFieldShareManager* q);
- ~QNearFieldShareManagerPrivateImpl();
-
- static QNearFieldShareManager::ShareModes supportedShareModes();
-};
-
-QT_END_NAMESPACE
-
-#endif /* QNEARFIELDSHAREMANAGERIMPL_P_H_ */
diff --git a/src/nfc/qnearfieldsharetarget.cpp b/src/nfc/qnearfieldsharetarget.cpp
deleted file mode 100644
index 16ba88f7..00000000
--- a/src/nfc/qnearfieldsharetarget.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#include "qnearfieldsharetarget.h"
-#include "qnearfieldsharetarget_p.h"
-
-#include "qnearfieldsharetargetimpl_p.h"
-
-#include "qnearfieldsharemanager.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QNearFieldShareTarget
- \brief The QNearFieldShareTarget class transfers data to remote device over NFC.
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
- \since 5.3
-
- The QNearFieldShareTarget class can be used for sharing NDEF message or files to a remote
- NFC enabled device supporting the same protocol.
-
- \sa QNearFieldShareManager
-*/
-
-/*!
- \fn void QNearFieldShareTarget::error(QNearFieldShareManager::ShareError error)
-
- This signal is emitted whenever an \a error occurs during transfer.
-*/
-
-/*!
- \fn void QNearFieldShareTarget::shareFinished()
-
- This signal is emitted whenever a data or file transfer has completed successfully.
-*/
-
-/*!
- Constructs a new near field share target with \a parent.
-*/
-QNearFieldShareTarget::QNearFieldShareTarget(QNearFieldShareManager::ShareModes modes, QObject *parent)
-: QObject(parent), d_ptr(new QNearFieldShareTargetPrivateImpl(modes, this))
-{
-}
-
-/*!
- Destroys the near field share target.
-*/
-QNearFieldShareTarget::~QNearFieldShareTarget()
-{
-}
-
-/*!
- Returns the share mode supported by the share target.
-*/
-QNearFieldShareManager::ShareModes QNearFieldShareTarget::shareModes() const
-{
- Q_D(const QNearFieldShareTarget);
- return d->shareModes();
-}
-
-/*!
- Share the NDEF \a message via the share target. This method starts sharing asynchronously and returns immediately.
- The method returns true if the request is accepted, otherwise returns false. Sharing is completed when the shareFinished()
- signal is emitted.
-*/
-bool QNearFieldShareTarget::share(const QNdefMessage &message)
-{
- Q_D(QNearFieldShareTarget);
- return d->share(message);
-}
-
-/*!
- Share the \a files via the share target. This method starts sharing asynchronously and returns immediately.
- The method returns true if the request is accepted, otherwise returns false. Sharing is completed when the shareFinished()
- signal is emitted.
-*/
-bool QNearFieldShareTarget::share(const QList<QFileInfo> &files)
-{
- Q_D(QNearFieldShareTarget);
- return d->share(files);
-}
-
-/*!
- Cancel the data or file sharing in progress.
-*/
-void QNearFieldShareTarget::cancel()
-{
- Q_D(QNearFieldShareTarget);
- d->cancel();
-}
-
-/*!
- Returns true if data or file sharing is in progress, otherwise returns false.
-*/
-bool QNearFieldShareTarget::isShareInProgress() const
-{
- Q_D(const QNearFieldShareTarget);
- return d->isShareInProgress();
-}
-
-/*!
- Returns the error code of the error that occurred.
- */
-QNearFieldShareManager::ShareError QNearFieldShareTarget::shareError() const
-{
- Q_D(const QNearFieldShareTarget);
- return d->shareError();
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldsharetarget.h b/src/nfc/qnearfieldsharetarget.h
deleted file mode 100644
index 441ffda7..00000000
--- a/src/nfc/qnearfieldsharetarget.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-
-#ifndef QNEARFIELDSHARETARGET_H
-#define QNEARFIELDSHARETARGET_H
-
-#include <QtCore/QObject>
-#include <QtCore/QFileInfo>
-#include <QtNfc/QNdefMessage>
-#include <QtNfc/QNearFieldShareManager>
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldShareTargetPrivate;
-
-class Q_NFC_EXPORT QNearFieldShareTarget : public QObject
-{
- Q_OBJECT
-
-public:
- ~QNearFieldShareTarget();
-
- QNearFieldShareManager::ShareModes shareModes() const;
- bool share(const QNdefMessage &message);
- bool share(const QList<QFileInfo> &files);
- void cancel();
- bool isShareInProgress() const;
- QNearFieldShareManager::ShareError shareError() const;
-
-Q_SIGNALS:
- void error(QNearFieldShareManager::ShareError error);
- void shareFinished();
-
-private:
- explicit QNearFieldShareTarget(QNearFieldShareManager::ShareModes modes, QObject *parent = nullptr);
-
- QNearFieldShareTargetPrivate *d_ptr;
- Q_DECLARE_PRIVATE(QNearFieldShareTarget)
- Q_DISABLE_COPY(QNearFieldShareTarget)
-
- friend class QNearFieldShareManagerPrivateImpl;
- friend class QNearFieldShareTargetPrivateImpl;
-};
-
-QT_END_NAMESPACE
-
-#endif /* QNEARFIELDSHARETARGET_H */
diff --git a/src/nfc/qnearfieldsharetarget_p.h b/src/nfc/qnearfieldsharetarget_p.h
deleted file mode 100644
index c6ae59d9..00000000
--- a/src/nfc/qnearfieldsharetarget_p.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-
-#ifndef QNEARFIELDSHARETARGET_P_H
-#define QNEARFIELDSHARETARGET_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qnearfieldsharetarget.h"
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldShareTargetPrivate : public QObject
-{
- Q_OBJECT
-
-public:
- QNearFieldShareTargetPrivate(QNearFieldShareManager::ShareModes modes, QNearFieldShareTarget *q)
- : QObject(q)
- {
- Q_UNUSED(modes)
- }
-
- ~QNearFieldShareTargetPrivate()
- {
- }
-
- virtual QNearFieldShareManager::ShareModes shareModes() const
- {
- return QNearFieldShareManager::NoShare;
- }
-
- virtual bool share(const QNdefMessage &message)
- {
- Q_UNUSED(message)
- return false;
- }
-
- virtual bool share(const QList<QFileInfo> &files)
- {
- Q_UNUSED(files)
- return false;
- }
-
- virtual void cancel()
- {
- }
-
- virtual bool isShareInProgress() const
- {
- return false;
- }
-
- virtual QNearFieldShareManager::ShareError shareError() const
- {
- return QNearFieldShareManager::NoError;
- }
-};
-
-QT_END_NAMESPACE
-
-#endif /* QNEARFIELDSHARETARGET_P_H */
diff --git a/src/nfc/qnearfieldsharetargetimpl_p.cpp b/src/nfc/qnearfieldsharetargetimpl_p.cpp
deleted file mode 100644
index fbc35f6c..00000000
--- a/src/nfc/qnearfieldsharetargetimpl_p.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#include "qnearfieldsharetargetimpl_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QNearFieldShareTargetPrivateImpl::QNearFieldShareTargetPrivateImpl(QNearFieldShareManager::ShareModes /*modes*/, QNearFieldShareTarget *q)
- : QNearFieldShareTargetPrivate(QNearFieldShareManager::NoShare, q)
-{
-}
-
-QNearFieldShareTargetPrivateImpl::~QNearFieldShareTargetPrivateImpl()
-{
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldsharetargetimpl_p.h b/src/nfc/qnearfieldsharetargetimpl_p.h
deleted file mode 100644
index 3df99271..00000000
--- a/src/nfc/qnearfieldsharetargetimpl_p.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/***************************************************************************
- **
- ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the QtNfc module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-
-#ifndef QNEARFIELDSHARETARGETIMPL_P_H
-#define QNEARFIELDSHARETARGETIMPL_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qnearfieldsharetarget_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldShareTargetPrivateImpl : public QNearFieldShareTargetPrivate
-{
-public:
- QNearFieldShareTargetPrivateImpl(QNearFieldShareManager::ShareModes modes, QNearFieldShareTarget *q);
- ~QNearFieldShareTargetPrivateImpl();
-};
-
-QT_END_NAMESPACE
-
-#endif /* QNEARFIELDSHARETARGETIMPL_P_H */
diff --git a/src/nfc/qnearfieldtagtype1.cpp b/src/nfc/qnearfieldtagtype1.cpp
deleted file mode 100644
index b3479203..00000000
--- a/src/nfc/qnearfieldtagtype1.cpp
+++ /dev/null
@@ -1,738 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnearfieldtagtype1_p.h"
-#include "qnearfieldtarget_p.h"
-#include "qndefmessage.h"
-#include "qtlv_p.h"
-
-#include <QtCore/QByteArray>
-#include <QtCore/QVariant>
-
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QNearFieldTagType1
- \brief The QNearFieldTagType1 class provides an interface for communicating with an NFC Tag
- Type 1 tag.
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
- \internal
-*/
-
-/*!
- \enum QNearFieldTagType1::WriteMode
- \brief This enum describes the write modes that are supported.
-
- \value EraseAndWrite The memory is erased before the new value is written.
- \value WriteOnly The memory is not erased before the new value is written. The effect of
- this mode is that the final value store is the bitwise or of the data
- to be written and the original data value.
-*/
-
-/*!
- \fn Type QNearFieldTagType1::type() const
- \reimp
-*/
-
-class QNearFieldTagType1Private
-{
- Q_DECLARE_PUBLIC(QNearFieldTagType1)
-
-public:
- QNearFieldTagType1Private(QNearFieldTagType1 *q)
- : q_ptr(q), m_readNdefMessageState(NotReadingNdefMessage),
- m_tlvReader(0),
- m_writeNdefMessageState(NotWritingNdefMessage),
- m_tlvWriter(0)
- { }
-
- QNearFieldTagType1 *q_ptr;
-
- QMap<QNearFieldTarget::RequestId, QByteArray> m_pendingInternalCommands;
-
- enum ReadNdefMessageState {
- NotReadingNdefMessage,
- NdefReadCheckingIdentification,
- NdefReadCheckingNdefMagicNumber,
- NdefReadReadingTlv
- };
-
- void progressToNextNdefReadMessageState();
- ReadNdefMessageState m_readNdefMessageState;
- QNearFieldTarget::RequestId m_readNdefRequestId;
-
- QTlvReader *m_tlvReader;
- QNearFieldTarget::RequestId m_nextExpectedRequestId;
-
- enum WriteNdefMessageState {
- NotWritingNdefMessage,
- NdefWriteCheckingIdentification,
- NdefWriteCheckingNdefMagicNumber,
- NdefWriteReadingTlv,
- NdefWriteWritingTlv,
- NdefWriteWritingTlvFlush
- };
-
- void progressToNextNdefWriteMessageState();
- WriteNdefMessageState m_writeNdefMessageState;
- QNearFieldTarget::RequestId m_writeNdefRequestId;
- QList<QNdefMessage> m_ndefWriteMessages;
-
- QTlvWriter *m_tlvWriter;
-
- typedef QPair<quint8, QByteArray> Tlv;
- QList<Tlv> m_tlvs;
-};
-
-void QNearFieldTagType1Private::progressToNextNdefReadMessageState()
-{
- Q_Q(QNearFieldTagType1);
-
- switch (m_readNdefMessageState) {
- case NotReadingNdefMessage:
- m_readNdefMessageState = NdefReadCheckingIdentification;
- m_nextExpectedRequestId = q->readIdentification();
- break;
- case NdefReadCheckingIdentification: {
- const QByteArray data = q->requestResponse(m_nextExpectedRequestId).toByteArray();
-
- if (data.isEmpty()) {
- m_readNdefMessageState = NotReadingNdefMessage;
- m_nextExpectedRequestId = QNearFieldTarget::RequestId();
- emit q->error(QNearFieldTarget::NdefReadError, m_readNdefRequestId);
- m_readNdefRequestId = QNearFieldTarget::RequestId();
- break;
- }
-
- quint8 hr0 = data.at(0);
-
- // Check if target is a NFC TagType1 tag
- if (!(hr0 & 0x10)) {
- m_readNdefMessageState = NotReadingNdefMessage;
- m_nextExpectedRequestId = QNearFieldTarget::RequestId();
- emit q->error(QNearFieldTarget::NdefReadError, m_readNdefRequestId);
- m_readNdefRequestId = QNearFieldTarget::RequestId();
- break;
- }
-
- m_readNdefMessageState = NdefReadCheckingNdefMagicNumber;
- m_nextExpectedRequestId = q->readByte(8);
- break;
- }
- case NdefReadCheckingNdefMagicNumber: {
- quint8 ndefMagicNumber = q->requestResponse(m_nextExpectedRequestId).toUInt();
- m_nextExpectedRequestId = QNearFieldTarget::RequestId();
-
- if (ndefMagicNumber != 0xe1) {
- m_readNdefMessageState = NotReadingNdefMessage;
- emit q->error(QNearFieldTarget::NdefReadError, m_readNdefRequestId);
- m_readNdefRequestId = QNearFieldTarget::RequestId();
- break;
- }
-
- m_readNdefMessageState = NdefReadReadingTlv;
- delete m_tlvReader;
- m_tlvReader = new QTlvReader(q);
-
- Q_FALLTHROUGH(); // fall through
- }
- case NdefReadReadingTlv:
- Q_ASSERT(m_tlvReader);
- while (!m_tlvReader->atEnd()) {
- if (!m_tlvReader->readNext())
- break;
-
- // NDEF Message TLV
- if (m_tlvReader->tag() == 0x03) {
- Q_Q(QNearFieldTagType1);
-
- emit q->ndefMessageRead(QNdefMessage::fromByteArray(m_tlvReader->data()));
- }
- }
-
- m_nextExpectedRequestId = m_tlvReader->requestId();
- if (!m_nextExpectedRequestId.isValid()) {
- delete m_tlvReader;
- m_tlvReader = 0;
- m_readNdefMessageState = NotReadingNdefMessage;
- emit q->requestCompleted(m_readNdefRequestId);
- m_readNdefRequestId = QNearFieldTarget::RequestId();
- }
- break;
- }
-}
-
-void QNearFieldTagType1Private::progressToNextNdefWriteMessageState()
-{
- Q_Q(QNearFieldTagType1);
-
- switch (m_writeNdefMessageState) {
- case NotWritingNdefMessage:
- m_writeNdefMessageState = NdefWriteCheckingIdentification;
- m_nextExpectedRequestId = q->readIdentification();
- break;
- case NdefWriteCheckingIdentification: {
- const QByteArray data = q->requestResponse(m_nextExpectedRequestId).toByteArray();
-
- if (data.isEmpty()) {
- m_writeNdefMessageState = NotWritingNdefMessage;
- m_nextExpectedRequestId = QNearFieldTarget::RequestId();
- emit q->error(QNearFieldTarget::NdefWriteError, m_writeNdefRequestId);
- m_writeNdefRequestId = QNearFieldTarget::RequestId();
- break;
- }
-
- quint8 hr0 = data.at(0);
-
- // Check if target is a NFC TagType1 tag
- if (!(hr0 & 0x10)) {
- m_writeNdefMessageState = NotWritingNdefMessage;
- m_nextExpectedRequestId = QNearFieldTarget::RequestId();
- emit q->error(QNearFieldTarget::NdefWriteError, m_writeNdefRequestId);
- m_writeNdefRequestId = QNearFieldTarget::RequestId();
- break;
- }
-
- m_writeNdefMessageState = NdefWriteCheckingNdefMagicNumber;
- m_nextExpectedRequestId = q->readByte(8);
- break;
- }
- case NdefWriteCheckingNdefMagicNumber: {
- quint8 ndefMagicNumber = q->requestResponse(m_nextExpectedRequestId).toUInt();
- m_nextExpectedRequestId = QNearFieldTarget::RequestId();
-
- if (ndefMagicNumber != 0xe1) {
- m_writeNdefMessageState = NotWritingNdefMessage;
- emit q->error(QNearFieldTarget::NdefWriteError, m_writeNdefRequestId);
- m_writeNdefRequestId = QNearFieldTarget::RequestId();
- break;
- }
-
- m_writeNdefMessageState = NdefWriteReadingTlv;
- delete m_tlvReader;
- m_tlvReader = new QTlvReader(q);
-
- Q_FALLTHROUGH(); // fall through
- }
- case NdefWriteReadingTlv:
- Q_ASSERT(m_tlvReader);
- while (!m_tlvReader->atEnd()) {
- if (!m_tlvReader->readNext())
- break;
-
- quint8 tag = m_tlvReader->tag();
- if (tag == 0x01 || tag == 0x02 || tag == 0xfd)
- m_tlvs.append(qMakePair(tag, m_tlvReader->data()));
- }
-
- m_nextExpectedRequestId = m_tlvReader->requestId();
- if (m_nextExpectedRequestId.isValid())
- break;
-
- delete m_tlvReader;
- m_tlvReader = 0;
- m_writeNdefMessageState = NdefWriteWritingTlv;
-
- // fall through
- case NdefWriteWritingTlv:
- delete m_tlvWriter;
- m_tlvWriter = new QTlvWriter(q);
-
- // write old TLVs
- for (const Tlv &tlv : qAsConst(m_tlvs))
- m_tlvWriter->writeTlv(tlv.first, tlv.second);
-
- // write new NDEF message TLVs
- for (const QNdefMessage &message : qAsConst(m_ndefWriteMessages))
- m_tlvWriter->writeTlv(0x03, message.toByteArray());
-
- // write terminator TLV
- m_tlvWriter->writeTlv(0xfe);
-
- m_writeNdefMessageState = NdefWriteWritingTlvFlush;
-
- // fall through
- case NdefWriteWritingTlvFlush:
- // flush the writer
- Q_ASSERT(m_tlvWriter);
- if (m_tlvWriter->process(true)) {
- m_nextExpectedRequestId = QNearFieldTarget::RequestId();
- m_writeNdefMessageState = NotWritingNdefMessage;
- delete m_tlvWriter;
- m_tlvWriter = 0;
- emit q->ndefMessagesWritten();
- emit q->requestCompleted(m_writeNdefRequestId);
- m_writeNdefRequestId = QNearFieldTarget::RequestId();
- } else {
- m_nextExpectedRequestId = m_tlvWriter->requestId();
- if (!m_nextExpectedRequestId.isValid()) {
- m_writeNdefMessageState = NotWritingNdefMessage;
- delete m_tlvWriter;
- m_tlvWriter = 0;
- emit q->error(QNearFieldTarget::NdefWriteError, m_writeNdefRequestId);
- m_writeNdefRequestId = QNearFieldTarget::RequestId();
- }
- }
- break;
- }
-}
-
-static QVariant decodeResponse(const QByteArray &command, const QByteArray &response)
-{
- switch (command.at(0)) {
- case 0x01: // READ
- if (command.at(1) == response.at(0))
- return quint8(response.at(1));
- break;
- case 0x53: { // WRITE-E
- quint8 address = command.at(1);
- quint8 data = command.at(2);
- quint8 writeAddress = response.at(0);
- quint8 writeData = response.at(1);
-
- return ((writeAddress == address) && (writeData == data));
- }
- case 0x1a: { // WRITE-NE
- quint8 address = command.at(1);
- quint8 data = command.at(2);
- quint8 writeAddress = response.at(0);
- quint8 writeData = response.at(1);
-
- return ((writeAddress == address) && ((writeData & data) == data));
- }
- case 0x10: { // RSEG
- quint8 segmentAddress = quint8(command.at(1)) >> 4;
- quint8 readSegmentAddress = quint8(response.at(0)) >> 4;
- if (readSegmentAddress == segmentAddress)
- return response.mid(1);
- break;
- }
- case 0x02: { // READ8
- quint8 blockAddress = command.at(1);
- quint8 readBlockAddress = response.at(0);
- if (readBlockAddress == blockAddress)
- return response.mid(1);
- break;
- }
- case 0x54: { // WRITE-E8
- quint8 blockAddress = command.at(1);
- QByteArray data = command.mid(2, 8);
- quint8 writeBlockAddress = response.at(0);
- QByteArray writeData = response.mid(1);
-
- return ((writeBlockAddress == blockAddress) && (writeData == data));
- }
- case 0x1b: { // WRITE-NE8
- quint8 blockAddress = command.at(1);
- QByteArray data = command.mid(2, 8);
- quint8 writeBlockAddress = response.at(0);
- QByteArray writeData = response.mid(1);
-
- if (writeBlockAddress != blockAddress)
- return false;
-
- for (int i = 0; i < writeData.length(); ++i) {
- if ((writeData.at(i) & data.at(i)) != data.at(i))
- return false;
- }
-
- return true;
- }
- }
-
- return QVariant();
-}
-
-/*!
- Constructs a new tag type 1 near field target with \a parent.
-*/
-QNearFieldTagType1::QNearFieldTagType1(QObject *parent)
-: QNearFieldTarget(parent), d_ptr(new QNearFieldTagType1Private(this))
-{
-}
-
-/*!
- Destroys the tag type 1 near field target.
-*/
-QNearFieldTagType1::~QNearFieldTagType1()
-{
- delete d_ptr;
-}
-
-/*!
- \reimp
-*/
-bool QNearFieldTagType1::hasNdefMessage()
-{
- RequestId id = readAll();
- if (!waitForRequestCompleted(id))
- return false;
-
- const QByteArray data = requestResponse(id).toByteArray();
-
- if (data.isEmpty())
- return false;
-
- quint8 hr0 = data.at(0);
-
- // Check if target is a NFC TagType1 tag
- if (!(hr0 & 0x10))
- return false;
-
- // Check if NDEF Message Magic number is present
- quint8 nmn = data.at(10);
- if (nmn != 0xe1)
- return false;
-
- // Check if TLV contains NDEF Message
- return true;
-}
-
-/*!
- \reimp
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::readNdefMessages()
-{
- Q_D(QNearFieldTagType1);
-
- d->m_readNdefRequestId = RequestId(new RequestIdPrivate);
-
- if (d->m_readNdefMessageState == QNearFieldTagType1Private::NotReadingNdefMessage) {
- d->progressToNextNdefReadMessageState();
- } else {
- reportError(QNearFieldTarget::NdefReadError, d->m_readNdefRequestId);
- }
-
- return d->m_readNdefRequestId;
-}
-
-/*!
- \reimp
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::writeNdefMessages(const QList<QNdefMessage> &messages)
-{
- Q_D(QNearFieldTagType1);
-
- d->m_writeNdefRequestId = RequestId(new RequestIdPrivate);
-
- if (d->m_readNdefMessageState == QNearFieldTagType1Private::NotReadingNdefMessage &&
- d->m_writeNdefMessageState == QNearFieldTagType1Private::NotWritingNdefMessage) {
- d->m_ndefWriteMessages = messages;
- d->progressToNextNdefWriteMessageState();
- } else {
- reportError(QNearFieldTarget::NdefWriteError, d->m_readNdefRequestId);
- }
-
- return d->m_writeNdefRequestId;
-}
-
-/*!
- Returns the NFC Tag Type 1 specification version number that the tag supports.
-*/
-quint8 QNearFieldTagType1::version()
-{
- RequestId id = readByte(9);
- if (!waitForRequestCompleted(id))
- return 0;
-
- quint8 versionNumber = requestResponse(id).toUInt();
- return versionNumber;
-}
-
-/*!
- Returns the memory size in bytes of the tag.
-*/
-int QNearFieldTagType1::memorySize()
-{
- RequestId id = readByte(10);
- if (!waitForRequestCompleted(id))
- return 0;
-
- quint8 tms = requestResponse(id).toUInt();
-
- return 8 * (tms + 1);
-}
-
-/*!
- Requests the identification bytes from the target. Returns a request id which can be used to
- track the completion status of the request.
-
- Once the request completes successfully the response can be retrieved from the
- requestResponse() function. The response of this request will be a QByteArray containing: HR0,
- HR1, UID0, UID1, UID2 and UID3 in order.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::readIdentification()
-{
- QByteArray command;
- command.append(char(0x78)); // RID
- command.append(char(0x00)); // Address (unused)
- command.append(char(0x00)); // Data (unused)
- command.append(uid().left(4)); // 4 bytes of UID
-
- return sendCommand(command);
-}
-
-/*!
- Requests all data in the static memory area of the target. Returns a request id which can be
- used to track the completion status of the request.
-
- Once the request completes successfully the response can be retrieved from the
- requestResponse() function. The response of this request will be a QByteArray containing: HR0
- and HR1 followed by the 120 bytes of data stored in the static memory area of the target.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::readAll()
-{
- QByteArray command;
- command.append(char(0x00)); // RALL
- command.append(char(0x00)); // Address (unused)
- command.append(char(0x00)); // Data (unused)
- command.append(uid().left(4));// 4 bytes of UID
-
- return sendCommand(command);
-}
-
-/*!
- Requests a single byte from the static memory area of the tag. The \a address parameter
- specifices the linear byte address to read. Returns a request id which can be used to track
- the completion status of the request.
-
- Once the request completes successfully the response can be retrieved from the
- requestResponse() function. The response of this request will be a quint8.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::readByte(quint8 address)
-{
- if (address & 0x80)
- return RequestId();
-
- QByteArray command;
- command.append(char(0x01)); // READ
- command.append(char(address)); // Address
- command.append(char(0x00)); // Data (unused)
- command.append(uid().left(4)); // 4 bytes of UID
-
- RequestId id = sendCommand(command);
-
- Q_D(QNearFieldTagType1);
-
- d->m_pendingInternalCommands.insert(id, command);
-
- return id;
-}
-
-/*!
- Writes a single \a data byte to the linear byte \a address on the tag. If \a mode is
- EraseAndWrite the byte will be erased before writing. If \a mode is WriteOnly the contents will
- not be erased before writing. This is equivelant to writing the result of the bitwise OR of
- \a data and the original value.
-
- Returns a request id which can be used to track the completion status of the request.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a boolean value, true for success; otherwise false.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::writeByte(quint8 address, quint8 data,
- WriteMode mode)
-{
- if (address & 0x80)
- return RequestId();
-
- QByteArray command;
-
- if (mode == EraseAndWrite)
- command.append(char(0x53)); // WRITE-E
- else if (mode == WriteOnly)
- command.append(char(0x1a)); // WRITE-NE
- else
- return RequestId();
-
- command.append(char(address)); // Address
- command.append(char(data)); // Data
- command.append(uid().left(4)); // 4 bytes of UID
-
- RequestId id = sendCommand(command);
-
- Q_D(QNearFieldTagType1);
-
- d->m_pendingInternalCommands.insert(id, command);
-
- return id;
-}
-
-/*!
- Requests 128 bytes of data from the segment specified by \a segmentAddress. Returns a request
- id which can be used to track the completion status of the request.
-
- Once the request completes successfully the response can be retrieved from the
- requestResponse() function. The response of this request will be a QByteArray.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::readSegment(quint8 segmentAddress)
-{
- if (segmentAddress & 0xf0)
- return RequestId();
-
- QByteArray command;
- command.append(char(0x10)); // RSEG
- command.append(char(segmentAddress << 4)); // Segment address
- command.append(QByteArray(8, char(0x00))); // Data (unused)
- command.append(uid().left(4)); // 4 bytes of UID
-
- RequestId id = sendCommand(command);
-
- Q_D(QNearFieldTagType1);
-
- d->m_pendingInternalCommands.insert(id, command);
-
- return id;
-}
-
-/*!
- Requests 8 bytes of data from the block specified by \a blockAddress. Returns a request id
- which can be used to track the completion status of the request.
-
- Once the request completes successfully the response can be retrieved from the
- requestResponse() function. The response of this request will be a QByteArray.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::readBlock(quint8 blockAddress)
-{
- QByteArray command;
- command.append(char(0x02)); // READ8
- command.append(char(blockAddress)); // Block address
- command.append(QByteArray(8, char(0x00))); // Data (unused)
- command.append(uid().left(4)); // 4 bytes of UID
-
- RequestId id = sendCommand(command);
-
- Q_D(QNearFieldTagType1);
-
- d->m_pendingInternalCommands.insert(id, command);
-
- return id;
-}
-
-/*!
- Writes 8 bytes of \a data to the block specified by \a blockAddress. If \a mode is
- EraseAndWrite the bytes will be erased before writing. If \a mode is WriteOnly the contents
- will not be erased before writing. This is equivelant to writing the result of the bitwise OR
- of \a data and the original value.
-
- Returns a request id which can be used to track the completion status of the request.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a boolean value, true for success; otherwise false.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType1::writeBlock(quint8 blockAddress,
- const QByteArray &data,
- WriteMode mode)
-{
- if (data.length() != 8)
- return RequestId();
-
- QByteArray command;
-
- if (mode == EraseAndWrite)
- command.append(char(0x54)); // WRITE-E8
- else if (mode == WriteOnly)
- command.append(char(0x1b)); // WRITE-NE8
- else
- return RequestId();
-
- command.append(char(blockAddress)); // Block address
- command.append(data); // Data
- command.append(uid().left(4)); // 4 bytes of UID
-
- RequestId id = sendCommand(command);
-
- Q_D(QNearFieldTagType1);
-
- d->m_pendingInternalCommands.insert(id, command);
-
- return id;
-}
-
-/*!
- \reimp
-*/
-bool QNearFieldTagType1::handleResponse(const QNearFieldTarget::RequestId &id,
- const QByteArray &response)
-{
- Q_D(QNearFieldTagType1);
-
- bool handled;
-
- if (d->m_pendingInternalCommands.contains(id)) {
- const QByteArray command = d->m_pendingInternalCommands.take(id);
-
- QVariant decodedResponse = decodeResponse(command, response);
- setResponseForRequest(id, decodedResponse);
-
- handled = true;
- } else {
- handled = QNearFieldTarget::handleResponse(id, response);
- }
-
- // continue reading / writing NDEF message
- if (d->m_nextExpectedRequestId == id) {
- if (d->m_readNdefMessageState != QNearFieldTagType1Private::NotReadingNdefMessage)
- d->progressToNextNdefReadMessageState();
- else if (d->m_writeNdefMessageState != QNearFieldTagType1Private::NotWritingNdefMessage)
- d->progressToNextNdefWriteMessageState();
- }
-
- return handled;
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtagtype1_p.h b/src/nfc/qnearfieldtagtype1_p.h
deleted file mode 100644
index ea288da7..00000000
--- a/src/nfc/qnearfieldtagtype1_p.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNEARFIELDTAGTYPE1_H
-#define QNEARFIELDTAGTYPE1_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtNfc/QNearFieldTarget>
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldTagType1Private;
-
-class Q_AUTOTEST_EXPORT QNearFieldTagType1 : public QNearFieldTarget
-{
- Q_OBJECT
-
- Q_DECLARE_PRIVATE(QNearFieldTagType1)
-
-public:
- enum WriteMode {
- EraseAndWrite,
- WriteOnly
- };
- Q_ENUM(WriteMode)
-
- explicit QNearFieldTagType1(QObject *parent = 0);
- ~QNearFieldTagType1();
-
- Type type() const { return NfcTagType1; }
-
- bool hasNdefMessage();
- RequestId readNdefMessages();
- RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
-
- quint8 version();
- virtual int memorySize();
-
- // DIGPROTO
- virtual RequestId readIdentification();
-
- // static memory functions
- virtual RequestId readAll();
- virtual RequestId readByte(quint8 address);
- virtual RequestId writeByte(quint8 address, quint8 data, WriteMode mode = EraseAndWrite);
-
- // dynamic memory functions
- virtual RequestId readSegment(quint8 segmentAddress);
- virtual RequestId readBlock(quint8 blockAddress);
- virtual RequestId writeBlock(quint8 blockAddress, const QByteArray &data,
- WriteMode mode = EraseAndWrite);
-
-protected:
- bool handleResponse(const QNearFieldTarget::RequestId &id, const QByteArray &response);
-
-private:
- QNearFieldTagType1Private *d_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QNEARFIELDTAGTYPE1_H
diff --git a/src/nfc/qnearfieldtagtype2.cpp b/src/nfc/qnearfieldtagtype2.cpp
deleted file mode 100644
index 492dc5e3..00000000
--- a/src/nfc/qnearfieldtagtype2.cpp
+++ /dev/null
@@ -1,325 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnearfieldtagtype2_p.h"
-#include "qnearfieldtarget_p.h"
-
-#include <QtCore/QVariant>
-#include <QtCore/QCoreApplication>
-#include <QtCore/QTime>
-
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QNearFieldTagType2
- \brief The QNearFieldTagType2 class provides an interface for communicating with an NFC Tag
- Type 2 tag.
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
- \internal
-*/
-
-/*!
- \fn Type QNearFieldTagType2::type() const
- \reimp
-*/
-
-struct SectorSelectState {
- int timerId; // id of timer used for passive ack
- quint8 sector; // sector being selected
-};
-
-class QNearFieldTagType2Private
-{
-public:
- QNearFieldTagType2Private() : m_currentSector(0) { }
-
- QMap<QNearFieldTarget::RequestId, QByteArray> m_pendingInternalCommands;
-
- quint8 m_currentSector;
-
- QMap<QNearFieldTarget::RequestId, SectorSelectState> m_pendingSectorSelectCommands;
-};
-
-static QVariant decodeResponse(const QByteArray &command, const QByteArray &response)
-{
- quint8 opcode = command.at(0);
-
- switch (opcode) {
- case 0xa2: // WRITE
- return quint8(response.at(0)) == 0x0a;
- case 0xc2: // SECTOR SELECT (Command Packet 1)
- return quint8(response.at(0)) == 0x0a;
- }
-
- return QVariant();
-}
-
-/*!
- Constructs a new tag type 2 near field target with \a parent.
-*/
-QNearFieldTagType2::QNearFieldTagType2(QObject *parent)
-: QNearFieldTarget(parent), d_ptr(new QNearFieldTagType2Private)
-{
-}
-
-/*!
- Destroys the tag type 2 near field target.
-*/
-QNearFieldTagType2::~QNearFieldTagType2()
-{
- delete d_ptr;
-}
-
-/*!
- \reimp
-*/
-bool QNearFieldTagType2::hasNdefMessage()
-{
- qWarning() << Q_FUNC_INFO << "is unimplemeted";
- return false;
-}
-
-/*!
- \reimp
-*/
-QNearFieldTarget::RequestId QNearFieldTagType2::readNdefMessages()
-{
- return RequestId();
-}
-
-/*!
- \reimp
-*/
-QNearFieldTarget::RequestId QNearFieldTagType2::writeNdefMessages(const QList<QNdefMessage> &messages)
-{
- Q_UNUSED(messages);
-
- return RequestId();
-}
-
-/*!
- Returns the NFC Tag Type 2 specification version number that the tag supports.
-*/
-quint8 QNearFieldTagType2::version()
-{
- Q_D(QNearFieldTagType2);
- if (d->m_currentSector != 0) {
- RequestId id = selectSector(0);
- if (!waitForRequestCompleted(id))
- return 0;
- }
-
- RequestId id = readBlock(0);
- if (!waitForRequestCompleted(id))
- return 0;
-
- const QByteArray data = requestResponse(id).toByteArray();
- return data.at(13);
-}
-
-/*!
- Returns the memory size in bytes of the tag.
-*/
-int QNearFieldTagType2::memorySize()
-{
- Q_D(QNearFieldTagType2);
- if (d->m_currentSector != 0) {
- RequestId id = selectSector(0);
- if (!waitForRequestCompleted(id))
- return 0;
- }
-
- RequestId id = readBlock(0);
- if (!waitForRequestCompleted(id))
- return 0;
-
- const QByteArray data = requestResponse(id).toByteArray();
- return 8 * quint8(data.at(14));
-}
-
-/*!
- Requests 16 bytes of data starting at \a blockAddress. Returns a request id which can be used
- to track the completion status of the request.
-
- Once the request completes successfully the response can be retrieved from the
- requestResponse() function. The response of this request will be a QByteArray.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType2::readBlock(quint8 blockAddress)
-{
- QByteArray command;
- command.append(char(0x30)); // READ
- command.append(char(blockAddress)); // Block address
-
- return sendCommand(command);
-}
-
-/*!
- Writes 4 bytes of \a data to the block at \a blockAddress. Returns a request id which can be
- used to track the completion status of the request.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a boolean value, true for success; otherwise false.
-
- Returns true on success; otherwise returns false.
-*/
-QNearFieldTarget::RequestId QNearFieldTagType2::writeBlock(quint8 blockAddress,
- const QByteArray &data)
-{
- if (data.length() != 4)
- return RequestId();
-
- QByteArray command;
- command.append(char(0xa2)); // WRITE
- command.append(char(blockAddress)); // Block address
- command.append(data); // Data
-
- RequestId id = sendCommand(command);
-
- Q_D(QNearFieldTagType2);
-
- d->m_pendingInternalCommands.insert(id, command);
-
- return id;
-}
-
-/*!
- Selects the \a sector upon which subsequent readBlock() and writeBlock() operations will act.
-
- Returns a request id which can be used to track the completion status of the request.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a boolean value, true for success; otherwise false.
-
- \note this request has a passive acknowledgement mechanism. The operation is deemed successful
- if no response is received within 1ms. It will therefore take a minimum of 1 millisecond for
- the requestCompleted() signal to be emitted and calling waitForRequestCompleted() on the
- returned request id may cause the current thread to block for up to 1 millisecond.
-*/
-QNearFieldTarget::RequestId QNearFieldTagType2::selectSector(quint8 sector)
-{
- QByteArray command;
- command.append(char(0xc2)); // SECTOR SELECT (Command Packet 1)
- command.append(char(0xff));
-
- RequestId id = sendCommand(command);
-
- Q_D(QNearFieldTagType2);
-
- d->m_pendingInternalCommands.insert(id, command);
-
- SectorSelectState state;
- state.timerId = -1;
- state.sector = sector;
-
- d->m_pendingSectorSelectCommands.insert(id, state);
-
- return id;
-}
-
-/*!
- \reimp
-*/
-bool QNearFieldTagType2::handleResponse(const QNearFieldTarget::RequestId &id,
- const QByteArray &response)
-{
- Q_D(QNearFieldTagType2);
-
- if (d->m_pendingInternalCommands.contains(id)) {
- const QByteArray command = d->m_pendingInternalCommands.take(id);
-
- QVariant decodedResponse = decodeResponse(command, response);
- if (quint8(command.at(0)) == 0xc2 && decodedResponse.toBool()) {
- // SECTOR SELECT (Command Packet 2)
- SectorSelectState &state = d->m_pendingSectorSelectCommands[id];
-
- QByteArray packet2;
- packet2.append(char(state.sector));
- packet2.append(QByteArray(3, 0x00));
-
- sendCommand(packet2);
-
- state.timerId = startTimer(1);
- } else {
- setResponseForRequest(id, decodedResponse);
- }
-
- return true;
- } else if (d->m_pendingSectorSelectCommands.contains(id)) {
- if (!response.isEmpty()) {
- d->m_pendingSectorSelectCommands.remove(id);
- setResponseForRequest(id, false);
-
- return true;
- }
- }
-
- return QNearFieldTarget::handleResponse(id, response);
-}
-
-/*!
- \internal
-*/
-void QNearFieldTagType2::timerEvent(QTimerEvent *event)
-{
- Q_D(QNearFieldTagType2);
-
- killTimer(event->timerId());
-
- for (auto i = d->m_pendingSectorSelectCommands.begin(), end = d->m_pendingSectorSelectCommands.end(); i != end; ++i) {
-
- SectorSelectState &state = i.value();
-
- if (state.timerId == event->timerId()) {
- d->m_currentSector = state.sector;
-
- setResponseForRequest(i.key(), true);
-
- d->m_pendingSectorSelectCommands.erase(i);
- break;
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtagtype2_p.h b/src/nfc/qnearfieldtagtype2_p.h
deleted file mode 100644
index 29faa119..00000000
--- a/src/nfc/qnearfieldtagtype2_p.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNEARFIELDTAGTYPE2_H
-#define QNEARFIELDTAGTYPE2_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtNfc/QNearFieldTarget>
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldTagType2Private;
-
-class Q_AUTOTEST_EXPORT QNearFieldTagType2 : public QNearFieldTarget
-{
- Q_OBJECT
-
- Q_DECLARE_PRIVATE(QNearFieldTagType2)
-
-public:
- explicit QNearFieldTagType2(QObject *parent = 0);
- ~QNearFieldTagType2();
-
- Type type() const { return NfcTagType2; }
-
- bool hasNdefMessage();
- RequestId readNdefMessages();
- RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
-
- quint8 version();
- int memorySize();
-
- virtual RequestId readBlock(quint8 blockAddress);
- virtual RequestId writeBlock(quint8 blockAddress, const QByteArray &data);
- virtual RequestId selectSector(quint8 sector);
-
- void timerEvent(QTimerEvent *event);
-
-protected:
- bool handleResponse(const QNearFieldTarget::RequestId &id, const QByteArray &response);
-
-private:
- QNearFieldTagType2Private *d_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QNEARFIELDTAGTYPE2_H
diff --git a/src/nfc/qnearfieldtagtype3.cpp b/src/nfc/qnearfieldtagtype3.cpp
deleted file mode 100644
index 0954d65f..00000000
--- a/src/nfc/qnearfieldtagtype3.cpp
+++ /dev/null
@@ -1,185 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnearfieldtagtype3_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QNearFieldTagType3
- \brief The QNearFieldTagType3 class provides an interface for communicating with an NFC Tag
- Type 3 tag.
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
- \internal
-*/
-
-/*!
- \fn Type QNearFieldTagType3::type() const
- \reimp
-*/
-
-/*!
- Constructs a new tag type 3 near field target with \a parent.
-*/
-QNearFieldTagType3::QNearFieldTagType3(QObject *parent) :
- QNearFieldTarget(parent)
-{
-}
-
-/*!
- Returns the system code of the target.
-*/
-quint16 QNearFieldTagType3::systemCode()
-{
- return 0;
-}
-
-/*!
- Returns a list of available services.
-*/
-QList<quint16> QNearFieldTagType3::services()
-{
- return QList<quint16>();
-}
-
-/*!
- Returns the memory size of the service specified by \a serviceCode.
-*/
-int QNearFieldTagType3::serviceMemorySize(quint16 serviceCode)
-{
- Q_UNUSED(serviceCode);
-
- return 0;
-}
-
-/*!
- Requests the data contents of the service specified by \a serviceCode. Returns a request id
- which can be used to track the completion status of the request.
-
- Once the request completes successfully the service data can be retrieved from the
- requestResponse() function. The response of this request will be a QByteArray.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType3::serviceData(quint16 serviceCode)
-{
- Q_UNUSED(serviceCode);
-
- return RequestId();
-}
-
-/*!
- Writes \a data to the service specified by \a serviceCode. Returns a request id which can
- be used to track the completion status of the request.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a boolean value, true for success; otherwise false.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType3::writeServiceData(quint16 serviceCode,
- const QByteArray &data)
-{
- Q_UNUSED(serviceCode);
- Q_UNUSED(data);
-
- return RequestId();
-}
-
-/*!
- Sends the \e check request to the target. Requests the service data blocks specified by
- \a serviceBlockList. Returns a request id which can be used to track the completion status of
- the request.
-
- The \a serviceBlockList parameter is a map with the key being the service code and the value
- being a list of block indexes to retrieve.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a QMap<quint16, QByteArray>, with the key being the
- service code and the value being the concatenated blocks retrieved for that service.
-
- This is a low level function, to retrieve the entire data contents of a service use
- serviceData().
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType3::check(const QMap<quint16, QList<quint16> > &serviceBlockList)
-{
- Q_UNUSED(serviceBlockList);
-
- return RequestId();
-}
-
-/*!
- Sends the \e update request to the target. Writes \a data to the services and block indexes
- sepecified by \a serviceBlockList. Returns a request id which can be used to track the
- completion status of the request.
-
- The \a serviceBlockList parameter is a map with the key being the service code and the value
- being a list of block indexes to write to.
-
- Once the request completes the response can be retried from the requestResponse() function. The
- response of this request will be a boolean value, true for success; otherwise false.
-
- This is a low level function, to write the entire data contents of a service use
- writeServiceData().
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType3::update(const QMap<quint16, QList<quint16> > &serviceBlockList,
- const QByteArray &data)
-{
- Q_UNUSED(serviceBlockList);
- Q_UNUSED(data);
-
- return RequestId();
-}
-
-/*!
- \reimp
-*/
-bool QNearFieldTagType3::handleResponse(const QNearFieldTarget::RequestId &id,
- const QByteArray &response)
-{
- return QNearFieldTarget::handleResponse(id, response);
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtagtype3_p.h b/src/nfc/qnearfieldtagtype3_p.h
deleted file mode 100644
index a91bd7b5..00000000
--- a/src/nfc/qnearfieldtagtype3_p.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNEARFIELDTAGTYPE3_H
-#define QNEARFIELDTAGTYPE3_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/QList>
-#include <QtCore/QMap>
-#include <QtNfc/QNearFieldTarget>
-
-QT_BEGIN_NAMESPACE
-
-class Q_AUTOTEST_EXPORT QNearFieldTagType3 : public QNearFieldTarget
-{
- Q_OBJECT
-
-public:
- explicit QNearFieldTagType3(QObject *parent = 0);
-
- Type type() const { return NfcTagType3; }
-
- quint16 systemCode();
- QList<quint16> services();
- int serviceMemorySize(quint16 serviceCode);
-
- virtual RequestId serviceData(quint16 serviceCode);
- virtual RequestId writeServiceData(quint16 serviceCode, const QByteArray &data);
-
- virtual RequestId check(const QMap<quint16, QList<quint16> > &serviceBlockList);
- virtual RequestId update(const QMap<quint16, QList<quint16> > &serviceBlockList,
- const QByteArray &data);
-
-protected:
- bool handleResponse(const QNearFieldTarget::RequestId &id, const QByteArray &response);
-};
-
-QT_END_NAMESPACE
-
-#endif // QNEARFIELDTAGTYPE3_H
diff --git a/src/nfc/qnearfieldtagtype4.cpp b/src/nfc/qnearfieldtagtype4.cpp
deleted file mode 100644
index ce56a861..00000000
--- a/src/nfc/qnearfieldtagtype4.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnearfieldtagtype4_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QNearFieldTagType4
- \brief The QNearFieldTagType4 class provides an interface for communicating with an NFC Tag
- Type 4 tag.
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
- \internal
-*/
-
-/*!
- \fn Type QNearFieldTagType4::type() const
- \reimp
-*/
-
-/*!
- Constructs a new tag type 4 near field target with \a parent.
-*/
-QNearFieldTagType4::QNearFieldTagType4(QObject *parent)
-: QNearFieldTarget(parent)
-{
-}
-
-/*!
- Destroys the tag type 4 near field target.
-*/
-QNearFieldTagType4::~QNearFieldTagType4()
-{
-}
-
-/*!
- Returns the NFC Tag Type 4 specification version number that the tag supports.
-*/
-quint8 QNearFieldTagType4::version()
-{
- return 0;
-}
-
-/*!
- Requests that the file specified by \a name be selected. Upon success calls to read() and
- write() will act on the selected file. Returns a request id which can be used to track the
- completion status of the request.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a boolean value, true for success; otherwise false.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType4::select(const QByteArray &name)
-{
- Q_UNUSED(name);
-
- return RequestId();
-}
-
-/*!
- Requests that the file specified by \a fileIdentifier be selected. Upon success calls to read()
- and write() will act on the selected file. Returns a request id which can be used to track the
- completion status of the request.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a boolean value, true for success; otherwise false.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType4::select(quint16 fileIdentifier)
-{
- Q_UNUSED(fileIdentifier);
-
- return RequestId();
-}
-
-/*!
- Requests that \a length bytes be read from the currently selected file starting from
- \a startOffset. If \a length is 0 all data or the maximum read size bytes will be read,
- whichever is smaller. Returns a request id which can be used to track the completion status of
- the request.
-
- Once the request completes successfully the response can be retrieved from the
- requestResponse() function. The response of this request will be a QByteArray.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType4::read(quint16 length, quint16 startOffset)
-{
- Q_UNUSED(length);
- Q_UNUSED(startOffset);
-
- return RequestId();
-}
-
-/*!
- Writes \a data to the currently selected file starting at \a startOffset. Returns a request id
- which can be used to track the completion status of the request.
-
- Once the request completes the response can be retrieved from the requestResponse() function.
- The response of this request will be a boolean value, true for success; otherwise false.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTagType4::write(const QByteArray &data, quint16 startOffset)
-{
- Q_UNUSED(data);
- Q_UNUSED(startOffset);
-
- return RequestId();
-}
-
-/*!
- \reimp
-*/
-bool QNearFieldTagType4::handleResponse(const QNearFieldTarget::RequestId &id,
- const QByteArray &response)
-{
- return QNearFieldTarget::handleResponse(id, response);
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtagtype4_p.h b/src/nfc/qnearfieldtagtype4_p.h
deleted file mode 100644
index 92bd0aaf..00000000
--- a/src/nfc/qnearfieldtagtype4_p.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNEARFIELDTAGTYPE4_H
-#define QNEARFIELDTAGTYPE4_H
-
-#include <QtNfc/QNearFieldTarget>
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-QT_BEGIN_NAMESPACE
-
-class Q_AUTOTEST_EXPORT QNearFieldTagType4 : public QNearFieldTarget
-{
- Q_OBJECT
-
-public:
- explicit QNearFieldTagType4(QObject *parent = 0);
- ~QNearFieldTagType4();
-
- Type type() const { return NfcTagType4; }
-
- quint8 version();
-
- virtual RequestId select(const QByteArray &name);
- virtual RequestId select(quint16 fileIdentifier);
-
- virtual RequestId read(quint16 length = 0, quint16 startOffset = 0);
- virtual RequestId write(const QByteArray &data, quint16 startOffset = 0);
-
-protected:
- bool handleResponse(const QNearFieldTarget::RequestId &id, const QByteArray &response);
-};
-
-QT_END_NAMESPACE
-
-#endif // QNEARFIELDTAGTYPE4_H
diff --git a/src/nfc/qnearfieldtarget.cpp b/src/nfc/qnearfieldtarget.cpp
index 7d83db78..dbcca2bd 100644
--- a/src/nfc/qnearfieldtarget.cpp
+++ b/src/nfc/qnearfieldtarget.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qnearfieldtarget.h"
#include "qnearfieldtarget_p.h"
@@ -43,15 +7,15 @@
#include <QtCore/QString>
#include <QtCore/QUrl>
-#include <QtCore/QVariant>
#include <QtCore/QDebug>
-#include <QElapsedTimer>
#include <QCoreApplication>
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN_TAGGED(QNearFieldTarget::RequestId, QNearFieldTarget__RequestId)
+
/*!
\class QNearFieldTarget
\brief The QNearFieldTarget class provides an interface for communicating with a target
@@ -75,11 +39,7 @@ QT_BEGIN_NAMESPACE
and set the NDEF message.
If the target supports TagTypeSpecificAccess, sendCommand() can be used to send a single
- proprietary command to the target and retrieve the response. sendCommands() can be used to
- send multiple proprietary commands to the target and retrieve all of the responses.
-
- If the target supports LlcpAccess, the QLlcpSocket class can be used to connected to a
- service provided by the target.
+ proprietary command to the target and retrieve the response.
*/
/*!
@@ -91,7 +51,10 @@ QT_BEGIN_NAMESPACE
\value NfcTagType1 An NFC tag type 1 target.
\value NfcTagType2 An NFC tag type 2 target.
\value NfcTagType3 An NFC tag type 3 target.
- \value NfcTagType4 An NFC tag type 4 target.
+ \value NfcTagType4 An NFC tag type 4 target. This value is used if the NfcTagType4
+ cannot be further refined by NfcTagType4A or NfcTagType4B below.
+ \value NfcTagType4A An NFC tag type 4 target based on ISO/IEC 14443-3A.
+ \value NfcTagType4B An NFC tag type 4 target based on ISO/IEC 14443-3B.
\value MifareTag A Mifare target.
*/
@@ -104,8 +67,8 @@ QT_BEGIN_NAMESPACE
\value NdefAccess The target supports reading and writing NDEF messages using
readNdefMessages() and writeNdefMessages().
\value TagTypeSpecificAccess The target supports sending tag type specific commands using
- sendCommand() and sendCommands().
- \value LlcpAccess The target supports peer-to-peer LLCP communication.
+ sendCommand().
+ \value AnyAccess The target supports any of the known access types.
*/
/*!
@@ -121,23 +84,14 @@ QT_BEGIN_NAMESPACE
\value NoResponseError The target did not respond.
\value ChecksumMismatchError The checksum has detected a corrupted response.
\value InvalidParametersError Invalid parameters were passed to a tag type specific function.
+ \value ConnectionError Failed to connect to the target.
\value NdefReadError Failed to read NDEF messages from the target.
\value NdefWriteError Failed to write NDEF messages to the target.
\value CommandError Failed to send a command to the target.
+ \value TimeoutError The request could not be completed within the time
+ specified in waitForRequestCompleted().
*/
-#if QT_DEPRECATED_SINCE(5, 9)
-/*!
- \relates QNearFieldTarget
-
- Returns the NFC checksum of the first \a len bytes of \a data.
-*/
-quint16 qNfcChecksum(const char *data, uint len)
-{
- return qChecksum(data, len, Qt::ChecksumItuV41);
-}
-#endif
-
/*!
\fn void QNearFieldTarget::disconnected()
@@ -153,14 +107,6 @@ quint16 qNfcChecksum(const char *data, uint len)
*/
/*!
- \fn void QNearFieldTarget::ndefMessagesWritten()
-
- This signal is emitted when NDEF messages have been successfully written to the target.
-
- \sa writeNdefMessages()
-*/
-
-/*!
\fn void QNearFieldTarget::requestCompleted(const QNearFieldTarget::RequestId &id)
This signal is emitted when a request \a id completes.
@@ -176,6 +122,13 @@ quint16 qNfcChecksum(const char *data, uint len)
*/
/*!
+ \class QNearFieldTarget::RequestId
+ \inmodule QtNfc
+ \inheaderfile QNearFieldTarget
+ \brief A request id handle.
+*/
+
+/*!
Constructs a new invalid request id handle.
*/
QNearFieldTarget::RequestId::RequestId()
@@ -206,7 +159,7 @@ QNearFieldTarget::RequestId::~RequestId()
}
/*!
- Returns true if this is a valid request id; otherwise returns false.
+ Returns \c true if this is a valid request id; otherwise returns \c false.
*/
bool QNearFieldTarget::RequestId::isValid() const
{
@@ -219,7 +172,7 @@ bool QNearFieldTarget::RequestId::isValid() const
int QNearFieldTarget::RequestId::refCount() const
{
if (d)
- return d->ref.load();
+ return d->ref.loadRelaxed();
return 0;
}
@@ -229,7 +182,7 @@ int QNearFieldTarget::RequestId::refCount() const
*/
bool QNearFieldTarget::RequestId::operator<(const RequestId &other) const
{
- return d < other.d;
+ return std::less<const RequestIdPrivate*>()(d.constData(), other.d.constData());
}
/*!
@@ -261,11 +214,8 @@ QNearFieldTarget::RequestId &QNearFieldTarget::RequestId::operator=(const Reques
Constructs a new near field target with \a parent.
*/
QNearFieldTarget::QNearFieldTarget(QObject *parent)
-: QObject(parent), d_ptr(new QNearFieldTargetPrivate(this))
+: QNearFieldTarget(new QNearFieldTargetPrivate(this), parent)
{
- qRegisterMetaType<QNearFieldTarget::RequestId>();
- qRegisterMetaType<QNearFieldTarget::Error>();
- qRegisterMetaType<QNdefMessage>();
}
/*!
@@ -273,97 +223,73 @@ QNearFieldTarget::QNearFieldTarget(QObject *parent)
*/
QNearFieldTarget::~QNearFieldTarget()
{
- delete d_ptr;
+ Q_D(QNearFieldTarget);
+
+ d->disconnect();
}
/*!
- \fn QByteArray QNearFieldTarget::uid() const = 0
-
Returns the UID of the near field target.
-*/
-/*!
- Returns the URL of the near field target.
+ \note On iOS, this function returns an empty QByteArray for
+ a near field target discovered using NdefAccess method.
+
+ \sa QNearFieldTarget::AccessMethod
*/
-QUrl QNearFieldTarget::url() const
+QByteArray QNearFieldTarget::uid() const
{
- return QUrl();
+ Q_D(const QNearFieldTarget);
+
+ return d->uid();
}
/*!
- \fn QNearFieldTarget::Type QNearFieldTarget::type() const = 0
-
Returns the type of tag type of this near field target.
*/
-
-/*!
- \fn QNearFieldTarget::AccessMethods QNearFieldTarget::accessMethods() const = 0
-
- Returns the access methods support by this near field target.
-*/
-
-/*!
- \since 5.9
-
- Returns true if this feature is enabled.
-
- \sa setKeepConnection(), disconnect()
-*/
-bool QNearFieldTarget::keepConnection() const
+QNearFieldTarget::Type QNearFieldTarget::type() const
{
- return d_ptr->keepConnection();
+ Q_D(const QNearFieldTarget);
+
+ return d->type();
}
/*!
- \since 5.9
-
- Preserves the connection to the target device after processing a command or
- reading/writing NDEF messages if \a isPersistent is \c true.
- By default, this behavior is not enabled.
-
- Returns \c true if enabling this feature was successful. A possible
- reason for a failure is the lack of support on the used platform.
-
- Enabling this feature requires to use the disconnect() function too, to close the
- connection manually and enable communication with the target from a different instance.
- Disabling this feature will also close an open connection.
-
- \sa keepConnection(), disconnect()
+ Returns the access methods supported by this near field target.
*/
-bool QNearFieldTarget::setKeepConnection(bool isPersistent)
+QNearFieldTarget::AccessMethods QNearFieldTarget::accessMethods() const
{
- return d_ptr->setKeepConnection(isPersistent);
+ Q_D(const QNearFieldTarget);
+
+ return d->accessMethods();
}
/*!
\since 5.9
- Closes the connection to the target.
+ Closes the connection to the target to enable communication with the target
+ from a different instance. The connection will also be closed, when the
+ QNearFieldTarget is destroyed. A connection to the target device is
+ (re)created to process a command or read/write a NDEF messages.
- Returns true only if an existing connection was successfully closed.
-
- \sa keepConnection(), setKeepConnection()
+ Returns \c true only if an existing connection was successfully closed;
+ otherwise returns \c false.
*/
bool QNearFieldTarget::disconnect()
{
- return d_ptr->disconnect();
-}
+ Q_D(QNearFieldTarget);
-/*!
- Returns true if the target is processing commands; otherwise returns false.
-*/
-bool QNearFieldTarget::isProcessingCommand() const
-{
- return false;
+ return d->disconnect();
}
/*!
- Returns true if at least one NDEF message is stored on the near field target; otherwise returns
- false.
+ Returns \c true if at least one NDEF message is stored on the near field
+ target; otherwise returns \c false.
*/
bool QNearFieldTarget::hasNdefMessage()
{
- return false;
+ Q_D(QNearFieldTarget);
+
+ return d->hasNdefMessage();
}
/*!
@@ -374,10 +300,16 @@ bool QNearFieldTarget::hasNdefMessage()
An ndefMessageRead() signal will be emitted for each NDEF message. The requestCompleted()
signal will be emitted was all NDEF messages have been read. The error() signal is emitted if
an error occurs.
+
+ \note An attempt to read an NDEF message from a tag, that is in INITIALIZED
+ state as defined by NFC Forum, will fail with the \l NdefReadError, as the
+ tag is formatted to support NDEF but does not contain a message yet.
*/
QNearFieldTarget::RequestId QNearFieldTarget::readNdefMessages()
{
- return RequestId();
+ Q_D(QNearFieldTarget);
+
+ return d->readNdefMessages();
}
/*!
@@ -385,14 +317,14 @@ QNearFieldTarget::RequestId QNearFieldTarget::readNdefMessages()
to track the completion status of the request. An invalid request id will be returned if the
target does not support reading NDEF messages.
- The ndefMessagesWritten() signal will be emitted when the write operation completes
+ The requestCompleted() signal will be emitted when the write operation completes
successfully; otherwise the error() signal is emitted.
*/
QNearFieldTarget::RequestId QNearFieldTarget::writeNdefMessages(const QList<QNdefMessage> &messages)
{
- Q_UNUSED(messages);
+ Q_D(QNearFieldTarget);
- return RequestId();
+ return d->writeNdefMessages(messages);
}
/*!
@@ -401,11 +333,13 @@ QNearFieldTarget::RequestId QNearFieldTarget::writeNdefMessages(const QList<QNde
Returns the maximum number of bytes that can be sent with sendCommand. 0 will
be returned if the target does not support sending tag type specific commands.
- \sa sendCommand(), sendCommands()
+ \sa sendCommand()
*/
int QNearFieldTarget::maxCommandLength() const
{
- return d_ptr->maxCommandLength();
+ Q_D(const QNearFieldTarget);
+
+ return d->maxCommandLength();
}
/*!
@@ -423,123 +357,59 @@ int QNearFieldTarget::maxCommandLength() const
*/
QNearFieldTarget::RequestId QNearFieldTarget::sendCommand(const QByteArray &command)
{
- Q_UNUSED(command);
-
- emit error(UnsupportedError, RequestId());
-
- return RequestId();
-}
-
-/*!
- Sends multiple \a commands to the near field target. Returns a request id which can be used to
- track the completion status of the request. An invalid request id will be returned if the
- target does not support sending tag type specific commands.
-
- If all commands complete successfully the requestCompleted() signal will be emitted; otherwise
- the error() signal will be emitted. If a command fails succeeding commands from this call will
- not be processed.
-
- Once the request completes the response for successfully completed requests can be retrieved
- from the requestResponse() function. The response of this request will be a QList<QByteArray>.
-
- \sa requestCompleted(), waitForRequestCompleted()
-*/
-QNearFieldTarget::RequestId QNearFieldTarget::sendCommands(const QList<QByteArray> &commands)
-{
- Q_UNUSED(commands);
-
- emit error(UnsupportedError, RequestId());
+ Q_D(QNearFieldTarget);
- return RequestId();
+ return d->sendCommand(command);
}
/*!
- Waits up to \a msecs milliseconds for the request \a id to complete. Returns true if the
- request completes successfully and the requestCompeted() signal is emitted; otherwise returns
- false.
+ Waits up to \a msecs milliseconds for the request \a id to complete.
+ Returns \c true if the request completes successfully and the
+ requestCompeted() signal is emitted; otherwise returns \c false.
*/
bool QNearFieldTarget::waitForRequestCompleted(const RequestId &id, int msecs)
{
Q_D(QNearFieldTarget);
- QElapsedTimer timer;
- timer.start();
-
- do {
- if (d->m_decodedResponses.contains(id))
- return true;
- else
- QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents, 1);
- } while (timer.elapsed() <= msecs);
-
- return false;
+ return d->waitForRequestCompleted(id, msecs);
}
/*!
Returns the decoded response for request \a id. If the request is unknown or has not yet been
completed an invalid QVariant is returned.
*/
-QVariant QNearFieldTarget::requestResponse(const RequestId &id)
+QVariant QNearFieldTarget::requestResponse(const RequestId &id) const
{
- Q_D(QNearFieldTarget);
+ Q_D(const QNearFieldTarget);
- return d->m_decodedResponses.value(id);
+ return d->requestResponse(id);
}
/*!
- Sets the decoded response for request \a id to \a response. If \a emitRequestCompleted is true
- the requestCompleted() signal will be emitted for \a id; otherwise no signal will be emitted.
-
- \sa requestResponse()
+ \internal
*/
-void QNearFieldTarget::setResponseForRequest(const QNearFieldTarget::RequestId &id,
- const QVariant &response, bool emitRequestCompleted)
+QNearFieldTarget::QNearFieldTarget(QNearFieldTargetPrivate *backend, QObject *parent)
+: QObject(parent), d_ptr(backend)
{
Q_D(QNearFieldTarget);
- for (auto i = d->m_decodedResponses.begin(), end = d->m_decodedResponses.end(); i != end; /* erasing */) {
- // no more external references
- if (i.key().refCount() == 1)
- i = d->m_decodedResponses.erase(i);
- else
- ++i;
- }
-
- d->m_decodedResponses.insert(id, response);
+ d->q_ptr = this;
+ d->setParent(this);
- if (emitRequestCompleted)
- emit requestCompleted(id);
-}
-
-/*!
- Handles the \a response received for the request \a id. Returns true if the response is
- handled; otherwise returns false.
-
- Classes reimplementing this virtual function should call the base class implementation to
- ensure that requests initiated by those classes are handled correctly.
-
- The default implementation stores the response such that it can be retrieved by
- requestResponse().
-*/
-bool QNearFieldTarget::handleResponse(const QNearFieldTarget::RequestId &id,
- const QByteArray &response)
-{
- setResponseForRequest(id, response);
-
- return true;
-}
-
-/*!
- \since 5.12
+ qRegisterMetaType<QNearFieldTarget::RequestId>();
+ qRegisterMetaType<QNearFieldTarget::Error>();
+ qRegisterMetaType<QNdefMessage>();
- Reports the \a error for the request \a id by appending the signal emission to the event queue.
-*/
-void QNearFieldTarget::reportError(QNearFieldTarget::Error error,
- const QNearFieldTarget::RequestId &id)
-{
- QMetaObject::invokeMethod(this, [this, error, id]() {
- Q_EMIT this->error(error, id);
- }, Qt::QueuedConnection);
+ connect(d, &QNearFieldTargetPrivate::disconnected,
+ this, &QNearFieldTarget::disconnected);
+ connect(d, &QNearFieldTargetPrivate::ndefMessageRead,
+ this, &QNearFieldTarget::ndefMessageRead);
+ connect(d, &QNearFieldTargetPrivate::requestCompleted,
+ this, &QNearFieldTarget::requestCompleted);
+ connect(d, &QNearFieldTargetPrivate::error,
+ this, &QNearFieldTarget::error);
}
QT_END_NAMESPACE
+
+#include "moc_qnearfieldtarget.cpp"
diff --git a/src/nfc/qnearfieldtarget.h b/src/nfc/qnearfieldtarget.h
index 868b52d5..0d67011d 100644
--- a/src/nfc/qnearfieldtarget.h
+++ b/src/nfc/qnearfieldtarget.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNEARFIELDTARGET_H
#define QNEARFIELDTARGET_H
@@ -45,23 +9,21 @@
#include <QtCore/QMetaType>
#include <QtCore/QObject>
#include <QtCore/QSharedDataPointer>
+#include <QtCore/QVariant>
#include <QtNfc/qtnfcglobal.h>
QT_BEGIN_NAMESPACE
-class QString;
-class QUrl;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
class QNdefMessage;
class QNearFieldTargetPrivate;
+class QNearFieldManagerPrivateImpl;
class Q_NFC_EXPORT QNearFieldTarget : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QNearFieldTarget)
+ friend class QNearFieldManagerPrivateImpl;
public:
enum Type {
@@ -70,6 +32,8 @@ public:
NfcTagType2,
NfcTagType3,
NfcTagType4,
+ NfcTagType4A,
+ NfcTagType4B,
MifareTag
};
Q_ENUM(Type)
@@ -78,7 +42,7 @@ public:
UnknownAccess = 0x00,
NdefAccess = 0x01,
TagTypeSpecificAccess = 0x02,
- LlcpAccess = 0x04
+ AnyAccess = 0xff
};
Q_ENUM(AccessMethod)
Q_DECLARE_FLAGS(AccessMethods, AccessMethod)
@@ -91,9 +55,11 @@ public:
NoResponseError,
ChecksumMismatchError,
InvalidParametersError,
+ ConnectionError,
NdefReadError,
NdefWriteError,
- CommandError
+ CommandError,
+ TimeoutError
};
Q_ENUM(Error)
@@ -119,64 +85,47 @@ public:
};
explicit QNearFieldTarget(QObject *parent = nullptr);
- virtual ~QNearFieldTarget();
+ ~QNearFieldTarget();
- virtual QByteArray uid() const = 0;
- virtual QUrl url() const;
+ QByteArray uid() const;
+ Type type() const;
+ AccessMethods accessMethods() const;
- virtual Type type() const = 0;
- virtual AccessMethods accessMethods() const = 0;
-
- bool keepConnection() const;
- bool setKeepConnection(bool isPersistent);
bool disconnect();
- bool isProcessingCommand() const;
-
// NdefAccess
- virtual bool hasNdefMessage();
- virtual RequestId readNdefMessages();
- virtual RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
+ bool hasNdefMessage();
+ RequestId readNdefMessages();
+ RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
// TagTypeSpecificAccess
int maxCommandLength() const;
- virtual RequestId sendCommand(const QByteArray &command);
- virtual RequestId sendCommands(const QList<QByteArray> &commands);
-
- virtual bool waitForRequestCompleted(const RequestId &id, int msecs = 5000);
+ RequestId sendCommand(const QByteArray &command);
- QVariant requestResponse(const RequestId &id);
- void setResponseForRequest(const QNearFieldTarget::RequestId &id, const QVariant &response,
- bool emitRequestCompleted = true);
-
-protected:
- Q_INVOKABLE virtual bool handleResponse(const QNearFieldTarget::RequestId &id,
- const QByteArray &response);
-
- void reportError(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id);
+ bool waitForRequestCompleted(const RequestId &id, int msecs = 5000);
+ QVariant requestResponse(const RequestId &id) const;
Q_SIGNALS:
void disconnected();
void ndefMessageRead(const QNdefMessage &message);
- void ndefMessagesWritten();
void requestCompleted(const QNearFieldTarget::RequestId &id);
void error(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id);
+protected:
+ QNearFieldTarget(QNearFieldTargetPrivate *backend, QObject *parent = nullptr);
+
private:
QNearFieldTargetPrivate *d_ptr;
};
-#if QT_DEPRECATED_SINCE(5, 9)
-Q_NFC_EXPORT quint16 qNfcChecksum(const char * data, uint len);
-#endif
-
Q_DECLARE_OPERATORS_FOR_FLAGS(QNearFieldTarget::AccessMethods)
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QNearFieldTarget::RequestId)
+QT_DECL_METATYPE_EXTERN_TAGGED(QNearFieldTarget::RequestId, QNearFieldTarget__RequestId,
+ Q_NFC_EXPORT)
#endif // QNEARFIELDTARGET_H
diff --git a/src/nfc/qnearfieldtarget_android.cpp b/src/nfc/qnearfieldtarget_android.cpp
index 78da6ac2..c7f842ae 100644
--- a/src/nfc/qnearfieldtarget_android.cpp
+++ b/src/nfc/qnearfieldtarget_android.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Centria research and development
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qnearfieldtarget_android_p.h"
#include "android/androidjninfc_p.h"
@@ -57,88 +21,73 @@
#define NFCTAGTYPE3 QStringLiteral("org.nfcforum.ndef.type3")
#define NFCTAGTYPE4 QStringLiteral("org.nfcforum.ndef.type4")
-NearFieldTarget::NearFieldTarget(QAndroidJniObject intent, const QByteArray uid, QObject *parent) :
- QNearFieldTarget(parent),
- m_intent(intent),
- m_uid(uid),
- m_keepConnection(false)
+QNearFieldTargetPrivateImpl::QNearFieldTargetPrivateImpl(QJniObject intent,
+ const QByteArray uid,
+ QObject *parent)
+: QNearFieldTargetPrivate(parent),
+ targetIntent(intent),
+ targetUid(uid)
{
updateTechList();
updateType();
setupTargetCheckTimer();
}
-NearFieldTarget::~NearFieldTarget()
+QNearFieldTargetPrivateImpl::~QNearFieldTargetPrivateImpl()
{
releaseIntent();
- emit targetDestroyed(m_uid);
+ Q_EMIT targetDestroyed(targetUid);
}
-QByteArray NearFieldTarget::uid() const
+QByteArray QNearFieldTargetPrivateImpl::uid() const
{
- return m_uid;
+ return targetUid;
}
-QNearFieldTarget::Type NearFieldTarget::type() const
+QNearFieldTarget::Type QNearFieldTargetPrivateImpl::type() const
{
- return m_type;
+ return tagType;
}
-QNearFieldTarget::AccessMethods NearFieldTarget::accessMethods() const
+QNearFieldTarget::AccessMethods QNearFieldTargetPrivateImpl::accessMethods() const
{
- AccessMethods result = UnknownAccess;
+ QNearFieldTarget::AccessMethods result = QNearFieldTarget::UnknownAccess;
- if (m_techList.contains(NDEFTECHNOLOGY)
- || m_techList.contains(NDEFFORMATABLETECHNOLOGY))
- result |= NdefAccess;
+ if (techList.contains(NDEFTECHNOLOGY)
+ || techList.contains(NDEFFORMATABLETECHNOLOGY))
+ result |= QNearFieldTarget::NdefAccess;
- if (m_techList.contains(ISODEPTECHNOLOGY)
- || m_techList.contains(NFCATECHNOLOGY)
- || m_techList.contains(NFCBTECHNOLOGY)
- || m_techList.contains(NFCFTECHNOLOGY)
- || m_techList.contains(NFCVTECHNOLOGY))
- result |= TagTypeSpecificAccess;
+ if (techList.contains(ISODEPTECHNOLOGY)
+ || techList.contains(NFCATECHNOLOGY)
+ || techList.contains(NFCBTECHNOLOGY)
+ || techList.contains(NFCFTECHNOLOGY)
+ || techList.contains(NFCVTECHNOLOGY))
+ result |= QNearFieldTarget::TagTypeSpecificAccess;
return result;
}
-bool NearFieldTarget::keepConnection() const
+bool QNearFieldTargetPrivateImpl::disconnect()
{
- return m_keepConnection;
-}
-
-bool NearFieldTarget::setKeepConnection(bool isPersistent)
-{
- m_keepConnection = isPersistent;
-
- if (!m_keepConnection)
- disconnect();
-
- return true;
-}
-
-bool NearFieldTarget::disconnect()
-{
- if (!m_tagTech.isValid())
+ if (!tagTech.isValid())
return false;
-
- bool connected = m_tagTech.callMethod<jboolean>("isConnected");
- if (catchJavaExceptions())
- return false;
-
+ QJniEnvironment env;
+ bool connected = tagTech.callMethod<jboolean>("isConnected");
if (!connected)
return false;
-
- m_tagTech.callMethod<void>("close");
- return !catchJavaExceptions();
+ auto methodId = env.findMethod<void>(tagTech.objectClass(), "close");
+ if (!methodId)
+ return false;
+ env->CallVoidMethod(tagTech.object(), methodId);
+ return !env.checkAndClearExceptions();
}
-bool NearFieldTarget::hasNdefMessage()
+bool QNearFieldTargetPrivateImpl::hasNdefMessage()
{
- return m_techList.contains(NDEFTECHNOLOGY);
+ return techList.contains(NDEFTECHNOLOGY);
}
-QNearFieldTarget::RequestId NearFieldTarget::readNdefMessages()
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::readNdefMessages()
{
// Making sure that target has NDEF messages
if (!hasNdefMessage())
@@ -146,7 +95,7 @@ QNearFieldTarget::RequestId NearFieldTarget::readNdefMessages()
// Making sure that target is still in range
QNearFieldTarget::RequestId requestId(new QNearFieldTarget::RequestIdPrivate);
- if (!m_intent.isValid()) {
+ if (!targetIntent.isValid()) {
reportError(QNearFieldTarget::TargetOutOfRangeError, requestId);
return requestId;
}
@@ -159,32 +108,25 @@ QNearFieldTarget::RequestId NearFieldTarget::readNdefMessages()
// Connect
if (!connect()) {
- reportError(QNearFieldTarget::TargetOutOfRangeError, requestId);
+ reportError(QNearFieldTarget::ConnectionError, requestId);
return requestId;
}
// Get NdefMessage object
- QAndroidJniObject ndefMessage = m_tagTech.callObjectMethod("getNdefMessage", "()Landroid/nfc/NdefMessage;");
- if (catchJavaExceptions())
- ndefMessage = QAndroidJniObject();
+ QJniObject ndefMessage = tagTech.callMethod<QtJniTypes::NdefMessage>("getNdefMessage");
if (!ndefMessage.isValid()) {
reportError(QNearFieldTarget::NdefReadError, requestId);
return requestId;
}
// Convert to byte array
- QAndroidJniObject ndefMessageBA = ndefMessage.callObjectMethod("toByteArray", "()[B");
+ QJniObject ndefMessageBA = ndefMessage.callMethod<jbyteArray>("toByteArray");
QByteArray ndefMessageQBA = jbyteArrayToQByteArray(ndefMessageBA.object<jbyteArray>());
- if (!m_keepConnection) {
- // Closing connection
- disconnect(); // IOException at this point does not matter anymore.
- }
-
// Sending QNdefMessage, requestCompleted and exit.
QNdefMessage qNdefMessage = QNdefMessage::fromByteArray(ndefMessageQBA);
QMetaObject::invokeMethod(this, [this, qNdefMessage]() {
- Q_EMIT this->QNearFieldTarget::ndefMessageRead(qNdefMessage);
+ Q_EMIT this->q_ptr->ndefMessageRead(qNdefMessage);
}, Qt::QueuedConnection);
QMetaObject::invokeMethod(this, [this, requestId]() {
Q_EMIT this->requestCompleted(requestId);
@@ -197,51 +139,47 @@ QNearFieldTarget::RequestId NearFieldTarget::readNdefMessages()
return requestId;
}
-int NearFieldTarget::maxCommandLength() const
+int QNearFieldTargetPrivateImpl::maxCommandLength() const
{
- QAndroidJniObject tagTech;
- if (m_techList.contains(ISODEPTECHNOLOGY))
+ QJniObject tagTech;
+ if (techList.contains(ISODEPTECHNOLOGY))
tagTech = getTagTechnology(ISODEPTECHNOLOGY);
- else if (m_techList.contains(NFCATECHNOLOGY))
+ else if (techList.contains(NFCATECHNOLOGY))
tagTech = getTagTechnology(NFCATECHNOLOGY);
- else if (m_techList.contains(NFCBTECHNOLOGY))
+ else if (techList.contains(NFCBTECHNOLOGY))
tagTech = getTagTechnology(NFCBTECHNOLOGY);
- else if (m_techList.contains(NFCFTECHNOLOGY))
+ else if (techList.contains(NFCFTECHNOLOGY))
tagTech = getTagTechnology(NFCFTECHNOLOGY);
- else if (m_techList.contains(NFCVTECHNOLOGY))
+ else if (techList.contains(NFCVTECHNOLOGY))
tagTech = getTagTechnology(NFCVTECHNOLOGY);
else
return 0;
- int returnVal = tagTech.callMethod<jint>("getMaxTransceiveLength");
- if (catchJavaExceptions())
- return 0;
-
- return returnVal;
+ return tagTech.callMethod<jint>("getMaxTransceiveLength");
}
-QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &command)
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::sendCommand(const QByteArray &command)
{
if (command.size() == 0 || command.size() > maxCommandLength()) {
- Q_EMIT QNearFieldTarget::error(QNearFieldTarget::InvalidParametersError, QNearFieldTarget::RequestId());
+ Q_EMIT error(QNearFieldTarget::InvalidParametersError, QNearFieldTarget::RequestId());
return QNearFieldTarget::RequestId();
}
// Making sure that target has commands
- if (!(accessMethods() & TagTypeSpecificAccess))
+ if (!(accessMethods() & QNearFieldTarget::TagTypeSpecificAccess))
return QNearFieldTarget::RequestId();
- QAndroidJniEnvironment env;
+ QJniEnvironment env;
if (!setTagTechnology({ISODEPTECHNOLOGY, NFCATECHNOLOGY, NFCBTECHNOLOGY, NFCFTECHNOLOGY, NFCVTECHNOLOGY})) {
- Q_EMIT QNearFieldTarget::error(QNearFieldTarget::UnsupportedError, QNearFieldTarget::RequestId());
+ Q_EMIT error(QNearFieldTarget::UnsupportedError, QNearFieldTarget::RequestId());
return QNearFieldTarget::RequestId();
}
// Connecting
QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
if (!connect()) {
- reportError(QNearFieldTarget::TargetOutOfRangeError, requestId);
+ reportError(QNearFieldTarget::ConnectionError, requestId);
return requestId;
}
@@ -251,20 +189,22 @@ QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &comma
env->SetByteArrayRegion(jba, 0, ba.size(), reinterpret_cast<jbyte*>(ba.data()));
// Writing
- QAndroidJniObject myNewVal = m_tagTech.callObjectMethod("transceive", "([B)[B", jba);
- if (catchJavaExceptions()) {
+ QJniObject myNewVal = tagTech.callMethod<jbyteArray>("transceive", jba);
+ if (!myNewVal.isValid()) {
+ // Some devices (Samsung, Huawei) throw an exception when the card is lost:
+ // "android.nfc.TagLostException: Tag was lost". But there seems to be a bug that
+ // isConnected still reports true. So we need to invalidate the target as soon as
+ // possible and treat the card as lost.
+ handleTargetLost();
+
reportError(QNearFieldTarget::CommandError, requestId);
return requestId;
}
QByteArray result = jbyteArrayToQByteArray(myNewVal.object<jbyteArray>());
env->DeleteLocalRef(jba);
- handleResponse(requestId, result);
+ setResponseForRequest(requestId, result, false);
- if (!m_keepConnection) {
- // Closing connection
- disconnect(); // IOException at this point does not matter anymore.
- }
QMetaObject::invokeMethod(this, [this, requestId]() {
Q_EMIT this->requestCompleted(requestId);
}, Qt::QueuedConnection);
@@ -272,15 +212,7 @@ QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &comma
return requestId;
}
-QNearFieldTarget::RequestId NearFieldTarget::sendCommands(const QList<QByteArray> &commands)
-{
- QNearFieldTarget::RequestId requestId;
- for (int i=0; i < commands.size(); i++)
- requestId = sendCommand(commands.at(i));
- return requestId;
-}
-
-QNearFieldTarget::RequestId NearFieldTarget::writeNdefMessages(const QList<QNdefMessage> &messages)
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::writeNdefMessages(const QList<QNdefMessage> &messages)
{
if (messages.size() == 0)
return QNearFieldTarget::RequestId();
@@ -288,14 +220,14 @@ QNearFieldTarget::RequestId NearFieldTarget::writeNdefMessages(const QList<QNdef
if (messages.size() > 1)
qWarning("QNearFieldTarget::writeNdefMessages: Android supports writing only one NDEF message per tag.");
- QAndroidJniEnvironment env;
+ QJniEnvironment env;
const char *writeMethod;
if (!setTagTechnology({NDEFFORMATABLETECHNOLOGY, NDEFTECHNOLOGY}))
return QNearFieldTarget::RequestId();
// Getting write method
- if (m_tech == NDEFFORMATABLETECHNOLOGY)
+ if (selectedTech == NDEFFORMATABLETECHNOLOGY)
writeMethod = "format";
else
writeMethod = "writeNdefMessage";
@@ -303,58 +235,65 @@ QNearFieldTarget::RequestId NearFieldTarget::writeNdefMessages(const QList<QNdef
// Connecting
QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
if (!connect()) {
- reportError(QNearFieldTarget::TargetOutOfRangeError, requestId);
+ reportError(QNearFieldTarget::ConnectionError, requestId);
return requestId;
}
// Making NdefMessage object
const QNdefMessage &message = messages.first();
QByteArray ba = message.toByteArray();
- QAndroidJniObject jba = env->NewByteArray(ba.size());
+ QJniObject jba = env->NewByteArray(ba.size());
env->SetByteArrayRegion(jba.object<jbyteArray>(), 0, ba.size(), reinterpret_cast<jbyte*>(ba.data()));
- QAndroidJniObject jmessage = QAndroidJniObject("android/nfc/NdefMessage", "([B)V", jba.object<jbyteArray>());
- if (catchJavaExceptions()) {
+ QJniObject jmessage = QJniObject::construct<QtJniTypes::NdefMessage>(jba.object<jbyteArray>());
+ if (!jmessage.isValid()) {
reportError(QNearFieldTarget::UnknownError, requestId);
return requestId;
}
// Writing
- m_tagTech.callMethod<void>(writeMethod, "(Landroid/nfc/NdefMessage;)V", jmessage.object<jobject>());
- if (catchJavaExceptions()) {
+ auto methodId =
+ env.findMethod<void, QtJniTypes::NdefMessage>(tagTech.objectClass(), writeMethod);
+ if (methodId)
+ env->CallVoidMethod(tagTech.object(), methodId, jmessage.object<jobject>());
+ if (!methodId || env.checkAndClearExceptions()) {
reportError(QNearFieldTarget::NdefWriteError, requestId);
return requestId;
}
- if (!m_keepConnection)
- disconnect(); // IOException at this point does not matter anymore.
- QMetaObject::invokeMethod(this, "ndefMessagesWritten", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(this, [this, requestId]() {
+ Q_EMIT this->requestCompleted(requestId);
+ }, Qt::QueuedConnection);
return requestId;
}
-void NearFieldTarget::setIntent(QAndroidJniObject intent)
+void QNearFieldTargetPrivateImpl::setIntent(QJniObject intent)
{
- if (m_intent == intent)
+ if (targetIntent == intent)
return;
releaseIntent();
- m_intent = intent;
- if (m_intent.isValid()) {
+ targetIntent = intent;
+ if (targetIntent.isValid()) {
// Updating tech list and type in case of there is another tag with same UID as one before.
updateTechList();
updateType();
- m_targetCheckTimer->start();
+ targetCheckTimer->start();
}
}
-void NearFieldTarget::checkIsTargetLost()
+void QNearFieldTargetPrivateImpl::checkIsTargetLost()
{
- if (!m_intent.isValid() || !setTagTechnology(m_techList)) {
+ if (!targetIntent.isValid() || !setTagTechnology({selectedTech})) {
handleTargetLost();
return;
}
- bool connected = m_tagTech.callMethod<jboolean>("isConnected");
- if (catchJavaExceptions()) {
+ QJniEnvironment env;
+ bool connected = false;
+ auto methodId = env.findMethod<jboolean>(tagTech.objectClass(), "isConnected");
+ if (methodId)
+ connected = env->CallBooleanMethod(tagTech.object(), methodId);
+ if (!methodId || env.checkAndClearExceptions()) {
handleTargetLost();
return;
}
@@ -362,184 +301,194 @@ void NearFieldTarget::checkIsTargetLost()
if (connected)
return;
- m_tagTech.callMethod<void>("connect");
- if (catchJavaExceptions(false)) {
+ methodId = env.findMethod<void>(tagTech.objectClass(), "connect");
+ if (methodId)
+ env->CallVoidMethod(tagTech.object(), methodId);
+ if (!methodId || env.checkAndClearExceptions(QJniEnvironment::OutputMode::Silent)) {
handleTargetLost();
return;
}
- m_tagTech.callMethod<void>("close");
- if (catchJavaExceptions(false))
+ methodId = env.findMethod<void>(tagTech.objectClass(), "close");
+ if (methodId)
+ env->CallVoidMethod(tagTech.object(), methodId);
+ if (!methodId || env.checkAndClearExceptions(QJniEnvironment::OutputMode::Silent))
handleTargetLost();
}
-void NearFieldTarget::releaseIntent()
+void QNearFieldTargetPrivateImpl::releaseIntent()
{
- m_targetCheckTimer->stop();
+ targetCheckTimer->stop();
- m_intent = QAndroidJniObject();
+ targetIntent = QJniObject();
}
-void NearFieldTarget::updateTechList()
+void QNearFieldTargetPrivateImpl::updateTechList()
{
- if (!m_intent.isValid())
+ if (!targetIntent.isValid())
return;
// Getting tech list
- QAndroidJniEnvironment env;
- QAndroidJniObject tag = AndroidNfc::getTag(m_intent);
+ QJniEnvironment env;
+ QJniObject tag = QtNfc::getTag(targetIntent);
Q_ASSERT_X(tag.isValid(), "updateTechList", "could not get Tag object");
- QAndroidJniObject techListArray = tag.callObjectMethod("getTechList", "()[Ljava/lang/String;");
+ QJniObject techListArray = tag.callMethod<QtJniTypes::StringArray>("getTechList");
if (!techListArray.isValid()) {
handleTargetLost();
return;
}
// Converting tech list array to QStringList.
- m_techList.clear();
+ techList.clear();
jsize techCount = env->GetArrayLength(techListArray.object<jobjectArray>());
for (jsize i = 0; i < techCount; ++i) {
- QAndroidJniObject tech = env->GetObjectArrayElement(techListArray.object<jobjectArray>(), i);
- m_techList.append(tech.callObjectMethod<jstring>("toString").toString());
+ QJniObject tech = env->GetObjectArrayElement(techListArray.object<jobjectArray>(), i);
+ techList.append(tech.callMethod<jstring>("toString").toString());
}
}
-void NearFieldTarget::updateType()
+void QNearFieldTargetPrivateImpl::updateType()
{
- m_type = getTagType();
+ tagType = getTagType();
}
-QNearFieldTarget::Type NearFieldTarget::getTagType() const
+QNearFieldTarget::Type QNearFieldTargetPrivateImpl::getTagType() const
{
- QAndroidJniEnvironment env;
-
- if (m_techList.contains(NDEFTECHNOLOGY)) {
- QAndroidJniObject ndef = getTagTechnology(NDEFTECHNOLOGY);
- QString qtype = ndef.callObjectMethod("getType", "()Ljava/lang/String;").toString();
+ if (techList.contains(NDEFTECHNOLOGY)) {
+ QJniObject ndef = getTagTechnology(NDEFTECHNOLOGY);
+ QString qtype = ndef.callMethod<jstring>("getType").toString();
if (qtype.compare(MIFARETAG) == 0)
- return MifareTag;
+ return QNearFieldTarget::MifareTag;
if (qtype.compare(NFCTAGTYPE1) == 0)
- return NfcTagType1;
+ return QNearFieldTarget::NfcTagType1;
if (qtype.compare(NFCTAGTYPE2) == 0)
- return NfcTagType2;
+ return QNearFieldTarget::NfcTagType2;
if (qtype.compare(NFCTAGTYPE3) == 0)
- return NfcTagType3;
+ return QNearFieldTarget::NfcTagType3;
if (qtype.compare(NFCTAGTYPE4) == 0)
- return NfcTagType4;
- return ProprietaryTag;
- } else if (m_techList.contains(NFCATECHNOLOGY)) {
- if (m_techList.contains(MIFARECLASSICTECHNOLOGY))
- return MifareTag;
+ return QNearFieldTarget::NfcTagType4;
+ return QNearFieldTarget::ProprietaryTag;
+ } else if (techList.contains(NFCATECHNOLOGY)) {
+ if (techList.contains(MIFARECLASSICTECHNOLOGY))
+ return QNearFieldTarget::MifareTag;
// Checking ATQA/SENS_RES
// xxx0 0000 xxxx xxxx: Identifies tag Type 1 platform
- QAndroidJniObject nfca = getTagTechnology(NFCATECHNOLOGY);
- QAndroidJniObject atqaBA = nfca.callObjectMethod("getAtqa", "()[B");
+ QJniObject nfca = getTagTechnology(NFCATECHNOLOGY);
+ QJniObject atqaBA = nfca.callMethod<jbyteArray>("getAtqa");
QByteArray atqaQBA = jbyteArrayToQByteArray(atqaBA.object<jbyteArray>());
if (atqaQBA.isEmpty())
- return ProprietaryTag;
+ return QNearFieldTarget::ProprietaryTag;
if ((atqaQBA[0] & 0x1F) == 0x00)
- return NfcTagType1;
+ return QNearFieldTarget::NfcTagType1;
// Checking SAK/SEL_RES
// xxxx xxxx x00x x0xx: Identifies tag Type 2 platform
// xxxx xxxx x01x x0xx: Identifies tag Type 4 platform
jshort sakS = nfca.callMethod<jshort>("getSak");
if ((sakS & 0x0064) == 0x0000)
- return NfcTagType2;
+ return QNearFieldTarget::NfcTagType2;
else if ((sakS & 0x0064) == 0x0020)
- return NfcTagType4;
- return ProprietaryTag;
- } else if (m_techList.contains(NFCBTECHNOLOGY)) {
- return NfcTagType4;
- } else if (m_techList.contains(NFCFTECHNOLOGY)) {
- return NfcTagType3;
+ return QNearFieldTarget::NfcTagType4A;
+ return QNearFieldTarget::ProprietaryTag;
+ } else if (techList.contains(NFCBTECHNOLOGY)) {
+ return QNearFieldTarget::NfcTagType4B;
+ } else if (techList.contains(NFCFTECHNOLOGY)) {
+ return QNearFieldTarget::NfcTagType3;
}
- return ProprietaryTag;
+ return QNearFieldTarget::ProprietaryTag;
}
-void NearFieldTarget::setupTargetCheckTimer()
+void QNearFieldTargetPrivateImpl::setupTargetCheckTimer()
{
- m_targetCheckTimer = new QTimer(this);
- m_targetCheckTimer->setInterval(1000);
- QObject::connect(m_targetCheckTimer, &QTimer::timeout, this, &NearFieldTarget::checkIsTargetLost);
- m_targetCheckTimer->start();
+ targetCheckTimer = new QTimer(this);
+ targetCheckTimer->setInterval(1000);
+ QObject::connect(targetCheckTimer, &QTimer::timeout, this, &QNearFieldTargetPrivateImpl::checkIsTargetLost);
+ targetCheckTimer->start();
}
-void NearFieldTarget::handleTargetLost()
+void QNearFieldTargetPrivateImpl::handleTargetLost()
{
releaseIntent();
- emit targetLost(this);
+ Q_EMIT targetLost(this);
}
-QAndroidJniObject NearFieldTarget::getTagTechnology(const QString &tech) const
+QJniObject QNearFieldTargetPrivateImpl::getTagTechnology(const QString &tech) const
{
QString techClass(tech);
techClass.replace(QLatin1Char('.'), QLatin1Char('/'));
// Getting requested technology
- QAndroidJniObject tag = AndroidNfc::getTag(m_intent);
+ QJniObject tag = QtNfc::getTag(targetIntent);
Q_ASSERT_X(tag.isValid(), "getTagTechnology", "could not get Tag object");
const QString sig = QString::fromUtf8("(Landroid/nfc/Tag;)L%1;");
- QAndroidJniObject tagTech = QAndroidJniObject::callStaticObjectMethod(techClass.toUtf8().constData(), "get",
+ QJniObject tagTech = QJniObject::callStaticObjectMethod(techClass.toUtf8().constData(), "get",
sig.arg(techClass).toUtf8().constData(), tag.object<jobject>());
return tagTech;
}
-bool NearFieldTarget::setTagTechnology(const QStringList &techList)
+bool QNearFieldTargetPrivateImpl::setTagTechnology(const QStringList &technologies)
{
- for (const QString &tech : techList) {
- if (m_techList.contains(tech)) {
- if (m_tech == tech) {
+ for (const QString &tech : technologies) {
+ if (techList.contains(tech)) {
+ if (selectedTech == tech) {
return true;
}
- m_tech = tech;
- m_tagTech = getTagTechnology(tech);
- return m_tagTech.isValid();
+ selectedTech = tech;
+ tagTech = getTagTechnology(tech);
+ return tagTech.isValid();
}
}
return false;
}
-bool NearFieldTarget::connect()
+bool QNearFieldTargetPrivateImpl::connect()
{
- if (!m_tagTech.isValid())
+ if (!tagTech.isValid())
return false;
- bool connected = m_tagTech.callMethod<jboolean>("isConnected");
- if (catchJavaExceptions())
+ QJniEnvironment env;
+ auto methodId = env.findMethod<jboolean>(tagTech.objectClass(), "isConnected");
+ bool connected = false;
+ if (methodId)
+ connected = env->CallBooleanMethod(tagTech.object(), methodId);
+ if (!methodId || env.checkAndClearExceptions())
return false;
if (connected)
return true;
- m_tagTech.callMethod<void>("connect");
- return !catchJavaExceptions();
+ setCommandTimeout(2000);
+ methodId = env.findMethod<void>(tagTech.objectClass(), "connect");
+ if (!methodId)
+ return false;
+ env->CallVoidMethod(tagTech.object(), methodId);
+ return !env.checkAndClearExceptions();
}
-QByteArray NearFieldTarget::jbyteArrayToQByteArray(const jbyteArray &byteArray) const
+bool QNearFieldTargetPrivateImpl::setCommandTimeout(int timeout)
{
- QAndroidJniEnvironment env;
+ if (!tagTech.isValid())
+ return false;
+
+ QJniEnvironment env;
+ auto methodId = env.findMethod<void, jint>(tagTech.objectClass(), "setTimeout");
+ if (methodId)
+ env->CallVoidMethod(tagTech.object(), methodId, timeout);
+ return methodId && !env.checkAndClearExceptions();
+}
+
+QByteArray QNearFieldTargetPrivateImpl::jbyteArrayToQByteArray(const jbyteArray &byteArray) const
+{
+ QJniEnvironment env;
QByteArray resultArray;
jsize len = env->GetArrayLength(byteArray);
resultArray.resize(len);
env->GetByteArrayRegion(byteArray, 0, len, reinterpret_cast<jbyte*>(resultArray.data()));
return resultArray;
}
-
-bool NearFieldTarget::catchJavaExceptions(bool verbose) const
-{
- QAndroidJniEnvironment env;
- if (env->ExceptionCheck()) {
- if (verbose)
- env->ExceptionDescribe();
- env->ExceptionClear();
- return true;
- }
- return false;
-}
diff --git a/src/nfc/qnearfieldtarget_android_p.cpp b/src/nfc/qnearfieldtarget_android_p.cpp
deleted file mode 100644
index de553ea9..00000000
--- a/src/nfc/qnearfieldtarget_android_p.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Governikus GmbH & Co. KG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QCoreApplication>
-
-#include "qnearfieldtarget_p.h"
-#include "qnearfieldtarget_android_p.h"
-
-QT_BEGIN_NAMESPACE
-
-bool QNearFieldTargetPrivate::keepConnection() const
-{
- NEARFIELDTARGET_Q();
- return q->keepConnection();
-}
-
-bool QNearFieldTargetPrivate::setKeepConnection(bool isPersistent)
-{
- NEARFIELDTARGET_Q();
- return q->setKeepConnection(isPersistent);
-}
-
-bool QNearFieldTargetPrivate::disconnect()
-{
- NEARFIELDTARGET_Q();
- return q->disconnect();
-}
-
-int QNearFieldTargetPrivate::maxCommandLength() const
-{
- NEARFIELDTARGET_Q();
- return q->maxCommandLength();
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtarget_android_p.h b/src/nfc/qnearfieldtarget_android_p.h
index 0063e9a5..bdfe6b19 100644
--- a/src/nfc/qnearfieldtarget_android_p.h
+++ b/src/nfc/qnearfieldtarget_android_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Centria research and development
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Centria research and development
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNEARFIELDTARGET_ANDROID_P_H
#define QNEARFIELDTARGET_ANDROID_P_H
@@ -52,43 +16,44 @@
//
#include "android/androidjninfc_p.h"
-#include "qnearfieldtarget.h"
#include "qnearfieldtarget_p.h"
#include "qndefmessage.h"
#include "qlist.h"
#include "qstringlist.h"
#include <QTimer>
-#include <QtAndroidExtras/QAndroidJniObject>
-#include <QtAndroidExtras/QAndroidJniEnvironment>
+#include <QtCore/QJniObject>
+#include <QtCore/QJniEnvironment>
QT_BEGIN_NAMESPACE
-class NearFieldTarget : public QNearFieldTarget
+class QNearFieldTargetPrivateImpl : public QNearFieldTargetPrivate
{
Q_OBJECT
public:
- NearFieldTarget(QAndroidJniObject intent,
- const QByteArray uid,
- QObject *parent = 0);
- virtual ~NearFieldTarget();
- virtual QByteArray uid() const;
- virtual Type type() const;
- virtual AccessMethods accessMethods() const;
- bool keepConnection() const;
- bool setKeepConnection(bool isPersistent);
- bool disconnect();
- virtual bool hasNdefMessage();
- virtual RequestId readNdefMessages();
- int maxCommandLength() const;
- virtual RequestId sendCommand(const QByteArray &command);
- virtual RequestId sendCommands(const QList<QByteArray> &commands);
- virtual RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
- void setIntent(QAndroidJniObject intent);
+ QNearFieldTargetPrivateImpl(QJniObject intent,
+ const QByteArray uid,
+ QObject *parent = nullptr);
+ ~QNearFieldTargetPrivateImpl() override;
+
+ QByteArray uid() const override;
+ QNearFieldTarget::Type type() const override;
+ QNearFieldTarget::AccessMethods accessMethods() const override;
+
+ bool disconnect() override;
+
+ bool hasNdefMessage() override;
+ QNearFieldTarget::RequestId readNdefMessages() override;
+ QNearFieldTarget::RequestId writeNdefMessages(const QList<QNdefMessage> &messages) override;
+
+ int maxCommandLength() const override;
+ QNearFieldTarget::RequestId sendCommand(const QByteArray &command) override;
+
+ void setIntent(QJniObject intent);
signals:
void targetDestroyed(const QByteArray &tagId);
- void targetLost(QNearFieldTarget *target);
+ void targetLost(QNearFieldTargetPrivateImpl *target);
void ndefMessageRead(const QNdefMessage &message, const QNearFieldTarget::RequestId &id);
protected slots:
@@ -98,24 +63,24 @@ protected:
void releaseIntent();
void updateTechList();
void updateType();
- Type getTagType() const;
+ QNearFieldTarget::Type getTagType() const;
void setupTargetCheckTimer();
void handleTargetLost();
- QAndroidJniObject getTagTechnology(const QString &tech) const;
- bool setTagTechnology(const QStringList &techList);
+ QJniObject getTagTechnology(const QString &tech) const;
+ bool setTagTechnology(const QStringList &technologies);
bool connect();
+ bool setCommandTimeout(int timeout);
QByteArray jbyteArrayToQByteArray(const jbyteArray &byteArray) const;
- bool catchJavaExceptions(bool verbose = true) const;
protected:
- QAndroidJniObject m_intent;
- QByteArray m_uid;
- QStringList m_techList;
- Type m_type;
- QTimer *m_targetCheckTimer;
- QString m_tech;
- QAndroidJniObject m_tagTech;
- bool m_keepConnection;
+ QJniObject targetIntent;
+ QByteArray targetUid;
+ QTimer *targetCheckTimer;
+
+ QString selectedTech;
+ QStringList techList;
+ QNearFieldTarget::Type tagType;
+ QJniObject tagTech;
};
QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtarget_emulator.cpp b/src/nfc/qnearfieldtarget_emulator.cpp
deleted file mode 100644
index aecd743e..00000000
--- a/src/nfc/qnearfieldtarget_emulator.cpp
+++ /dev/null
@@ -1,297 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnearfieldtarget_emulator_p.h"
-#include "qnearfieldtarget_p.h"
-
-#include <QtCore/QByteArray>
-#include <QtCore/QCoreApplication>
-#include <QtCore/QDateTime>
-#include <QtCore/QDirIterator>
-#include <QtCore/QMutex>
-#include <QtCore/QSettings>
-
-QT_BEGIN_NAMESPACE
-
-static QMutex tagMutex;
-static QMap<TagBase *, bool> tagMap;
-
-Q_GLOBAL_STATIC(TagActivator, globalTagActivator);
-
-TagType1::TagType1(TagBase *tag, QObject *parent)
-: QNearFieldTagType1(parent), m_tag(tag)
-{
-}
-
-TagType1::~TagType1()
-{
-}
-
-QByteArray TagType1::uid() const
-{
- QMutexLocker locker(&tagMutex);
-
- return m_tag->uid();
-}
-
-QNearFieldTarget::AccessMethods TagType1::accessMethods() const
-{
- return NdefAccess | TagTypeSpecificAccess;
-}
-
-QNearFieldTarget::RequestId TagType1::sendCommand(const QByteArray &command)
-{
- QMutexLocker locker(&tagMutex);
-
- RequestId id(new RequestIdPrivate);
-
- // tag not in proximity
- if (!tagMap.value(m_tag)) {
- reportError(QNearFieldTarget::TargetOutOfRangeError, id);
- return id;
- }
-
- quint16 crc = qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41);
-
- QByteArray response = m_tag->processCommand(command + char(crc & 0xff) + char(crc >> 8));
-
- if (response.isEmpty()) {
- reportError(QNearFieldTarget::NoResponseError, id);
- return id;
- }
-
- // check crc
- if (qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41) != 0) {
- reportError(QNearFieldTarget::ChecksumMismatchError, id);
- return id;
- }
-
- response.chop(2);
-
- QMetaObject::invokeMethod(this, "handleResponse", Qt::QueuedConnection,
- Q_ARG(QNearFieldTarget::RequestId, id), Q_ARG(QByteArray, response));
-
- return id;
-}
-
-bool TagType1::waitForRequestCompleted(const RequestId &id, int msecs)
-{
- QCoreApplication::sendPostedEvents(this, QEvent::MetaCall);
-
- return QNearFieldTagType1::waitForRequestCompleted(id, msecs);
-}
-
-
-TagType2::TagType2(TagBase *tag, QObject *parent)
-: QNearFieldTagType2(parent), m_tag(tag)
-{
-}
-
-TagType2::~TagType2()
-{
-}
-
-QByteArray TagType2::uid() const
-{
- QMutexLocker locker(&tagMutex);
-
- return m_tag->uid();
-}
-
-QNearFieldTarget::AccessMethods TagType2::accessMethods() const
-{
- return NdefAccess | TagTypeSpecificAccess;
-}
-
-QNearFieldTarget::RequestId TagType2::sendCommand(const QByteArray &command)
-{
- QMutexLocker locker(&tagMutex);
-
- RequestId id(new RequestIdPrivate);
-
- // tag not in proximity
- if (!tagMap.value(m_tag)) {
- reportError(QNearFieldTarget::TargetOutOfRangeError, id);
- return id;
- }
-
- quint16 crc = qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41);
-
- QByteArray response = m_tag->processCommand(command + char(crc & 0xff) + char(crc >> 8));
-
- if (response.isEmpty())
- return id;
-
- if (response.length() > 1) {
- // check crc
- if (qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41) != 0) {
- reportError(QNearFieldTarget::ChecksumMismatchError, id);
- return id;
- }
-
- response.chop(2);
- }
-
- QMetaObject::invokeMethod(this, "handleResponse", Qt::QueuedConnection,
- Q_ARG(QNearFieldTarget::RequestId, id), Q_ARG(QByteArray, response));
-
- return id;
-}
-
-bool TagType2::waitForRequestCompleted(const RequestId &id, int msecs)
-{
- QCoreApplication::sendPostedEvents(this, QEvent::MetaCall);
-
- return QNearFieldTagType2::waitForRequestCompleted(id, msecs);
-}
-
-
-TagActivator::TagActivator()
-: timerId(-1)
-{
- qRegisterMetaType<QNearFieldTarget::Error>();
-}
-
-TagActivator::~TagActivator()
-{
- QMutexLocker locker(&tagMutex);
- qDeleteAll(tagMap.keys());
- tagMap.clear();
-}
-
-void TagActivator::initialize()
-{
- QMutexLocker locker(&tagMutex);
-
- if (!tagMap.isEmpty())
- return;
-
-#ifndef BUILTIN_TESTDATA
- QDirIterator nfcTargets(QDir::currentPath(), QStringList(QStringLiteral("*.nfc")), QDir::Files);
-#else
- QDirIterator nfcTargets(":/nfcdata", QStringList(QStringLiteral("*.nfc")), QDir::Files);
-#endif
- while (nfcTargets.hasNext()) {
- const QString targetFilename = nfcTargets.next();
-
- QSettings target(targetFilename, QSettings::IniFormat);
-
- target.beginGroup(QStringLiteral("Target"));
-
- const QString tagType = target.value(QStringLiteral("Type")).toString();
-
- target.endGroup();
-
- if (tagType == QLatin1String("TagType1")) {
- NfcTagType1 *tag = new NfcTagType1;
- tag->load(&target);
-
- tagMap.insert(tag, false);
- } else if (tagType == QLatin1String("TagType2")) {
- NfcTagType2 *tag = new NfcTagType2;
- tag->load(&target);
-
- tagMap.insert(tag, false);
- } else {
- qWarning("Unknown tag type %s\n", qPrintable(tagType));
- }
- }
-
- m_current = tagMap.end();
-
- timerId = startTimer(1000);
-}
-
-void TagActivator::reset()
-{
- QMutexLocker locker(&tagMutex);
-
- killTimer(timerId);
- timerId = -1;
-
- qDeleteAll(tagMap.keys());
- tagMap.clear();
-}
-
-TagActivator *TagActivator::instance()
-{
- return globalTagActivator();
-}
-
-void TagActivator::timerEvent(QTimerEvent *e)
-{
- Q_UNUSED(e);
-
- tagMutex.lock();
-
- if (m_current != tagMap.end()) {
- if (m_current.key()->lastAccessTime() + 1500 > QDateTime::currentMSecsSinceEpoch()) {
- tagMutex.unlock();
- return;
- }
-
- *m_current = false;
-
- TagBase *tag = m_current.key();
-
- tagMutex.unlock();
- emit tagDeactivated(tag);
- tagMutex.lock();
- }
-
- if (m_current != tagMap.end())
- ++m_current;
-
- if (m_current == tagMap.end())
- m_current = tagMap.begin();
-
- if (m_current != tagMap.end()) {
- *m_current = true;
-
- TagBase *tag = m_current.key();
-
- tagMutex.unlock();
- emit tagActivated(tag);
- tagMutex.lock();
- }
-
- tagMutex.unlock();
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtarget_emulator_p.h b/src/nfc/qnearfieldtarget_emulator_p.h
deleted file mode 100644
index 70a67be8..00000000
--- a/src/nfc/qnearfieldtarget_emulator_p.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNEARFIELDTARGET_EMULATOR_P_H
-#define QNEARFIELDTARGET_EMULATOR_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qnearfieldtagtype1_p.h"
-#include "qnearfieldtagtype2_p.h"
-#include "targetemulator_p.h"
-
-#include <QtCore/QMap>
-
-QT_BEGIN_NAMESPACE
-
-class TagType1 : public QNearFieldTagType1
-{
- Q_OBJECT
-
-public:
- TagType1(TagBase *tag, QObject *parent);
- ~TagType1();
-
- QByteArray uid() const;
-
- AccessMethods accessMethods() const;
-
- RequestId sendCommand(const QByteArray &command);
- bool waitForRequestCompleted(const RequestId &id, int msecs = 5000);
-
-private:
- TagBase *m_tag;
-};
-
-class TagType2 : public QNearFieldTagType2
-{
- Q_OBJECT
-
-public:
- TagType2(TagBase *tag, QObject *parent);
- ~TagType2();
-
- QByteArray uid() const;
-
- AccessMethods accessMethods() const;
-
- RequestId sendCommand(const QByteArray &command);
- bool waitForRequestCompleted(const RequestId &id, int msecs = 5000);
-
-private:
- TagBase *m_tag;
-};
-
-class TagActivator : public QObject
-{
- Q_OBJECT
-
-public:
- TagActivator();
- ~TagActivator();
-
- void initialize();
- void reset();
-
- static TagActivator *instance();
-
-protected:
- void timerEvent(QTimerEvent *e);
-
-signals:
- void tagActivated(TagBase *tag);
- void tagDeactivated(TagBase *tag);
-
-private:
- QMap<TagBase *, bool>::Iterator m_current;
- int timerId;
-};
-
-QT_END_NAMESPACE
-
-#endif // QNEARFIELDTARGET_EMULATOR_P_H
diff --git a/src/nfc/qnearfieldtarget_ios.mm b/src/nfc/qnearfieldtarget_ios.mm
new file mode 100644
index 00000000..b058ad75
--- /dev/null
+++ b/src/nfc/qnearfieldtarget_ios.mm
@@ -0,0 +1,467 @@
+// Copyright (C) 2020 Governikus GmbH & Co. KG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "ios/qiosnfcndefsessiondelegate_p.h"
+#include "ios/qiosndefnotifier_p.h"
+
+#include "qnearfieldtarget_ios_p.h"
+
+#import <CoreNFC/NFCNDEFReaderSession.h>
+#import <CoreNFC/NFCReaderSession.h>
+#import <CoreNFC/NFCTagReaderSession.h>
+#import <CoreNFC/NFCISO7816Tag.h>
+#import <CoreNFC/NFCTag.h>
+
+#include <QtCore/qapplicationstatic.h>
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_APPLICATION_STATIC(ResponseProvider, responseProvider)
+
+void ResponseProvider::provideResponse(QNearFieldTarget::RequestId requestId, bool success, QByteArray recvBuffer) {
+ Q_EMIT responseReceived(requestId, success, recvBuffer);
+}
+
+void NfcDeleter::operator()(void *obj)
+{
+ id some = static_cast<id>(obj);
+
+ if ([some conformsToProtocol:@protocol(NFCNDEFTag)])
+ [static_cast<id<NFCNDEFTag>>(some) release];
+ else if ([some conformsToProtocol:@protocol(NFCTag)])
+ [static_cast<id<NFCTag>>(some) release];
+ else
+ Q_UNREACHABLE();
+}
+
+QNearFieldTargetPrivateImpl:: QNearFieldTargetPrivateImpl(void *tag, QObject *parent) :
+ QNearFieldTargetPrivate(parent),
+ nfcTag(tag)
+{
+ Q_ASSERT(nfcTag);
+
+ QObject::connect(this, &QNearFieldTargetPrivate::error, this, &QNearFieldTargetPrivateImpl::onTargetError);
+ QObject::connect(responseProvider, &ResponseProvider::responseReceived, this, &QNearFieldTargetPrivateImpl::onResponseReceived);
+ QObject::connect(&targetCheckTimer, &QTimer::timeout, this, &QNearFieldTargetPrivateImpl::onTargetCheck);
+ targetCheckTimer.start(500);
+}
+
+QNearFieldTargetPrivateImpl:: QNearFieldTargetPrivateImpl(void *delegate, void *tag, QObject *parent) :
+ QNearFieldTargetPrivate(parent),
+ nfcTag(tag)
+{
+ Q_ASSERT(delegate && tag);
+ Q_ASSERT([id(tag) conformsToProtocol:@protocol(NFCNDEFTag)]);
+
+ auto qtDelegate = static_cast<QIosNfcNdefSessionDelegate *>(sessionDelegate = delegate);
+ notifier = [qtDelegate ndefNotifier];
+ Q_ASSERT(notifier);
+
+ // The 'notifier' lives on a (potentially different, unspecified) thread,
+ // thus connection is 'queued'.
+ QObject::connect(notifier, &QNfcNdefNotifier::tagError, this,
+ &QNearFieldTargetPrivate::error, Qt::QueuedConnection);
+
+ QObject::connect(this, &QNearFieldTargetPrivate::error, this, &QNearFieldTargetPrivateImpl::onTargetError);
+ QObject::connect(&targetCheckTimer, &QTimer::timeout, this, &QNearFieldTargetPrivateImpl::onTargetCheck);
+
+ targetCheckTimer.start(500);
+}
+
+QNearFieldTargetPrivateImpl::~QNearFieldTargetPrivateImpl()
+{
+}
+
+void QNearFieldTargetPrivateImpl::invalidate()
+{
+ queue.clear();
+ ndefOperations.clear();
+
+ if (isNdefTag()) {
+ Q_ASSERT(notifier);
+
+ QObject::disconnect(notifier, nullptr, this, nullptr);
+ notifier = nullptr;
+ }
+
+ nfcTag.reset();
+ sessionDelegate = nil;
+
+ targetCheckTimer.stop();
+
+ QMetaObject::invokeMethod(this, [this]() {
+ Q_EMIT targetLost(this);
+ }, Qt::QueuedConnection);
+}
+
+QByteArray QNearFieldTargetPrivateImpl::uid() const
+{
+ if (!nfcTag || isNdefTag()) // NFCNDEFTag does not have this information ...
+ return {};
+
+ if (@available(iOS 13, *)) {
+ id<NFCTag> tag = static_cast<id<NFCTag>>(nfcTag.get());
+ id<NFCISO7816Tag> iso7816Tag = tag.asNFCISO7816Tag;
+ if (iso7816Tag)
+ return QByteArray::fromNSData(iso7816Tag.identifier);
+ }
+
+ return {};
+}
+
+QNearFieldTarget::Type QNearFieldTargetPrivateImpl::type() const
+{
+ if (!nfcTag || isNdefTag()) // No information provided by NFCNDEFTag.
+ return QNearFieldTarget::ProprietaryTag;
+
+ if (@available(iOS 13, *)) {
+ id<NFCTag> tag = static_cast<id<NFCTag>>(nfcTag.get());
+ id<NFCISO7816Tag> iso7816Tag = tag.asNFCISO7816Tag;
+
+ if (tag.type != NFCTagTypeISO7816Compatible || iso7816Tag == nil)
+ return QNearFieldTarget::ProprietaryTag;
+
+ if (iso7816Tag.historicalBytes != nil && iso7816Tag.applicationData == nil)
+ return QNearFieldTarget::NfcTagType4A;
+
+ if (iso7816Tag.historicalBytes == nil && iso7816Tag.applicationData != nil)
+ return QNearFieldTarget::NfcTagType4B;
+
+ return QNearFieldTarget::NfcTagType4;
+ }
+
+ return QNearFieldTarget::ProprietaryTag;
+}
+
+QNearFieldTarget::AccessMethods QNearFieldTargetPrivateImpl::accessMethods() const
+{
+ if (isNdefTag())
+ return QNearFieldTarget::NdefAccess;
+
+ if (@available(iOS 13, *)) {
+ id<NFCTag> tag = static_cast<id<NFCTag>>(nfcTag.get());
+ if (tag && [tag conformsToProtocol:@protocol(NFCISO7816Tag)])
+ return QNearFieldTarget::TagTypeSpecificAccess;
+ }
+
+ return QNearFieldTarget::UnknownAccess;
+}
+
+int QNearFieldTargetPrivateImpl::maxCommandLength() const
+{
+ if (accessMethods() & QNearFieldTarget::TagTypeSpecificAccess)
+ return 0xFEFF;
+
+ // TODO: check if 'capacity' of NFCNDEFTag can be used?
+ return 0;
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::sendCommand(const QByteArray &command)
+{
+ QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
+
+ if (!(accessMethods() & QNearFieldTarget::TagTypeSpecificAccess)) {
+ reportError(QNearFieldTarget::UnsupportedError, requestId);
+ return requestId;
+ }
+
+ queue.enqueue(std::pair(requestId, command));
+
+ if (!connect()) {
+ reportError(QNearFieldTarget::TargetOutOfRangeError, requestId);
+ return requestId;
+ }
+
+ onExecuteRequest();
+ return requestId;
+}
+
+bool QNearFieldTargetPrivateImpl::hasNdefMessage()
+{
+ return hasNDEFMessage;
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::readNdefMessages()
+{
+ hasNDEFMessage = false;
+
+ QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate);
+
+ if (!(accessMethods() & QNearFieldTarget::NdefAccess) || !isNdefTag()) {
+ qCWarning(QT_IOS_NFC, "Target does not allow to read NDEF messages, "
+ "was not detected as NDEF tag by the reader session?");
+ reportError(QNearFieldTarget::UnsupportedError, requestId);
+ return requestId;
+ }
+
+ NdefOperation op;
+ op.type = NdefOperation::Read;
+ op.requestId = requestId;
+
+ ndefOperations.push_back(op);
+ onExecuteRequest();
+
+ return requestId;
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::writeNdefMessages(const QList<QNdefMessage> &messages)
+{
+ auto requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate);
+
+ if (!(accessMethods() & QNearFieldTarget::NdefAccess) || !isNdefTag()) {
+ qCWarning(QT_IOS_NFC, "Target does not allow to write NDEF messages, "
+ "was not detected as NDEF tag by the reader session?");
+ reportError(QNearFieldTarget::UnsupportedError, requestId);
+ return requestId;
+ }
+
+ if (messages.size() != 1) {
+ // The native framework does not allow to write 'messages', only _one_ message
+ // at a time. Not to multiply the complexity of having 'ndefOperations' queue
+ // with some queue inside the delegate's code (plus some unpredictable errors
+ // handling) - require a single message as a single request.
+ qCWarning(QT_IOS_NFC, "Only one NDEF message per request ID can be written");
+ return requestId;
+ }
+
+ NdefOperation op;
+ op.type = NdefOperation::Write;
+ op.requestId = requestId;
+ op.message = messages.first();
+
+ ndefOperations.push_back(op);
+ onExecuteRequest();
+
+ return requestId;
+}
+
+bool QNearFieldTargetPrivateImpl::isAvailable() const
+{
+ if (requestInProgress.isValid())
+ return true;
+
+ const auto tagIsAvailable = [this](auto tag) {
+ return tag && (!connected || tag.available);
+ };
+
+ if (isNdefTag())
+ return tagIsAvailable(static_cast<id<NFCNDEFTag>>(nfcTag.get()));
+
+ if (@available(iOS 13, *))
+ return tagIsAvailable(static_cast<id<NFCTag>>(nfcTag.get()));
+
+ return false;
+}
+
+bool QNearFieldTargetPrivateImpl::connect()
+{
+ if (connected || requestInProgress.isValid())
+ return true;
+
+ if (isNdefTag())
+ return connected = true;
+
+ if (!isAvailable() || queue.isEmpty())
+ return false;
+
+ if (@available(iOS 13, *)) {
+ requestInProgress = queue.head().first;
+ id<NFCTag> tag = static_cast<id<NFCTag>>(nfcTag.get());
+ NFCTagReaderSession* session = tag.session;
+ [session connectToTag: tag completionHandler: ^(NSError* error){
+ const bool success = error == nil;
+ QMetaObject::invokeMethod(this, [this, success] {
+ requestInProgress = QNearFieldTarget::RequestId();
+ if (success) {
+ connected = true;
+ onExecuteRequest();
+ } else {
+ const auto requestId = queue.dequeue().first;
+ reportError(QNearFieldTarget::ConnectionError, requestId);
+ invalidate();
+ }
+ });
+ }];
+ return true;
+ }
+
+ return false;
+}
+
+bool QNearFieldTargetPrivateImpl::isNdefTag() const
+{
+ const id tag = static_cast<id>(nfcTag.get());
+ if ([tag conformsToProtocol:@protocol(NFCMiFareTag)])
+ return false;
+ if ([tag conformsToProtocol:@protocol(NFCFeliCaTag)])
+ return false;
+ if ([tag conformsToProtocol:@protocol(NFCISO15693Tag)])
+ return false;
+ if ([tag conformsToProtocol:@protocol(NFCISO7816Tag)])
+ return false;
+ return [tag conformsToProtocol:@protocol(NFCNDEFTag)];
+}
+
+void QNearFieldTargetPrivateImpl::onTargetCheck()
+{
+ if (!isAvailable())
+ invalidate();
+}
+
+void QNearFieldTargetPrivateImpl::onTargetError(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id)
+{
+ Q_UNUSED(id);
+
+ if (error == QNearFieldTarget::TimeoutError)
+ invalidate();
+}
+
+namespace {
+
+QNdefMessage ndefToQtNdefMessage(NFCNDEFMessage *nativeMessage)
+{
+ if (!nativeMessage)
+ return {};
+
+ QList<QNdefRecord> ndefRecords;
+ for (NFCNDEFPayload *ndefRecord in nativeMessage.records) {
+ QNdefRecord qtNdefRecord;
+ if (ndefRecord.typeNameFormat != NFCTypeNameFormatUnchanged) // Does not match anything in Qt.
+ qtNdefRecord.setTypeNameFormat(QNdefRecord::TypeNameFormat(ndefRecord.typeNameFormat));
+ if (ndefRecord.identifier)
+ qtNdefRecord.setId(QByteArray::fromNSData(ndefRecord.identifier));
+ if (ndefRecord.type)
+ qtNdefRecord.setType(QByteArray::fromNSData(ndefRecord.type));
+ if (ndefRecord.payload)
+ qtNdefRecord.setPayload(QByteArray::fromNSData(ndefRecord.payload));
+ ndefRecords.push_back(qtNdefRecord);
+ }
+
+ return QNdefMessage{ndefRecords};
+}
+
+} // Unnamed namespace.
+
+void QNearFieldTargetPrivateImpl::onExecuteRequest()
+{
+ if (!nfcTag || requestInProgress.isValid())
+ return;
+
+ if (isNdefTag()) {
+ if (ndefOperations.empty())
+ return;
+
+ auto *ndefDelegate = static_cast<QIosNfcNdefSessionDelegate *>(sessionDelegate);
+ Q_ASSERT(ndefDelegate);
+
+ Q_ASSERT(qt_Nfc_Queue()); // This is where callbacks get called.
+
+ const auto op = ndefOperations.front();
+ ndefOperations.pop_front();
+ requestInProgress = op.requestId;
+ auto requestId = requestInProgress; // Copy so we capture by value in the block.
+
+ id<NFCNDEFTag> ndefTag = static_cast<id<NFCNDEFTag>>(nfcTag.get());
+
+ std::unique_ptr<QNfcNdefNotifier> guard(new QNfcNdefNotifier);
+ auto *cbNotifier = guard.get();
+
+ QObject::connect(cbNotifier, &QNfcNdefNotifier::tagError, this,
+ &QNearFieldTargetPrivate::error, Qt::QueuedConnection);
+
+ if (op.type == NdefOperation::Read) {
+ QObject::connect(cbNotifier, &QNfcNdefNotifier::ndefMessageRead,
+ this, &QNearFieldTargetPrivateImpl::messageRead,
+ Qt::QueuedConnection);
+
+ // We call it here, but the callback will be executed on an unspecified thread.
+ [ndefTag readNDEFWithCompletionHandler:^(NFCNDEFMessage * _Nullable msg, NSError * _Nullable err) {
+ const std::unique_ptr<QNfcNdefNotifier> notifierGuard(cbNotifier);
+ if (err) {
+ NSLog(@"Reading NDEF messaged ended with error: %@", err);
+ emit cbNotifier->tagError(QNearFieldTarget::NdefReadError, requestId);
+ return;
+ }
+
+ const QNdefMessage ndefMessage(ndefToQtNdefMessage(msg));
+ emit cbNotifier->ndefMessageRead(ndefMessage, requestId);
+ }];
+ } else {
+ QObject::connect(cbNotifier, &QNfcNdefNotifier::ndefMessageWritten,
+ this, &QNearFieldTargetPrivateImpl::messageWritten,
+ Qt::QueuedConnection);
+
+ NSData *ndefData = op.message.toByteArray().toNSData(); // autoreleased.
+ Q_ASSERT(ndefData);
+
+ NFCNDEFMessage *ndefMessage = [NFCNDEFMessage ndefMessageWithData:ndefData]; // autoreleased.
+ Q_ASSERT(ndefMessage);
+
+ [ndefTag writeNDEF:ndefMessage completionHandler:^(NSError *err) {
+ const std::unique_ptr<QNfcNdefNotifier> notifierGuard(cbNotifier);
+ if (err) {
+ NSLog(@"Writing NDEF messaged ended with error: %@", err);
+ emit cbNotifier->tagError(QNearFieldTarget::NdefWriteError, requestId);
+ return;
+ }
+
+ emit cbNotifier->ndefMessageWritten(requestId);
+ }];
+ }
+ guard.release(); // Owned by the completion handler now.
+ return;
+ }
+
+ if (@available(iOS 13, *)) {
+ if (queue.isEmpty())
+ return;
+ const auto request = queue.dequeue();
+ requestInProgress = request.first;
+ const auto tag = static_cast<id<NFCISO7816Tag>>(nfcTag.get());
+ auto *apdu = [[[NFCISO7816APDU alloc] initWithData: request.second.toNSData()] autorelease];
+ [tag sendCommandAPDU: apdu completionHandler: ^(NSData* responseData, uint8_t sw1, uint8_t sw2, NSError* error){
+ QByteArray recvBuffer = QByteArray::fromNSData(responseData);
+ recvBuffer += static_cast<char>(sw1);
+ recvBuffer += static_cast<char>(sw2);
+ const bool success = error == nil;
+ responseProvider->provideResponse(request.first, success, recvBuffer);
+ }];
+ }
+}
+
+void QNearFieldTargetPrivateImpl::onResponseReceived(QNearFieldTarget::RequestId requestId, bool success, QByteArray recvBuffer)
+{
+ if (requestInProgress != requestId)
+ return;
+
+ requestInProgress = QNearFieldTarget::RequestId();
+ if (success) {
+ setResponseForRequest(requestId, recvBuffer, true);
+ onExecuteRequest();
+ } else {
+ reportError(QNearFieldTarget::CommandError, requestId);
+ invalidate();
+ }
+}
+
+void QNearFieldTargetPrivateImpl::messageRead(const QNdefMessage &message, QNearFieldTarget::RequestId requestId)
+{
+ hasNDEFMessage = message.size() != 0;
+
+ setResponseForRequest(requestId, message.toByteArray(), true);
+ requestInProgress = {}; // Invalidating, so we can execute the next one.
+ onExecuteRequest();
+
+ Q_EMIT ndefMessageRead(message);
+}
+
+void QNearFieldTargetPrivateImpl::messageWritten(QNearFieldTarget::RequestId requestId)
+{
+ requestInProgress = {}; // Invalidating, so we can execute the next one.
+ onExecuteRequest();
+
+ Q_EMIT requestCompleted(requestId);
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtarget_ios_p.h b/src/nfc/qnearfieldtarget_ios_p.h
new file mode 100644
index 00000000..c0cde0b6
--- /dev/null
+++ b/src/nfc/qnearfieldtarget_ios_p.h
@@ -0,0 +1,119 @@
+// Copyright (C) 2020 Governikus GmbH & Co. KG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNEARFIELDTARGET_IOS_P_H
+#define QNEARFIELDTARGET_IOS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qnearfieldtarget_p.h"
+#include "qnearfieldtarget.h"
+
+#include "qndefmessage.h"
+
+#include <QQueue>
+#include <QTimer>
+
+#include <memory>
+#include <deque>
+
+QT_BEGIN_NAMESPACE
+
+class ResponseProvider : public QObject
+{
+ Q_OBJECT
+
+ public:
+ void provideResponse(QNearFieldTarget::RequestId requestId, bool success, QByteArray recvBuffer);
+
+ Q_SIGNALS:
+ void responseReceived(QNearFieldTarget::RequestId requestId, bool success, QByteArray recvBuffer);
+};
+
+struct NfcDeleter
+{
+ void operator()(void *tag);
+};
+
+struct NdefOperation
+{
+ enum Type {
+ Read,
+ Write
+ } type = Read;
+
+ QNearFieldTarget::RequestId requestId;
+ QNdefMessage message;
+};
+
+class QNfcNdefNotifier;
+
+class QNearFieldTargetPrivateImpl : public QNearFieldTargetPrivate
+{
+ Q_OBJECT
+
+public:
+ QNearFieldTargetPrivateImpl(void *tag, QObject *parent = nullptr);
+ QNearFieldTargetPrivateImpl(void *sessionDelegate, void *tag, QObject *parent = nullptr);
+ ~QNearFieldTargetPrivateImpl() override;
+ void invalidate();
+
+ QByteArray uid() const override;
+ QNearFieldTarget::Type type() const override;
+ QNearFieldTarget::AccessMethods accessMethods() const override;
+
+ int maxCommandLength() const override;
+ QNearFieldTarget::RequestId sendCommand(const QByteArray &command) override;
+
+ // NdefAccess
+ bool hasNdefMessage() override;
+ QNearFieldTarget::RequestId readNdefMessages() override;
+ QNearFieldTarget::RequestId writeNdefMessages(const QList<QNdefMessage> &messages) override;
+
+
+ bool isAvailable() const;
+
+Q_SIGNALS:
+ void targetLost(QNearFieldTargetPrivateImpl *target);
+
+private:
+ std::unique_ptr<void, NfcDeleter> nfcTag;
+
+ // Owned by the near field manager.
+ void *sessionDelegate = nil;
+ // Owned by the session delegate.
+ QNfcNdefNotifier *notifier = nullptr;
+ bool hasNDEFMessage = false;
+
+ bool connected = false;
+ QTimer targetCheckTimer;
+ QNearFieldTarget::RequestId requestInProgress;
+ QQueue<std::pair<QNearFieldTarget::RequestId, QByteArray>> queue;
+ std::deque<NdefOperation> ndefOperations;
+
+ bool connect();
+
+ bool isNdefTag() const;
+
+private Q_SLOTS:
+ void onTargetCheck();
+ void onTargetError(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id);
+ void onExecuteRequest();
+ void onResponseReceived(QNearFieldTarget::RequestId requestId, bool success, QByteArray recvBuffer);
+ // NDEF:
+ void messageRead(const QNdefMessage &ndefMessage, QNearFieldTarget::RequestId request);
+ void messageWritten(QNearFieldTarget::RequestId request);
+};
+
+QT_END_NAMESPACE
+
+#endif // QNEARFIELDTARGET_IOS_P_H
diff --git a/src/nfc/qnearfieldtarget_neard_p.cpp b/src/nfc/qnearfieldtarget_neard_p.cpp
index 4ed17a15..d6982030 100644
--- a/src/nfc/qnearfieldtarget_neard_p.cpp
+++ b/src/nfc/qnearfieldtarget_neard_p.cpp
@@ -1,68 +1,325 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Governikus GmbH & Co. K
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QCoreApplication>
-
-#include "qnearfieldtarget.h"
-#include "qnearfieldtarget_p.h"
+// Copyright (C) 2016 BlackBerry Limited, Copyright (C) 2016 BasysKom GmbH
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qnearfieldtarget_neard_p.h"
+
+#include <qndefnfctextrecord.h>
+#include <qndefnfcsmartposterrecord.h>
+#include <qndefnfcurirecord.h>
QT_BEGIN_NAMESPACE
-bool QNearFieldTargetPrivate::keepConnection() const
+Q_DECLARE_LOGGING_CATEGORY(QT_NFC_NEARD)
+
+QNearFieldTargetPrivateImpl::QNearFieldTargetPrivateImpl(QObject *parent, QDBusObjectPath interfacePath)
+ : QNearFieldTargetPrivate(parent),
+ m_tagPath(interfacePath),
+ m_readRequested(false)
+{
+ m_readErrorTimer.setSingleShot(true);
+ m_recordPathsCollectedTimer.setSingleShot(true);
+ m_delayedWriteTimer.setSingleShot(true);
+
+ qCDebug(QT_NFC_NEARD) << "tag found at path" << interfacePath.path();
+ m_dbusProperties = new OrgFreedesktopDBusPropertiesInterface(QStringLiteral("org.neard"),
+ interfacePath.path(), QDBusConnection::systemBus(), this);
+ if (!m_dbusProperties->isValid()) {
+ qCWarning(QT_NFC_NEARD) << "Could not connect to dbus property interface at path"
+ << interfacePath.path();
+ return;
+ }
+
+ QDBusPendingReply<QVariantMap> reply = m_dbusProperties->GetAll(QStringLiteral("org.neard.Tag"));
+ reply.waitForFinished();
+ if (reply.isError()) {
+ qCWarning(QT_NFC_NEARD) << "Could not get properties of org.neard.Tag dbus interface";
+ return;
+ }
+
+ const QString &type = reply.value().value(QStringLiteral("Type")).toString();
+ m_type = QNearFieldTarget::ProprietaryTag;
+
+ if (type == QStringLiteral("Type 1"))
+ m_type = QNearFieldTarget::NfcTagType1;
+ else if (type == QStringLiteral("Type 2"))
+ m_type = QNearFieldTarget::NfcTagType2;
+ else if (type == QStringLiteral("Type 3"))
+ m_type = QNearFieldTarget::NfcTagType3;
+ else if (type == QStringLiteral("Type 4"))
+ m_type = QNearFieldTarget::NfcTagType4;
+
+ qCDebug(QT_NFC_NEARD) << "tag type" << type;
+
+ connect(&m_recordPathsCollectedTimer, &QTimer::timeout,
+ this, &QNearFieldTargetPrivateImpl::createNdefMessage);
+ connect(&m_readErrorTimer, &QTimer::timeout,
+ this, &QNearFieldTargetPrivateImpl::handleReadError);
+ connect(&m_delayedWriteTimer, &QTimer::timeout,
+ this, &QNearFieldTargetPrivateImpl::handleWriteRequest);
+ connect(NeardHelper::instance(), &NeardHelper::recordFound,
+ this, &QNearFieldTargetPrivateImpl::handleRecordFound);
+}
+
+QNearFieldTargetPrivateImpl::~QNearFieldTargetPrivateImpl()
+{
+}
+
+bool QNearFieldTargetPrivateImpl::isValid()
+{
+ return m_dbusProperties->isValid() && NeardHelper::instance()->dbusObjectManager()->isValid();
+}
+
+QByteArray QNearFieldTargetPrivateImpl::uid() const
+{
+ return QByteArray(); // TODO figure out a workaround because neard does not offer
+ // this property
+}
+
+QNearFieldTarget::Type QNearFieldTargetPrivateImpl::type() const
+{
+ return m_type;
+}
+
+QNearFieldTarget::AccessMethods QNearFieldTargetPrivateImpl::accessMethods() const
+{
+ return QNearFieldTarget::NdefAccess;
+}
+
+bool QNearFieldTargetPrivateImpl::hasNdefMessage()
+{
+ return !m_recordPaths.isEmpty();
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::readNdefMessages()
+{
+ if (isValid()) {
+ // if the user calls readNdefMessages before the previous request has been completed
+ // return the current request id.
+ if (m_currentReadRequestId.isValid())
+ return m_currentReadRequestId;
+
+ QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
+ // save the id so it can be passed along with requestCompleted
+ m_currentReadRequestId = requestId;
+ // since the triggering of interfaceAdded will ultimately lead to createNdefMessage being called
+ // we need to make sure that ndefMessagesRead will only be triggered when readNdefMessages has
+ // been called before. In case readNdefMessages is called again after that we can directly call
+ // call createNdefMessage.
+ m_readRequested = true;
+ if (hasNdefMessage())
+ createNdefMessage();
+ else
+ m_readErrorTimer.start(1000);
+
+ return requestId;
+ } else {
+ return QNearFieldTarget::RequestId();
+ }
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::sendCommand(const QByteArray &command)
+{
+ Q_UNUSED(command);
+ return QNearFieldTarget::RequestId();
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::writeNdefMessages(const QList<QNdefMessage> &messages)
+{
+ // disabling write due to neard crash (see QTBUG-43802)
+ qWarning("QNearFieldTarget::WriteNdefMessages() disabled. See QTBUG-43802\n");
+ return QNearFieldTarget::RequestId();
+
+
+ // return old request id when previous write request hasn't completed
+ if (m_currentWriteRequestId.isValid())
+ return m_currentWriteRequestId;
+
+ qCDebug(QT_NFC_NEARD) << "writing messages";
+ if (messages.isEmpty() || messages.first().isEmpty()) {
+ qCWarning(QT_NFC_NEARD) << "No record specified";
+ return QNearFieldTarget::RequestId();
+ }
+ if (messages.count() > 1 || messages.first().count() > 1) {
+ // neard only supports one ndef record per tag
+ qCWarning(QT_NFC_NEARD) << "Writing of only one NDEF record and message is supported";
+ return QNearFieldTarget::RequestId();
+ }
+ QNdefRecord record = messages.first().first();
+
+ if (record.typeNameFormat() == QNdefRecord::NfcRtd) {
+ m_currentWriteRequestData.clear();
+ if (record.isRecordType<QNdefNfcUriRecord>()) {
+ m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("URI"));
+ QNdefNfcUriRecord uriRecord = static_cast<QNdefNfcUriRecord>(record);
+ m_currentWriteRequestData.insert(QStringLiteral("URI"), uriRecord.uri().toString());
+ } else if (record.isRecordType<QNdefNfcSmartPosterRecord>()) {
+ m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("SmartPoster"));
+ QNdefNfcSmartPosterRecord spRecord = static_cast<QNdefNfcSmartPosterRecord>(record);
+ m_currentWriteRequestData.insert(QStringLiteral("URI"), spRecord.uri().toString());
+ // Currently neard only supports the uri property for writing
+ } else if (record.isRecordType<QNdefNfcTextRecord>()) {
+ m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("Text"));
+ QNdefNfcTextRecord textRecord = static_cast<QNdefNfcTextRecord>(record);
+ m_currentWriteRequestData.insert(QStringLiteral("Representation"), textRecord.text());
+ m_currentWriteRequestData.insert(QStringLiteral("Encoding"),
+ textRecord.encoding() == QNdefNfcTextRecord::Utf8 ?
+ QStringLiteral("UTF-8") : QStringLiteral("UTF-16") );
+ m_currentWriteRequestData.insert(QStringLiteral("Language"), textRecord.locale());
+ } else {
+ qCWarning(QT_NFC_NEARD) << "Record type not supported for writing";
+ return QNearFieldTarget::RequestId();
+ }
+
+ m_currentWriteRequestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
+ // trigger delayed write
+ m_delayedWriteTimer.start(100);
+
+ return m_currentWriteRequestId;
+ }
+
+ return QNearFieldTarget::RequestId();
+}
+
+QNdefRecord QNearFieldTargetPrivateImpl::readRecord(const QDBusObjectPath &path)
+{
+ qCDebug(QT_NFC_NEARD) << "reading record for path" << path.path();
+ OrgFreedesktopDBusPropertiesInterface recordInterface(QStringLiteral("org.neard"), path.path(),
+ QDBusConnection::systemBus());
+ if (!recordInterface.isValid())
+ return QNdefRecord();
+
+ QDBusPendingReply<QVariantMap> reply = recordInterface.GetAll(QStringLiteral("org.neard.Record"));
+ reply.waitForFinished();
+ if (reply.isError())
+ return QNdefRecord();
+
+ const QString &value = reply.value().value(QStringLiteral("Representation")).toString();
+ const QString &locale = reply.value().value(QStringLiteral("Language")).toString();
+ const QString &encoding = reply.value().value(QStringLiteral("Encoding")).toString();
+ const QString &uri = reply.value().value(QStringLiteral("URI")).toString();
+
+ //const QString &mime = reply.value().value(QStringLiteral("MIME")).toString();
+ //const QString &arr = reply.value().value(QStringLiteral("ARR")).toString();
+
+ const QString type = reply.value().value(QStringLiteral("Type")).toString();
+ if (type == QStringLiteral("Text")) {
+ QNdefNfcTextRecord textRecord;
+ textRecord.setText(value);
+ textRecord.setLocale(locale);
+ textRecord.setEncoding((encoding == QStringLiteral("UTF-8")) ? QNdefNfcTextRecord::Utf8
+ : QNdefNfcTextRecord::Utf16);
+ return textRecord;
+ } else if (type == QStringLiteral("SmartPoster")) {
+ QNdefNfcSmartPosterRecord spRecord;
+ if (!value.isEmpty()) {
+ spRecord.addTitle(value, locale, (encoding == QStringLiteral("UTF-8"))
+ ? QNdefNfcTextRecord::Utf8
+ : QNdefNfcTextRecord::Utf16);
+ }
+
+ if (!uri.isEmpty())
+ spRecord.setUri(QUrl(uri));
+
+ const QString &action = reply.value().value(QStringLiteral("Action")).toString();
+ if (!action.isEmpty()) {
+ if (action == QStringLiteral("Do"))
+ spRecord.setAction(QNdefNfcSmartPosterRecord::DoAction);
+ else if (action == QStringLiteral("Save"))
+ spRecord.setAction(QNdefNfcSmartPosterRecord::SaveAction);
+ else if (action == QStringLiteral("Edit"))
+ spRecord.setAction(QNdefNfcSmartPosterRecord::EditAction);
+ }
+
+ if (reply.value().contains(QStringLiteral("Size"))) {
+ uint size = reply.value().value(QStringLiteral("Size")).toUInt();
+ spRecord.setSize(size);
+ }
+
+ const QString &mimeType = reply.value().value(QStringLiteral("MIMEType")).toString();
+ if (!mimeType.isEmpty()) {
+ spRecord.setTypeInfo(mimeType);
+ }
+
+
+ return spRecord;
+ } else if (type == QStringLiteral("URI")) {
+ QNdefNfcUriRecord uriRecord;
+ uriRecord.setUri(QUrl(uri));
+ return uriRecord;
+ } else if (type == QStringLiteral("MIME")) {
+
+ } else if (type == QStringLiteral("AAR")) {
+
+ }
+
+ return QNdefRecord();
+}
+
+void QNearFieldTargetPrivateImpl::handleRecordFound(const QDBusObjectPath &path)
{
- return false;
+ m_recordPaths.append(path);
+ // FIXME: this timer only exists because neard doesn't currently supply enough
+ // information to let us know when all record interfaces have been added or
+ // how many records are actually contained on a tag. We assume that when no
+ // signal has been received for 100ms all record interfaces have been added.
+ m_recordPathsCollectedTimer.start(100);
+ // as soon as record paths have been added we can handle errors without the timer.
+ m_readErrorTimer.stop();
}
-bool QNearFieldTargetPrivate::setKeepConnection(bool isPersistent)
+void QNearFieldTargetPrivateImpl::createNdefMessage()
{
- Q_UNUSED(isPersistent);
- return false;
+ if (m_readRequested) {
+ qCDebug(QT_NFC_NEARD) << "creating Ndef message, reading" << m_recordPaths.length() << "record paths";
+ QNdefMessage newNdefMessage;
+ for (const QDBusObjectPath &recordPath : std::as_const(m_recordPaths))
+ newNdefMessage.append(readRecord(recordPath));
+
+ if (!newNdefMessage.isEmpty()) {
+ QMetaObject::invokeMethod(this, "ndefMessageRead", Qt::QueuedConnection,
+ Q_ARG(QNdefMessage, newNdefMessage));
+ // the request id in requestCompleted has to match the one created in readNdefMessages
+ QMetaObject::invokeMethod(this, [this]() {
+ Q_EMIT requestCompleted(m_currentReadRequestId);
+ }, Qt::QueuedConnection);
+ } else {
+ reportError(QNearFieldTarget::UnknownError, m_currentReadRequestId);
+ }
+
+ m_readRequested = false;
+ // invalidate the current request id
+ m_currentReadRequestId = QNearFieldTarget::RequestId(0);
+ }
}
-bool QNearFieldTargetPrivate::disconnect()
+void QNearFieldTargetPrivateImpl::handleReadError()
{
- return false;
+ reportError(QNearFieldTarget::UnknownError, m_currentReadRequestId);
+ m_currentReadRequestId = QNearFieldTarget::RequestId(0);
}
-int QNearFieldTargetPrivate::maxCommandLength() const
+void QNearFieldTargetPrivateImpl::handleWriteRequest()
{
- return 0;
+ OrgNeardTagInterface tagInterface(QStringLiteral("org.neard"), m_tagPath.path(),
+ QDBusConnection::systemBus());
+ if (!tagInterface.isValid()) {
+ qCWarning(QT_NFC_NEARD) << "tag interface invalid";
+ } else {
+ QDBusPendingReply<> reply;
+ reply = tagInterface.Write(m_currentWriteRequestData);
+ reply.waitForFinished();
+ if (reply.isError()) {
+ qCWarning(QT_NFC_NEARD) << "Error writing to NFC tag" << reply.error();
+ reportError(QNearFieldTarget::UnknownError, m_currentWriteRequestId);
+ }
+
+ QMetaObject::invokeMethod(this, [this]() {
+ Q_EMIT requestCompleted(m_currentWriteRequestId);
+ }, Qt::QueuedConnection);
+ }
+
+ // invalidate current write request
+ m_currentWriteRequestId = QNearFieldTarget::RequestId(0);
}
QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtarget_neard_p.h b/src/nfc/qnearfieldtarget_neard_p.h
index 9844d99e..8e403e86 100644
--- a/src/nfc/qnearfieldtarget_neard_p.h
+++ b/src/nfc/qnearfieldtarget_neard_p.h
@@ -1,42 +1,5 @@
-/***************************************************************************
-**
-** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
-** Copyright (C) 2016 BasysKom GmbH.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 BlackBerry Limited, Copyright (C) 2016 BasysKom GmbH
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNEARFIELDTARGET_NEARD_P_H
#define QNEARFIELDTARGET_NEARD_P_H
@@ -61,346 +24,39 @@
#include <qndefmessage.h>
#include "neard/neard_helper_p.h"
-#include "neard/dbusproperties_p.h"
-#include "neard/dbusobjectmanager_p.h"
-#include "neard/tag_p.h"
-
-#include <qndefnfctextrecord.h>
-#include <qndefnfcsmartposterrecord.h>
-#include <qndefnfcurirecord.h>
+#include "properties_interface.h"
+#include "objectmanager_interface.h"
+#include "tag_interface.h"
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_NFC_NEARD)
-template <typename T>
-class NearFieldTarget : public T
+class QNearFieldTargetPrivateImpl : public QNearFieldTargetPrivate
{
public:
+ QNearFieldTargetPrivateImpl(QObject *parent, QDBusObjectPath interfacePath);
- NearFieldTarget(QObject *parent, QDBusObjectPath interfacePath)
- : T(parent),
- m_tagPath(interfacePath),
- m_readRequested(false)
- {
- m_readErrorTimer.setSingleShot(true);
- m_recordPathsCollectedTimer.setSingleShot(true);
- m_delayedWriteTimer.setSingleShot(true);
-
- qCDebug(QT_NFC_NEARD) << "tag found at path" << interfacePath.path();
- m_dbusProperties = new OrgFreedesktopDBusPropertiesInterface(QStringLiteral("org.neard"),
- interfacePath.path(),
- QDBusConnection::systemBus(),
- this);
- if (!m_dbusProperties->isValid()) {
- qCWarning(QT_NFC_NEARD) << "Could not connect to dbus property interface at path" << interfacePath.path();
- return;
- }
-
- QDBusPendingReply<QVariantMap> reply = m_dbusProperties->GetAll(QStringLiteral("org.neard.Tag"));
- reply.waitForFinished();
- if (reply.isError()) {
- qCWarning(QT_NFC_NEARD) << "Could not get properties of org.neard.Tag dbus interface";
- return;
- }
-
- const QString &type = reply.value().value(QStringLiteral("Type")).toString();
- m_type = QNearFieldTarget::ProprietaryTag;
-
- if (type == QStringLiteral("Type 1"))
- m_type = QNearFieldTarget::NfcTagType1;
- else if (type == QStringLiteral("Type 2"))
- m_type = QNearFieldTarget::NfcTagType2;
- else if (type == QStringLiteral("Type 3"))
- m_type = QNearFieldTarget::NfcTagType3;
- else if (type == QStringLiteral("Type 4"))
- m_type = QNearFieldTarget::NfcTagType4;
-
- qCDebug(QT_NFC_NEARD) << "tag type" << type;
-
- QObject::connect(&m_recordPathsCollectedTimer, &QTimer::timeout,
- this, &NearFieldTarget::createNdefMessage);
- QObject::connect(&m_readErrorTimer, &QTimer::timeout,
- this, &NearFieldTarget::handleReadError);
- QObject::connect(&m_delayedWriteTimer, &QTimer::timeout,
- this, &NearFieldTarget::handleWriteRequest);
- QObject::connect(NeardHelper::instance(), &NeardHelper::recordFound,
- this, &NearFieldTarget::handleRecordFound);
- }
-
- ~NearFieldTarget()
- {
- }
-
- bool isValid()
- {
- return m_dbusProperties->isValid() && NeardHelper::instance()->dbusObjectManager()->isValid();
- }
-
- QByteArray uid() const
- {
- return QByteArray(); // TODO figure out a workaround because neard does not offer
- // this property
- }
-
- QNearFieldTarget::Type type() const
- {
- return m_type;
- }
-
- QNearFieldTarget::AccessMethods accessMethods() const
- {
- return QNearFieldTarget::NdefAccess;
- }
-
- bool hasNdefMessage()
- {
- return !m_recordPaths.isEmpty();
- }
-
- QNearFieldTarget::RequestId readNdefMessages()
- {
- if (isValid()) {
- // if the user calls readNdefMessages before the previous request has been completed
- // return the current request id.
- if (m_currentReadRequestId.isValid())
- return m_currentReadRequestId;
-
- QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
- // save the id so it can be passed along with requestCompleted
- m_currentReadRequestId = requestId;
- // since the triggering of interfaceAdded will ultimately lead to createNdefMessage being called
- // we need to make sure that ndefMessagesRead will only be triggered when readNdefMessages has
- // been called before. In case readNdefMessages is called again after that we can directly call
- // call createNdefMessage.
- m_readRequested = true;
- if (hasNdefMessage())
- createNdefMessage();
- else
- m_readErrorTimer.start(1000);
-
- return requestId;
- } else {
- return QNearFieldTarget::RequestId();
- }
- }
-
- QNearFieldTarget::RequestId sendCommand(const QByteArray &command)
- {
- Q_UNUSED(command);
- return QNearFieldTarget::RequestId();
- }
-
- QNearFieldTarget::RequestId sendCommands(const QList<QByteArray> &commands)
- {
- Q_UNUSED(commands);
- return QNearFieldTarget::RequestId();
- }
-
- QNearFieldTarget::RequestId writeNdefMessages(const QList<QNdefMessage> &messages)
- {
- // disabling write due to neard crash (see QTBUG-43802)
- qWarning("QNearFieldTarget::WriteNdefMessages() disabled. See QTBUG-43802\n");
- return QNearFieldTarget::RequestId();
-
-
- // return old request id when previous write request hasn't completed
- if (m_currentWriteRequestId.isValid())
- return m_currentReadRequestId;
-
- qCDebug(QT_NFC_NEARD) << "writing messages";
- if (messages.isEmpty() || messages.first().isEmpty()) {
- qCWarning(QT_NFC_NEARD) << "No record specified";
- return QNearFieldTarget::RequestId();
- }
- if (messages.count() > 1 || messages.first().count() > 1) {
- // neard only supports one ndef record per tag
- qCWarning(QT_NFC_NEARD) << "Writing of only one NDEF record and message is supported";
- return QNearFieldTarget::RequestId();
- }
- QNdefRecord record = messages.first().first();
+ ~QNearFieldTargetPrivateImpl();
- if (record.typeNameFormat() == QNdefRecord::NfcRtd) {
- m_currentWriteRequestData.clear();
- if (record.isRecordType<QNdefNfcUriRecord>()) {
- m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("URI"));
- QNdefNfcUriRecord uriRecord = static_cast<QNdefNfcUriRecord>(record);
- m_currentWriteRequestData.insert(QStringLiteral("URI"), uriRecord.uri().toString());
- } else if (record.isRecordType<QNdefNfcSmartPosterRecord>()) {
- m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("SmartPoster"));
- QNdefNfcSmartPosterRecord spRecord = static_cast<QNdefNfcSmartPosterRecord>(record);
- m_currentWriteRequestData.insert(QStringLiteral("URI"), spRecord.uri().toString());
- // Currently neard only supports the uri property for writing
- } else if (record.isRecordType<QNdefNfcTextRecord>()) {
- m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("Text"));
- QNdefNfcTextRecord textRecord = static_cast<QNdefNfcTextRecord>(record);
- m_currentWriteRequestData.insert(QStringLiteral("Representation"), textRecord.text());
- m_currentWriteRequestData.insert(QStringLiteral("Encoding"),
- textRecord.encoding() == QNdefNfcTextRecord::Utf8 ?
- QStringLiteral("UTF-8") : QStringLiteral("UTF-16") );
- m_currentWriteRequestData.insert(QStringLiteral("Language"), textRecord.locale());
- } else {
- qCWarning(QT_NFC_NEARD) << "Record type not supported for writing";
- return QNearFieldTarget::RequestId();
- }
+ bool isValid();
+ QByteArray uid() const override;
- m_currentWriteRequestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
- // trigger delayed write
- m_delayedWriteTimer.start(100);
+ QNearFieldTarget::Type type() const override;
+ QNearFieldTarget::AccessMethods accessMethods() const override;
- return m_currentWriteRequestId;
- }
-
- return QNearFieldTarget::RequestId();
- }
+ bool hasNdefMessage() override;
+ QNearFieldTarget::RequestId readNdefMessages() override;
+ QNearFieldTarget::RequestId sendCommand(const QByteArray &command) override;
+ QNearFieldTarget::RequestId writeNdefMessages(const QList<QNdefMessage> &messages) override;
private:
- QNdefRecord readRecord(const QDBusObjectPath &path)
- {
- qCDebug(QT_NFC_NEARD) << "reading record for path" << path.path();
- OrgFreedesktopDBusPropertiesInterface recordInterface(QStringLiteral("org.neard"),
- path.path(),
- QDBusConnection::systemBus());
- if (!recordInterface.isValid())
- return QNdefRecord();
-
- QDBusPendingReply<QVariantMap> reply = recordInterface.GetAll(QStringLiteral("org.neard.Record"));
- reply.waitForFinished();
- if (reply.isError())
- return QNdefRecord();
-
- const QString &value = reply.value().value(QStringLiteral("Representation")).toString();
- const QString &locale = reply.value().value(QStringLiteral("Language")).toString();
- const QString &encoding = reply.value().value(QStringLiteral("Encoding")).toString();
- const QString &uri = reply.value().value(QStringLiteral("URI")).toString();
-
-// const QString &mime = reply.value().value(QStringLiteral("MIME")).toString();
-// const QString &arr = reply.value().value(QStringLiteral("ARR")).toString();
-
- const QString type = reply.value().value(QStringLiteral("Type")).toString();
- if (type == QStringLiteral("Text")) {
- QNdefNfcTextRecord textRecord;
- textRecord.setText(value);
- textRecord.setLocale(locale);
- textRecord.setEncoding((encoding == QStringLiteral("UTF-8")) ? QNdefNfcTextRecord::Utf8
- : QNdefNfcTextRecord::Utf16);
- return textRecord;
- } else if (type == QStringLiteral("SmartPoster")) {
- QNdefNfcSmartPosterRecord spRecord;
- if (!value.isEmpty()) {
- spRecord.addTitle(value, locale, (encoding == QStringLiteral("UTF-8"))
- ? QNdefNfcTextRecord::Utf8
- : QNdefNfcTextRecord::Utf16);
- }
-
- if (!uri.isEmpty())
- spRecord.setUri(QUrl(uri));
-
- const QString &action = reply.value().value(QStringLiteral("Action")).toString();
- if (!action.isEmpty()) {
- if (action == QStringLiteral("Do"))
- spRecord.setAction(QNdefNfcSmartPosterRecord::DoAction);
- else if (action == QStringLiteral("Save"))
- spRecord.setAction(QNdefNfcSmartPosterRecord::SaveAction);
- else if (action == QStringLiteral("Edit"))
- spRecord.setAction(QNdefNfcSmartPosterRecord::EditAction);
- }
-
- if (reply.value().contains(QStringLiteral("Size"))) {
- uint size = reply.value().value(QStringLiteral("Size")).toUInt();
- spRecord.setSize(size);
- }
-
- const QString &mimeType = reply.value().value(QStringLiteral("MIMEType")).toString();
- if (!mimeType.isEmpty()) {
- spRecord.setTypeInfo(mimeType.toUtf8());
- }
-
-
- return spRecord;
- } else if (type == QStringLiteral("URI")) {
- QNdefNfcUriRecord uriRecord;
- uriRecord.setUri(QUrl(uri));
- return uriRecord;
- } else if (type == QStringLiteral("MIME")) {
-
- } else if (type == QStringLiteral("AAR")) {
-
- }
-
- return QNdefRecord();
- }
-
- void handleRecordFound(const QDBusObjectPath &path)
- {
- m_recordPaths.append(path);
- // FIXME: this timer only exists because neard doesn't currently supply enough
- // information to let us know when all record interfaces have been added or
- // how many records are actually contained on a tag. We assume that when no
- // signal has been received for 100ms all record interfaces have been added.
- m_recordPathsCollectedTimer.start(100);
- // as soon as record paths have been added we can handle errors without the timer.
- m_readErrorTimer.stop();
- }
-
- void createNdefMessage()
- {
- if (m_readRequested) {
- qCDebug(QT_NFC_NEARD) << "creating Ndef message, reading" << m_recordPaths.length() << "record paths";
- QNdefMessage newNdefMessage;
- for (const QDBusObjectPath &recordPath : qAsConst(m_recordPaths))
- newNdefMessage.append(readRecord(recordPath));
-
- if (!newNdefMessage.isEmpty()) {
- QMetaObject::invokeMethod(this, "ndefMessageRead", Qt::QueuedConnection,
- Q_ARG(QNdefMessage, newNdefMessage));
- // the request id in requestCompleted has to match the one created in readNdefMessages
- QMetaObject::invokeMethod(this, [this]() {
- Q_EMIT this->requestCompleted(this->m_currentReadRequestId);
- }, Qt::QueuedConnection);
- } else {
- this->reportError(QNearFieldTarget::UnknownError, m_currentReadRequestId);
- }
-
- m_readRequested = false;
- // invalidate the current request id
- m_currentReadRequestId = QNearFieldTarget::RequestId(0);
- }
- }
-
- void handleReadError()
- {
- emit QNearFieldTarget::error(QNearFieldTarget::UnknownError, m_currentReadRequestId);
- m_currentReadRequestId = QNearFieldTarget::RequestId(0);
- }
-
- void handleWriteRequest()
- {
- OrgNeardTagInterface tagInterface(QStringLiteral("org.neard"),
- m_tagPath.path(),
- QDBusConnection::systemBus());
- if (!tagInterface.isValid()) {
- qCWarning(QT_NFC_NEARD) << "tag interface invalid";
- } else {
- QDBusPendingReply<> reply;
- reply = tagInterface.Write(m_currentWriteRequestData);
- reply.waitForFinished();
- if (reply.isError()) {
- qCWarning(QT_NFC_NEARD) << "Error writing to NFC tag" << reply.error();
- this->reportError(QNearFieldTarget::UnknownError, m_currentWriteRequestId);
- }
-
- QMetaObject::invokeMethod(this, "ndefMessagesWritten", Qt::QueuedConnection);
- QMetaObject::invokeMethod(this, [this]() {
- Q_EMIT this->requestCompleted(this->m_currentWriteRequestId);
- }, Qt::QueuedConnection);
- }
-
- // invalidate current write request
- m_currentWriteRequestId = QNearFieldTarget::RequestId(0);
- }
+ QNdefRecord readRecord(const QDBusObjectPath &path);
+ void handleRecordFound(const QDBusObjectPath &path);
+ void createNdefMessage();
+ void handleReadError();
+ void handleWriteRequest();
-protected:
QDBusObjectPath m_tagPath;
OrgFreedesktopDBusPropertiesInterface *m_dbusProperties;
QList<QDBusObjectPath> m_recordPaths;
diff --git a/src/nfc/qnearfieldtarget_p.cpp b/src/nfc/qnearfieldtarget_p.cpp
index 4ed17a15..ff69eecd 100644
--- a/src/nfc/qnearfieldtarget_p.cpp
+++ b/src/nfc/qnearfieldtarget_p.cpp
@@ -1,58 +1,34 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Governikus GmbH & Co. K
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QCoreApplication>
-
-#include "qnearfieldtarget.h"
+// Copyright (C) 2017 Governikus GmbH & Co. K
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
#include "qnearfieldtarget_p.h"
+#include <QtCore/QCoreApplication>
+#include <QtCore/QElapsedTimer>
+#include <QtCore/QPointer>
+
QT_BEGIN_NAMESPACE
-bool QNearFieldTargetPrivate::keepConnection() const
+
+QNearFieldTargetPrivate::QNearFieldTargetPrivate(QObject *parent)
+: QObject(parent)
+, q_ptr(nullptr)
{
- return false;
}
-bool QNearFieldTargetPrivate::setKeepConnection(bool isPersistent)
+QByteArray QNearFieldTargetPrivate::uid() const
{
- Q_UNUSED(isPersistent);
- return false;
+ return QByteArray();
+}
+
+QNearFieldTarget::Type QNearFieldTargetPrivate::type() const
+{
+ return QNearFieldTarget::Type::ProprietaryTag;
+}
+
+QNearFieldTarget::AccessMethods QNearFieldTargetPrivate::accessMethods() const
+{
+ return QNearFieldTarget::AccessMethod::UnknownAccess;
}
bool QNearFieldTargetPrivate::disconnect()
@@ -60,9 +36,99 @@ bool QNearFieldTargetPrivate::disconnect()
return false;
}
+// NdefAccess
+bool QNearFieldTargetPrivate::hasNdefMessage()
+{
+ return false;
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivate::readNdefMessages()
+{
+ const QNearFieldTarget::RequestId id;
+ Q_EMIT error(QNearFieldTarget::UnsupportedError, id);
+ return id;
+}
+
+QNearFieldTarget::RequestId
+QNearFieldTargetPrivate::writeNdefMessages(const QList<QNdefMessage> &messages)
+{
+ Q_UNUSED(messages);
+
+ const QNearFieldTarget::RequestId id;
+ Q_EMIT error(QNearFieldTarget::UnsupportedError, id);
+ return id;
+}
+
+// TagTypeSpecificAccess
int QNearFieldTargetPrivate::maxCommandLength() const
{
return 0;
}
+QNearFieldTarget::RequestId QNearFieldTargetPrivate::sendCommand(const QByteArray &command)
+{
+ Q_UNUSED(command);
+
+ const QNearFieldTarget::RequestId id;
+ Q_EMIT error(QNearFieldTarget::UnsupportedError, id);
+ return id;
+}
+
+bool QNearFieldTargetPrivate::waitForRequestCompleted(const QNearFieldTarget::RequestId &id,
+ int msecs)
+{
+ QElapsedTimer timer;
+ timer.start();
+
+ const QPointer<QNearFieldTargetPrivate> weakThis = this;
+
+ do {
+ if (!weakThis)
+ return false;
+
+ if (m_decodedResponses.contains(id))
+ return true;
+ else
+ QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents, 1);
+ } while (timer.elapsed() <= msecs);
+
+ reportError(QNearFieldTarget::TimeoutError, id);
+
+ return false;
+}
+
+QVariant QNearFieldTargetPrivate::requestResponse(const QNearFieldTarget::RequestId &id) const
+{
+ return m_decodedResponses.value(id);
+}
+
+void QNearFieldTargetPrivate::setResponseForRequest(const QNearFieldTarget::RequestId &id,
+ const QVariant &response,
+ bool emitRequestCompleted)
+{
+ for (auto i = m_decodedResponses.begin(), end = m_decodedResponses.end(); i != end; /* erasing */) {
+ // no more external references
+ if (i.key().refCount() == 1)
+ i = m_decodedResponses.erase(i);
+ else
+ ++i;
+ }
+
+ m_decodedResponses.insert(id, response);
+
+ if (emitRequestCompleted)
+ Q_EMIT requestCompleted(id);
+}
+
+void QNearFieldTargetPrivate::reportError(QNearFieldTarget::Error error,
+ const QNearFieldTarget::RequestId &id)
+{
+ setResponseForRequest(id, QVariant(), false);
+ QMetaObject::invokeMethod(this, [this, error, id]() {
+ Q_EMIT this->error(error, id);
+ }, Qt::QueuedConnection);
+}
+
QT_END_NAMESPACE
+
+#include "moc_qnearfieldtarget_p.cpp"
diff --git a/src/nfc/qnearfieldtarget_p.h b/src/nfc/qnearfieldtarget_p.h
index 9c1a2954..dd7550ad 100644
--- a/src/nfc/qnearfieldtarget_p.h
+++ b/src/nfc/qnearfieldtarget_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QNEARFIELDTARGET_P_H
#define QNEARFIELDTARGET_P_H
@@ -51,15 +15,14 @@
// We mean it.
//
-#include "qtnfcglobal.h"
-
#include "qnearfieldtarget.h"
-#include <QtCore/QMap>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QObject>
#include <QtCore/QSharedData>
#include <QtCore/QVariant>
-
-#define NEARFIELDTARGET_Q() NearFieldTarget * const q = reinterpret_cast<NearFieldTarget *>(q_ptr)
+#include <QtCore/QMap>
QT_BEGIN_NAMESPACE
@@ -67,20 +30,51 @@ class QNearFieldTarget::RequestIdPrivate : public QSharedData
{
};
-class QNearFieldTargetPrivate
+class Q_AUTOTEST_EXPORT QNearFieldTargetPrivate : public QObject
{
- QNearFieldTarget *q_ptr;
- Q_DECLARE_PUBLIC(QNearFieldTarget)
+ Q_OBJECT
public:
- QNearFieldTargetPrivate(QNearFieldTarget *q) : q_ptr(q) {}
+ QNearFieldTarget *q_ptr;
+
+ explicit QNearFieldTargetPrivate(QObject *parent = nullptr);
+ virtual ~QNearFieldTargetPrivate() = default;
+
+ virtual QByteArray uid() const;
+ virtual QNearFieldTarget::Type type() const;
+ virtual QNearFieldTarget::AccessMethods accessMethods() const;
+
+ virtual bool disconnect();
+ // NdefAccess
+ virtual bool hasNdefMessage();
+ virtual QNearFieldTarget::RequestId readNdefMessages();
+ virtual QNearFieldTarget::RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
+
+ // TagTypeSpecificAccess
+ virtual int maxCommandLength() const;
+ virtual QNearFieldTarget::RequestId sendCommand(const QByteArray &command);
+
+ bool waitForRequestCompleted(const QNearFieldTarget::RequestId &id, int msecs = 5000);
+ QVariant requestResponse(const QNearFieldTarget::RequestId &id) const;
+
+Q_SIGNALS:
+ void disconnected();
+
+ void ndefMessageRead(const QNdefMessage &message);
+
+ void requestCompleted(const QNearFieldTarget::RequestId &id);
+
+ void error(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id);
+
+protected:
QMap<QNearFieldTarget::RequestId, QVariant> m_decodedResponses;
- bool keepConnection() const;
- bool setKeepConnection(bool isPersistent);
- bool disconnect();
- int maxCommandLength() const;
+ virtual void setResponseForRequest(const QNearFieldTarget::RequestId &id,
+ const QVariant &response,
+ bool emitRequestCompleted = true);
+
+ void reportError(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id);
};
QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtarget_pcsc.cpp b/src/nfc/qnearfieldtarget_pcsc.cpp
new file mode 100644
index 00000000..76bc685f
--- /dev/null
+++ b/src/nfc/qnearfieldtarget_pcsc.cpp
@@ -0,0 +1,161 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qnearfieldtarget_pcsc_p.h"
+#include "qndefmessage.h"
+#include <QtCore/QLoggingCategory>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_NFC_PCSC)
+
+/*
+ Construct QNearFieldTargetPrivateImpl instance.
+
+ This object communicates with a QPcscCard object that lives inside the
+ worker thread via signal-slot mechanism.
+*/
+QNearFieldTargetPrivateImpl::QNearFieldTargetPrivateImpl(
+ const QByteArray &uid, QNearFieldTarget::AccessMethods accessMethods, int maxInputLength,
+ QObject *parent)
+ : QNearFieldTargetPrivate(parent),
+ m_uid(uid),
+ m_accessMethods(accessMethods),
+ m_maxInputLength(maxInputLength)
+{
+ qCDebug(QT_NFC_PCSC) << "New card with UID" << m_uid.toHex(':');
+}
+
+QNearFieldTargetPrivateImpl::~QNearFieldTargetPrivateImpl()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+}
+
+QByteArray QNearFieldTargetPrivateImpl::uid() const
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ return m_uid;
+}
+
+QNearFieldTarget::Type QNearFieldTargetPrivateImpl::type() const
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ // Currently NDEF access is only supported for Type 4 tags
+ if (m_accessMethods & QNearFieldTarget::NdefAccess)
+ return QNearFieldTarget::NfcTagType4;
+
+ return QNearFieldTarget::ProprietaryTag;
+}
+
+QNearFieldTarget::AccessMethods QNearFieldTargetPrivateImpl::accessMethods() const
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ return m_accessMethods;
+}
+
+bool QNearFieldTargetPrivateImpl::disconnect()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_connected || !m_isValid)
+ return false;
+
+ Q_EMIT disconnectRequest();
+ return true;
+}
+
+int QNearFieldTargetPrivateImpl::maxCommandLength() const
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+ return m_maxInputLength;
+}
+
+void QNearFieldTargetPrivateImpl::onRequestCompleted(const QNearFieldTarget::RequestId &request,
+ QNearFieldTarget::Error reason,
+ const QVariant &result)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (reason == QNearFieldTarget::NoError)
+ setResponseForRequest(request, result);
+ else
+ reportError(reason, request);
+}
+
+void QNearFieldTargetPrivateImpl::onNdefMessageRead(const QNdefMessage &message)
+{
+ Q_EMIT ndefMessageRead(message);
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::sendCommand(const QByteArray &command)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid)
+ return QNearFieldTarget::RequestId(nullptr);
+
+ m_connected = true;
+
+ QNearFieldTarget::RequestId reqId(new QNearFieldTarget::RequestIdPrivate);
+ Q_EMIT sendCommandRequest(reqId, command);
+
+ return reqId;
+}
+
+QNearFieldTarget::RequestId QNearFieldTargetPrivateImpl::readNdefMessages()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid)
+ return QNearFieldTarget::RequestId(nullptr);
+
+ m_connected = true;
+
+ QNearFieldTarget::RequestId reqId(new QNearFieldTarget::RequestIdPrivate);
+ Q_EMIT readNdefMessagesRequest(reqId);
+
+ return reqId;
+}
+
+QNearFieldTarget::RequestId
+QNearFieldTargetPrivateImpl::writeNdefMessages(const QList<QNdefMessage> &messages)
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid)
+ return QNearFieldTarget::RequestId(nullptr);
+
+ m_connected = true;
+
+ QNearFieldTarget::RequestId reqId(new QNearFieldTarget::RequestIdPrivate);
+ Q_EMIT writeNdefMessagesRequest(reqId, messages);
+
+ return reqId;
+}
+
+void QNearFieldTargetPrivateImpl::onDisconnected()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_connected)
+ return;
+
+ m_connected = false;
+
+ Q_EMIT disconnected();
+}
+
+void QNearFieldTargetPrivateImpl::onInvalidated()
+{
+ qCDebug(QT_NFC_PCSC) << Q_FUNC_INFO;
+
+ if (!m_isValid)
+ return;
+
+ m_isValid = false;
+
+ Q_EMIT targetLost(this);
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldtarget_pcsc_p.h b/src/nfc/qnearfieldtarget_pcsc_p.h
new file mode 100644
index 00000000..c5631af1
--- /dev/null
+++ b/src/nfc/qnearfieldtarget_pcsc_p.h
@@ -0,0 +1,67 @@
+// Copyright (C) 2022q The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNEARFIELDTARGET_PCSC_P_H
+#define QNEARFIELDTARGET_PCSC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qnearfieldtarget_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QNearFieldTargetPrivateImpl : public QNearFieldTargetPrivate
+{
+ Q_OBJECT
+public:
+ QNearFieldTargetPrivateImpl(const QByteArray &uid,
+ QNearFieldTarget::AccessMethods accessMethods, int maxInputLength,
+ QObject *parent);
+ ~QNearFieldTargetPrivateImpl() override;
+
+ QByteArray uid() const override;
+ QNearFieldTarget::Type type() const override;
+ QNearFieldTarget::AccessMethods accessMethods() const override;
+
+ bool disconnect() override;
+
+ int maxCommandLength() const override;
+ QNearFieldTarget::RequestId sendCommand(const QByteArray &command) override;
+ QNearFieldTarget::RequestId readNdefMessages() override;
+ QNearFieldTarget::RequestId writeNdefMessages(const QList<QNdefMessage> &messages) override;
+
+private:
+ const QByteArray m_uid;
+ QNearFieldTarget::AccessMethods m_accessMethods;
+ int m_maxInputLength;
+ bool m_connected = false;
+ bool m_isValid = true;
+
+public Q_SLOTS:
+ void onDisconnected();
+ void onInvalidated();
+ void onRequestCompleted(const QNearFieldTarget::RequestId &request,
+ QNearFieldTarget::Error reason, const QVariant &result);
+ void onNdefMessageRead(const QNdefMessage &message);
+
+Q_SIGNALS:
+ void disconnectRequest();
+ void sendCommandRequest(const QNearFieldTarget::RequestId &request, const QByteArray &command);
+ void readNdefMessagesRequest(const QNearFieldTarget::RequestId &request);
+ void writeNdefMessagesRequest(const QNearFieldTarget::RequestId &request,
+ const QList<QNdefMessage> &messages);
+ void targetLost(QNearFieldTargetPrivate *target);
+};
+
+QT_END_NAMESPACE
+
+#endif // QNEARFIELDTARGET_PCSC_P_H
diff --git a/src/nfc/qnfc.cpp b/src/nfc/qnfc.cpp
deleted file mode 100644
index 56a4f4f3..00000000
--- a/src/nfc/qnfc.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/QLoggingCategory>
-#include <QtNfc/qtnfcglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(QT_NFC_NEARD, "qt.nfc.neard")
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qqmlndefrecord.cpp b/src/nfc/qqmlndefrecord.cpp
deleted file mode 100644
index 5a96bec8..00000000
--- a/src/nfc/qqmlndefrecord.cpp
+++ /dev/null
@@ -1,356 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qqmlndefrecord.h"
-
-#include <QtCore/QMap>
-#include <QtCore/QRegularExpression>
-
-#include <QtCore/qglobalstatic.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QQmlNdefRecord
- \brief The QQmlNdefRecord class implements the NdefRecord type in QML.
-
- \ingroup connectivity-nfc
- \inmodule QtNfc
- \since 5.2
-
- \sa NdefRecord
-
- The QQmlNdefRecord class is the base class for all NdefRecord types in QML. To
- support a new NDEF record type in QML subclass this class and expose new properties, member
- functions and signals appropriate for the new record type. The following must be done to
- create a new NDEF record type in QML:
-
- \list
- \li The subclass must have a Q_OBJECT macro in its declaration.
- \li The subclass must have an \l {Q_INVOKABLE}{invokable} constructor that takes a
- QNdefRecord and a QObject pointer.
- \li The subclass must be declared as an NDEF record by expanding the Q_DECLARE_NDEFRECORD()
- macro in the implementation file of the subclass.
- \li The subclass must be registered with QML.
- \endlist
-
- For example the declaration of such a class may look like the following.
-
- \snippet foorecord.h Foo declaration
-
- Within the implementation file the Q_DECLARE_NDEFRECORD() macro is expanded:
-
- \snippet foorecord.cpp Declare foo record
-
- Finially the application or plugin code calls qmlRegisterType():
-
- \code
- qmlRegisterType<QQmlNdefFooRecord>(uri, 1, 0, "NdefFooRecord");
- \endcode
-*/
-
-/*!
- \qmltype NdefRecord
- \instantiates QQmlNdefRecord
- \brief The NdefRecord type represents a record in an NDEF message.
-
- \ingroup nfc-qml
- \inqmlmodule QtNfc
-
- \sa NdefFilter
- \sa NearField
-
- \sa QNdefRecord
-
- The NdefRecord type is the base type for all NDEF record types in QML. It contains
- a single property holding the type of record.
-
- This class is not intended to be used directly, but extended from C++.
-
- \sa QQmlNdefRecord
-*/
-
-/*!
- \qmlproperty string NdefRecord::type
-
- This property holds the type of the NDEF record.
-*/
-
-/*!
- \qmlproperty enumeration NdefRecord::typeNameFormat
-
- This property holds the TNF of the NDEF record.
-
- \table
- \header \li Property \li Description
- \row \li \c NdefRecord.Empty
- \li An empty NDEF record, the record does not contain a payload.
- \row \li \c NdefRecord.NfcRtd
- \li The NDEF record type is defined by an NFC RTD Specification.
- \row \li \c NdefRecord.Mime
- \li The NDEF record type follows the construct described in RFC 2046.
- \row \li \c NdefRecord.Uri
- \li The NDEF record type follows the construct described in RFC 3986.
- \row \li \c NdefRecord.ExternalRtd
- \li The NDEF record type follows the construct for external type names
- described the NFC RTD Specification.
- \endtable
-
- \sa QNdefRecord::typeNameFormat()
-*/
-
-/*!
- \qmlproperty string NdefRecord::record
-
- This property holds the NDEF record.
-*/
-
-/*!
- \fn void QQmlNdefRecord::typeChanged()
-
- This signal is emitted when the record type changes.
-*/
-
-/*!
- \property QQmlNdefRecord::record
-
- This property hold the NDEF record that this class represents.
-*/
-
-/*!
- \property QQmlNdefRecord::type
-
- This property hold the type of the NDEF record.
-*/
-
-/*!
- \property QQmlNdefRecord::typeNameFormat
-
- This property hold the TNF of the NDEF record.
-*/
-
-/*!
- \macro Q_DECLARE_NDEFRECORD(className, typeNameFormat, type)
- \relates QQmlNdefRecord
-
- This macro ensures that \a className is declared as the class implementing the NDEF record
- identified by \a typeNameFormat and \a type.
-
- This macro should be expanded in the implementation file for \a className.
-*/
-
-typedef QMap<QString, const QMetaObject *> NDefRecordTypesMap;
-Q_GLOBAL_STATIC(NDefRecordTypesMap, registeredNdefRecordTypes)
-
-class QQmlNdefRecordPrivate
-{
-public:
- QNdefRecord record;
-};
-
-static QString urnForRecordType(QNdefRecord::TypeNameFormat typeNameFormat, const QByteArray &type)
-{
- switch (typeNameFormat) {
- case QNdefRecord::NfcRtd:
- return QStringLiteral("urn:nfc:wkt:") + QString::fromLatin1(type);
- case QNdefRecord::ExternalRtd:
- return QStringLiteral("urn:nfc:ext:") + QString::fromLatin1(type);
- case QNdefRecord::Mime:
- return QStringLiteral("urn:nfc:mime:") + QString::fromLatin1(type);
- default:
- return QString();
- }
-}
-
-/*!
- \internal
-*/
-void qRegisterNdefRecordTypeHelper(const QMetaObject *metaObject,
- QNdefRecord::TypeNameFormat typeNameFormat,
- const QByteArray &type)
-{
- registeredNdefRecordTypes()->insert(urnForRecordType(typeNameFormat, type), metaObject);
-}
-
-/*!
- \internal
-*/
-QQmlNdefRecord *qNewDeclarativeNdefRecordForNdefRecord(const QNdefRecord &record)
-{
- const QString urn = urnForRecordType(record.typeNameFormat(), record.type());
-
- const auto *rt = registeredNdefRecordTypes();
-
- for (auto i = rt->cbegin(), end = rt->cend(); i != end; ++i) {
- QRegularExpression rx(QRegularExpression::anchoredPattern(i.key()));
- if (!rx.match(urn).hasMatch())
- continue;
-
- const QMetaObject *metaObject = i.value();
- if (!metaObject)
- continue;
-
- return static_cast<QQmlNdefRecord *>(metaObject->newInstance(
- Q_ARG(QNdefRecord, record), Q_ARG(QObject*, 0)));
- }
-
- return new QQmlNdefRecord(record);
-}
-
-/*!
- Constructs a new empty QQmlNdefRecord with \a parent.
-*/
-QQmlNdefRecord::QQmlNdefRecord(QObject *parent)
-: QObject(parent), d_ptr(new QQmlNdefRecordPrivate)
-{
-}
-
-/*!
- Constructs a new QQmlNdefRecord representing \a record. The parent of the newly
- constructed object will be set to \a parent.
-*/
-QQmlNdefRecord::QQmlNdefRecord(const QNdefRecord &record, QObject *parent)
-: QObject(parent), d_ptr(new QQmlNdefRecordPrivate)
-{
- d_ptr->record = record;
-}
-
-/*!
- Destroys the QQmlNdefRecord instance.
-*/
-QQmlNdefRecord::~QQmlNdefRecord()
-{
- delete d_ptr;
-}
-
-/*!
- \enum QQmlNdefRecord::TypeNameFormat
-
- This enum describes the type name format of an NDEF record. The values of this enum are according to
- \l QNdefRecord::TypeNameFormat
-
- \value Empty An empty NDEF record, the record does not contain a payload.
- \value NfcRtd The NDEF record type is defined by an NFC RTD Specification.
- \value Mime The NDEF record type follows the construct described in RFC 2046.
- \value Uri The NDEF record type follows the construct described in RFC 3986.
- \value ExternalRtd The NDEF record type follows the construct for external type names
- described the NFC RTD Specification.
- \value Unknown The NDEF record type is unknown.
-*/
-
-/*!
- Returns the type of the record.
-
- \sa QNdefRecord::setType(), QNdefRecord::type()
-*/
-QString QQmlNdefRecord::type() const
-{
- Q_D(const QQmlNdefRecord);
-
- return QLatin1String(d->record.type());
-}
-
-/*!
- Sets the record type to \a newtype if it is not currently equal to \l type(); otherwise does
- nothing. If the record type is set the typeChanged() signal will be emitted.
-
- \sa QNdefRecord::setType(), QNdefRecord::type()
-*/
-void QQmlNdefRecord::setType(const QString &newtype)
-{
- if (newtype == type())
- return;
-
- Q_D(QQmlNdefRecord);
- d->record.setType(newtype.toUtf8());
-
- emit typeChanged();
-}
-
-/*!
- Sets the type name format of the NDEF record to \a newTypeNameFormat.
-*/
-void QQmlNdefRecord::setTypeNameFormat(QQmlNdefRecord::TypeNameFormat newTypeNameFormat)
-{
- if (newTypeNameFormat == typeNameFormat())
- return;
-
- Q_D(QQmlNdefRecord);
- d->record.setTypeNameFormat(static_cast<QNdefRecord::TypeNameFormat>(newTypeNameFormat));
-
- emit typeNameFormatChanged();
-}
-
-/*!
- \fn QQmlNdefRecord::TypeNameFormat QQmlNdefRecord::typeNameFormat() const
-
- Returns the type name format of the NDEF record.
-*/
-QQmlNdefRecord::TypeNameFormat QQmlNdefRecord::typeNameFormat() const
-{
- Q_D(const QQmlNdefRecord);
- return static_cast<QQmlNdefRecord::TypeNameFormat>(d->record.typeNameFormat());
-}
-
-/*!
- Returns a copy of the record.
-*/
-QNdefRecord QQmlNdefRecord::record() const
-{
- Q_D(const QQmlNdefRecord);
-
- return d->record;
-}
-
-/*!
- Sets the record to \a record. If the record is set the recordChanged() signal will
- be emitted.
-*/
-void QQmlNdefRecord::setRecord(const QNdefRecord &record)
-{
- Q_D(QQmlNdefRecord);
-
- if (d->record == record)
- return;
-
- d->record = record;
- emit recordChanged();
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qqmlndefrecord.h b/src/nfc/qqmlndefrecord.h
deleted file mode 100644
index 0f624505..00000000
--- a/src/nfc/qqmlndefrecord.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQMLNDEFRECORD_H
-#define QQMLNDEFRECORD_H
-
-#include <QtCore/QObject>
-#include <QtCore/QMetaType>
-#include <QtNfc/QNdefRecord>
-
-QT_BEGIN_NAMESPACE
-
-class QQmlNdefRecordPrivate;
-
-class Q_NFC_EXPORT QQmlNdefRecord : public QObject
-{
- Q_OBJECT
-
- Q_DECLARE_PRIVATE(QQmlNdefRecord)
-
- Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
- Q_PROPERTY(TypeNameFormat typeNameFormat READ typeNameFormat WRITE setTypeNameFormat NOTIFY typeNameFormatChanged)
- Q_PROPERTY(QNdefRecord record READ record WRITE setRecord NOTIFY recordChanged)
-
-public:
- enum TypeNameFormat {
- Empty = QNdefRecord::Empty,
- NfcRtd = QNdefRecord::NfcRtd,
- Mime = QNdefRecord::Mime,
- Uri = QNdefRecord::Uri,
- ExternalRtd = QNdefRecord::ExternalRtd,
- Unknown = QNdefRecord::Unknown
- };
- Q_ENUM(TypeNameFormat)
-
- explicit QQmlNdefRecord(QObject *parent = nullptr);
- explicit QQmlNdefRecord(const QNdefRecord &record, QObject *parent = nullptr);
- ~QQmlNdefRecord();
-
- QString type() const;
- void setType(const QString &t);
-
- void setTypeNameFormat(TypeNameFormat typeNameFormat);
- TypeNameFormat typeNameFormat() const;
-
- QNdefRecord record() const;
- void setRecord(const QNdefRecord &record);
-
-Q_SIGNALS:
- void typeChanged();
- void typeNameFormatChanged();
- void recordChanged();
-
-private:
- QQmlNdefRecordPrivate *d_ptr;
-};
-
-void Q_NFC_EXPORT qRegisterNdefRecordTypeHelper(const QMetaObject *metaObject,
- QNdefRecord::TypeNameFormat typeNameFormat,
- const QByteArray &type);
-
-Q_NFC_EXPORT QQmlNdefRecord *qNewDeclarativeNdefRecordForNdefRecord(const QNdefRecord &record);
-
-template<typename T>
-bool qRegisterNdefRecordType(QNdefRecord::TypeNameFormat typeNameFormat, const QByteArray &type)
-{
- qRegisterNdefRecordTypeHelper(&T::staticMetaObject, typeNameFormat, type);
- return true;
-}
-
-#define Q_DECLARE_NDEFRECORD(className, typeNameFormat, type) \
-static bool _q_##className##_registered = qRegisterNdefRecordType<className>(typeNameFormat, type);
-
-QT_END_NAMESPACE
-
-#endif // QQMLNDEFRECORD_H
diff --git a/src/nfc/qtlv.cpp b/src/nfc/qtlv.cpp
deleted file mode 100644
index 3168854c..00000000
--- a/src/nfc/qtlv.cpp
+++ /dev/null
@@ -1,532 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qtlv_p.h"
-
-#include "qnearfieldtagtype1_p.h"
-
-#include <QtCore/QVariant>
-
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-QPair<int, int> qParseReservedMemoryControlTlv(const QByteArray &tlvData)
-{
- quint8 position = tlvData.at(0);
- int pageAddr = position >> 4;
- int byteOffset = position & 0x0f;
-
- int size = quint8(tlvData.at(1));
- if (size == 0)
- size = 256;
-
- quint8 pageControl = tlvData.at(2);
- int bytesPerPage = pageControl & 0x0f;
-
- if (!bytesPerPage)
- return qMakePair(0, 0);
-
- int byteAddress = pageAddr * (1 << bytesPerPage) + byteOffset;
- return qMakePair(byteAddress, size);
-}
-
-QPair<int, int> qParseLockControlTlv(const QByteArray &tlvData)
-{
- quint8 position = tlvData.at(0);
- int pageAddr = position >> 4;
- int byteOffset = position & 0x0f;
-
- int size = quint8(tlvData.at(1));
- if (size == 0)
- size = 256;
- size = size / 8;
-
- quint8 pageControl = tlvData.at(2);
- int bytesPerPage = pageControl & 0x0f;
-
- if (!bytesPerPage)
- return qMakePair(0, 0);
-
- int byteAddress = pageAddr * (1 << bytesPerPage) + byteOffset;
- return qMakePair(byteAddress, size);
-}
-
-QTlvReader::QTlvReader(QNearFieldTarget *target)
-: m_target(target), m_index(-1)
-{
- if (qobject_cast<QNearFieldTagType1 *>(m_target)) {
- addReservedMemory(0, 12); // skip uid, cc
- addReservedMemory(104, 16); // skip reserved block D, lock block E
-
- addReservedMemory(120, 8); // skip reserved block F
- }
-}
-
-QTlvReader::QTlvReader(const QByteArray &data)
-: m_target(0), m_rawData(data), m_index(-1)
-{
-}
-
-void QTlvReader::addReservedMemory(int offset, int length)
-{
- m_reservedMemory.insert(offset, length);
-}
-
-/*!
- Returns the number of bytes of reserved memory found so far. The actual number of reserved
- bytes will not be known until atEnd() returns true.
-*/
-int QTlvReader::reservedMemorySize() const
-{
- int total = 0;
-
- QMap<int, int>::ConstIterator i;
- for (i = m_reservedMemory.constBegin(); i != m_reservedMemory.constEnd(); ++i)
- total += i.value();
-
- return total;
-}
-
-/*!
- Returns the request id that the TLV reader is currently waiting on.
-*/
-QNearFieldTarget::RequestId QTlvReader::requestId() const
-{
- return m_requestId;
-}
-
-bool QTlvReader::atEnd() const
-{
- if (m_index == -1)
- return false;
-
- if (m_requestId.isValid())
- return false;
-
- return (m_index == m_tlvData.length()) || (tag() == 0xfe);
-}
-
-/*!
- Moves to the next TLV. Returns true on success; otherwise returns false.
-*/
-bool QTlvReader::readNext()
-{
- if (atEnd())
- return false;
-
- // Move to next TLV
- if (m_index == -1) {
- m_index = 0;
- } else if (m_requestId.isValid()) {
- // do nothing
- } else if (tag() == 0x00 || tag() == 0xfe) {
- ++m_index;
- } else {
- int tlvLength = length();
- m_index += (tlvLength < 0xff) ? tlvLength + 2 : tlvLength + 4;
- }
-
- // Ensure that tag byte is available
- if (!readMoreData(m_index))
- return false;
-
- // Ensure that length byte(s) are available
- if (length() == -1)
- return false;
-
- // Ensure that data bytes are available
- int tlvLength = length();
-
- int dataOffset = (tlvLength < 0xff) ? m_index + 2 : m_index + 4;
-
- if (!readMoreData(dataOffset + tlvLength - 1))
- return false;
-
- switch (tag()) {
- case 0x01: { // Lock Control TLV
- QPair<int, int> locked = qParseLockControlTlv(data());
- addReservedMemory(locked.first, locked.second);
- break;
- }
- case 0x02: { // Reserved Memory Control TLV
- QPair<int, int> reserved = qParseReservedMemoryControlTlv(data());
- addReservedMemory(reserved.first, reserved.second);
- break;
- }
- }
-
- return true;
-}
-
-quint8 QTlvReader::tag() const
-{
- return m_tlvData.at(m_index);
-}
-
-int QTlvReader::length()
-{
- if (tag() == 0x00 || tag() == 0xfe)
- return 0;
-
- if (!readMoreData(m_index + 1))
- return -1;
-
- quint8 shortLength = m_tlvData.at(m_index + 1);
- if (shortLength != 0xff)
- return shortLength;
-
- if (!readMoreData(m_index + 3))
- return -1;
-
- quint16 longLength = (quint8(m_tlvData.at(m_index + 2)) << 8) |
- quint8(m_tlvData.at(m_index + 3));
-
- if (longLength < 0xff || longLength == 0xffff) {
- qWarning("Invalid 3 byte length");
- return 0;
- }
-
- return longLength;
-}
-
-QByteArray QTlvReader::data()
-{
- int tlvLength = length();
-
- int dataOffset = (tlvLength < 0xff) ? m_index + 2 : m_index + 4;
-
- if (!readMoreData(dataOffset + tlvLength - 1))
- return QByteArray();
-
- return m_tlvData.mid(dataOffset, tlvLength);
-}
-
-bool QTlvReader::readMoreData(int sparseOffset)
-{
- while (sparseOffset >= m_tlvData.length()) {
- int absOffset = absoluteOffset(m_tlvData.length());
-
- QByteArray data;
-
- if (!m_rawData.isEmpty()) {
- data = m_rawData.mid(absOffset, dataLength(absOffset));
- } else if (QNearFieldTagType1 *tag = qobject_cast<QNearFieldTagType1 *>(m_target)) {
- quint8 segment = absOffset / 128;
-
- if (m_requestId.isValid()) {
- QVariant v = m_target->requestResponse(m_requestId);
- if (!v.isValid())
- return false;
-
- m_requestId = QNearFieldTarget::RequestId();
-
- data = v.toByteArray();
-
- if (absOffset < 120)
- data = data.mid(2);
-
- int length = dataLength(absOffset);
-
- data = data.mid(absOffset - (segment * 128), length);
- } else {
- m_requestId = (absOffset < 120) ? tag->readAll() : tag->readSegment(segment);
-
- return false;
- }
- }
-
- if (data.isEmpty() && sparseOffset >= m_tlvData.length())
- return false;
-
- m_tlvData.append(data);
- }
-
- return true;
-}
-
-int QTlvReader::absoluteOffset(int sparseOffset) const
-{
- int absoluteOffset = sparseOffset;
- const QList<int> offsets = m_reservedMemory.keys();
- for (const int offset : offsets) {
- if (offset <= absoluteOffset)
- absoluteOffset += m_reservedMemory.value(offset);
- }
-
- return absoluteOffset;
-}
-
-/*!
- Returns the length of the contiguous non-reserved data block starting from absolute offset
- \a startOffset. -1 is return as the length of the last contiguous data block.
-*/
-int QTlvReader::dataLength(int startOffset) const
-{
- const QList<int> offsets = m_reservedMemory.keys();
- for (const int offset : offsets) {
- if (offset <= startOffset)
- continue;
-
- return offset - startOffset;
- }
-
- return -1;
-}
-
-
-QTlvWriter::QTlvWriter(QNearFieldTarget *target)
-: m_target(target), m_rawData(0), m_index(0), m_tagMemorySize(-1)
-{
- if (qobject_cast<QNearFieldTagType1 *>(m_target)) {
- addReservedMemory(0, 12); // skip uid, cc
- addReservedMemory(104, 16); // skip reserved block D, lock block E
-
- addReservedMemory(120, 8); // skip reserved block F
- }
-}
-
-QTlvWriter::QTlvWriter(QByteArray *data)
-: m_target(0), m_rawData(data), m_index(0), m_tagMemorySize(-1)
-{
-}
-
-QTlvWriter::~QTlvWriter()
-{
- if (m_rawData)
- process(true);
-}
-
-void QTlvWriter::addReservedMemory(int offset, int length)
-{
- m_reservedMemory.insert(offset, length);
-}
-
-void QTlvWriter::writeTlv(quint8 tagType, const QByteArray &data)
-{
- m_buffer.append(tagType);
-
- if (tagType != 0x00 && tagType != 0xfe) {
- int length = data.length();
- if (length < 0xff) {
- m_buffer.append(quint8(length));
- } else {
- m_buffer.append(char(0xff));
- m_buffer.append(quint16(length) >> 8);
- m_buffer.append(quint16(length) & 0x00ff);
- }
-
- m_buffer.append(data);
- }
-
- process();
-
- switch (tagType) {
- case 0x01: { // Lock Control TLV
- QPair<int, int> locked = qParseLockControlTlv(data);
- addReservedMemory(locked.first, locked.second);
- break;
- }
- case 0x02: { // Reserved Memory Control TLV
- QPair<int, int> reserved = qParseReservedMemoryControlTlv(data);
- addReservedMemory(reserved.first, reserved.second);
- break;
- }
- }
-}
-
-/*!
- Processes more of the TLV writer process. Returns true if the TLVs have been successfully
- written to the target or buffer; otherwise returns false.
-
- A false return value indicates that an NFC request is pending (if requestId() returns a valid
- request identifier) or the write process has failed (requestId() returns an invalid request
- identifier).
-*/
-bool QTlvWriter::process(bool all)
-{
- if (m_requestId.isValid()) {
- QVariant v = m_target->requestResponse(m_requestId);
- if (!v.isValid())
- return false;
- }
-
- if (m_tagMemorySize == -1) {
- if (m_rawData)
- m_tagMemorySize = m_rawData->length();
- else if (QNearFieldTagType1 *tag = qobject_cast<QNearFieldTagType1 *>(m_target)) {
- if (m_requestId.isValid()) {
- m_tagMemorySize = 8 * (tag->requestResponse(m_requestId).toUInt() + 1);
- m_requestId = QNearFieldTarget::RequestId();
- } else {
- m_requestId = tag->readByte(10);
- return false;
- }
- }
- }
-
- while (!m_buffer.isEmpty()) {
- int spaceRemaining = moveToNextAvailable();
- if (spaceRemaining < 1)
- return false;
-
- int length = qMin(spaceRemaining, m_buffer.length());
-
- if (m_rawData) {
- m_rawData->replace(m_index, length, m_buffer);
- m_index += length;
- m_buffer = m_buffer.mid(length);
- } else if (QNearFieldTagType1 *tag = qobject_cast<QNearFieldTagType1 *>(m_target)) {
- int bufferIndex = 0;
-
- // static memory - can only use writeByte()
- while (m_index < 120 && bufferIndex < length) {
- if (m_requestId.isValid()) {
- if (!m_target->requestResponse(m_requestId).toBool())
- return false;
-
- m_requestId = QNearFieldTarget::RequestId();
-
- ++m_index;
- ++bufferIndex;
- } else {
- m_requestId = tag->writeByte(m_index, m_buffer.at(bufferIndex));
- m_buffer = m_buffer.mid(bufferIndex);
- return false;
- }
- }
-
-
- // dynamic memory - writeBlock() full
- while (m_index >= 120 && (m_index % 8 == 0) && bufferIndex + 8 < length) {
- if (m_requestId.isValid()) {
- if (!m_target->requestResponse(m_requestId).toBool())
- return false;
-
- m_requestId = QNearFieldTarget::RequestId();
-
- m_index += 8;
- bufferIndex += 8;
- } else {
- m_requestId = tag->writeBlock(m_index / 8, m_buffer.mid(bufferIndex, 8));
- m_buffer = m_buffer.mid(bufferIndex);
- return false;
- }
- }
-
- // partial block
- int currentBlock = m_index / 8;
- int nextBlock = currentBlock + 1;
- int currentBlockStart = currentBlock * 8;
- int nextBlockStart = nextBlock * 8;
-
- int fillLength = qMin(nextBlockStart - m_index, spaceRemaining - bufferIndex);
-
- if (fillLength && (all || m_buffer.length() - bufferIndex >= fillLength) &&
- (m_buffer.length() != bufferIndex)) {
- // sufficient data available
- if (m_requestId.isValid()) {
- const QVariant v = tag->requestResponse(m_requestId);
- if (v.type() == QVariant::ByteArray) {
- // read in block
- QByteArray block = v.toByteArray();
-
- int fill = qMin(fillLength, m_buffer.length() - bufferIndex);
-
- for (int i = m_index - currentBlockStart; i < fill; ++i)
- block[i] = m_buffer.at(bufferIndex++);
-
- // now write block
- m_requestId = tag->writeBlock(currentBlock, block);
- return false;
- } else if (v.type() == QVariant::Bool) {
- m_requestId = QNearFieldTarget::RequestId();
- int fill = qMin(fillLength, m_buffer.length() - bufferIndex);
- bufferIndex = fill - (m_index - currentBlockStart);
-
- // write complete
- if (!v.toBool())
- return false;
- }
- } else {
- // read in block
- m_requestId = tag->readBlock(currentBlock);
- m_buffer = m_buffer.mid(bufferIndex);
- return false;
- }
- }
-
- m_buffer = m_buffer.mid(bufferIndex);
- }
- }
-
- return true;
-}
-
-QNearFieldTarget::RequestId QTlvWriter::requestId() const
-{
- return m_requestId;
-}
-
-int QTlvWriter::moveToNextAvailable()
-{
- int length = -1;
-
- // move index to next available byte
- QMap<int, int>::ConstIterator i;
- for (i = m_reservedMemory.constBegin(); i != m_reservedMemory.constEnd(); ++i) {
- if (m_index < i.key()) {
- length = i.key() - m_index;
- break;
- } else if (m_index == i.key()) {
- m_index += i.value();
- } else if (m_index > i.key() && m_index < (i.key() + i.value())) {
- m_index = i.key() + i.value();
- }
- }
-
- if (length == -1)
- return m_tagMemorySize - m_index;
-
- Q_ASSERT(length != -1);
-
- return length;
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/qtlv_p.h b/src/nfc/qtlv_p.h
deleted file mode 100644
index 1a4c6def..00000000
--- a/src/nfc/qtlv_p.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QTLV_P_H
-#define QTLV_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qtnfcglobal.h"
-
-#include "qnearfieldtarget.h"
-
-#include <QtCore/QByteArray>
-#include <QtCore/QMap>
-#include <QtCore/QPair>
-
-QT_BEGIN_NAMESPACE
-
-class QNearFieldTarget;
-class Q_AUTOTEST_EXPORT QTlvReader
-{
-public:
- explicit QTlvReader(QNearFieldTarget *target);
- explicit QTlvReader(const QByteArray &data);
-
- void addReservedMemory(int offset, int length);
- int reservedMemorySize() const;
-
- QNearFieldTarget::RequestId requestId() const;
-
- bool atEnd() const;
-
- bool readNext();
-
- quint8 tag() const;
- int length();
- QByteArray data();
-
-private:
- bool readMoreData(int sparseOffset);
- int absoluteOffset(int sparseOffset) const;
- int dataLength(int startOffset) const;
-
- QNearFieldTarget *m_target;
- QByteArray m_rawData;
- QNearFieldTarget::RequestId m_requestId;
-
- QByteArray m_tlvData;
- int m_index;
- QMap<int, int> m_reservedMemory;
-};
-
-class QTlvWriter
-{
-public:
- explicit QTlvWriter(QNearFieldTarget *target);
- explicit QTlvWriter(QByteArray *data);
- ~QTlvWriter();
-
- void addReservedMemory(int offset, int length);
-
- void writeTlv(quint8 tag, const QByteArray &data = QByteArray());
-
- bool process(bool all = false);
-
- QNearFieldTarget::RequestId requestId() const;
-
-private:
- int moveToNextAvailable();
-
- QNearFieldTarget *m_target;
- QByteArray *m_rawData;
-
- int m_index;
- int m_tagMemorySize;
- QMap<int, int> m_reservedMemory;
-
- QByteArray m_buffer;
-
- QNearFieldTarget::RequestId m_requestId;
-};
-
-QPair<int, int> qParseReservedMemoryControlTlv(const QByteArray &tlvData);
-QPair<int, int> qParseLockControlTlv(const QByteArray &tlvData);
-
-QT_END_NAMESPACE
-
-#endif // QTLV_P_H
diff --git a/src/nfc/qtnfcglobal.h b/src/nfc/qtnfcglobal.h
index 2a1e40b4..d80b25bf 100644
--- a/src/nfc/qtnfcglobal.h
+++ b/src/nfc/qtnfcglobal.h
@@ -1,59 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTNFC_H
#define QTNFC_H
#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_NFC_LIB)
-# define Q_NFC_EXPORT Q_DECL_EXPORT
-# else
-# define Q_NFC_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_NFC_EXPORT
-#endif
-
-QT_END_NAMESPACE
+#include <QtNfc/qtnfcexports.h>
#endif // QTNFC_H
diff --git a/src/nfc/qtnfcglobal_p.h b/src/nfc/qtnfcglobal_p.h
index 2f40d464..f4ec0497 100644
--- a/src/nfc/qtnfcglobal_p.h
+++ b/src/nfc/qtnfcglobal_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTNFCGLOBAL_P_H
#define QTNFCGLOBAL_P_H
diff --git a/src/nfc/targetemulator.cpp b/src/nfc/targetemulator.cpp
deleted file mode 100644
index 4b347208..00000000
--- a/src/nfc/targetemulator.cpp
+++ /dev/null
@@ -1,389 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "targetemulator_p.h"
-
-#include <QtCore/QSettings>
-#include <QtCore/QDateTime>
-
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-TagBase::TagBase()
-: lastAccess(0)
-{
-}
-
-TagBase::~TagBase()
-{
-}
-
-static inline quint8 blockByteToAddress(quint8 block, quint8 byte)
-{
- return ((block & 0x0f) << 3) | (byte & 0x07);
-}
-
-NfcTagType1::NfcTagType1()
-: hr0(0x11), hr1(0x00), memory(120, '\0')
-{
- // Locked blocks
- memory[(0x0e << 3) | 0x00] = 0x01;
- memory[(0x0e << 3) | 0x01] = 0x60;
-}
-
-NfcTagType1::~NfcTagType1()
-{
-}
-
-void NfcTagType1::load(QSettings *settings)
-{
- settings->beginGroup(QStringLiteral("TagType1"));
-
- hr0 = settings->value(QStringLiteral("HR0"), 0x11).toUInt();
-
- if (!(hr0 & 0x10)) {
- settings->endGroup();
- return;
- }
-
- hr1 = settings->value(QStringLiteral("HR1"), 0x00).toUInt();
-
- memory = settings->value(QStringLiteral("Data")).toByteArray();
-
- //quint8 nmn = memory.at(8);
-
- quint8 vno = memory.at(9);
- if (vno != 0x10)
- qWarning("Only NFC TagType1 v1.0 behavior is supported.");
-
- quint8 tms = memory.at(10);
- if (memory.length() != 8 * (tms + 1))
- qWarning("Static memory size does not match TMS value.");
-
- quint8 rwa = memory.at(11);
- switch (rwa >> 4) {
- case 0:
- // Unrestricted read access tag
- break;
- default:
- // tag with unknown read attributes
- ;
- }
-
- switch (rwa & 0x0f) {
- case 0:
- // Unrestricted write access tag
- break;
- case 0x0f:
- // Read only tag
- break;
- default:
- // tag with unknown write attributes
- ;
- }
-
- //quint16 lock = (quint8(memory[blockByteToAddress(0x0e, 1)]) << 8) |
- // quint8(memory[blockByteToAddress(0x0e, 0)]);
-
- settings->endGroup();
-}
-
-QByteArray NfcTagType1::uid() const
-{
- lastAccess = QDateTime::currentMSecsSinceEpoch();
-
- return memory.left(7);
-}
-
-quint8 NfcTagType1::readData(quint8 block, quint8 byte)
-{
- return memory.at((block << 3) | byte);
-}
-
-QByteArray NfcTagType1::processCommand(const QByteArray &command)
-{
- lastAccess = QDateTime::currentMSecsSinceEpoch();
-
- QByteArray response;
-
- bool tagType1 = (hr0 & 0xf0) == 0x10;
- bool dynamic = (hr0 & 0x0f) != 0x01;
-
- if (command.length() == 9) {
- // static memory model command
- quint8 opcode = command.at(0);
- quint8 address = command.at(1);
- quint8 data = command.at(2);
- QByteArray uid = command.mid(3, 4);
-
- // check checksum
- if (qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41) != 0)
- return QByteArray();
-
- // check UID
- if (uid != memory.left(4))
- return QByteArray();
-
- switch (opcode) {
- case 0x00: // RALL
- response.append(hr0);
- response.append(hr1);
- response.append(memory.left(120));
- break;
- case 0x01: // READ
- response.append(address);
- if (address & 0x80)
- response.append(char(0x00));
- else
- response.append(memory.at(address));
- break;
- case 0x53: { // WRITE-E
- quint8 block = address >> 3;
- if (block == 0x00 || block == 0x0d || block == 0x0e) // locked blocks
- break;
-
- quint16 lock = (readData(0x0e, 0x01) << 8) | readData(0x0e, 0x00);
- if ((0x01 << block) & lock) // locked blocks
- break;
-
- // FIXME: Test dynamic lock bytes
-
- memory[address] = data;
-
- response.append(address);
- response.append(data);
- break;
- }
- case 0x1a: { // WRITE-NE
- quint8 block = address >> 3;
- if (block == 0x00 || block == 0x0d) // locked blocks
- break;
-
- quint16 lock = (readData(0x0e, 0x01) << 8) | readData(0x0e, 0x00);
- if ((0x01 << block) & lock) // locked blocks
- break;
-
-
- // FIXME: Test dynamic lock bytes
-
- memory[address] = memory.at(address) | data;
-
- response.append(address);
- response.append(memory.at(address));
- break;
- }
- case 0x78: // RID
- response.append(hr0);
- response.append(hr1);
- response.append(memory.left(4));
- break;
- }
- } else if (tagType1 && dynamic && command.length() == 16) {
- // dynamic memory model command
- quint8 opcode = command.at(0);
- quint8 address = command.at(1);
- QByteArray data = command.mid(2, 8);
- QByteArray uid = command.mid(10, 4);
-
- // check checksum
- if (qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41) != 0)
- return QByteArray();
-
- // check UID
- if (uid != memory.left(4))
- return QByteArray();
-
- switch (opcode) {
- case 0x10: // RSEG
- response.append(address);
- response.append(memory.mid(128 * (address >> 4), 128));
- break;
- case 0x02: // READ8
- response.append(address);
- response.append(memory.mid(8 * address, 8));
- break;
- case 0x54: { // WRITE-E8
- // locked blocks
- if (address == 0x00 || address == 0x0d || address == 0x0e || address == 0x0f)
- break;
-
- quint16 lock = (readData(0x0e, 0x01) << 8) | readData(0x0e, 0x00);
- if (address <= 0x0e && ((0x01 << address) & lock)) // locked blocks
- break;
-
- // FIXME: Test dynamic lock bytes
-
- memory.replace(address * 8, 8, data);
-
- response.append(address);
- response.append(memory.mid(address * 8, 8));
- break;
- }
- case 0x1b: // WRITE-NE8
- // locked blocks
- if (address == 0x00 || address == 0x0d || address == 0x0e || address == 0x0f)
- break;
-
- quint16 lock = (readData(0x0e, 0x01) << 8) | readData(0x0e, 0x00);
- if (address <= 0x0e && ((0x01 << address) & lock)) // locked blocks
- break;
-
- // FIXME: Test dynamic lock bytes
-
- for (int i = 0; i < 8; ++i)
- memory[address * 8 + i] = memory.at(address * 8 + i) | data.at(i);
-
- response.append(address);
- response.append(memory.mid(address * 8, 8));
- break;
- }
- }
-
- if (!response.isEmpty()) {
- quint16 crc = qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41);
- response.append(quint8(crc & 0xff));
- response.append(quint8(crc >> 8));
- }
-
- return response;
-}
-
-
-NfcTagType2::NfcTagType2()
-: memory(64, 0x00), currentSector(0), expectPacket2(false)
-{
-}
-
-NfcTagType2::~NfcTagType2()
-{
-}
-
-void NfcTagType2::load(QSettings *settings)
-{
- settings->beginGroup(QStringLiteral("TagType2"));
-
- memory = settings->value(QStringLiteral("Data")).toByteArray();
-
- settings->endGroup();
-}
-
-QByteArray NfcTagType2::uid() const
-{
- lastAccess = QDateTime::currentMSecsSinceEpoch();
-
- return memory.left(3) + memory.mid(4, 4);
-}
-
-#define NACK QByteArray("\x05")
-#define ACK QByteArray("\x0a")
-
-QByteArray NfcTagType2::processCommand(const QByteArray &command)
-{
- lastAccess = QDateTime::currentMSecsSinceEpoch();
-
- QByteArray response;
-
- // check checksum
- if (qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41) != 0)
- return QByteArray();
-
- if (expectPacket2) {
- expectPacket2 = false;
- quint8 sector = command.at(0);
- if (sector * 1024 > memory.length())
- return NACK;
- else {
- currentSector = sector;
- return QByteArray();
- }
- }
-
- quint8 opcode = command.at(0);
-
- switch (opcode) {
- case 0x30: { // READ BLOCK
- quint8 block = command.at(1);
- int absoluteBlock = currentSector * 256 + block;
-
- response.append(memory.mid(absoluteBlock * 4, 16));
- if (response.length() != 16)
- response.append(QByteArray(16 - response.length(), '\0'));
-
- break;
- }
- case 0xa2: { // WRITE BLOCK
- quint8 block = command.at(1);
- int absoluteBlock = currentSector * 256 + block;
-
- // locked blocks
- if (absoluteBlock == 0 || absoluteBlock == 1)
- return NACK;
-
- const QByteArray data = command.mid(2, 4);
-
- memory.replace(absoluteBlock * 4, 4, data);
-
- return ACK;
- }
- case 0xc2: // SECTOR SELECT - Packet 1
- if (memory.length() > 1024) {
- expectPacket2 = true;
- return ACK;
- }
-
- return NACK;
- default:
- qDebug() << "Unknown opcode for Tag Type 2" << Qt::hex << opcode;
- qDebug() << "command:" << command.toHex();
-
- return NACK;
- ;
- }
-
- if (!response.isEmpty()) {
- quint16 crc = qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41);
- response.append(quint8(crc & 0xff));
- response.append(quint8(crc >> 8));
- }
-
- return response;
-}
-
-QT_END_NAMESPACE
diff --git a/src/nfc/targetemulator_p.h b/src/nfc/targetemulator_p.h
deleted file mode 100644
index 1f682704..00000000
--- a/src/nfc/targetemulator_p.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNfc module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef TARGETEMULATOR_P_H
-#define TARGETEMULATOR_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/QtGlobal>
-#include <QtCore/QByteArray>
-#include <QtNfc/qtnfcglobal.h>
-
-QT_FORWARD_DECLARE_CLASS(QSettings)
-
-QT_BEGIN_NAMESPACE
-
-class TagBase
-{
-public:
- TagBase();
- virtual ~TagBase();
-
- virtual void load(QSettings *settings) = 0;
-
- virtual QByteArray processCommand(const QByteArray &command) = 0;
-
- virtual QByteArray uid() const = 0;
-
- qint64 lastAccessTime() const { return lastAccess; }
-
-protected:
- mutable qint64 lastAccess;
-};
-
-class NfcTagType1 : public TagBase
-{
-public:
- NfcTagType1();
- ~NfcTagType1();
-
- void load(QSettings *settings);
-
- QByteArray processCommand(const QByteArray &command);
-
- QByteArray uid() const;
-
-private:
- quint8 readData(quint8 block, quint8 byte);
-
- quint8 hr0;
- quint8 hr1;
-
- QByteArray memory;
-};
-
-class NfcTagType2 : public TagBase
-{
-public:
- NfcTagType2();
- ~NfcTagType2();
-
- void load(QSettings *settings);
-
- QByteArray processCommand(const QByteArray &command);
-
- QByteArray uid() const;
-
-private:
- QByteArray memory;
- quint8 currentSector;
- bool expectPacket2;
-};
-
-QT_END_NAMESPACE
-
-#endif // TARGETEMULATOR_P_H