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 QSCXMLEVENT_P_H |
5 | #define QSCXMLEVENT_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 <QtScxml/qscxmlevent.h> |
19 | #include <QtScxml/private/qscxmlexecutablecontent_p.h> |
20 | |
21 | #ifndef BUILD_QSCXMLC |
22 | #include <QtScxml/qscxmlstatemachine.h> |
23 | #endif |
24 | |
25 | #include <QtCore/qatomic.h> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | #ifndef BUILD_QSCXMLC |
30 | class QScxmlEventBuilder |
31 | { |
32 | QScxmlStateMachine *stateMachine; |
33 | QScxmlExecutableContent::StringId instructionLocation; |
34 | QString event; |
35 | QScxmlExecutableContent::EvaluatorId eventexpr; |
36 | QString contents; |
37 | QScxmlExecutableContent::EvaluatorId contentExpr; |
38 | const QScxmlExecutableContent::Array<QScxmlExecutableContent::ParameterInfo> *params; |
39 | QScxmlEvent::EventType eventType; |
40 | QString id; |
41 | QString idLocation; |
42 | QString target; |
43 | QScxmlExecutableContent::EvaluatorId targetexpr; |
44 | QString type; |
45 | QScxmlExecutableContent::EvaluatorId typeexpr; |
46 | const QScxmlExecutableContent::Array<QScxmlExecutableContent::StringId> *namelist; |
47 | |
48 | static QAtomicInt idCounter; |
49 | QString generateId() const |
50 | { |
51 | QString id = QString::number(++idCounter); |
52 | id.prepend(QStringLiteral("id-" )); |
53 | return id; |
54 | } |
55 | |
56 | QScxmlEventBuilder() |
57 | { init(); } |
58 | |
59 | void init() // Because stupid VS2012 can't cope with non-static field initializers. |
60 | { |
61 | stateMachine = nullptr; |
62 | eventexpr = QScxmlExecutableContent::NoEvaluator; |
63 | contentExpr = QScxmlExecutableContent::NoEvaluator; |
64 | params = nullptr; |
65 | eventType = QScxmlEvent::ExternalEvent; |
66 | targetexpr = QScxmlExecutableContent::NoEvaluator; |
67 | typeexpr = QScxmlExecutableContent::NoEvaluator; |
68 | namelist = nullptr; |
69 | } |
70 | |
71 | public: |
72 | QScxmlEventBuilder(QScxmlStateMachine *stateMachine, const QString &eventName, const QScxmlExecutableContent::DoneData *doneData) |
73 | { |
74 | init(); |
75 | this->stateMachine = stateMachine; |
76 | Q_ASSERT(doneData); |
77 | instructionLocation = doneData->location; |
78 | event = eventName; |
79 | contents = stateMachine->tableData()->string(id: doneData->contents); |
80 | contentExpr = doneData->expr; |
81 | params = &doneData->params; |
82 | eventType = QScxmlEvent::InternalEvent; |
83 | } |
84 | |
85 | QScxmlEventBuilder(QScxmlStateMachine *stateMachine, const QScxmlExecutableContent::Send &send) |
86 | { |
87 | init(); |
88 | this->stateMachine = stateMachine; |
89 | instructionLocation = send.instructionLocation; |
90 | event = stateMachine->tableData()->string(id: send.event); |
91 | eventexpr = send.eventexpr; |
92 | contents = stateMachine->tableData()->string(id: send.content); |
93 | contentExpr = send.contentexpr; |
94 | params = send.params(); |
95 | id = stateMachine->tableData()->string(id: send.id); |
96 | idLocation = stateMachine->tableData()->string(id: send.idLocation); |
97 | target = stateMachine->tableData()->string(id: send.target); |
98 | targetexpr = send.targetexpr; |
99 | type = stateMachine->tableData()->string(id: send.type); |
100 | typeexpr = send.typeexpr; |
101 | namelist = &send.namelist; |
102 | } |
103 | |
104 | QScxmlEvent *operator()() { return buildEvent(); } |
105 | |
106 | QScxmlEvent *buildEvent(); |
107 | |
108 | static QScxmlEvent *errorEvent(QScxmlStateMachine *stateMachine, const QString &name, |
109 | const QString &message, const QString &sendid); |
110 | |
111 | bool evaluate(const QScxmlExecutableContent::ParameterInfo ¶m, |
112 | QScxmlStateMachine *stateMachine, QVariantMap &keyValues); |
113 | |
114 | bool evaluate( |
115 | const QScxmlExecutableContent::Array<QScxmlExecutableContent::ParameterInfo> *params, |
116 | QScxmlStateMachine *stateMachine, QVariantMap &keyValues); |
117 | |
118 | void submitError(const QString &type, const QString &msg, const QString &sendid = QString()); |
119 | }; |
120 | #endif // BUILD_QSCXMLC |
121 | |
122 | class QScxmlEventPrivate |
123 | { |
124 | public: |
125 | QScxmlEventPrivate() |
126 | : eventType(QScxmlEvent::ExternalEvent) |
127 | , delayInMiliSecs(0) |
128 | {} |
129 | |
130 | QString name; |
131 | QScxmlEvent::EventType eventType; |
132 | QVariant data; // extra data |
133 | QString sendid; // if set, or id of <send> if failure |
134 | QString origin; // uri to answer by setting the target of send, empty for internal and platform events |
135 | QString originType; // type to answer by setting the type of send, empty for internal and platform events |
136 | QString invokeId; // id of the invocation that triggered the child process if this was invoked |
137 | int delayInMiliSecs; |
138 | |
139 | static QByteArray debugString(QScxmlEvent *event); |
140 | }; |
141 | |
142 | QT_END_NAMESPACE |
143 | |
144 | #endif // QSCXMLEVENT_P_H |
145 | |
146 | |