summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/scxml/qscxmlcompiler.cpp36
-rw-r--r--src/scxml/qscxmlexecutablecontent.h10
-rw-r--r--src/scxml/qscxmlinvokableservice.cpp229
-rw-r--r--src/scxml/qscxmlinvokableservice.h91
-rw-r--r--src/scxml/qscxmlinvokableservice_p.h101
-rw-r--r--src/scxml/qscxmlstatemachine.cpp11
-rw-r--r--src/scxml/qscxmlstatemachine.h2
-rw-r--r--src/scxml/qscxmltabledata.cpp15
-rw-r--r--src/scxml/qscxmltabledata_p.h8
-rw-r--r--src/scxml/scxml.pro1
-rw-r--r--tools/qscxmlc/data.t20
-rw-r--r--tools/qscxmlc/scxmlcppdumper.cpp64
12 files changed, 296 insertions, 292 deletions
diff --git a/src/scxml/qscxmlcompiler.cpp b/src/scxml/qscxmlcompiler.cpp
index 9a3af4a..691f87a 100644
--- a/src/scxml/qscxmlcompiler.cpp
+++ b/src/scxml/qscxmlcompiler.cpp
@@ -50,7 +50,7 @@
#ifndef BUILD_QSCXMLC
#include "qscxmlecmascriptdatamodel.h"
-#include "qscxmlinvokableservice.h"
+#include "qscxmlinvokableservice_p.h"
#include "qscxmldatamodel_p.h"
#include "qscxmlstatemachine_p.h"
#include "qscxmlstatemachine.h"
@@ -476,17 +476,10 @@ private:
class InvokeDynamicScxmlFactory: public QScxmlScxmlServiceFactory
{
public:
- InvokeDynamicScxmlFactory(QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
+ InvokeDynamicScxmlFactory(const QScxmlExecutableContent::InvokeInfo &invokeInfo,
const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool autoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize)
- : QScxmlScxmlServiceFactory(invokeLocation, srcexpr, id, idPrefix, idlocation,
- namelist, autoforward, params, finalize)
+ const QVector<QScxmlExecutableContent::ParameterInfo> &params)
+ : QScxmlScxmlServiceFactory(invokeInfo, namelist, params)
{}
void setContent(const QSharedPointer<DocumentModel::ScxmlDocument> &content)
@@ -617,25 +610,12 @@ public:
auto stateMachine = new DynamicStateMachine;
MetaDataInfo info;
DataModelInfo dm;
- auto factoryIdCreator = [stateMachine](QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
+ auto factoryIdCreator = [stateMachine](
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool autoforward,
const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize,
const QSharedPointer<DocumentModel::ScxmlDocument> &content) -> int {
- auto factory = new InvokeDynamicScxmlFactory(invokeLocation,
- srcexpr,
- id,
- idPrefix,
- idlocation,
- namelist,
- autoforward,
- params,
- finalize);
+ auto factory = new InvokeDynamicScxmlFactory(invokeInfo, namelist, params);
factory->setContent(content);
stateMachine->m_allFactoriesById.append(factory);
return stateMachine->m_allFactoriesById.size() - 1;
@@ -667,7 +647,7 @@ inline QScxmlInvokableService *InvokeDynamicScxmlFactory::invoke(
QScxmlStateMachine *parentStateMachine)
{
bool ok = true;
- auto srcexpr = calculateSrcexpr(parentStateMachine, &ok);
+ auto srcexpr = d->calculateSrcexpr(parentStateMachine, &ok);
if (!ok)
return Q_NULLPTR;
diff --git a/src/scxml/qscxmlexecutablecontent.h b/src/scxml/qscxmlexecutablecontent.h
index d394940..cdf6b2b 100644
--- a/src/scxml/qscxmlexecutablecontent.h
+++ b/src/scxml/qscxmlexecutablecontent.h
@@ -81,6 +81,16 @@ struct ParameterInfo {
EvaluatorId expr;
StringId location;
};
+
+struct InvokeInfo {
+ StringId id;
+ StringId prefix;
+ StringId location;
+ StringId context;
+ EvaluatorId expr;
+ ContainerId finalize;
+ bool autoforward;
+};
#if defined(Q_CC_MSVC) || defined(Q_CC_GNU)
#pragma pack(pop)
#endif
diff --git a/src/scxml/qscxmlinvokableservice.cpp b/src/scxml/qscxmlinvokableservice.cpp
index f31cb48..9af6be7 100644
--- a/src/scxml/qscxmlinvokableservice.cpp
+++ b/src/scxml/qscxmlinvokableservice.cpp
@@ -38,41 +38,31 @@
****************************************************************************/
#include "qscxmlglobals_p.h"
-#include "qscxmlinvokableservice.h"
+#include "qscxmlinvokableservice_p.h"
#include "qscxmlstatemachine_p.h"
QT_BEGIN_NAMESPACE
-class QScxmlInvokableServicePrivate : public QObjectPrivate
-{
-public:
- QScxmlInvokableServicePrivate(QScxmlInvokableServiceFactory *factory,
- QScxmlStateMachine *parentStateMachine)
- : factory(factory), parentStateMachine(parentStateMachine)
- {}
-
- QScxmlInvokableServiceFactory *factory;
- QScxmlStateMachine *parentStateMachine;
-};
-
-static void registerMetatype()
+QScxmlInvokableServicePrivate::QScxmlInvokableServicePrivate(QScxmlStateMachine *parentStateMachine)
+ : parentStateMachine(parentStateMachine)
{
static int metaType = qRegisterMetaType<QScxmlInvokableService *>();
Q_UNUSED(metaType);
}
-QScxmlInvokableService::QScxmlInvokableService(QScxmlInvokableServiceFactory *factory,
- QScxmlStateMachine *parentStateMachine,
- QObject *parent) :
- QObject(*(new QScxmlInvokableServicePrivate(factory, parentStateMachine)), parent)
-{
- registerMetatype();
-}
+QScxmlInvokableServiceFactoryPrivate::QScxmlInvokableServiceFactoryPrivate(
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &namelist,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters)
+ : invokeInfo(invokeInfo)
+ , names(namelist)
+ , parameters(parameters)
+{}
-bool QScxmlInvokableService::autoforward() const
+QScxmlInvokableService::QScxmlInvokableService(QScxmlStateMachine *parentStateMachine,
+ QObject *parent) :
+ QObject(*(new QScxmlInvokableServicePrivate(parentStateMachine)), parent)
{
- Q_D(const QScxmlInvokableService);
- return d->factory->autoforward();
}
QScxmlStateMachine *QScxmlInvokableService::parentStateMachine() const
@@ -81,11 +71,8 @@ QScxmlStateMachine *QScxmlInvokableService::parentStateMachine() const
return d->parentStateMachine;
}
-void QScxmlInvokableService::finalize()
+void QScxmlInvokableService::finalize(QScxmlExecutableContent::ContainerId finalize)
{
- Q_D(QScxmlInvokableService);
- QScxmlExecutableContent::ContainerId finalize = d->factory->finalizeContent();
-
if (finalize != QScxmlExecutableContent::NoInstruction) {
auto psm = parentStateMachine();
qCDebug(qscxmlLog) << psm << "running finalize on event";
@@ -94,71 +81,16 @@ void QScxmlInvokableService::finalize()
}
}
-QScxmlInvokableServiceFactory *QScxmlInvokableService::factory() const
-{
- Q_D(const QScxmlInvokableService);
- return d->factory;
-}
-
QScxmlInvokableService::QScxmlInvokableService(QScxmlInvokableServicePrivate &dd, QObject *parent) :
QObject(dd, parent)
{
- registerMetatype();
}
-class QScxmlInvokableServiceFactoryPrivate
-{
-public:
- QScxmlInvokableServiceFactoryPrivate(QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
- const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool autoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize)
- : invokeLocation(invokeLocation)
- , srcexpr(srcexpr)
- , id(id)
- , idPrefix(idPrefix)
- , idlocation(idlocation)
- , namelist(namelist)
- , params(params)
- , finalize(finalize)
- , autoforward(autoforward)
- {}
-
- QScxmlExecutableContent::StringId invokeLocation;
- QScxmlExecutableContent::EvaluatorId srcexpr;
- QScxmlExecutableContent::StringId id;
- QScxmlExecutableContent::StringId idPrefix;
- QScxmlExecutableContent::StringId idlocation;
- QVector<QScxmlExecutableContent::StringId> namelist;
- QVector<QScxmlExecutableContent::ParameterInfo> params;
- QScxmlExecutableContent::ContainerId finalize;
- bool autoforward;
-};
-
QScxmlInvokableServiceFactory::QScxmlInvokableServiceFactory(
- QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
- const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool autoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize)
- : d(new QScxmlInvokableServiceFactoryPrivate(invokeLocation,
- srcexpr,
- id,
- idPrefix,
- idlocation,
- namelist,
- autoforward,
- params,
- finalize))
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters)
+ : d(new QScxmlInvokableServiceFactoryPrivate(invokeInfo, names, parameters))
{}
QScxmlInvokableServiceFactory::~QScxmlInvokableServiceFactory()
@@ -166,15 +98,31 @@ QScxmlInvokableServiceFactory::~QScxmlInvokableServiceFactory()
delete d;
}
-QString QScxmlInvokableServiceFactory::calculateSrcexpr(QScxmlStateMachine *parent, bool *ok) const
+QScxmlExecutableContent::InvokeInfo QScxmlInvokableServiceFactory::invokeInfo() const
+{
+ return d->invokeInfo;
+}
+
+QVector<QScxmlExecutableContent::ParameterInfo> QScxmlInvokableServiceFactory::parameters() const
+{
+ return d->parameters;
+}
+
+QVector<QScxmlExecutableContent::StringId> QScxmlInvokableServiceFactory::names() const
+{
+ return d->names;
+}
+
+QString QScxmlInvokableServiceFactoryPrivate::calculateSrcexpr(QScxmlStateMachine *parent,
+ bool *ok) const
{
Q_ASSERT(ok);
*ok = true;
auto dataModel = parent->dataModel();
- if (d->srcexpr != QScxmlExecutableContent::NoEvaluator) {
+ if (invokeInfo.expr != QScxmlExecutableContent::NoEvaluator) {
*ok = false;
- auto v = dataModel->evaluateToString(d->srcexpr, ok);
+ auto v = dataModel->evaluateToString(invokeInfo.expr, ok);
if (!*ok)
return QString();
return v;
@@ -183,31 +131,37 @@ QString QScxmlInvokableServiceFactory::calculateSrcexpr(QScxmlStateMachine *pare
return QString();
}
-QString QScxmlInvokableServiceFactory::calculateId(QScxmlStateMachine *parent, bool *ok) const
+QString QScxmlInvokableServicePrivate::calculateId(
+ QScxmlStateMachine *parent, const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ bool *ok) const
{
Q_ASSERT(ok);
*ok = true;
auto stateMachine = parent->tableData();
- if (d->id != QScxmlExecutableContent::NoString) {
- return stateMachine->string(d->id);
+ if (invokeInfo.id != QScxmlExecutableContent::NoString) {
+ return stateMachine->string(invokeInfo.id);
}
- const QString id
- = QScxmlStateMachinePrivate::generateSessionId(stateMachine->string(d->idPrefix));
+ const QString newId = QScxmlStateMachinePrivate::generateSessionId(
+ stateMachine->string(invokeInfo.prefix));
- if (d->idlocation != QScxmlExecutableContent::NoString) {
- auto idloc = stateMachine->string(d->idlocation);
- auto ctxt = stateMachine->string(d->invokeLocation);
- *ok = parent->dataModel()->setScxmlProperty(idloc, id, ctxt);
+ if (invokeInfo.location != QScxmlExecutableContent::NoString) {
+ auto idloc = stateMachine->string(invokeInfo.location);
+ auto ctxt = stateMachine->string(invokeInfo.context);
+ *ok = parent->dataModel()->setScxmlProperty(idloc, newId, ctxt);
if (!*ok)
return QString();
}
- return id;
+ return newId;
}
-QVariantMap QScxmlInvokableServiceFactory::calculateData(QScxmlStateMachine *parent, bool *ok) const
+QVariantMap QScxmlInvokableServicePrivate::calculateData(
+ QScxmlStateMachine *parent,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ bool *ok) const
{
Q_ASSERT(ok);
@@ -215,7 +169,7 @@ QVariantMap QScxmlInvokableServiceFactory::calculateData(QScxmlStateMachine *par
auto dataModel = parent->dataModel();
auto tableData = parent->tableData();
- for (const QScxmlExecutableContent::ParameterInfo &param : qAsConst(d->params)) {
+ for (const QScxmlExecutableContent::ParameterInfo &param : parameters) {
auto name = tableData->string(param.name);
if (param.expr != QScxmlExecutableContent::NoEvaluator) {
@@ -241,7 +195,7 @@ QVariantMap QScxmlInvokableServiceFactory::calculateData(QScxmlStateMachine *par
}
}
- for (QScxmlExecutableContent::StringId locid : qAsConst(d->namelist)) {
+ for (QScxmlExecutableContent::StringId locid : names) {
QString loc;
if (locid != QScxmlExecutableContent::NoString) {
loc = tableData->string(locid);
@@ -263,31 +217,9 @@ QVariantMap QScxmlInvokableServiceFactory::calculateData(QScxmlStateMachine *par
return result;
}
-bool QScxmlInvokableServiceFactory::autoforward() const
-{
- return d->autoforward;
-}
-
-QScxmlExecutableContent::ContainerId QScxmlInvokableServiceFactory::finalizeContent() const
-{
- return d->finalize;
-}
-
-class QScxmlScxmlServicePrivate : public QScxmlInvokableServicePrivate
-{
-public:
- QScxmlScxmlServicePrivate(QScxmlInvokableServiceFactory *factory,
- QScxmlStateMachine *stateMachine,
- QScxmlStateMachine *parentStateMachine);
- ~QScxmlScxmlServicePrivate();
-
- QScxmlStateMachine *stateMachine;
-};
-
-QScxmlScxmlServicePrivate::QScxmlScxmlServicePrivate(
- QScxmlInvokableServiceFactory *factory, QScxmlStateMachine *stateMachine,
- QScxmlStateMachine *parentStateMachine) :
- QScxmlInvokableServicePrivate(factory, parentStateMachine), stateMachine(stateMachine)
+QScxmlScxmlServicePrivate::QScxmlScxmlServicePrivate(QScxmlStateMachine *stateMachine,
+ QScxmlStateMachine *parentStateMachine) :
+ QScxmlInvokableServicePrivate(parentStateMachine), stateMachine(stateMachine)
{}
QScxmlScxmlServicePrivate::~QScxmlScxmlServicePrivate()
@@ -295,26 +227,27 @@ QScxmlScxmlServicePrivate::~QScxmlScxmlServicePrivate()
delete stateMachine;
}
-QScxmlScxmlService::QScxmlScxmlService(QScxmlInvokableServiceFactory *factory,
- QScxmlStateMachine *stateMachine,
+QScxmlScxmlService::QScxmlScxmlService(QScxmlStateMachine *stateMachine,
QScxmlStateMachine *parentStateMachine,
QObject *parent)
- : QScxmlInvokableService(*(new QScxmlScxmlServicePrivate(factory, stateMachine,
- parentStateMachine)), parent)
+ : QScxmlInvokableService(*(new QScxmlScxmlServicePrivate(stateMachine, parentStateMachine)),
+ parent)
{
QScxmlStateMachinePrivate::get(stateMachine)->m_parentStateMachine = parentStateMachine;
}
-bool QScxmlScxmlService::start()
+bool QScxmlScxmlService::start(const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters,
+ const QVector<QScxmlExecutableContent::StringId> &names)
{
Q_D(QScxmlScxmlService);
qCDebug(qscxmlLog) << parentStateMachine() << "preparing to start" << d->stateMachine;
bool ok = false;
- auto id = factory()->calculateId(parentStateMachine(), &ok);
+ auto id = d->calculateId(parentStateMachine(), invokeInfo, &ok);
if (!ok)
return false;
- auto data = factory()->calculateData(parentStateMachine(), &ok);
+ auto data = d->calculateData(parentStateMachine(), parameters, names, &ok);
if (!ok)
return false;
@@ -355,31 +288,31 @@ QScxmlStateMachine *QScxmlScxmlService::stateMachine() const
}
QScxmlScxmlServiceFactory::QScxmlScxmlServiceFactory(
- QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
- const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool doAutoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize)
- : QScxmlInvokableServiceFactory(invokeLocation, srcexpr, id, idPrefix, idlocation, namelist,
- doAutoforward, params, finalize)
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters)
+ : QScxmlInvokableServiceFactory(invokeInfo, names, parameters)
{}
QScxmlScxmlService *QScxmlScxmlServiceFactory::invokeStatic(QScxmlStateMachine *childStateMachine,
QScxmlStateMachine *parentStateMachine)
{
QScxmlStateMachinePrivate::get(childStateMachine)->setIsInvoked(true);
- return new QScxmlScxmlService(this, childStateMachine, parentStateMachine);
+ return new QScxmlScxmlService(childStateMachine, parentStateMachine);
}
+QScxmlDynamicScxmlServiceFactory::QScxmlDynamicScxmlServiceFactory(
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters)
+ : QScxmlScxmlServiceFactory(invokeInfo, names, parameters)
+{}
+
QScxmlInvokableService *QScxmlDynamicScxmlServiceFactory::invoke(
QScxmlStateMachine *parentStateMachine)
{
bool ok = true;
- auto srcexpr = calculateSrcexpr(parentStateMachine, &ok);
+ auto srcexpr = d->calculateSrcexpr(parentStateMachine, &ok);
if (!ok)
return Q_NULLPTR;
diff --git a/src/scxml/qscxmlinvokableservice.h b/src/scxml/qscxmlinvokableservice.h
index e7bec4e..6efc07d 100644
--- a/src/scxml/qscxmlinvokableservice.h
+++ b/src/scxml/qscxmlinvokableservice.h
@@ -47,7 +47,6 @@ QT_BEGIN_NAMESPACE
class QScxmlEvent;
class QScxmlStateMachine;
-class QScxmlInvokableServiceFactory;
class QScxmlInvokableServicePrivate;
class Q_SCXML_EXPORT QScxmlInvokableService : public QObject
@@ -55,27 +54,25 @@ class Q_SCXML_EXPORT QScxmlInvokableService : public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(QScxmlInvokableService)
Q_PROPERTY(QScxmlStateMachine *parentStateMachine READ parentStateMachine CONSTANT)
- Q_PROPERTY(bool autoforward READ autoforward CONSTANT)
Q_PROPERTY(QString id READ id CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
public:
- QScxmlInvokableService(QScxmlInvokableServiceFactory *factory,
- QScxmlStateMachine *parentStateMachine,
+ QScxmlInvokableService(QScxmlStateMachine *parentStateMachine,
QObject *parent = nullptr);
- bool autoforward() const;
QScxmlStateMachine *parentStateMachine() const;
- virtual bool start() = 0;
+ virtual bool start(const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters,
+ const QVector<QScxmlExecutableContent::StringId> &names) = 0;
virtual QString id() const = 0;
virtual QString name() const = 0;
virtual void postEvent(QScxmlEvent *event) = 0;
- void finalize();
+ void finalize(QScxmlExecutableContent::ContainerId finalize);
protected:
- QScxmlInvokableServiceFactory *factory() const;
QScxmlInvokableService(QScxmlInvokableServicePrivate &dd, QObject *parent = nullptr);
};
@@ -83,27 +80,18 @@ class QScxmlInvokableServiceFactoryPrivate;
class Q_SCXML_EXPORT QScxmlInvokableServiceFactory
{
public:
- QScxmlInvokableServiceFactory(QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
- const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool autoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalizeContent);
+ QScxmlInvokableServiceFactory(
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters);
virtual ~QScxmlInvokableServiceFactory();
virtual QScxmlInvokableService *invoke(QScxmlStateMachine *parentStateMachine) = 0;
+ QScxmlExecutableContent::InvokeInfo invokeInfo() const;
+ QVector<QScxmlExecutableContent::ParameterInfo> parameters() const;
+ QVector<QScxmlExecutableContent::StringId> names() const;
-public: // callbacks from the service:
- QString calculateSrcexpr(QScxmlStateMachine *parent, bool *ok) const;
- QString calculateId(QScxmlStateMachine *parent, bool *ok) const;
- QVariantMap calculateData(QScxmlStateMachine *parent, bool *ok) const;
- bool autoforward() const;
- QScxmlExecutableContent::ContainerId finalizeContent() const;
-
-private:
+protected:
QScxmlInvokableServiceFactoryPrivate *d;
};
@@ -114,10 +102,13 @@ class Q_SCXML_EXPORT QScxmlScxmlService: public QScxmlInvokableService
Q_DECLARE_PRIVATE(QScxmlScxmlService)
Q_PROPERTY(QScxmlStateMachine *stateMachine READ stateMachine CONSTANT)
public:
- QScxmlScxmlService(QScxmlInvokableServiceFactory *factory, QScxmlStateMachine *stateMachine,
- QScxmlStateMachine *parentStateMachine, QObject *parent = nullptr);
+ QScxmlScxmlService(QScxmlStateMachine *stateMachine,
+ QScxmlStateMachine *parentStateMachine,
+ QObject *parent = nullptr);
- bool start() Q_DECL_OVERRIDE;
+ bool start(const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters,
+ const QVector<QScxmlExecutableContent::StringId> &names) Q_DECL_OVERRIDE;
QString id() const Q_DECL_OVERRIDE;
QString name() const Q_DECL_OVERRIDE;
void postEvent(QScxmlEvent *event) Q_DECL_OVERRIDE;
@@ -128,15 +119,9 @@ public:
class Q_SCXML_EXPORT QScxmlScxmlServiceFactory: public QScxmlInvokableServiceFactory
{
public:
- QScxmlScxmlServiceFactory(QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
- const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool doAutoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize);
+ QScxmlScxmlServiceFactory(const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters);
protected:
QScxmlScxmlService *invokeDynamic(QScxmlStateMachine *parentStateMachine,
@@ -149,17 +134,11 @@ template<class T>
class QScxmlStaticScxmlServiceFactory: public QScxmlScxmlServiceFactory
{
public:
- QScxmlStaticScxmlServiceFactory(QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
- const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool doAutoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize)
- : QScxmlScxmlServiceFactory(invokeLocation, QScxmlExecutableContent::NoInstruction,
- id, idPrefix, idlocation, namelist, doAutoforward,
- params, finalize)
+ QScxmlStaticScxmlServiceFactory(
+ const QScxmlExecutableContent::InvokeInfo &newInvokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &newNameList,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &newParameters)
+ : QScxmlScxmlServiceFactory(newInvokeInfo, newNameList, newParameters)
{}
QScxmlInvokableService *invoke(QScxmlStateMachine *parentStateMachine) Q_DECL_OVERRIDE
@@ -171,18 +150,10 @@ public:
class Q_SCXML_EXPORT QScxmlDynamicScxmlServiceFactory: public QScxmlScxmlServiceFactory
{
public:
- QScxmlDynamicScxmlServiceFactory(QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
- const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool doAutoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize)
- : QScxmlScxmlServiceFactory(invokeLocation, srcexpr, id, idPrefix, idlocation,
- namelist, doAutoforward, params, finalize)
- {}
+ QScxmlDynamicScxmlServiceFactory(
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters);
QScxmlInvokableService *invoke(QScxmlStateMachine *parentStateMachine) Q_DECL_OVERRIDE;
};
diff --git a/src/scxml/qscxmlinvokableservice_p.h b/src/scxml/qscxmlinvokableservice_p.h
new file mode 100644
index 0000000..52bd6d0
--- /dev/null
+++ b/src/scxml/qscxmlinvokableservice_p.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtScxml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSCXMLINVOKABLESERVICE_P_H
+#define QSCXMLINVOKABLESERVICE_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 "qscxmlinvokableservice.h"
+#include <QtCore/private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QScxmlInvokableServicePrivate : public QObjectPrivate
+{
+public:
+ QScxmlInvokableServicePrivate(QScxmlStateMachine *parentStateMachine);
+
+ QString calculateId(QScxmlStateMachine *parent,
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo, bool *ok) const;
+ QVariantMap calculateData(QScxmlStateMachine *parent,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ bool *ok) const;
+
+ QScxmlStateMachine *parentStateMachine;
+};
+
+class QScxmlInvokableServiceFactoryPrivate
+{
+public:
+ QScxmlInvokableServiceFactoryPrivate(
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters);
+
+ QString calculateSrcexpr(QScxmlStateMachine *parent, bool *ok) const;
+
+ QScxmlExecutableContent::InvokeInfo invokeInfo;
+ QVector<QScxmlExecutableContent::StringId> names;
+ QVector<QScxmlExecutableContent::ParameterInfo> parameters;
+};
+
+class QScxmlScxmlServicePrivate : public QScxmlInvokableServicePrivate
+{
+public:
+ QScxmlScxmlServicePrivate(QScxmlStateMachine *stateMachine,
+ QScxmlStateMachine *parentStateMachine);
+ ~QScxmlScxmlServicePrivate();
+
+ QScxmlStateMachine *stateMachine;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSCXMLINVOKABLESERVICE_P_H
diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp
index c11898a..ef5a312 100644
--- a/src/scxml/qscxmlstatemachine.cpp
+++ b/src/scxml/qscxmlstatemachine.cpp
@@ -449,7 +449,7 @@ void QScxmlStateMachinePrivate::addService(int invokingState)
continue; // service failed to start
const QString serviceName = service->name();
m_invokedServices[size_t(id)] = { invokingState, service, serviceName };
- service->start();
+ service->start(factory->invokeInfo(), factory->parameters(), factory->names());
}
emitInvokedServicesChanged();
}
@@ -526,16 +526,17 @@ void QScxmlStateMachinePrivate::postEvent(QScxmlEvent *event)
Q_Q(QScxmlStateMachine);
if (!event->name().startsWith(QStringLiteral("done.invoke."))) {
- for (auto invokedService : m_invokedServices) {
- auto service = invokedService.service;
+ for (int id = 0, end = static_cast<int>(m_invokedServices.size()); id != end; ++id) {
+ auto service = m_invokedServices[id].service;
if (service == nullptr)
continue;
+ auto factory = serviceFactory(id);
if (event->invokeId() == service->id()) {
setEvent(event);
- service->finalize();
+ service->finalize(factory->invokeInfo().finalize);
resetEvent();
}
- if (service->autoforward()) {
+ if (factory->invokeInfo().autoforward) {
qCDebug(qscxmlLog) << q << "auto-forwarding event" << event->name()
<< "from" << q->name()
<< "to child" << service->id();
diff --git a/src/scxml/qscxmlstatemachine.h b/src/scxml/qscxmlstatemachine.h
index 0750323..626dc1c 100644
--- a/src/scxml/qscxmlstatemachine.h
+++ b/src/scxml/qscxmlstatemachine.h
@@ -333,7 +333,7 @@ public Q_SLOTS:
protected: // methods for friends:
friend class QScxmlDataModel;
friend class QScxmlEventBuilder;
- friend class QScxmlInvokableServiceFactory;
+ friend class QScxmlInvokableServicePrivate;
friend class QScxmlExecutionEngine;
#ifndef Q_QDOC
diff --git a/src/scxml/qscxmltabledata.cpp b/src/scxml/qscxmltabledata.cpp
index 3b9cabd..2457840 100644
--- a/src/scxml/qscxmltabledata.cpp
+++ b/src/scxml/qscxmltabledata.cpp
@@ -273,11 +273,16 @@ protected: // visitor
auto srcexpr = createEvaluatorString(QStringLiteral("invoke"),
QStringLiteral("srcexpr"),
invoke->srcexpr);
- const int factoryId = createFactoryId(
- ctxt, srcexpr, addString(invoke->id),
- addString(state->id + QStringLiteral(".session-")),
- addString(invoke->idLocation), namelist, invoke->autoforward, params,
- finalize, invoke->content);
+ QScxmlExecutableContent::InvokeInfo invokeInfo;
+ invokeInfo.id = addString(invoke->id);
+ invokeInfo.prefix = addString(state->id + QStringLiteral(".session-"));
+ invokeInfo.location = addString(invoke->idLocation);
+ invokeInfo.context = ctxt;
+ invokeInfo.expr = srcexpr;
+ invokeInfo.finalize = finalize;
+ invokeInfo.autoforward = invoke->autoforward;
+ const int factoryId = createFactoryId(invokeInfo, namelist, params,
+ invoke->content);
Q_ASSERT(factoryId >= 0);
factoryIds.append(factoryId);
m_stateTable.maxServiceId = std::max(m_stateTable.maxServiceId, factoryId);
diff --git a/src/scxml/qscxmltabledata_p.h b/src/scxml/qscxmltabledata_p.h
index 85fa91c..2c825db 100644
--- a/src/scxml/qscxmltabledata_p.h
+++ b/src/scxml/qscxmltabledata_p.h
@@ -71,15 +71,9 @@ class Q_SCXML_EXPORT GeneratedTableData: public QScxmlTableData
{
public:
typedef std::function<
- int(QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
+ int(const QScxmlExecutableContent::InvokeInfo &invokeInfo,
const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool autoforward,
const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize,
QSharedPointer<DocumentModel::ScxmlDocument> content)
> CreateFactoryId;
diff --git a/src/scxml/scxml.pro b/src/scxml/scxml.pro
index 2af47bf..1f5bc25 100644
--- a/src/scxml/scxml.pro
+++ b/src/scxml/scxml.pro
@@ -28,6 +28,7 @@ HEADERS += \
qscxmlcppdatamodel_p.h \
qscxmlcppdatamodel.h \
qscxmlerror.h \
+ qscxmlinvokableservice_p.h \
qscxmlinvokableservice.h \
qscxmltabledata.h \
qscxmltabledata_p.h \
diff --git a/tools/qscxmlc/data.t b/tools/qscxmlc/data.t
index 2c23de0..a813d01 100644
--- a/tools/qscxmlc/data.t
+++ b/tools/qscxmlc/data.t
@@ -55,6 +55,26 @@ struct ${classname}::Data: private QScxmlTableData {
return p;
}
+ static QScxmlExecutableContent::InvokeInfo invoke(
+ QScxmlExecutableContent::StringId id,
+ QScxmlExecutableContent::StringId prefix,
+ QScxmlExecutableContent::EvaluatorId expr,
+ QScxmlExecutableContent::StringId location,
+ QScxmlExecutableContent::StringId context,
+ QScxmlExecutableContent::ContainerId finalize,
+ bool autoforward)
+ {
+ QScxmlExecutableContent::InvokeInfo i;
+ i.id = id;
+ i.prefix = prefix;
+ i.expr = expr;
+ i.location = location;
+ i.context = context;
+ i.finalize = finalize;
+ i.autoforward = autoforward;
+ return i;
+ }
+
static qint32 theInstructions[];
static QScxmlExecutableContent::StringId dataIds[];
static QScxmlExecutableContent::EvaluatorInfo evaluators[];
diff --git a/tools/qscxmlc/scxmlcppdumper.cpp b/tools/qscxmlc/scxmlcppdumper.cpp
index 83a9886..c29ef90 100644
--- a/tools/qscxmlc/scxmlcppdumper.cpp
+++ b/tools/qscxmlc/scxmlcppdumper.cpp
@@ -378,30 +378,28 @@ void generateCppDataModelEvaluators(const GeneratedTableData::DataModelInfo &inf
int createFactoryId(QStringList &factories, const QString &className,
const QString &namespacePrefix,
- QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool autoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters,
bool useCxx11)
{
const int idx = factories.size();
QString line = QStringLiteral("case %1: return new ").arg(QString::number(idx));
- if (srcexpr == QScxmlExecutableContent::NoInstruction) {
- line += QStringLiteral("QScxmlStaticScxmlServiceFactory< %1::%2 >(%3, ")
- .arg(namespacePrefix, className, QString::number(invokeLocation));
+ if (invokeInfo.expr == QScxmlExecutableContent::NoInstruction) {
+ line += QStringLiteral("QScxmlStaticScxmlServiceFactory< %1::%2 >(")
+ .arg(namespacePrefix, className);
} else {
- line += QStringLiteral("QScxmlDynamicScxmlServiceFactory(%1, %2, ")
- .arg(invokeLocation).arg(srcexpr);
- }
- line += QStringLiteral("%1, ").arg(QString::number(id));
- line += QStringLiteral("%1, ").arg(QString::number(idPrefix));
- line += QStringLiteral("%1, ").arg(QString::number(idlocation));
+ line += QStringLiteral("QScxmlDynamicScxmlServiceFactory(");
+ }
+ line += QStringLiteral("invoke(%1, %2, %3, %4, %5, %6, %7), ")
+ .arg(QString::number(invokeInfo.id),
+ QString::number(invokeInfo.prefix),
+ QString::number(invokeInfo.expr),
+ QString::number(invokeInfo.location),
+ QString::number(invokeInfo.context),
+ QString::number(invokeInfo.finalize))
+ .arg(invokeInfo.autoforward ? QStringLiteral("true") : QStringLiteral("false"));
{
QStringList l;
for (auto name : namelist) {
@@ -410,21 +408,18 @@ int createFactoryId(QStringList &factories, const QString &className,
line += QStringLiteral("%1, ").arg(
createVector(QStringLiteral("QScxmlExecutableContent::StringId"), l, useCxx11));
}
- line += QStringLiteral("%1, ").arg(autoforward ? QStringLiteral("true")
- : QStringLiteral("false"));
{
QStringList l;
- for (const auto &param : params) {
+ for (const auto &parameter : parameters) {
l += QStringLiteral("param(%1, %2, %3)")
- .arg(QString::number(param.name),
- QString::number(param.expr),
- QString::number(param.location));
+ .arg(QString::number(parameter.name),
+ QString::number(parameter.expr),
+ QString::number(parameter.location));
}
- line += QStringLiteral("%1, ").arg(
+ line += QStringLiteral("%1);").arg(
createVector(QStringLiteral("QScxmlExecutableContent::ParameterInfo"), l,
useCxx11));
}
- line += QStringLiteral("%1);").arg(finalize);
factories.append(line);
return idx;
@@ -460,23 +455,16 @@ void CppDumper::dump(TranslationUnit *unit)
auto metaDataInfo = &metaDataInfos[i];
GeneratedTableData::build(doc, &tables[i], metaDataInfo, &dataModelInfos[i],
[this, &factories, i, &classnameForDocument, &namespacePrefix](
- QScxmlExecutableContent::StringId invokeLocation,
- QScxmlExecutableContent::EvaluatorId srcexpr,
- QScxmlExecutableContent::StringId id,
- QScxmlExecutableContent::StringId idPrefix,
- QScxmlExecutableContent::StringId idlocation,
- const QVector<QScxmlExecutableContent::StringId> &namelist,
- bool autoforward,
- const QVector<QScxmlExecutableContent::ParameterInfo> &params,
- QScxmlExecutableContent::ContainerId finalize,
+ const QScxmlExecutableContent::InvokeInfo &invokeInfo,
+ const QVector<QScxmlExecutableContent::StringId> &names,
+ const QVector<QScxmlExecutableContent::ParameterInfo> &parameters,
const QSharedPointer<DocumentModel::ScxmlDocument> &content) -> int {
QString className;
- if (srcexpr == QScxmlExecutableContent::NoInstruction) {
+ if (invokeInfo.expr == QScxmlExecutableContent::NoInstruction) {
className = mangleIdentifier(classnameForDocument.value(content.data()));
}
- return createFactoryId(factories[i], className, namespacePrefix, invokeLocation,
- srcexpr, id, idPrefix, idlocation, namelist, autoforward, params,
- finalize, m_translationUnit->useCxx11);
+ return createFactoryId(factories[i], className, namespacePrefix,
+ invokeInfo, names, parameters, m_translationUnit->useCxx11);
});
classNames.append(mangleIdentifier(classnameForDocument.value(doc)));
}