From d14e68eac202783f5ff1f9286e4d2b79690ff8a8 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 9 Nov 2021 16:00:18 +0100 Subject: [PATCH] Uniform ApplicationLauncher API: get rid of remoteStderr/out() Use existing appendMessage() for this purpose either with StdErrFormat for remoteStderr() or with StdOutFormat for remoteStdout(). In case when device process is used in ApplicationLauncher no appendMessage() was emitted so far with StdErrFormat or StdOutFormat. Change-Id: I2f6603aaf28113fea2a8bb6bd1738320cc39be75 Reviewed-by: hjk --- src/plugins/boot2qt/qdbdevice.cpp | 15 +++++---- src/plugins/boot2qt/qdbdevicedebugsupport.cpp | 5 --- .../boot2qt/qdbstopapplicationservice.cpp | 21 +++--------- .../boot2qt/qdbstopapplicationservice.h | 5 ++- .../projectexplorer/applicationlauncher.cpp | 4 +-- .../projectexplorer/applicationlauncher.h | 2 -- src/plugins/projectexplorer/runcontrol.cpp | 15 +-------- src/plugins/valgrind/valgrindrunner.cpp | 33 +++++-------------- 8 files changed, 27 insertions(+), 73 deletions(-) diff --git a/src/plugins/boot2qt/qdbdevice.cpp b/src/plugins/boot2qt/qdbdevice.cpp index 808eaf7f282..def8394d838 100644 --- a/src/plugins/boot2qt/qdbdevice.cpp +++ b/src/plugins/boot2qt/qdbdevice.cpp @@ -77,10 +77,8 @@ class DeviceApplicationObserver : public ApplicationLauncher public: DeviceApplicationObserver(const IDevice::ConstPtr &device, const CommandLine &command) { - connect(&m_appRunner, &ApplicationLauncher::remoteStdout, this, - &DeviceApplicationObserver::handleStdout); - connect(&m_appRunner, &ApplicationLauncher::remoteStderr, this, - &DeviceApplicationObserver::handleStderr); + connect(&m_appRunner, &ApplicationLauncher::appendMessage, this, + &DeviceApplicationObserver::handleAppendMessage); connect(&m_appRunner, &ApplicationLauncher::reportError, this, &DeviceApplicationObserver::handleError); connect(&m_appRunner, &ApplicationLauncher::finished, this, @@ -97,8 +95,13 @@ public: } private: - void handleStdout(const QString &data) { m_stdout += data; } - void handleStderr(const QString &data) { m_stderr += data; } + void handleAppendMessage(const QString &data, Utils::OutputFormat format) + { + if (format == Utils::StdOutFormat) + m_stdout += data; + else if (format == Utils::StdErrFormat) + m_stderr += data; + } void handleError(const QString &message) { m_error = message; } void handleFinished(bool success) diff --git a/src/plugins/boot2qt/qdbdevicedebugsupport.cpp b/src/plugins/boot2qt/qdbdevicedebugsupport.cpp index 04e5132ee46..a86c4a817b1 100644 --- a/src/plugins/boot2qt/qdbdevicedebugsupport.cpp +++ b/src/plugins/boot2qt/qdbdevicedebugsupport.cpp @@ -61,11 +61,6 @@ public: this, &RunWorker::reportStopped); connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage); - connect(&m_launcher, &ApplicationLauncher::remoteStdout, - this, [this](const QString &out) { appendMessage(out, StdOutFormat); }); - connect(&m_launcher, &ApplicationLauncher::remoteStderr, - this, [this](const QString &out) { appendMessage(out, StdErrFormat); }); - m_portsGatherer = new DebugServerPortsGatherer(runControl); m_portsGatherer->setUseGdbServer(useGdbServer || usePerf); m_portsGatherer->setUseQmlServer(useQmlServer); diff --git a/src/plugins/boot2qt/qdbstopapplicationservice.cpp b/src/plugins/boot2qt/qdbstopapplicationservice.cpp index f1043462868..acfc941ff39 100644 --- a/src/plugins/boot2qt/qdbstopapplicationservice.cpp +++ b/src/plugins/boot2qt/qdbstopapplicationservice.cpp @@ -78,29 +78,18 @@ void QdbStopApplicationService::handleProcessFinished(bool success) stopDeployment(); } -void QdbStopApplicationService::handleStderr(const QString &output) +void QdbStopApplicationService::handleAppendMessage(const QString &message, Utils::OutputFormat format) { - d->errorOutput.append(output); -} - -void QdbStopApplicationService::handleStdout(const QString &output) -{ - emit stdOutData(output); -} - -void QdbStopApplicationService::handleAppendMessage(const QString &message) -{ - emit stdOutData(message); + if (format == Utils::StdErrFormat) + d->errorOutput.append(message); + else + emit stdOutData(message); } void QdbStopApplicationService::doDeploy() { connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::reportError, this, &QdbStopApplicationService::stdErrData); - connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::remoteStderr, - this, &QdbStopApplicationService::handleStderr); - connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::remoteStdout, - this, &QdbStopApplicationService::handleStdout); connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::finished, this, &QdbStopApplicationService::handleProcessFinished); connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::appendMessage, diff --git a/src/plugins/boot2qt/qdbstopapplicationservice.h b/src/plugins/boot2qt/qdbstopapplicationservice.h index a29205ab6c0..406f8e50f9d 100644 --- a/src/plugins/boot2qt/qdbstopapplicationservice.h +++ b/src/plugins/boot2qt/qdbstopapplicationservice.h @@ -26,6 +26,7 @@ #pragma once #include +#include namespace Qdb { namespace Internal { @@ -41,9 +42,7 @@ public: private: void handleProcessFinished(bool success); - void handleStderr(const QString &output); - void handleStdout(const QString &output); - void handleAppendMessage(const QString &message); + void handleAppendMessage(const QString &message, Utils::OutputFormat format); bool isDeploymentNecessary() const final { return true; } void doDeviceSetup() final { handleDeviceSetupDone(true); } diff --git a/src/plugins/projectexplorer/applicationlauncher.cpp b/src/plugins/projectexplorer/applicationlauncher.cpp index bff194563a0..ad027910ee5 100644 --- a/src/plugins/projectexplorer/applicationlauncher.cpp +++ b/src/plugins/projectexplorer/applicationlauncher.cpp @@ -492,14 +492,14 @@ void ApplicationLauncherPrivate::handleRemoteStdout() { QTC_ASSERT(m_state == Run, return); const QByteArray output = m_deviceProcess->readAllStandardOutput(); - emit q->remoteStdout(QString::fromUtf8(output)); + emit q->appendMessage(QString::fromUtf8(output), Utils::StdOutFormat, false); } void ApplicationLauncherPrivate::handleRemoteStderr() { QTC_ASSERT(m_state == Run, return); const QByteArray output = m_deviceProcess->readAllStandardError(); - emit q->remoteStderr(QString::fromUtf8(output)); + emit q->appendMessage(QString::fromUtf8(output), Utils::StdErrFormat, false); } void ApplicationLauncherPrivate::doReportError(const QString &message) diff --git a/src/plugins/projectexplorer/applicationlauncher.h b/src/plugins/projectexplorer/applicationlauncher.h index 3cba409f9cf..e7d835b25ac 100644 --- a/src/plugins/projectexplorer/applicationlauncher.h +++ b/src/plugins/projectexplorer/applicationlauncher.h @@ -74,8 +74,6 @@ signals: void processExited(int exitCode, QProcess::ExitStatus); void error(QProcess::ProcessError error); - void remoteStdout(const QString &output); - void remoteStderr(const QString &output); void reportError(const QString &errorOutput); void remoteProcessStarted(); void finished(bool success); diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index 02a8ce542d2..5096c306b92 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -1257,16 +1257,6 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP reportFailure(msg); }); - connect(&m_launcher, &ApplicationLauncher::remoteStderr, - this, [this](const QString &output) { - appendMessage(output, Utils::StdErrFormat, false); - }); - - connect(&m_launcher, &ApplicationLauncher::remoteStdout, - this, [this](const QString &output) { - appendMessage(output, Utils::StdOutFormat, false); - }); - connect(&m_launcher, &ApplicationLauncher::finished, this, [this] { m_launcher.disconnect(this); @@ -1290,10 +1280,7 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP reportStarted(); }); - connect(&m_launcher, &ApplicationLauncher::appendMessage, - this, [this](const QString &progressString, Utils::OutputFormat format) { - appendMessage(progressString, format); - }); + connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage); m_launcher.start(runnable, device); } diff --git a/src/plugins/valgrind/valgrindrunner.cpp b/src/plugins/valgrind/valgrindrunner.cpp index a1ca7a2c120..a6bf8817eea 100644 --- a/src/plugins/valgrind/valgrindrunner.cpp +++ b/src/plugins/valgrind/valgrindrunner.cpp @@ -48,13 +48,10 @@ public: bool run(); - void handleRemoteStderr(const QString &b); - void handleRemoteStdout(const QString &b); - void closed(bool success); void localProcessStarted(); void remoteProcessStarted(); - void findPidOutputReceived(const QString &out); + void findPidOutputReceived(const QString &out, Utils::OutputFormat format); ValgrindRunner *q; Runnable m_debuggee; @@ -128,10 +125,6 @@ bool ValgrindRunner::Private::run() connect(&m_valgrindProcess, &ApplicationLauncher::finished, q, &ValgrindRunner::finished); - connect(&m_valgrindProcess, &ApplicationLauncher::remoteStderr, - this, &ValgrindRunner::Private::handleRemoteStderr); - connect(&m_valgrindProcess, &ApplicationLauncher::remoteStdout, - this, &ValgrindRunner::Private::handleRemoteStdout); connect(&m_valgrindProcess, &ApplicationLauncher::remoteProcessStarted, this, &ValgrindRunner::Private::remoteProcessStarted); @@ -161,18 +154,6 @@ bool ValgrindRunner::Private::run() return true; } -void ValgrindRunner::Private::handleRemoteStderr(const QString &b) -{ - if (!b.isEmpty()) - emit q->processOutputReceived(b, Utils::StdErrFormat); -} - -void ValgrindRunner::Private::handleRemoteStdout(const QString &b) -{ - if (!b.isEmpty()) - emit q->processOutputReceived(b, Utils::StdOutFormat); -} - void ValgrindRunner::Private::localProcessStarted() { qint64 pid = m_valgrindProcess.applicationPID().pid(); @@ -207,19 +188,21 @@ void ValgrindRunner::Private::remoteProcessStarted() "\"").arg(proc, m_debuggee.command.executable().fileName(), procEscaped)); // m_remote.m_findPID = m_remote.m_connection->createRemoteProcess(cmd.toUtf8()); - connect(&m_findPID, &ApplicationLauncher::remoteStderr, - this, &ValgrindRunner::Private::handleRemoteStderr); - connect(&m_findPID, &ApplicationLauncher::remoteStdout, + connect(&m_findPID, &ApplicationLauncher::appendMessage, this, &ValgrindRunner::Private::findPidOutputReceived); m_findPID.start(findPid, m_device); } -void ValgrindRunner::Private::findPidOutputReceived(const QString &out) +void ValgrindRunner::Private::findPidOutputReceived(const QString &out, Utils::OutputFormat format) { + if (format != Utils::StdOutFormat) { + emit q->processOutputReceived(out, format); + return; + } if (out.isEmpty()) return; bool ok; - qint64 pid = out.trimmed().toLongLong(&ok); + const qint64 pid = out.trimmed().toLongLong(&ok); if (!ok) { // m_remote.m_errorString = tr("Could not determine remote PID."); // emit ValgrindRunner::Private::error(QProcess::FailedToStart);