summaryrefslogtreecommitdiffstats
path: root/src/qscxmllib/scxmlevent_p.h
blob: 128a80ab607375753f1338ea408003eb162e565d (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
104
105
/****************************************************************************
 **
 ** Copyright (c) 2015 Digia Plc
 ** For any questions to Digia, please use contact form at http://qt.digia.com/
 **
 ** All Rights Reserved.
 **
 ** NOTICE: All information contained herein is, and remains
 ** the property of Digia Plc and its suppliers,
 ** if any. The intellectual and technical concepts contained
 ** herein are proprietary to Digia Plc
 ** and its suppliers and may be covered by Finnish and Foreign Patents,
 ** patents in process, and are protected by trade secret or copyright law.
 ** Dissemination of this information or reproduction of this material
 ** is strictly forbidden unless prior written permission is obtained
 ** from Digia Plc.
 ****************************************************************************/

#ifndef SCXMLEVENT_P_H
#define SCXMLEVENT_P_H

#include "scxmlevent.h"
#include "scxmlstatetable.h"
#include "executablecontent_p.h"

#include <QAtomicInt>

namespace Scxml {

class EventBuilder
{
    StateTable* table = nullptr;
    ExecutableContent::StringId instructionLocation;
    QByteArray event;
    EvaluatorId eventexpr = NoEvaluator;
    QString contents;
    EvaluatorId contentExpr = NoEvaluator;
    const ExecutableContent::Array<ExecutableContent::Param> *params = nullptr;
    ScxmlEvent::EventType eventType = ScxmlEvent::External;
    QByteArray id;
    QString idLocation;
    QString target;
    EvaluatorId targetexpr = NoEvaluator;
    QString type;
    EvaluatorId typeexpr = NoEvaluator;
    const ExecutableContent::Array<ExecutableContent::StringId> *namelist = nullptr;

    static QAtomicInt idCounter;
    QByteArray generateId() const
    {
        QByteArray id = QByteArray::number(++idCounter);
        id.prepend("id-");
        return id;
    }

    EventBuilder()
    {}

public:
    EventBuilder(StateTable *table, const QString &eventName, const ExecutableContent::DoneData *doneData)
        : table(table)
    {
        Q_ASSERT(doneData);
        instructionLocation = doneData->location;
        event = eventName.toUtf8();
        contents = table->tableData()->string(doneData->contents);
        contentExpr = doneData->expr;
        params = &doneData->params;
    }

    EventBuilder(StateTable *table, ExecutableContent::Send &send)
        : table(table)
        , instructionLocation(send.instructionLocation)
        , event(table->tableData()->byteArray(send.event))
        , eventexpr(send.eventexpr)
        , contents(table->tableData()->string(send.content))
        , params(send.params())
        , id(table->tableData()->byteArray(send.id))
        , idLocation(table->tableData()->string(send.idLocation))
        , target(table->tableData()->string(send.target))
        , targetexpr(send.targetexpr)
        , type(table->tableData()->string(send.type))
        , typeexpr(send.typeexpr)
        , namelist(&send.namelist)
    {}

    ScxmlEvent *operator()() { return buildEvent(); }

    ScxmlEvent *buildEvent();

    static ScxmlEvent *errorEvent(const QByteArray &name, const QByteArray &sendid)
    {
        EventBuilder event;
        event.event = name;
        event.eventType = ScxmlEvent::Platform; // Errors are platform events. See e.g. test331.
        // _event.data == null, see test528
        event.id = sendid;
        return event();
    }
};

} // Scxml namespace

#endif // SCXMLEVENT_P_H