42 #include "private/qdeclarativeworkerscript_p.h" 43 #include "private/qdeclarativelistmodel_p.h" 44 #include "private/qdeclarativelistmodelworkeragent_p.h" 45 #include "private/qdeclarativeengine_p.h" 46 #include "private/qdeclarativeexpression_p.h" 48 #include <QtCore/qcoreevent.h> 49 #include <QtCore/qcoreapplication.h> 50 #include <QtCore/qdebug.h> 51 #include <QtScript/qscriptengine.h> 52 #include <QtCore/qmutex.h> 53 #include <QtCore/qwaitcondition.h> 54 #include <QtScript/qscriptvalueiterator.h> 55 #include <QtCore/qfile.h> 56 #include <QtCore/qdatetime.h> 57 #include <QtNetwork/qnetworkaccessmanager.h> 58 #include <QtDeclarative/qdeclarativeinfo.h> 139 if (!accessManager) {
146 return accessManager;
189 void processMessage(
int,
const QVariant &);
190 void processLoad(
int,
const QUrl &);
195 : workerEngine(0), qmlengine(engine), m_nextId(0)
336 qWarning().nospace() <<
"WorkerScript: Cannot find source file " << url.
toString();
364 }
else if (value.
isDate()) {
375 for (
quint32 ii = 0; ii < length; ++ii) {
426 }
else if (value.
userType() == qMetaTypeId<QDeclarativeListModelWorkerAgent::VariantRef>()) {
536 : id(-1), initialized(false),
owner(0)
543 script->
id =
d->m_nextId++;
547 d->workers.insert(script->
id, script);
580 delete d->workerEngine;
d->workerEngine = 0;
630 :
QObject(parent), m_engine(0), m_scriptId(-1), m_componentComplete(true)
689 qWarning(
"QDeclarativeWorkerScript: Attempt to send message before WorkerScript establishment");
707 qWarning(
"QDeclarativeWorkerScript: engine() called without qmlEngine() set");
761 #include <qdeclarativeworkerscript.moc> The QVariant class acts like a union for the most common Qt data types.
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
WorkerLoadEvent(int workerId, const QUrl &url)
static QString urlToLocalFileOrQrc(const QUrl &url)
void processMessage(int, const QVariant &)
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
The QScriptContext class represents a Qt Script function invocation.
static uint hash(const uchar *p, int n)
virtual void componentComplete()
Invoked after the root component that caused this instantiation has completed construction.
virtual QNetworkAccessManager * create(QObject *parent)=0
Creates and returns a network access manager with the specified parent.
QDeclarativeListModelWorkerAgent * a
QDeclarativeWorkerScript * owner
QScriptValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue's property with the given name, using the given mode to resolv...
QDeclarativeWorkerScriptEngine * m_engine
void sendMessage(const QScriptValue &)
QDeclarativeError m_error
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
QDeclarativeWorkerScriptEnginePrivate(QDeclarativeEngine *eng)
QRegExp toRegExp() const
Returns the variant as a QRegExp if the variant has type() RegExp ; otherwise returns an empty QRegEx...
QDeclarativeWorkerScriptEngine(QDeclarativeEngine *parent=0)
#define QT_END_NAMESPACE
This macro expands to.
void lock()
Locks the mutex.
The QMutex class provides access serialization between threads.
bool isBool() const
Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false...
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
QDateTime toDateTime() const
Returns a QDateTime representation of this value, in local time.
void processLoad(int, const QUrl &)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
static QScriptValue onMessage(QScriptContext *ctxt, QScriptEngine *engine)
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
QDeclarativeWorkerScriptEngine * engine()
The QByteArray class provides an array of bytes.
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
QString name() const
Returns the name of the last property that was jumped over using next() or previous().
int registerWorkerScript(QDeclarativeWorkerScript *)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QScriptValue newRegExp(const QRegExp ®exp)
Creates a QtScript object of class RegExp with the given regexp.
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
int count(const T &t) const
Returns the number of occurrences of value in the list.
void popContext()
Pops the current execution context and restores the previous one.
virtual bool event(QEvent *)
This handler is called when a message msg is received from a worker script in another thread through ...
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
virtual void run()
The starting point for the thread.
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
void reportScriptException(WorkerScript *)
The QHash class is a template class that provides a hash-table-based dictionary.
QDeclarativeError error() const
The QObject class is the base class of all Qt objects.
void setSource(const QUrl &)
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
virtual void classBegin()
Invoked after class creation, but before any properties have been set.
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &)
static QScriptValue variantToScriptValue(const QVariant &, QScriptEngine *)
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
void quit()
Tells the thread's event loop to exit with return code 0 (success).
QScriptEngine * scriptEngine() const
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
WorkerDataEvent(int workerId, const QVariant &data)
void setActivationObject(const QScriptValue &activation)
Sets the activation object of this QScriptContext to be the given activation.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
QUrl source
This holds the url of the JavaScript file that implements the WorkerScript.
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void executeUrl(int, const QUrl &)
QDeclarativeEngine * qmlengine
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
static QDeclarativeWorkerScriptEnginePrivate * get(QScriptEngine *e)
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
const T & at(int i) const
Returns the item at index position i in the list.
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
QDeclarativeWorkerScriptEnginePrivate * d
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Q_CORE_EXPORT void qWarning(const char *,...)
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
static const char * data(const QByteArray &arr)
QDeclarativeListModelWorkerAgent * agent()
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
QScriptValue newObject()
Creates a QtScript object of class Object.
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
The QDeclarativeError class encapsulates a QML error.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
QDeclarativeNetworkAccessManagerFactory * networkAccessManagerFactory() const
Returns the current QDeclarativeNetworkAccessManagerFactory.
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
void sendMessage(int, const QVariant &)
The QNetworkAccessManager class allows the application to send network requests and receive replies...
void unlock()
Unlocks the mutex.
QDeclarativeWorkerScript(QObject *parent=0)
virtual ~QDeclarativeWorkerScript()
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
QDeclarativeWorkerScriptEnginePrivate * p
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue newQObject(QObject *object, ValueOwnership ownership=QtOwnership, const QObjectWrapOptions &options=0)
Creates a QtScript object that wraps the given QObject object, using the given ownership.
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
void removeWorkerScript(int)
QScriptValue data() const
Returns the internal data of this QScriptValue object.
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue's property with the given name to the given value.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
int userType() const
Returns the storage type of the value stored in the variant.
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
The QFile class provides an interface for reading from and writing to files.
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
Type
This enum type defines the valid event types in Qt.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
QNetworkAccessManager * accessManager
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
The QDeclarativeEngine class provides an environment for instantiating QML components.
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
QObject * parent() const
Returns a pointer to the parent object.
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
QScriptValue value() const
Returns the value of the last property that was jumped over using next() or previous().
ScriptEngine * workerEngine
WorkerErrorEvent(const QDeclarativeError &error)
void setScriptEngine(QScriptEngine *eng)
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
virtual ~WorkerDataEvent()
QRegExp toRegExp() const
Returns the QRegExp representation of this value.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
T qvariant_cast(const QVariant &)
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
void clearExceptions()
Clears any uncaught exceptions in this engine.
ScriptEngine(QDeclarativeWorkerScriptEnginePrivate *parent)
static void exceptionToError(QScriptEngine *, QDeclarativeError &)
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
QScriptValue newDate(qsreal value)
Creates a QtScript object of class Date with the given value (the number of milliseconds since 01 Jan...
void message(const QScriptValue &messageObject)
QHash< int, WorkerScript * > workers
static QVariant scriptValueToVariant(const QScriptValue &)
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue getWorker(int)
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
QScriptValue thisObject() const
Returns the `this' object associated with this QScriptContext.
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context's scope chain.
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
void warning(const QDeclarativeError &)
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
The QThread class provides a platform-independent way to manage threads.
The QScriptValue class acts as a container for the Qt Script data types.
static QScriptValue sendMessage(QScriptContext *ctxt, QScriptEngine *engine)
virtual ~QDeclarativeWorkerScriptEngine()
static QString fileName(const QString &fileUrl)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
WorkerRemoveEvent(int workerId)
QDeclarativeWorkerScriptEngine * getWorkerScriptEngine()
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this' object in the function call...
void deleteLater()
Schedules this object for deletion.
QScriptValue argument(int index) const
Returns the function argument at the given index.
void next()
Advances the iterator by one position.
QScriptValue newVariant(const QVariant &value)
Creates a QtScript object holding the given variant value.
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
bool hasNext() const
Returns true if there is at least one item ahead of the iterator (i.e.
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.
virtual QNetworkAccessManager * networkAccessManager()