From ca3e2f9d793d8a839048f8daabd276556a861380 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 28 Oct 2015 08:01:15 -0400 Subject: Remove the "waitForStarted()" function call in the external process launcher functions, and adjust the manual check for process started/running/finished to also account for the "Starting" State (only breaks out for the "NotRunning" process state now). --- libLumina/LuminaUtils.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libLumina') diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index 7b13adb9..987e3c5d 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -36,9 +36,9 @@ int LUtils::runCmd(QString cmd, QStringList args){ }else{ proc.start(cmd, args); } - if(!proc.waitForStarted(30000)){ return 1; } //process never started - max wait of 30 seconds + //if(!proc.waitForStarted(30000)){ return 1; } //process never started - max wait of 30 seconds while(!proc.waitForFinished(300)){ - if(proc.state() != QProcess::Running){ break; } //somehow missed the finished signal + if(proc.state() == QProcess::NotRunning){ break; } //somehow missed the finished signal QCoreApplication::processEvents(); } int ret = proc.exitCode(); @@ -58,9 +58,9 @@ QStringList LUtils::getCmdOutput(QString cmd, QStringList args){ }else{ proc.start(cmd,args); } - if(!proc.waitForStarted(30000)){ return QStringList(); } //process never started - max wait of 30 seconds - while(!proc.waitForFinished(500)){ - if(proc.state() != QProcess::Running){ break; } //somehow missed the finished signal + //if(!proc.waitForStarted(30000)){ return QStringList(); } //process never started - max wait of 30 seconds + while(!proc.waitForFinished(300)){ + if(proc.state() != QProcess::NotRunning){ break; } //somehow missed the finished signal QCoreApplication::processEvents(); } QStringList out = QString(proc.readAllStandardOutput()).split("\n"); -- cgit From eebcb9b10e97ed2241bb1792e7b3ec54b6b3e94e Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 28 Oct 2015 08:21:19 -0400 Subject: Ok, now the external process commands *truly* run in a separate thread through the QtConcurrent module. --- libLumina/LuminaUtils.cpp | 40 ++++++++++++++++++++++++++++++++++------ libLumina/libLumina.pro | 2 +- 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'libLumina') diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index 987e3c5d..4bcc548a 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -15,21 +15,45 @@ #include #include #include +#include +#include #include #include #include static QStringList fav; + +inline QStringList ProcessRun(QString cmd, QStringList args){ + //Assemble outputs + QStringList out; out << "1" << ""; //error code, string output + QProcess proc; + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert("LANG", "C"); + env.insert("LC_MESSAGES", "C"); + proc.setProcessEnvironment(env); + proc.setProcessChannelMode(QProcess::MergedChannels); + if(args.isEmpty()){ + proc.start(cmd); + }else{ + proc.start(cmd,args); + } + while(!proc.waitForFinished(500)){ + if(proc.state() == QProcess::NotRunning){ break; } //somehow missed the finished signal + } + out[0] = QString::number(proc.exitCode()); + out[1] = QString(proc.readAllStandardOutput()); + return out; +} //============= // LUtils Functions //============= QString LUtils::LuminaDesktopVersion(){ - return "0.8.7-Release"; + return "0.8.8-devel"; } int LUtils::runCmd(QString cmd, QStringList args){ - QProcess proc; + /*QProcess proc; proc.setProcessChannelMode(QProcess::MergedChannels); if(args.isEmpty()){ proc.start(cmd); @@ -42,12 +66,14 @@ int LUtils::runCmd(QString cmd, QStringList args){ QCoreApplication::processEvents(); } int ret = proc.exitCode(); - return ret; + return ret;*/ + QFuture future = QtConcurrent::run(ProcessRun, cmd, args); + return future.result()[0].toInt(); //turn it back into an integer return code } QStringList LUtils::getCmdOutput(QString cmd, QStringList args){ - QProcess proc; + /*QProcess proc; QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("LANG", "C"); env.insert("LC_MESSAGES", "C"); @@ -60,11 +86,13 @@ QStringList LUtils::getCmdOutput(QString cmd, QStringList args){ } //if(!proc.waitForStarted(30000)){ return QStringList(); } //process never started - max wait of 30 seconds while(!proc.waitForFinished(300)){ - if(proc.state() != QProcess::NotRunning){ break; } //somehow missed the finished signal + if(proc.state() == QProcess::NotRunning){ break; } //somehow missed the finished signal QCoreApplication::processEvents(); } QStringList out = QString(proc.readAllStandardOutput()).split("\n"); - return out; + return out;*/ + QFuture future = QtConcurrent::run(ProcessRun, cmd, args); + return future.result()[1].split("\n"); //Split the return message into lines } QStringList LUtils::readFile(QString filepath){ diff --git a/libLumina/libLumina.pro b/libLumina/libLumina.pro index 6fe81676..0a29325e 100644 --- a/libLumina/libLumina.pro +++ b/libLumina/libLumina.pro @@ -1,6 +1,6 @@ QT += core network -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets x11extras multimedia +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets x11extras multimedia concurrent TARGET=LuminaUtils -- cgit