| a6553f6 by Noam Rosenthal at 2009-06-07 |
1 |
/**************************************************************************** |
|
2 |
** |
| 3d88526 by No'am Rosenthal at 2009-11-26 |
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
6 |
** |
| 3d88526 by No'am Rosenthal at 2009-11-26 |
7 |
** This file is part of SCXML on Qt labs |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
8 |
** |
| 3d88526 by No'am Rosenthal at 2009-11-26 |
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
|
|
42 |
#ifndef QSCXML_H |
|
43 |
#define QSCXML_H |
| d0441f6 by Noam Rosenthal at 2009-06-08 |
44 |
#ifndef QT_NO_STATEMACHINE |
|
45 |
|
|
46 |
#include <QStateMachine> |
|
47 |
#include <QAbstractTransition> |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
48 |
#include <QVariant> |
|
49 |
#include <QEvent> |
|
50 |
#include <QStringList> |
|
51 |
#include <QScriptValue> |
|
52 |
#include <QUrl> |
| 7a19605 by No'am Rosenthal at 2009-11-26 |
53 |
#include <QScriptProgram> |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
54 |
class QScriptEngine; |
|
55 |
class QScxml; |
|
56 |
|
|
57 |
class QScxmlEvent : public QEvent |
|
58 |
{ |
|
59 |
public: |
|
60 |
static QEvent::Type eventType(); |
|
61 |
QString eventName() const; |
|
62 |
QStringList paramNames () const; |
|
63 |
QVariantList paramValues () const; |
|
64 |
QScriptValue content () const; |
|
65 |
QVariant param (const QString & name) const; |
|
66 |
QScxmlEvent ( |
|
67 |
const QString & name, |
|
68 |
const QStringList & paramNames = QStringList(), |
|
69 |
const QVariantList & paramValues = QVariantList(), |
|
70 |
const QScriptValue & content = QScriptValue()); |
|
71 |
|
|
72 |
struct MetaData |
|
73 |
{ |
|
74 |
QUrl origin,target; |
|
75 |
QString originType, targetType; |
|
76 |
QString invokeID; |
|
77 |
enum Kind { Platform, Internal, External } kind; |
|
78 |
}; |
|
79 |
|
|
80 |
MetaData metaData; |
|
81 |
|
|
82 |
private: |
|
83 |
QString ename; |
|
84 |
QStringList pnames; |
|
85 |
QVariantList pvals; |
|
86 |
QScriptValue cnt; |
|
87 |
}; |
|
88 |
|
|
89 |
|
|
90 |
class QScxmlTransition : public QAbstractTransition |
|
91 |
{ |
|
92 |
Q_OBJECT |
|
93 |
Q_PROPERTY(QString conditionExpression READ conditionExpression WRITE setConditionExpression) |
| 7a19605 by No'am Rosenthal at 2009-11-26 |
94 |
Q_PROPERTY(QStringList eventPrefixes READ eventPrefixes WRITE setEventPrefixes) |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
95 |
|
|
96 |
public: |
|
97 |
QScxmlTransition (QState* state, QScxml* machine); |
|
98 |
|
| 7a19605 by No'am Rosenthal at 2009-11-26 |
99 |
QString conditionExpression () const; |
|
100 |
void setConditionExpression (const QString & c); |
|
101 |
QStringList eventPrefixes () const { return ev; } |
|
102 |
void setEventPrefixes (const QStringList & e) { ev = e; } |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
103 |
|
|
104 |
protected: |
| d0441f6 by Noam Rosenthal at 2009-06-08 |
105 |
bool eventTest(QEvent*); |
| 6a9f40c by Noam Rosenthal at 2009-06-18 |
106 |
void onTransition (QEvent*); |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
107 |
private: |
|
108 |
QScxml* scxml; |
| 7a19605 by No'am Rosenthal at 2009-11-26 |
109 |
QStringList ev; |
|
110 |
QScriptProgram prog; |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
111 |
}; |
|
112 |
|
|
113 |
class QScxmlInvoker : public QObject |
|
114 |
{ |
|
115 |
Q_OBJECT |
| 9eb87e2 by Noam Rosenthal at 2009-06-09 |
116 |
Q_PROPERTY (QString id READ id WRITE setID) |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
117 |
|
|
118 |
protected: |
| d0441f6 by Noam Rosenthal at 2009-06-08 |
119 |
QScxmlInvoker(QScxmlEvent* ievent, QStateMachine* p) : QObject(p), initEvent(ievent),cancelled(false) {} |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
120 |
|
|
121 |
public: |
|
122 |
virtual ~QScxmlInvoker(); |
| 9eb87e2 by Noam Rosenthal at 2009-06-09 |
123 |
QString id () const; |
|
124 |
void setID(const QString &); |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
125 |
|
|
126 |
public Q_SLOTS: |
|
127 |
virtual void activate() = 0; |
|
128 |
virtual void cancel() { deleteLater(); } |
|
129 |
|
|
130 |
protected Q_SLOTS: |
|
131 |
void postParentEvent (const QString & event); |
|
132 |
|
|
133 |
protected: |
|
134 |
QScxml* parentStateMachine() { return (QScxml*)parent(); } |
|
135 |
void postParentEvent (QScxmlEvent* ev); |
|
136 |
QScxmlEvent* initEvent; |
| 9eb87e2 by Noam Rosenthal at 2009-06-09 |
137 |
bool cancelled; |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
138 |
|
|
139 |
friend struct QScxmlFunctions; |
|
140 |
}; |
|
141 |
|
|
142 |
struct QScxmlInvokerFactory |
|
143 |
{ |
|
144 |
virtual QScxmlInvoker* createInvoker (QScxmlEvent* event, QScxml* stateMachine) = 0; |
|
145 |
virtual bool isTypeSupported (const QString & type) const = 0; |
|
146 |
virtual void init (QScxml*) = 0; |
|
147 |
}; |
|
148 |
|
|
149 |
template <class T> |
|
150 |
class QScxmlAutoInvokerFactory : public QScxmlInvokerFactory |
|
151 |
{ |
|
152 |
QScxmlInvoker* createInvoker (QScxmlEvent* _e, QScxml* _sm) { return new T(_e,_sm); } |
|
153 |
bool isTypeSupported(const QString & _s) const { return T::isTypeSupported(_s); } |
|
154 |
void init (QScxml* sm) { T::initInvokerFactory(sm); } |
|
155 |
}; |
|
156 |
|
|
157 |
|
|
158 |
class QScxml : public QStateMachine |
|
159 |
{ |
|
160 |
Q_OBJECT |
|
161 |
|
|
162 |
Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl) |
|
163 |
|
|
164 |
|
|
165 |
public: |
| 084833d by No'am Rosenthal at 2009-07-13 |
166 |
QScxml(QScriptEngine* engine, QObject* o = NULL); |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
167 |
QScxml(QObject* o = NULL); |
|
168 |
virtual ~QScxml(); |
|
169 |
protected: |
|
170 |
// overloaded to store the event for the script environment's use (_event), and to convert |
|
171 |
// StateFinished events to "done." named events |
|
172 |
virtual void beginSelectTransitions(QEvent*); |
|
173 |
virtual void endMicrostep(QEvent*); |
|
174 |
|
|
175 |
public: |
|
176 |
QScriptEngine* scriptEngine () const; |
|
177 |
void registerObject (QObject* object, const QString & name = QString(), bool recursive = false); |
|
178 |
void registerInvokerFactory (QScxmlInvokerFactory* f); |
|
179 |
void setBaseUrl (const QUrl &); |
|
180 |
QUrl baseUrl () const; |
|
181 |
static QScxml* load (const QString & filename, QObject* o = NULL); |
| 7a19605 by No'am Rosenthal at 2009-11-26 |
182 |
QMap<QString,QVariant> data() const; |
|
183 |
QStringList knownEventNames() const; |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
184 |
|
|
185 |
public Q_SLOTS: |
|
186 |
void postNamedEvent(const QString &); |
|
187 |
void executeScript (const QString &); |
| 7a19605 by No'am Rosenthal at 2009-11-26 |
188 |
void executeScript (const QScriptProgram &); |
|
189 |
void setData(const QString & id, const QVariant & value); |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
190 |
|
|
191 |
private Q_SLOTS: |
|
192 |
void registerSession(); |
|
193 |
void unregisterSession(); |
| 9eb87e2 by Noam Rosenthal at 2009-06-09 |
194 |
void handleStateFinished(); |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
195 |
|
|
196 |
Q_SIGNALS: |
|
197 |
void eventTriggered(const QString &); |
| 7a19605 by No'am Rosenthal at 2009-11-26 |
198 |
void dataChanged (const QString &, const QVariant &); |
|
199 |
void configurationChanged(); |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
200 |
|
|
201 |
private: |
|
202 |
class QScxmlPrivate* pvt; |
|
203 |
friend class QScxmlLoader; |
|
204 |
friend struct QScxmlFunctions; |
| 084833d by No'am Rosenthal at 2009-07-13 |
205 |
void init(); |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
206 |
}; |
| d0441f6 by Noam Rosenthal at 2009-06-08 |
207 |
#endif |
| a6553f6 by Noam Rosenthal at 2009-06-07 |
208 |
#endif // QSCXML_H |