History

Name change and thread checks per comments.

Howard Stearns committed 11 years ago

Commit 1d0464e1 parent 759e6524 files · +19 −18Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+15−14
@@ -259,7 +259,7 @@ void ScriptEngine::errorInLoadingScript(const QUrl& url) { · 258 unmodified lines
259}259}
260 260
261// Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of261// Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of
262// invokeAnimationCallback requires that the type be registered.262// callAnimationStateHandler requires that the type be registered.
263static QScriptValue animVarMapToScriptValue(QScriptEngine* engine, const AnimVariantMap& parameters) {263static QScriptValue animVarMapToScriptValue(QScriptEngine* engine, const AnimVariantMap& parameters) {
264 return parameters.animVariantMapToScriptValue(engine);264 return parameters.animVariantMapToScriptValue(engine);
265}265}
@@ -340,7 +340,7 @@ void ScriptEngine::init() { · 74 unmodified lines
340void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {340void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
341 if (QThread::currentThread() != thread()) {341 if (QThread::currentThread() != thread()) {
342#ifdef THREAD_DEBUGGING342#ifdef THREAD_DEBUGGING
343 qDebug() << "*** WARNING *** ScriptEngine::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;343 qDebug() << "*** WARNING *** ScriptEngine::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]";
344#endif344#endif
345 QMetaObject::invokeMethod(this, "registerValue",345 QMetaObject::invokeMethod(this, "registerValue",
346 Q_ARG(const QString&, valueName),346 Q_ARG(const QString&, valueName),
@@ -729,8 +729,16 @@ void ScriptEngine::stop() { · 382 unmodified lines
729}729}
730 730
731// Other threads can invoke this through invokeMethod, which causes the callback to be asynchronously executed in this script's thread.731// Other threads can invoke this through invokeMethod, which causes the callback to be asynchronously executed in this script's thread.
732void ScriptEngine::invokeAnimationCallback(QScriptValue callback, AnimVariantMap parameters) {732void ScriptEngine::callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters) {
733 checkThread();733 if (QThread::currentThread() != thread()) {
734#ifdef THREAD_DEBUGGING
735 qDebug() << "*** WARNING *** ScriptEngine::callAnimationStateHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;
736#endif
737 QMetaObject::invokeMethod(this, "callAnimationStateHandler",
738 Q_ARG(QScriptValue, callback),
739 Q_ARG(AnimVariantMap, parameters));
740 return;
741 }
734 QScriptValue javascriptParametgers = parameters.animVariantMapToScriptValue(this);742 QScriptValue javascriptParametgers = parameters.animVariantMapToScriptValue(this);
735 QScriptValueList callingArguments;743 QScriptValueList callingArguments;
736 callingArguments << javascriptParametgers;744 callingArguments << javascriptParametgers;
@@ -923,19 +931,12 @@ void ScriptEngine::load(const QString& loadFile) { · 186 unmodified lines
923 }931 }
924}932}
925 933
926bool ScriptEngine::checkThread() const {934// Look up the handler associated with eventName and entityID. If found, evalute the argGenerator thunk and call the handler with those args
935void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& eventName, std::function<QScriptValueList()> argGenerator) {
927 if (QThread::currentThread() != thread()) {936 if (QThread::currentThread() != thread()) {
928 qDebug() << "*** ERROR *** ScriptEngine::generalHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]";937 qDebug() << "*** ERROR *** ScriptEngine::generalHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]";
929 assert(false);938 assert(false);
930 return true;939 return ;
931 }
932 return false;
933}
934
935// Look up the handler associated with eventName and entityID. If found, evalute the argGenerator thunk and call the handler with those args
936void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& eventName, std::function<QScriptValueList()> argGenerator) {
937 if (checkThread()) {
938 return;
939 }940 }
940 if (!_registeredHandlers.contains(entityID)) {941 if (!_registeredHandlers.contains(entityID)) {
941 return;942 return;