| 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 QQUICKWORKERSCRIPT_P_H |
| 5 | #define QQUICKWORKERSCRIPT_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 <qqml.h> |
| 19 | |
| 20 | #include <QtQmlWorkerScript/private/qtqmlworkerscriptglobal_p.h> |
| 21 | #include <QtQml/qqmlparserstatus.h> |
| 22 | #include <QtCore/qthread.h> |
| 23 | #include <QtQml/qjsvalue.h> |
| 24 | #include <QtCore/qurl.h> |
| 25 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | |
| 29 | class QQuickWorkerScript; |
| 30 | class QQuickWorkerScriptEnginePrivate; |
| 31 | class QQuickWorkerScriptEngine : public QThread |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | public: |
| 35 | QQuickWorkerScriptEngine(QQmlEngine *parent = nullptr); |
| 36 | ~QQuickWorkerScriptEngine(); |
| 37 | |
| 38 | int registerWorkerScript(QQuickWorkerScript *); |
| 39 | void removeWorkerScript(int); |
| 40 | void executeUrl(int, const QUrl &); |
| 41 | void sendMessage(int, const QByteArray &); |
| 42 | |
| 43 | protected: |
| 44 | void run() override; |
| 45 | |
| 46 | private: |
| 47 | QQuickWorkerScriptEnginePrivate *d; |
| 48 | }; |
| 49 | |
| 50 | class Q_QMLWORKERSCRIPT_EXPORT QQuickWorkerScript : public QObject, public QQmlParserStatus |
| 51 | { |
| 52 | Q_OBJECT |
| 53 | Q_DISABLE_COPY_MOVE(QQuickWorkerScript) |
| 54 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) |
| 55 | Q_PROPERTY(bool ready READ ready NOTIFY readyChanged REVISION(2, 15)) |
| 56 | |
| 57 | QML_NAMED_ELEMENT(WorkerScript); |
| 58 | QML_ADDED_IN_VERSION(2, 0) |
| 59 | |
| 60 | Q_INTERFACES(QQmlParserStatus) |
| 61 | public: |
| 62 | QQuickWorkerScript(QObject *parent = nullptr); |
| 63 | ~QQuickWorkerScript(); |
| 64 | |
| 65 | QUrl source() const; |
| 66 | void setSource(const QUrl &); |
| 67 | |
| 68 | bool ready() const; |
| 69 | |
| 70 | public Q_SLOTS: |
| 71 | void sendMessage(QQmlV4FunctionPtr); |
| 72 | |
| 73 | Q_SIGNALS: |
| 74 | void sourceChanged(); |
| 75 | Q_REVISION(2, 15) void readyChanged(); |
| 76 | void message(const QJSValue &messageObject); |
| 77 | |
| 78 | protected: |
| 79 | void classBegin() override; |
| 80 | void componentComplete() override; |
| 81 | bool event(QEvent *) override; |
| 82 | |
| 83 | private: |
| 84 | QQuickWorkerScriptEngine *engine(); |
| 85 | QQuickWorkerScriptEngine *m_engine; |
| 86 | int m_scriptId; |
| 87 | QUrl m_source; |
| 88 | bool m_componentComplete; |
| 89 | }; |
| 90 | |
| 91 | QT_END_NAMESPACE |
| 92 | |
| 93 | #endif // QQUICKWORKERSCRIPT_P_H |
| 94 |
