ConsoleProcess: Uniform the common interface of QtcProcess

This is a preliminary step before merging ConsoleProcess
into QtcProcess.

Rename:
processStarted() -> started()
processFinished() -> finished()

Change-Id: Ifd94722822c7628fc8130e3a6377d55d24db6eb3
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-01-18 19:10:30 +01:00
parent 2c8c7707c5
commit 404f7a1b31
5 changed files with 27 additions and 32 deletions

View File

@@ -596,7 +596,7 @@ bool ConsoleProcess::start()
return true; return true;
} }
void Utils::ConsoleProcess::cleanupAfterStartFailure(const QString &errorMessage) void ConsoleProcess::cleanupAfterStartFailure(const QString &errorMessage)
{ {
stubServerShutdown(); stubServerShutdown();
emitError(QProcess::FailedToStart, errorMessage); emitError(QProcess::FailedToStart, errorMessage);
@@ -604,6 +604,14 @@ void Utils::ConsoleProcess::cleanupAfterStartFailure(const QString &errorMessage
d->m_tempFile = nullptr; d->m_tempFile = nullptr;
} }
void ConsoleProcess::finish(int exitCode, QProcess::ExitStatus exitStatus)
{
d->m_appPid = 0;
d->m_appCode = exitCode;
d->m_appStatus = exitStatus;
emit finished();
}
void Utils::ConsoleProcess::kickoffProcess() void Utils::ConsoleProcess::kickoffProcess()
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@@ -640,8 +648,8 @@ void ConsoleProcess::killProcess()
d->m_stubSocket->write("k", 1); d->m_stubSocket->write("k", 1);
d->m_stubSocket->flush(); d->m_stubSocket->flush();
} }
d->m_appPid = 0;
#endif #endif
d->m_appPid = 0;
} }
void ConsoleProcess::killStub() void ConsoleProcess::killStub()
@@ -798,12 +806,10 @@ void ConsoleProcess::readStubOutput()
emitError(QProcess::UnknownError, tr("Cannot obtain exit status from inferior: %1") emitError(QProcess::UnknownError, tr("Cannot obtain exit status from inferior: %1")
.arg(winErrorMessage(GetLastError()))); .arg(winErrorMessage(GetLastError())));
cleanupInferior(); cleanupInferior();
d->m_appStatus = QProcess::NormalExit; finish(chldStatus, QProcess::NormalExit);
d->m_appCode = chldStatus;
emit processStopped(d->m_appCode, d->m_appStatus);
}); });
emit processStarted(); emit started();
} else { } else {
emitError(QProcess::UnknownError, msgUnexpectedOutput(out)); emitError(QProcess::UnknownError, msgUnexpectedOutput(out));
TerminateProcess(d->m_pid->hProcess, (unsigned)-1); TerminateProcess(d->m_pid->hProcess, (unsigned)-1);
@@ -822,17 +828,11 @@ void ConsoleProcess::readStubOutput()
d->m_stubPid = out.mid(4).toInt(); d->m_stubPid = out.mid(4).toInt();
} else if (out.startsWith("pid ")) { } else if (out.startsWith("pid ")) {
d->m_appPid = out.mid(4).toInt(); d->m_appPid = out.mid(4).toInt();
emit processStarted(); emit started();
} else if (out.startsWith("exit ")) { } else if (out.startsWith("exit ")) {
d->m_appStatus = QProcess::NormalExit; finish(out.mid(5).toInt(), QProcess::NormalExit);
d->m_appCode = out.mid(5).toInt();
d->m_appPid = 0;
emit processStopped(d->m_appCode, d->m_appStatus);
} else if (out.startsWith("crash ")) { } else if (out.startsWith("crash ")) {
d->m_appStatus = QProcess::CrashExit; finish(out.mid(6).toInt(), QProcess::CrashExit);
d->m_appCode = out.mid(6).toInt();
d->m_appPid = 0;
emit processStopped(d->m_appCode, d->m_appStatus);
} else { } else {
emitError(QProcess::UnknownError, msgUnexpectedOutput(out)); emitError(QProcess::UnknownError, msgUnexpectedOutput(out));
d->m_stubPid = 0; d->m_stubPid = 0;
@@ -855,9 +855,7 @@ void ConsoleProcess::stubExited()
if (d->m_hInferior != NULL) { if (d->m_hInferior != NULL) {
TerminateProcess(d->m_hInferior, (unsigned)-1); TerminateProcess(d->m_hInferior, (unsigned)-1);
cleanupInferior(); cleanupInferior();
d->m_appStatus = QProcess::CrashExit; finish(-1, QProcess::CrashExit);
d->m_appCode = -1;
emit processStopped(d->m_appCode, d->m_appStatus);
} }
#else #else
stubServerShutdown(); stubServerShutdown();
@@ -865,10 +863,7 @@ void ConsoleProcess::stubExited()
delete d->m_tempFile; delete d->m_tempFile;
d->m_tempFile = nullptr; d->m_tempFile = nullptr;
if (d->m_appPid) { if (d->m_appPid) {
d->m_appStatus = QProcess::CrashExit; finish(-1, QProcess::CrashExit);
d->m_appCode = -1;
d->m_appPid = 0;
emit processStopped(d->m_appCode, d->m_appStatus); // Maybe it actually did not, but keep state consistent
} }
#endif #endif
emit stubStopped(); emit stubStopped();
@@ -893,7 +888,6 @@ void ConsoleProcess::cleanupInferior()
d->inferiorFinishedNotifier = nullptr; d->inferiorFinishedNotifier = nullptr;
CloseHandle(d->m_hInferior); CloseHandle(d->m_hInferior);
d->m_hInferior = NULL; d->m_hInferior = NULL;
d->m_appPid = 0;
#endif #endif
} }

