WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
Public Slots | Signals | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Zbl::ZScriptWorker Class Reference

A class for executing javascript programs in a background worker thread. More...

#include <ZScriptWorker.h>

Inheritance diagram for Zbl::ZScriptWorker:
Inheritance graph
[legend]
Collaboration diagram for Zbl::ZScriptWorker:
Collaboration graph
[legend]

Public Slots

void execScript (qulonglong requestID, const QString &script, QString userData=QString())
 Executes the specified javascript program in the current thread and sends the execComplete signal when processing is complete. More...
 
void onStarted ()
 Called when QThread has started running. More...
 

Signals

void execComplete (qulonglong requestID, QString result, QString userData)
 Sent when the a javascript program execution started with execScript() has been completed. More...
 

Public Member Functions

 ZScriptWorker (ZScriptThread *container=nullptr, QObject *parent=nullptr)
 
virtual ~ZScriptWorker ()
 

Protected Member Functions

void initGlobalSpace ()
 

Protected Attributes

QJSEngine * m_engine
 The javascript engine for background processing. More...
 
QString m_script
 The most recent script that was executed. More...
 
QJSValue m_result
 Result returned by the most recent script execution. More...
 
QJSValue m_error
 A template javascript Error object. More...
 
ZblAppm_app
 An object to represent the running Zuble application. More...
 
ZblJsonHelperm_json
 An object to perform QJSValue/JSON data conversions on the fly. More...
 

Friends

class ZScriptThread
 

Detailed Description

A class for executing javascript programs in a background worker thread.

This class executes in the background thread and encapsulates the QJSEngine instance associated with the background javascript program. As such it holds the javascript program execution state.

Definition at line 51 of file ZScriptWorker.h.

Constructor & Destructor Documentation

◆ ZScriptWorker()

Zbl::ZScriptWorker::ZScriptWorker ( ZScriptThread container = nullptr,
QObject *  parent = nullptr 
)
explicit

Definition at line 43 of file ZScriptWorker.cpp.

◆ ~ZScriptWorker()

Zbl::ZScriptWorker::~ZScriptWorker ( )
virtual

Definition at line 54 of file ZScriptWorker.cpp.

Member Function Documentation

◆ execComplete

void Zbl::ZScriptWorker::execComplete ( qulonglong  requestID,
QString  result,
QString  userData 
)
signal

Sent when the a javascript program execution started with execScript() has been completed.

Parameters
requestIDuser-defined integer value that was passed to execScript()
resultThe javascript program execution result value in JSON format. Should be a string array or an object. Other data types won't survive JSON conversion.

When executing a function call this will be the function return value. When JSON conversion fails this will be undefined.

An Error object is returned when an error has occurred during script processing or execution.

Parameters
userDatauser-defined JSON string that was passed to execScript(). Contents may have been modified by script execution.

This may be used to hold context over a sequence of multiple script executions that are working on the same data set. Simply pass the userData object to each call to execScript() that was returned by the previous execComplete for that data set.

Referenced by execScript(), and Zbl::ZScriptThread::ZScriptThread().

◆ execScript

void Zbl::ZScriptWorker::execScript ( qulonglong  requestID,
const QString &  script,
QString  userData = QString() 
)
slot

Executes the specified javascript program in the current thread and sends the execComplete signal when processing is complete.

Parameters
scriptHolds a string containing the javascript program to execute.
userDatapassed to the script

Definition at line 69 of file ZScriptWorker.cpp.

◆ initGlobalSpace()

void Zbl::ZScriptWorker::initGlobalSpace ( )
protected

Definition at line 59 of file ZScriptWorker.cpp.

Referenced by ZScriptWorker().

◆ onStarted

void Zbl::ZScriptWorker::onStarted ( )
slot

Called when QThread has started running.

Definition at line 64 of file ZScriptWorker.cpp.

Referenced by Zbl::ZScriptThread::ZScriptThread().

Friends And Related Function Documentation

◆ ZScriptThread

friend class ZScriptThread
friend

Definition at line 53 of file ZScriptWorker.h.

Member Data Documentation

◆ m_app

ZblApp* Zbl::ZScriptWorker::m_app
protected

An object to represent the running Zuble application.

Definition at line 147 of file ZScriptWorker.h.

Referenced by execScript(), initGlobalSpace(), and ZScriptWorker().

◆ m_engine

QJSEngine* Zbl::ZScriptWorker::m_engine
protected

The javascript engine for background processing.

Definition at line 119 of file ZScriptWorker.h.

Referenced by execScript(), initGlobalSpace(), and ZScriptWorker().

◆ m_error

QJSValue Zbl::ZScriptWorker::m_error
protected

A template javascript Error object.

We make copies of this to propagate errors that don't originate in the QJSEngine itself.

Definition at line 141 of file ZScriptWorker.h.

Referenced by ZScriptWorker().

◆ m_json

ZblJsonHelper* Zbl::ZScriptWorker::m_json
protected

An object to perform QJSValue/JSON data conversions on the fly.

Definition at line 154 of file ZScriptWorker.h.

Referenced by execScript(), ZScriptWorker(), and ~ZScriptWorker().

◆ m_result

QJSValue Zbl::ZScriptWorker::m_result
protected

Result returned by the most recent script execution.

Definition at line 132 of file ZScriptWorker.h.

Referenced by execScript().

◆ m_script

QString Zbl::ZScriptWorker::m_script
protected

The most recent script that was executed.

Definition at line 125 of file ZScriptWorker.h.

Referenced by execScript().


The documentation for this class was generated from the following files: