| 36 |
|
// main needs to be called so the user code is evaluated |
| 37 |
|
// alternatively you can do: myFunc=engine.evaluate('(function main(){})'); myFunc.call(); |
| 38 |
|
// Note the () around the function |
| 39 |
< |
this->getXmlDataFunctions.append(new QScriptValue(this->scriptEngines[i]->evaluate("(function getXmlData() { return $xmlData; })"))); |
| 40 |
< |
this->setXmlDataFunctions.append(new QScriptValue(this->scriptEngines[i]->evaluate("(function setXmlData(newXmlData) { $xmlData=newXmlData; })"))); |
| 39 |
> |
this->getXmlDataFunctions.append(new QScriptValue(this->scriptEngines.at(i)->evaluate("(function getXmlData() { return $xmlData; })"))); |
| 40 |
> |
this->setXmlDataFunctions.append(new QScriptValue(this->scriptEngines.at(i)->evaluate("(function setXmlData(newXmlData) { $xmlData=newXmlData; })"))); |
| 41 |
|
|
| 42 |
|
// Add echo function so user can debug the code |
| 43 |
< |
QScriptValue echoFunction = this->scriptEngines[i]->newFunction(echo); |
| 44 |
< |
this->scriptEngines[i]->globalObject().setProperty("echo", echoFunction); |
| 43 |
> |
QScriptValue echoFunction = this->scriptEngines.at(i)->newFunction(echo); |
| 44 |
> |
this->scriptEngines.at(i)->globalObject().setProperty("echo", echoFunction); |
| 45 |
|
|
| 46 |
|
// Add the js library for XmlEditing |
| 47 |
< |
this->scriptEngines[i]->evaluate(jsxmlString); |
| 47 |
> |
this->scriptEngines.at(i)->evaluate(jsxmlString); |
| 48 |
|
} |
| 49 |
|
} |
| 50 |
|
} |
| 53 |
|
|
| 54 |
|
// Reconstruct script functions |
| 55 |
|
for(int i=0; i<this->numThreads; i++){ |
| 56 |
< |
*this->jsFunctions[i]=this->scriptEngines[i]->evaluate("(function main() {"+jsString+"})"); |
| 56 |
> |
*this->jsFunctions[i]=this->scriptEngines.at(i)->evaluate("(function main() {"+jsString+"})"); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
QString currXmlFileString; |
| 62 |
|
double elapsed_secs=0; // elapsed seconds that a user script took |
| 63 |
|
clock_t begin; // seconds that a script started |
| 64 |
|
|
| 65 |
< |
// Single tread if small files |
| 65 |
> |
// Single tread if small number of files |
| 66 |
|
if(filesToProcess.size()<CUSTOM_FILES_PER_THREAD){ |
| 67 |
|
// Process all XmlFiles |
| 68 |
|
for(int i=0; i<filesToProcess.size(); i++){ |
| 69 |
|
|
| 70 |
< |
customCodeUnwinding(filesToProcess.at(i),currXmlFileString,*this->scriptEngines[0],begin,elapsed_secs,engineResult, |
| 71 |
< |
*this->jsFunctions[0],*this->getXmlDataFunctions[0],*this->setXmlDataFunctions[0],backupsEnabled,verboseEnabled); |
| 70 |
> |
customCodeUnwinding(filesToProcess.at(i),currXmlFileString,*this->scriptEngines.at(0),begin,elapsed_secs,engineResult, |
| 71 |
> |
*this->jsFunctions.at(0),*this->getXmlDataFunctions.at(0),*this->setXmlDataFunctions.at(0),backupsEnabled,verboseEnabled); |
| 72 |
|
} |
| 73 |
|
} |
| 74 |
|
else{ // Multithread if there are many files |
| 84 |
|
double elapsedSecsThread=0; // elapsed seconds that a user script took |
| 85 |
|
clock_t beginThread; // seconds that a script started |
| 86 |
|
|
| 87 |
< |
customCodeUnwinding(filesToProcess.at(i),currXmlFileStringThread,*this->scriptEngines[tid],beginThread,elapsedSecsThread,engineResultThread, |
| 88 |
< |
*this->jsFunctions[tid],*this->getXmlDataFunctions[tid],*this->setXmlDataFunctions[tid],backupsEnabled,verboseEnabled); |
| 87 |
> |
customCodeUnwinding(filesToProcess.at(i),currXmlFileStringThread,*this->scriptEngines.at(tid),beginThread,elapsedSecsThread,engineResultThread, |
| 88 |
> |
*this->jsFunctions.at(tid),*this->getXmlDataFunctions.at(tid),*this->setXmlDataFunctions.at(tid),backupsEnabled,verboseEnabled); |
| 89 |
|
|
| 90 |
< |
customCodeUnwinding(filesToProcess.at(i+1),currXmlFileStringThread,*this->scriptEngines[tid],beginThread,elapsedSecsThread,engineResultThread, |
| 91 |
< |
*this->jsFunctions[tid],*this->getXmlDataFunctions[tid],*this->setXmlDataFunctions[tid],backupsEnabled,verboseEnabled); |
| 90 |
> |
customCodeUnwinding(filesToProcess.at(i+1),currXmlFileStringThread,*this->scriptEngines.at(tid),beginThread,elapsedSecsThread,engineResultThread, |
| 91 |
> |
*this->jsFunctions.at(tid),*this->getXmlDataFunctions.at(tid),*this->setXmlDataFunctions.at(tid),backupsEnabled,verboseEnabled); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
if(filesToProcess.size()%CUSTOM_FILES_PER_THREAD!=0){ |
| 97 |
|
|
| 98 |
|
for(int i=alreadyProcessedFiles; i<filesToProcess.size(); i++){ |
| 99 |
|
|
| 100 |
< |
customCodeUnwinding(filesToProcess.at(i),currXmlFileString,*this->scriptEngines[0],begin,elapsed_secs,engineResult, |
| 101 |
< |
*this->jsFunctions[0],*this->getXmlDataFunctions[0],*this->setXmlDataFunctions[0],backupsEnabled,verboseEnabled); |
| 100 |
> |
customCodeUnwinding(filesToProcess.at(i),currXmlFileString,*this->scriptEngines.at(0),begin,elapsed_secs,engineResult, |
| 101 |
> |
*this->jsFunctions.at(0),*this->getXmlDataFunctions.at(0),*this->setXmlDataFunctions.at(0),backupsEnabled,verboseEnabled); |
| 102 |
|
} |
| 103 |
|
} |
| 104 |
|
} |