25 #ifndef ZSCRIPTTHREAD_H 26 #define ZSCRIPTTHREAD_H 79 Q_ENUM(AlertConversion)
135 void setInitScript(const QString& script);
163 void execComplete(qulonglong requestID, QVariant result, QVariant userData);
199 void alert(const QString signalID, QVariant payload);
236 void execScript(qulonglong requestID, const QString& script, QVariantMap userData = QVariantMap());
398 #endif // ZSCRIPTTHREAD_H void execComplete(qulonglong requestID, QVariant result, QVariant userData)
Sent when an asynchronous background script execution has completed.
#define ZBL_DECLARE_LOGGED_OBJECT
void finished()
Sent from the associated thread right before it finishes executing.
QVariant m_initError
The error message generated when running the initScript, or an empty string if initScript was success...
static void registerType()
Registers ZScriptThread as a QML type.
enum Zbl::ZScriptThread::alertConversion AlertConversion
void setInitScript(const QString &script)
void onWorkerExecComplete(qulonglong requestID, QString result, QString userData)
Receives and propagates the ZScriptWorker::execComplete signal.
void execScript(qulonglong requestID, const QString &script, QVariantMap userData=QVariantMap())
Execute the specified javascript program fragment asynchronously in the background thread's javascrip...
void onFinished()
Called when QThread event loop has exited.
Q_INVOKABLE bool isInterrupted() const
Calls the QThread::isInterruptionRequested() method for this thread. Can be used to determine if this...
ZScriptThread(QObject *parent=nullptr)
bool ready
True if thread is ready to run scripts, false otherwise.
A thread class to support Zuble's background Javascript processing.
A class for executing javascript programs in a background worker thread.
void quit()
Causes the thread to stop processing events and exit the event loop.
static QString variantToJson(QVariant &var)
Converts QVariant to json string.
Q_INVOKABLE void onThreadAlert(QString signalID, QString payload, int conversion)
Called by ZblApp in background thread to trigger ZScriptThread::alert signal in foreground thread...
void beginShutdown()
Sent when the javascript thread is about to begin it's shutdown sequence.
ZScriptWorker * m_worker
Script worker object maintains this thread's javascript context.
void onStarted()
Called when QThread has started running.
The primary QML API to the Zuble plugin library. Zuble applications access this object through the ja...
void readyChanged()
Sent when ready property value changes.
static QVariant jsonToVariant(const QString &json)
Converts json string to QVariant.
void sendInterruptRequest()
Calls the QThread::requestInterruption() method for this thread. If the thread is checking Zbl...
bool m_initReady
true if thread initialization is complete, false otherwise
void completeChanged()
Sent when complete property value changes.
void destroyThread()
Stops the QThread, waits for it to exit and then deletes it and the ZScriptWorker object...
void alert(const QString signalID, QVariant payload)
Background scripts send this signal by calling the ZblApp::alert() method.
bool waitThreadComplete(unsigned long time=ULONG_MAX)
Blocks the current thread until the background thread finishes running its event loop or a timeout oc...
ZBL_DECLARE_LOGGED_OBJECT QThread * m_thread
QThread object in which ZScriptWorker object will run.
QString m_initScript
Thread's javascript context will be initialized by running this script.
void initComplete(QVariant status)
Sent when the javascript execution environment has completed initialization and is ready for use...
bool m_threadCompleted
true if thread has been shut down, false otherwise
void start()
Causes the tread to start execution.
QVariant initError
The error message generated when executing the initScript program, or the empty string if no error wa...
QString initScript
Thread initialization script.
bool complete
True when thread has been shut down, false otherwise.