Utils/Ssh: Move SshRemoteProces::isRunning() to QtcProcess base

... and use it on a few places.

Change-Id: Id2cea709e355a46821a720e593740ac032888ced
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2021-11-22 11:21:35 +01:00
parent 9c0bc16e94
commit e64ce914f9
11 changed files with 20 additions and 20 deletions

View File

@@ -315,7 +315,7 @@ QIODevice *ConnectionClient::ioDevice()
bool ConnectionClient::isProcessRunning(QtcProcess *process) bool ConnectionClient::isProcessRunning(QtcProcess *process)
{ {
return process && process->state() == QProcess::Running; return process && process->isRunning();
} }
void ConnectionClient::connectStandardOutputAndError(QtcProcess *process) const void ConnectionClient::connectStandardOutputAndError(QtcProcess *process) const

View File

@@ -97,7 +97,7 @@ struct SftpSession::SftpSessionPrivate
return; return;
if (pendingCommands.empty()) if (pendingCommands.empty())
return; return;
QTC_ASSERT(sftpProc.state() == QProcess::Running, return); QTC_ASSERT(sftpProc.isRunning(), return);
activeCommand = pendingCommands.dequeue(); activeCommand = pendingCommands.dequeue();
// The second newline forces the prompt to appear after the command has finished. // The second newline forces the prompt to appear after the command has finished.

View File

@@ -116,11 +116,6 @@ void SshRemoteProcess::start()
doStart(); doStart();
} }
bool SshRemoteProcess::isRunning() const
{
return state() == QProcess::Running;
}
Utils::CommandLine SshRemoteProcess::fullLocalCommandLine() const Utils::CommandLine SshRemoteProcess::fullLocalCommandLine() const
{ {
Utils::CommandLine cmd{SshSettings::sshFilePath()}; Utils::CommandLine cmd{SshSettings::sshFilePath()};

View File

@@ -47,7 +47,6 @@ public:
void requestX11Forwarding(const QString &displayName); void requestX11Forwarding(const QString &displayName);
void start(); void start();
bool isRunning() const;
Utils::CommandLine fullLocalCommandLine() const; Utils::CommandLine fullLocalCommandLine() const;
signals: signals:

View File

@@ -1077,6 +1077,11 @@ QProcess::ProcessState QtcProcess::state() const
return d->m_process->state(); return d->m_process->state();
} }
bool QtcProcess::isRunning() const
{
return state() == QProcess::Running;
}
QString QtcProcess::errorString() const QString QtcProcess::errorString() const
{ {
return d->m_process->errorString(); return d->m_process->errorString();

View File

@@ -171,6 +171,7 @@ public:
QProcess::ProcessError error() const; QProcess::ProcessError error() const;
QProcess::ProcessState state() const; QProcess::ProcessState state() const;
bool isRunning() const; // Short for state() == QProcess::Running.
QString errorString() const; QString errorString() const;
void setErrorString(const QString &str); void setErrorString(const QString &str);

View File

@@ -128,7 +128,7 @@ static CreateAvdInfo createAvdCommand(const AndroidConfig &config, const CreateA
.arg(avdManagerTool.toString(), arguments.join(' ')); .arg(avdManagerTool.toString(), arguments.join(' '));
return result; return result;
} }
QTC_CHECK(proc.state() == QProcess::Running); QTC_CHECK(proc.isRunning());
proc.write(QByteArray("yes\n")); // yes to "Do you wish to create a custom hardware profile" proc.write(QByteArray("yes\n")); // yes to "Do you wish to create a custom hardware profile"
auto start = chrono::steady_clock::now(); auto start = chrono::steady_clock::now();
@@ -151,7 +151,7 @@ static CreateAvdInfo createAvdCommand(const AndroidConfig &config, const CreateA
// The exit code is always 0, so we need to check stderr // The exit code is always 0, so we need to check stderr
// For now assume that any output at all indicates a error // For now assume that any output at all indicates a error
errorOutput = QString::fromLocal8Bit(proc.readAllStandardError()); errorOutput = QString::fromLocal8Bit(proc.readAllStandardError());
if (proc.state() != QProcess::Running) if (!proc.isRunning())
break; break;
// For a sane input and command, process should finish before timeout. // For a sane input and command, process should finish before timeout.

View File

@@ -719,7 +719,7 @@ void GdbEngine::runCommand(const DebuggerCommand &command)
QTC_ASSERT(false, return); QTC_ASSERT(false, return);
} }
if (m_gdbProc.state() != QProcess::Running) { if (!m_gdbProc.isRunning()) {
showMessage(QString("NO GDB PROCESS RUNNING, CMD IGNORED: %1 %2") showMessage(QString("NO GDB PROCESS RUNNING, CMD IGNORED: %1 %2")
.arg(cmd.function).arg(state())); .arg(cmd.function).arg(state()));
if (cmd.callback) { if (cmd.callback) {
@@ -767,7 +767,7 @@ void GdbEngine::runCommand(const DebuggerCommand &command)
cmd.function = "python theDumper." + cmd.function + "(" + cmd.argsToPython() + ")"; cmd.function = "python theDumper." + cmd.function + "(" + cmd.argsToPython() + ")";
} }
QTC_ASSERT(m_gdbProc.state() == QProcess::Running, return); QTC_ASSERT(m_gdbProc.isRunning(), return);
cmd.postTime = QTime::currentTime().msecsSinceStartOfDay(); cmd.postTime = QTime::currentTime().msecsSinceStartOfDay();
m_commandForToken[token] = cmd; m_commandForToken[token] = cmd;
@@ -1663,7 +1663,7 @@ void GdbEngine::handleInferiorShutdown(const DebuggerResponse &response)
// This happens when someone removed the binary behind our back. // This happens when someone removed the binary behind our back.
// It is not really an error from a user's point of view. // It is not really an error from a user's point of view.
showMessage("NOTE: " + msg); showMessage("NOTE: " + msg);
} else if (m_gdbProc.state() == QProcess::Running) { } else if (m_gdbProc.isRunning()) {
AsynchronousMessageBox::critical(tr("Failed to Shut Down Application"), AsynchronousMessageBox::critical(tr("Failed to Shut Down Application"),
msgInferiorStopFailed(msg)); msgInferiorStopFailed(msg));
} }

