| 36 |  | // Note the () around the function | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 37 |  | e.getXmlDataFunction = new QScriptValue(e.scriptEngine->evaluate("(function getXmlData() { return $xmlData; })")); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 38 |  | e.setXmlDataFunction = new QScriptValue(e.scriptEngine->evaluate("(function setXmlData(newXmlData) { $xmlData=newXmlData; })")); | 
 
 
 
 
 
 
 
 
 
 
 | 39 | < | e.isAvailable = true; | 
 
 
 
 
 
 
 
 
 | 39 | > | e.mutexForEngine = new QMutex; | 
 
 
 
 
 
 
 
 
 
 
 | 40 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 41 |  | // Add echo function so user can debug the code | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 42 |  | QScriptValue echoFunction = e.scriptEngine->newFunction(echo); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 74 |  | // Single tread if small number of files or number of threads = 1 | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 75 |  | if(filesToProcess.size()<=CUSTOM_FILES_PER_THREAD || numThreads == 1){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 76 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 77 | < | jsCustomCodeEngine &jsEngine = getAvailableJsEngine(); | 
 
 
 
 
 
 
 
 
 | 77 | > | jsCustomCodeEngine &jsEngine = this->jsScriptEngines.first(); | 
 
 
 
 
 
 
 
 
 
 
 | 78 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 79 |  | // Process all XmlFiles | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 80 |  | for(int i=0; i<filesToProcess.size(); i++){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 87 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 88 |  | QVector<QFuture<void>> executingThreads; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 89 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 90 | < | for(int i=0; i<=filesToProcess.size()-CUSTOM_FILES_PER_THREAD; i+=CUSTOM_FILES_PER_THREAD){ | 
 
 
 
 
 
 
 
 
 | 90 | > | for(int i=0, iteration = 0; i<=filesToProcess.size()-CUSTOM_FILES_PER_THREAD; i+=CUSTOM_FILES_PER_THREAD, ++iteration){ | 
 
 
 
 
 
 
 
 
 
 
 | 91 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 92 | < | executingThreads << | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 93 | < | QtConcurrent::run(&this->myThreadPool, [=]() | 
 
 
 
 
 
 
 
 
 | 92 | > | executingThreads << QtConcurrent::run(&this->myThreadPool, [=]() | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 93 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 94 | < | mutexIsAvailable.lock(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 95 | < | jsCustomCodeEngine &jsEngine = getAvailableJsEngine(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 96 | < | jsEngine.isAvailable = false; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 97 | < | mutexIsAvailable.unlock(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 94 | > |  | 
 
 
 
 
 | 95 | > | const int indexJsEngine = iteration % this->numThreads; | 
 
 
 
 
 | 96 | > |  | 
 
 
 
 
 | 97 | > | jsCustomCodeEngine &jsEngine = this->jsScriptEngines[indexJsEngine]; | 
 
 
 
 
 | 98 | > |  | 
 
 
 
 
 | 99 | > | jsEngine.mutexForEngine->lock(); | 
 
 
 
 
 
 
 
 
 
 
 | 100 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 101 |  | QString currXmlFileStringThread; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 102 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 116 |  | customCodeUnwinding(filesToProcess.at(i+3),currXmlFileStringThread,*jsEngine.scriptEngine,beginThread,elapsedSecsThread,engineResultThread, | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 117 |  | *jsEngine.jsFunction,*jsEngine.getXmlDataFunction,*jsEngine.setXmlDataFunction,backupsEnabled,verboseEnabled); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 118 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 119 | < | mutexIsAvailable.lock(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 119 | < | jsEngine.isAvailable = true; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 120 | < | mutexIsAvailable.unlock(); | 
 
 
 
 
 
 
 
 
 | 119 | > | jsEngine.mutexForEngine->unlock(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 120 |  | }); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 121 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 122 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 129 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 130 |  | int alreadyProcessedFiles=(filesToProcess.size()/CUSTOM_FILES_PER_THREAD)*CUSTOM_FILES_PER_THREAD; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 131 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 132 | < | jsCustomCodeEngine &jsEngine = getAvailableJsEngine(); | 
 
 
 
 
 
 
 
 
 | 132 | > | jsCustomCodeEngine &jsEngine = this->jsScriptEngines.first(); | 
 
 
 
 
 
 
 
 
 
 
 | 133 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 134 |  | for(int i=alreadyProcessedFiles; i<filesToProcess.size(); i++){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 135 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 145 |  | UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Uncaught js exception (user code) at line " +QString::number(engine.uncaughtExceptionLineNumber()) + ":\n" + engineResult.toString()); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 146 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 147 |  | } | 
 
 
 
 
 
 
 
 
 | 149 | – |  | 
 
 
 
 
 
 
 
 
 | 150 | – | XmlCustomCode::jsCustomCodeEngine& XmlCustomCode::getAvailableJsEngine(){ | 
 
 
 
 
 
 
 
 
 | 151 | – | for(jsCustomCodeEngine &e : this->jsScriptEngines){ | 
 
 
 
 
 
 
 
 
 | 152 | – | if(e.isAvailable){ | 
 
 
 
 
 
 
 
 
 | 153 | – | return e; | 
 
 
 
 
 
 
 
 
 | 154 | – | } | 
 
 
 
 
 
 
 
 
 | 155 | – | } | 
 
 
 
 
 
 
 
 
 | 156 | – |  | 
 
 
 
 
 
 
 
 
 | 157 | – | throw std::runtime_error("Could't find an available js engine for custom command."); | 
 
 
 
 
 
 
 
 
 | 158 | – | } |