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 UnsupportedTargetError,
64 };
65 Q_ENUM(Error)
66
67 class RequestIdPrivate;
68 class Q_NFC_EXPORT RequestId
69 {
70 public:
71 RequestId();
72 RequestId(const RequestId &other);
73 RequestId(RequestIdPrivate *p);
74 ~RequestId();
75
76 bool isValid() const;
77
78 int refCount() const;
79
80 bool operator<(const RequestId &other) const;
81 bool operator==(const RequestId &other) const;
82 bool operator!=(const RequestId &other) const;
83 RequestId &operator=(const RequestId &other);
84
85 QSharedDataPointer<RequestIdPrivate> d;
86 };
87
88 explicit QNearFieldTarget(QObject *parent = nullptr);
89 ~QNearFieldTarget();
90
91 QByteArray uid() const;
92 Type type() const;
93 AccessMethods accessMethods() const;
94
95 bool disconnect();
96
97 // NdefAccess
98 bool hasNdefMessage();
99 RequestId readNdefMessages();
100 RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
101
102 // TagTypeSpecificAccess
103 int maxCommandLength() const;
104 RequestId sendCommand(const QByteArray &command);
105
106 bool waitForRequestCompleted(const RequestId &id, int msecs = 5000);
107 QVariant requestResponse(const RequestId &id) const;
108
109Q_SIGNALS:
110 void disconnected();
111
112 void ndefMessageRead(const QNdefMessage &message);
113
114 void requestCompleted(const QNearFieldTarget::RequestId &id);
115
116 void error(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id);
117
118protected:
119 QNearFieldTarget(QNearFieldTargetPrivate *backend, QObject *parent = nullptr);
120
121private:
122 QNearFieldTargetPrivate *d_ptr;
123};
124
125Q_DECLARE_OPERATORS_FOR_FLAGS(QNearFieldTarget::AccessMethods)
126
127QT_END_NAMESPACE
128
129QT_DECL_METATYPE_EXTERN_TAGGED(QNearFieldTarget::RequestId, QNearFieldTarget__RequestId,
130 Q_NFC_EXPORT)
131
132#endif // QNEARFIELDTARGET_H
133

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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