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
259259 }
260260
261261 // 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.
263263 static QScriptValue animVarMapToScriptValue(QScriptEngine* engine, const AnimVariantMap& parameters) {
264264 return parameters.animVariantMapToScriptValue(engine);
265265 }
@@ -340,7 +340,7 @@ void ScriptEngine::init() { · 74 unmodified lines
340340 void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
341341 if (QThread::currentThread() != thread()) {
342342 #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() << "]";
344344 #endif
345345 QMetaObject::invokeMethod(this, "registerValue",
346346 Q_ARG(const QString&, valueName),
@@ -729,8 +729,16 @@ void ScriptEngine::stop() { · 382 unmodified lines
729729 }
730730
731731 // Other threads can invoke this through invokeMethod, which causes the callback to be asynchronously executed in this script's thread.
732−void ScriptEngine::invokeAnimationCallback(QScriptValue callback, AnimVariantMap parameters) {
733− checkThread();
732+void ScriptEngine::callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters) {
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+ }
734742 QScriptValue javascriptParametgers = parameters.animVariantMapToScriptValue(this);
735743 QScriptValueList callingArguments;
736744 callingArguments << javascriptParametgers;
@@ -923,19 +931,12 @@ void ScriptEngine::load(const QString& loadFile) { · 186 unmodified lines
923931 }
924932 }
925933
926−bool 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
935+void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& eventName, std::function<QScriptValueList()> argGenerator) {
927936 if (QThread::currentThread() != thread()) {
928937 qDebug() << "*** ERROR *** ScriptEngine::generalHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]";
929938 assert(false);
930− return true;
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
936−void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& eventName, std::function<QScriptValueList()> argGenerator) {
937− if (checkThread()) {
938− return;
939+ return ;
939940 }
940941 if (!_registeredHandlers.contains(entityID)) {
941942 return;