1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtScxml module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QSCXMLEVENT_P_H |
41 | #define QSCXMLEVENT_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists purely as an |
48 | // implementation detail. This header file may change from version to |
49 | // version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtScxml/qscxmlevent.h> |
55 | #include <QtScxml/private/qscxmlexecutablecontent_p.h> |
56 | |
57 | #ifndef BUILD_QSCXMLC |
58 | #include <QtScxml/qscxmlstatemachine.h> |
59 | #endif |
60 | |
61 | #include <QtCore/qatomic.h> |
62 | |
63 | QT_BEGIN_NAMESPACE |
64 | |
65 | #ifndef BUILD_QSCXMLC |
66 | class QScxmlEventBuilder |
67 | { |
68 | QScxmlStateMachine *stateMachine; |
69 | QScxmlExecutableContent::StringId instructionLocation; |
70 | QString event; |
71 | QScxmlExecutableContent::EvaluatorId eventexpr; |
72 | QString contents; |
73 | QScxmlExecutableContent::EvaluatorId contentExpr; |
74 | const QScxmlExecutableContent::Array<QScxmlExecutableContent::ParameterInfo> *params; |
75 | QScxmlEvent::EventType eventType; |
76 | QString id; |
77 | QString idLocation; |
78 | QString target; |
79 | QScxmlExecutableContent::EvaluatorId targetexpr; |
80 | QString type; |
81 | QScxmlExecutableContent::EvaluatorId typeexpr; |
82 | const QScxmlExecutableContent::Array<QScxmlExecutableContent::StringId> *namelist; |
83 | |
84 | static QAtomicInt idCounter; |
85 | QString generateId() const |
86 | { |
87 | QString id = QString::number(++idCounter); |
88 | id.prepend(QStringLiteral("id-" )); |
89 | return id; |
90 | } |
91 | |
92 | QScxmlEventBuilder() |
93 | { init(); } |
94 | |
95 | void init() // Because stupid VS2012 can't cope with non-static field initializers. |
96 | { |
97 | stateMachine = nullptr; |
98 | eventexpr = QScxmlExecutableContent::NoEvaluator; |
99 | contentExpr = QScxmlExecutableContent::NoEvaluator; |
100 | params = nullptr; |
101 | eventType = QScxmlEvent::ExternalEvent; |
102 | targetexpr = QScxmlExecutableContent::NoEvaluator; |
103 | typeexpr = QScxmlExecutableContent::NoEvaluator; |
104 | namelist = nullptr; |
105 | } |
106 | |
107 | public: |
108 | QScxmlEventBuilder(QScxmlStateMachine *stateMachine, const QString &eventName, const QScxmlExecutableContent::DoneData *doneData) |
109 | { |
110 | init(); |
111 | this->stateMachine = stateMachine; |
112 | Q_ASSERT(doneData); |
113 | instructionLocation = doneData->location; |
114 | event = eventName; |
115 | contents = stateMachine->tableData()->string(id: doneData->contents); |
116 | contentExpr = doneData->expr; |
117 | params = &doneData->params; |
118 | eventType = QScxmlEvent::InternalEvent; |
119 | } |
120 | |
121 | QScxmlEventBuilder(QScxmlStateMachine *stateMachine, const QScxmlExecutableContent::Send &send) |
122 | { |
123 | init(); |
124 | this->stateMachine = stateMachine; |
125 | instructionLocation = send.instructionLocation; |
126 | event = stateMachine->tableData()->string(id: send.event); |
127 | eventexpr = send.eventexpr; |
128 | contents = stateMachine->tableData()->string(id: send.content); |
129 | contentExpr = send.contentexpr; |
130 | params = send.params(); |
131 | id = stateMachine->tableData()->string(id: send.id); |
132 | idLocation = stateMachine->tableData()->string(id: send.idLocation); |
133 | target = stateMachine->tableData()->string(id: send.target); |
134 | targetexpr = send.targetexpr; |
135 | type = stateMachine->tableData()->string(id: send.type); |
136 | typeexpr = send.typeexpr; |
137 | namelist = &send.namelist; |
138 | } |
139 | |
140 | QScxmlEvent *operator()() { return buildEvent(); } |
141 | |
142 | QScxmlEvent *buildEvent(); |
143 | |
144 | static QScxmlEvent *errorEvent(QScxmlStateMachine *stateMachine, const QString &name, |
145 | const QString &message, const QString &sendid); |
146 | |
147 | bool evaluate(const QScxmlExecutableContent::ParameterInfo ¶m, |
148 | QScxmlStateMachine *stateMachine, QVariantMap &keyValues); |
149 | |
150 | bool evaluate( |
151 | const QScxmlExecutableContent::Array<QScxmlExecutableContent::ParameterInfo> *params, |
152 | QScxmlStateMachine *stateMachine, QVariantMap &keyValues); |
153 | |
154 | void submitError(const QString &type, const QString &msg, const QString &sendid = QString()); |
155 | }; |
156 | #endif // BUILD_QSCXMLC |
157 | |
158 | class QScxmlEventPrivate |
159 | { |
160 | public: |
161 | QScxmlEventPrivate() |
162 | : eventType(QScxmlEvent::ExternalEvent) |
163 | , delayInMiliSecs(0) |
164 | {} |
165 | |
166 | QString name; |
167 | QScxmlEvent::EventType eventType; |
168 | QVariant data; // extra data |
169 | QString sendid; // if set, or id of <send> if failure |
170 | QString origin; // uri to answer by setting the target of send, empty for internal and platform events |
171 | QString originType; // type to answer by setting the type of send, empty for internal and platform events |
172 | QString invokeId; // id of the invocation that triggered the child process if this was invoked |
173 | int delayInMiliSecs; |
174 | |
175 | static QByteArray debugString(QScxmlEvent *event); |
176 | }; |
177 | |
178 | QT_END_NAMESPACE |
179 | |
180 | #endif // QSCXMLEVENT_P_H |
181 | |
182 | |