View File

@@ -117,8 +117,8 @@ signals:
void processError(const QString &errorString); void processError(const QString &errorString);
// These reflect the state of the actual client process // These reflect the state of the actual client process
void processStarted(); void started();
void processStopped(int, QProcess::ExitStatus); void finished();
// These reflect the state of the console+stub // These reflect the state of the console+stub
void stubStarted(); void stubStarted();
@@ -129,6 +129,7 @@ private:
void readStubOutput(); void readStubOutput();
void stubExited(); void stubExited();
void cleanupAfterStartFailure(const QString &errorMessage); void cleanupAfterStartFailure(const QString &errorMessage);
void finish(int exitCode, QProcess::ExitStatus exitStatus);
static QString modeOption(Mode m); static QString modeOption(Mode m);
static QString msgCommChannelFailed(const QString &error); static QString msgCommChannelFailed(const QString &error);

View File

@@ -176,10 +176,10 @@ TerminalRunner::TerminalRunner(RunControl *runControl,
connect(&m_stubProc, &ConsoleProcess::processError, connect(&m_stubProc, &ConsoleProcess::processError,
this, &TerminalRunner::stubError); this, &TerminalRunner::stubError);
connect(&m_stubProc, &ConsoleProcess::processStarted, connect(&m_stubProc, &ConsoleProcess::started,
this, &TerminalRunner::stubStarted); this, &TerminalRunner::stubStarted);
connect(&m_stubProc, &ConsoleProcess::processStopped, connect(&m_stubProc, &ConsoleProcess::finished,
this, [this] { reportDone(); }); this, &TerminalRunner::reportDone);
} }
void TerminalRunner::kickoffProcess() void TerminalRunner::kickoffProcess()

View File

@@ -149,11 +149,11 @@ ApplicationLauncherPrivate::ApplicationLauncherPrivate(ApplicationLauncher *pare
m_consoleProcess.setSettings(Core::ICore::settings()); m_consoleProcess.setSettings(Core::ICore::settings());
connect(&m_consoleProcess, &ConsoleProcess::processStarted, connect(&m_consoleProcess, &ConsoleProcess::started,
this, &ApplicationLauncherPrivate::handleProcessStarted); this, &ApplicationLauncherPrivate::handleProcessStarted);
connect(&m_consoleProcess, &ConsoleProcess::processError, connect(&m_consoleProcess, &ConsoleProcess::processError,
this, &ApplicationLauncherPrivate::localConsoleProcessError); this, &ApplicationLauncherPrivate::localConsoleProcessError);
connect(&m_consoleProcess, &ConsoleProcess::processStopped, this, [this] { connect(&m_consoleProcess, &ConsoleProcess::finished, this, [this] {
localProcessDone(m_consoleProcess.exitCode(), m_consoleProcess.exitStatus()); localProcessDone(m_consoleProcess.exitCode(), m_consoleProcess.exitStatus());
}); });
connect(&m_consoleProcess, &ConsoleProcess::errorOccurred, connect(&m_consoleProcess, &ConsoleProcess::errorOccurred,

View File

@@ -195,9 +195,9 @@ void SshDeviceProcess::handleConnected()
d->process->setUseTerminal(true); d->process->setUseTerminal(true);
connect(&d->consoleProcess, &ConsoleProcess::errorOccurred, connect(&d->consoleProcess, &ConsoleProcess::errorOccurred,
this, &DeviceProcess::error); this, &DeviceProcess::error);
connect(&d->consoleProcess, &ConsoleProcess::processStarted, connect(&d->consoleProcess, &ConsoleProcess::started,
this, &SshDeviceProcess::handleProcessStarted); this, &SshDeviceProcess::handleProcessStarted);
connect(&d->consoleProcess, &ConsoleProcess::processStopped, connect(&d->consoleProcess, &ConsoleProcess::finished,
this, [this] { handleProcessFinished(d->consoleProcess.errorString()); }); this, [this] { handleProcessFinished(d->consoleProcess.errorString()); });
connect(&d->consoleProcess, &ConsoleProcess::stubStopped, connect(&d->consoleProcess, &ConsoleProcess::stubStopped,
this, [this] { handleProcessFinished(d->consoleProcess.errorString()); }); this, [this] { handleProcessFinished(d->consoleProcess.errorString()); });