Commit 0489adf0 authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

iostoolhandler: thighten stop process



gurantee that finished is emitted also when the process fails to start
and always after the sub process has actually finished.

Change-Id: I716ebf62074dc77790716e60e88348a932cbe9f6
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent 5a095237
......@@ -129,7 +129,7 @@ public:
virtual void requestDeviceInfo(const QString &deviceId, int timeout = 1000) = 0;
bool isRunning();
void start(const QString &exe, const QStringList &args);
void stop();
void stop(int errorCode);
// signals
void isTransferringApp(const QString &bundlePath, const QString &deviceId, int progress,
......@@ -226,20 +226,40 @@ void IosToolHandlerPrivate::start(const QString &exe, const QStringList &args)
state = StartedInferior;
}
void IosToolHandlerPrivate::stop()
void IosToolHandlerPrivate::stop(int errorCode)
{
if (debugToolHandler)
qDebug() << "IosToolHandlerPrivate::stop";
if (process.state() != QProcess::NotRunning) {
process.close();
process.kill();
if (debugToolHandler)
qDebug() << "killing";
}
if (state != Stopped) {
state = Stopped;
emit q->finished(q);
State oldState = state;
state = Stopped;
switch (oldState) {
case NonStarted:
qDebug() << "IosToolHandler::stop() when state was NonStarted";
// pass
case Starting:
switch (op){
case OpNone:
qDebug() << "IosToolHandler::stop() when op was OpNone";
break;
case OpAppTransfer:
didTransferApp(bundlePath, deviceId, IosToolHandler::Failure);
break;
case OpAppRun:
didStartApp(bundlePath, deviceId, IosToolHandler::Failure);
break;
case OpDeviceInfo:
break;
}
// pass
case StartedInferior:
case XmlEndProcessed:
toolExited(errorCode);
break;
case Stopped:
return;
}
if (process.state() != QProcess::NotRunning)
process.kill();
}
// signals
......@@ -296,67 +316,22 @@ void IosToolHandlerPrivate::toolExited(int code)
void IosToolHandlerPrivate::subprocessError(QProcess::ProcessError error)
{
switch (state) {
case NonStarted:
qDebug() << "subprocessError() when state was NonStarted";
// pass
case Starting:
switch (op){
case OpNone:
qDebug() << "subprocessError() when op is OpNone";
break;
case OpAppTransfer:
didTransferApp(bundlePath, deviceId, IosToolHandler::Failure);
break;
case OpAppRun:
didStartApp(bundlePath, deviceId, IosToolHandler::Failure);
break;
case OpDeviceInfo:
break;
}
// pass
case StartedInferior:
errorMsg(IosToolHandler::tr("Subprocess Error %1").arg(error));
toolExited(-1);
break;
case XmlEndProcessed:
case Stopped:
qDebug() << "IosToolHandler, subprocessError() in an already stopped process";
if (state != Stopped)
errorMsg(IosToolHandler::tr("iOS tool Error %1").arg(error));
stop(-1);
if (error == QProcess::FailedToStart) {
if (debugToolHandler)
qDebug() << "IosToolHandler::finished(" << this << ")";
emit q->finished(q);
}
}
void IosToolHandlerPrivate::subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
// process potentially pending data
subprocessHasData();
switch (state) {
case NonStarted:
qDebug() << "subprocessFinished() when state was NonStarted";
// pass
case Starting:
switch (op){
case OpNone:
qDebug() << "subprocessFinished() when op was OpNone";
break;
case OpAppTransfer:
didTransferApp(bundlePath, deviceId, IosToolHandler::Failure);
break;
case OpAppRun:
didStartApp(bundlePath, deviceId, IosToolHandler::Failure);
break;
case OpDeviceInfo:
break;
}
// pass
case StartedInferior:
case XmlEndProcessed:
toolExited((exitStatus == QProcess::CrashExit && exitCode == 0) ? -1 : exitCode);
break;
case Stopped:
if (debugToolHandler)
qDebug() << "IosToolHandler, subprocessFinished() in an already stopped process (normal)";
break;
}
stop((exitStatus == QProcess::NormalExit) ? exitCode : -1 );
if (debugToolHandler)
qDebug() << "IosToolHandler::finished(" << this << ")";
emit q->finished(q);
}
void IosToolHandlerPrivate::processXml()
......@@ -469,7 +444,8 @@ void IosToolHandlerPrivate::processXml()
break;
case ParserState::QueryResult:
state = XmlEndProcessed;
break;
stop(0);
return;
case ParserState::AppOutput:
break;
case ParserState::AppStarted:
......@@ -523,7 +499,7 @@ void IosToolHandlerPrivate::processXml()
if (outputParser.hasError()
&& outputParser.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
qDebug() << "error parsing iosTool output:" << outputParser.errorString();
stop();
stop(-1);
}
}
......@@ -544,7 +520,7 @@ void IosToolHandlerPrivate::subprocessHasData()
while (true) {
qint64 rRead = process.read(buf, sizeof(buf));
if (rRead == -1) {
stop();
stop(-1);
return;
}
if (rRead == 0)
......@@ -556,7 +532,7 @@ void IosToolHandlerPrivate::subprocessHasData()
}
}
case XmlEndProcessed:
stop();
stop(0);
return;
case Stopped:
return;
......@@ -737,7 +713,7 @@ IosToolHandler::~IosToolHandler()
void IosToolHandler::stop()
{
d->stop();
d->stop(-1);
}
void IosToolHandler::requestTransferApp(const QString &bundlePath, const QString &deviceId,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment