blob: 2a175bcc9bea6c937de4262d715dd44031508bea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
|