Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qndefaccessfsm_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QNDEFACCESSFSM_P_H
5#define QNDEFACCESSFSM_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qndefmessage.h"
19
20QT_BEGIN_NAMESPACE
21
22/*
23 Base class for FSMs that can be used to exchange NDEF messages with cards.
24
25 The user may call one of these methods to start a task:
26
27 - detectNdefSupport()
28 - readMessages()
29 - writeMessages()
30
31 The user is then expected to perform actions indicated by Action type.
32*/
33class QNdefAccessFsm
34{
35 Q_DISABLE_COPY_MOVE(QNdefAccessFsm)
36public:
37 QNdefAccessFsm() = default;
38 virtual ~QNdefAccessFsm() = default;
39
40 enum Action {
41 // The requested task has successfully completed. New tasks can be started.
42 Done,
43 // The requested task has failed. New tasks can be started.
44 Failed,
45 // An NDEF message was successfully read. The user must call getMessage().
46 GetMessage,
47 // The user's call was unexpected. The FSM may be in an invalid state.
48 Unexpected,
49 // The user must call getCommand() and then send the returned command to the card.
50 SendCommand,
51 // The user must call provideResponse() with the result of the last sent command.
52 ProvideResponse
53 };
54
55 /*
56 Returns a command to send to the card.
57
58 This method must be called if the FMS has requested SendCommand action.
59
60 Next action will be ProvideResponse or Unexpected.
61 */
62 virtual QByteArray getCommand(Action &nextAction) = 0;
63
64 /*
65 This method must be called by the user to provide response for
66 a completed command.
67
68 An empty QByteArray can be provided to indicate that the command
69 has failed.
70 */
71 virtual Action provideResponse(const QByteArray &response) = 0;
72
73 /*
74 Returns an NDEF message that was read from the card.
75
76 This method must be called if the FSM has requested GetMessage action.
77 */
78 virtual QNdefMessage getMessage(Action &nextAction) = 0;
79
80 /*
81 Start NDEF support detection.
82 */
83 virtual Action detectNdefSupport() = 0;
84
85 /*
86 Start reading NDEF messages.
87
88 This call also performs NDEF support detection if it was not performed
89 earlier.
90 */
91 virtual Action readMessages() = 0;
92
93 /*
94 Start writing the given messages to the card.
95
96 This call also performs NDEF detection if is was not performed earlier.
97 */
98 virtual Action writeMessages(const QList<QNdefMessage> &messages) = 0;
99};
100
101QT_END_NAMESPACE
102
103#endif // QNDEFACCESSFSM_P_H
Action provideResponse(const QByteArray &response) override
Action writeMessages(const QList< QNdefMessage > &messages) override
Action readMessages() override
QNdefMessage getMessage(Action &nextAction) override
Action detectNdefSupport() override
QByteArray getCommand(Action &nextAction) override