1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QNEARFIELDTARGET_H
5#define QNEARFIELDTARGET_H
6
7#include <QtCore/QByteArray>
8#include <QtCore/QList>
9#include <QtCore/QMetaType>
10#include <QtCore/QObject>
11#include <QtCore/QSharedDataPointer>
12#include <QtCore/QVariant>
13#include <QtNfc/qtnfcglobal.h>
14
15QT_BEGIN_NAMESPACE
16
17class QNdefMessage;
18class QNearFieldTargetPrivate;
19class QNearFieldManagerPrivateImpl;
20
21class Q_NFC_EXPORT QNearFieldTarget : public QObject
22{
23 Q_OBJECT
24
25 Q_DECLARE_PRIVATE(QNearFieldTarget)
26 friend class QNearFieldManagerPrivateImpl;
27
28public:
29 enum Type {
30 ProprietaryTag,
31 NfcTagType1,
32 NfcTagType2,
33 NfcTagType3,
34 NfcTagType4,
35 NfcTagType4A,
36 NfcTagType4B,
37 MifareTag
38 };
39 Q_ENUM(Type)
40
41 enum AccessMethod {
42 UnknownAccess = 0x00,
43 NdefAccess = 0x01,
44 TagTypeSpecificAccess = 0x02,
45 AnyAccess = 0xff
46 };
47 Q_ENUM(AccessMethod)
48 Q_DECLARE_FLAGS(AccessMethods, AccessMethod)
49
50 enum Error {
51 NoError,
52 UnknownError,
53 UnsupportedError,
54 TargetOutOfRangeError,
55 NoResponseError,
56 ChecksumMismatchError,
57 InvalidParametersError,
58 ConnectionError,
59 NdefReadError,
60 NdefWriteError,
61 CommandError,
62 TimeoutError
63 };
64 Q_ENUM(Error)
65
66 class RequestIdPrivate;
67 class Q_NFC_EXPORT RequestId
68 {
69 public:
70 RequestId();
71 RequestId(const RequestId &other);
72 RequestId(RequestIdPrivate *p);
73 ~RequestId();
74
75 bool isValid() const;
76
77 int refCount() const;
78
79 bool operator<(const RequestId &other) const;
80 bool operator==(const RequestId &other) const;
81 bool operator!=(const RequestId &other) const;
82 RequestId &operator=(const RequestId &other);
83
84 QSharedDataPointer<RequestIdPrivate> d;
85 };
86
87 explicit QNearFieldTarget(QObject *parent = nullptr);
88 ~QNearFieldTarget();
89
90 QByteArray uid() const;
91 Type type() const;
92 AccessMethods accessMethods() const;
93
94 bool disconnect();
95
96 // NdefAccess
97 bool hasNdefMessage();
98 RequestId readNdefMessages();
99 RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
100
101 // TagTypeSpecificAccess
102 int maxCommandLength() const;
103 RequestId sendCommand(const QByteArray &command);
104
105 bool waitForRequestCompleted(const RequestId &id, int msecs = 5000);
106 QVariant requestResponse(const RequestId &id) const;
107
108Q_SIGNALS:
109 void disconnected();
110
111 void ndefMessageRead(const QNdefMessage &message);
112
113 void requestCompleted(const QNearFieldTarget::RequestId &id);
114
115 void error(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id);
116
117protected:
118 QNearFieldTarget(QNearFieldTargetPrivate *backend, QObject *parent = nullptr);
119
120private:
121 QNearFieldTargetPrivate *d_ptr;
122};
123
124Q_DECLARE_OPERATORS_FOR_FLAGS(QNearFieldTarget::AccessMethods)
125
126QT_END_NAMESPACE
127
128QT_DECL_METATYPE_EXTERN_TAGGED(QNearFieldTarget::RequestId, QNearFieldTarget__RequestId,
129 Q_NFC_EXPORT)
130
131#endif // QNEARFIELDTARGET_H
132

source code of qtconnectivity/src/nfc/qnearfieldtarget.h