View File

@@ -126,7 +126,7 @@ void LldbEngine::executeDebuggerCommand(const QString &command)
void LldbEngine::runCommand(const DebuggerCommand &command) void LldbEngine::runCommand(const DebuggerCommand &command)
{ {
if (m_lldbProc.state() != QProcess::Running) { if (!m_lldbProc.isRunning()) {
// This can legally happen e.g. through a reloadModule() // This can legally happen e.g. through a reloadModule()
// triggered by changes in view visibility. // triggered by changes in view visibility.
showMessage(QString("NO LLDB PROCESS RUNNING, CMD IGNORED: %1 %2") showMessage(QString("NO LLDB PROCESS RUNNING, CMD IGNORED: %1 %2")
@@ -185,7 +185,7 @@ void LldbEngine::shutdownInferior()
void LldbEngine::shutdownEngine() void LldbEngine::shutdownEngine()
{ {
QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << state()); QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << state());
if (m_lldbProc.state() == QProcess::Running) if (m_lldbProc.isRunning())
m_lldbProc.terminate(); m_lldbProc.terminate();
else else
notifyEngineShutdownFinished(); notifyEngineShutdownFinished();
@@ -193,7 +193,7 @@ void LldbEngine::shutdownEngine()
void LldbEngine::abortDebuggerProcess() void LldbEngine::abortDebuggerProcess()
{ {
if (m_lldbProc.state() == QProcess::Running) if (m_lldbProc.isRunning())
m_lldbProc.kill(); m_lldbProc.kill();
else else
notifyEngineShutdownFinished(); notifyEngineShutdownFinished();

View File

@@ -76,13 +76,13 @@ void PdbEngine::executeDebuggerCommand(const QString &command)
showMessage("PDB PROCESS NOT RUNNING, PLAIN CMD IGNORED: " + command); showMessage("PDB PROCESS NOT RUNNING, PLAIN CMD IGNORED: " + command);
return; return;
} }
QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll()); QTC_ASSERT(m_proc.isRunning(), notifyEngineIll());
postDirectCommand(command); postDirectCommand(command);
} }
void PdbEngine::postDirectCommand(const QString &command) void PdbEngine::postDirectCommand(const QString &command)
{ {
QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll()); QTC_ASSERT(m_proc.isRunning(), notifyEngineIll());
showMessage(command, LogInput); showMessage(command, LogInput);
m_proc.write(command.toUtf8() + '\n'); m_proc.write(command.toUtf8() + '\n');
} }
@@ -93,7 +93,7 @@ void PdbEngine::runCommand(const DebuggerCommand &cmd)
showMessage("IGNORED COMMAND: " + cmd.function); showMessage("IGNORED COMMAND: " + cmd.function);
return; return;
} }
QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll()); QTC_ASSERT(m_proc.isRunning(), notifyEngineIll());
QString command = "qdebug('" + cmd.function + "'," + cmd.argsToPython() + ")"; QString command = "qdebug('" + cmd.function + "'," + cmd.argsToPython() + ")";
showMessage(command, LogInput); showMessage(command, LogInput);
m_proc.write(command.toUtf8() + '\n'); m_proc.write(command.toUtf8() + '\n');

View File

@@ -887,7 +887,7 @@ void DockerDevicePrivate::startContainer()
m_shell->start(); m_shell->start();
m_shell->waitForStarted(); m_shell->waitForStarted();
if (m_shell->state() != QProcess::Running) { if (!m_shell->isRunning()) {
DockerPlugin::setGlobalDaemonState(false); DockerPlugin::setGlobalDaemonState(false);
LOG("DOCKER SHELL FAILED"); LOG("DOCKER SHELL FAILED");
return; return;