diff options
author | Christian Kandeler <christian.kandeler@nokia.com> | 2012-06-08 09:42:32 +0200 |
---|---|---|
committer | hjk <qthjk@ovi.com> | 2012-06-08 10:15:43 +0200 |
commit | 79de09f2663f818bb07c24752e6520b19b28e6ec (patch) | |
tree | 4ee8e676e73646f42476f4f01df3756997836f48 | |
parent | 303e67304e42cc419b735ca609104ad4ed386d54 (diff) |
SSH: Streamline SshRemoteProcessRunner's output handling.
Make it just like SshRemoteProcess (and QProcess). The current
implementation annoyingly forces client code to establish additional
signal/slot connections, even if they only want to evaluate the output
at the end.
Change-Id: Id8c30dd156574d7d26d848d8e0705856a16d3747
Reviewed-by: hjk <qthjk@ovi.com>
24 files changed, 111 insertions, 181 deletions
diff --git a/src/libs/ssh/sshremoteprocessrunner.cpp b/src/libs/ssh/sshremoteprocessrunner.cpp index 598f1cfaee..d9c5b9153f 100644 --- a/src/libs/ssh/sshremoteprocessrunner.cpp +++ b/src/libs/ssh/sshremoteprocessrunner.cpp @@ -62,6 +62,8 @@ public: QString m_lastConnectionErrorString; SshRemoteProcess::ExitStatus m_exitStatus; SshRemoteProcess::Signal m_exitSignal; + QByteArray m_stdout; + QByteArray m_stderr; int m_exitCode; QString m_processErrorString; State m_state; @@ -187,12 +189,14 @@ void SshRemoteProcessRunner::handleProcessFinished(int exitStatus) void SshRemoteProcessRunner::handleStdout() { - emit processOutputAvailable(d->m_process->readAllStandardOutput()); + d->m_stdout += d->m_process->readAllStandardOutput(); + emit readyReadStandardOutput(); } void SshRemoteProcessRunner::handleStderr() { - emit processErrorOutputAvailable(d->m_process->readAllStandardError()); + d->m_stderr += d->m_process->readAllStandardError(); + emit readyReadStandardError(); } void SshRemoteProcessRunner::setState(int newState) @@ -249,6 +253,20 @@ QString SshRemoteProcessRunner::processErrorString() const return d->m_processErrorString; } +QByteArray SshRemoteProcessRunner::readAllStandardOutput() +{ + const QByteArray data = d->m_stdout; + d->m_stdout.clear(); + return data; +} + +QByteArray SshRemoteProcessRunner::readAllStandardError() +{ + const QByteArray data = d->m_stderr; + d->m_stderr.clear(); + return data; +} + void SshRemoteProcessRunner::writeDataToProcess(const QByteArray &data) { QSSH_ASSERT(isProcessRunning()); diff --git a/src/libs/ssh/sshremoteprocessrunner.h b/src/libs/ssh/sshremoteprocessrunner.h index 57d755bc0f..de8f583f21 100644 --- a/src/libs/ssh/sshremoteprocessrunner.h +++ b/src/libs/ssh/sshremoteprocessrunner.h @@ -65,6 +65,15 @@ public: SshRemoteProcess::Signal processExitSignal() const; int processExitCode() const; QString processErrorString() const; + QByteArray readAllStandardOutput(); + QByteArray readAllStandardError(); + +signals: + void connectionError(); + void processStarted(); + void readyReadStandardOutput(); + void readyReadStandardError(); + void processClosed(int exitStatus); // values are of type SshRemoteProcess::ExitStatus private slots: void handleConnected(); @@ -75,13 +84,6 @@ private slots: void handleStdout(); void handleStderr(); -signals: - void connectionError(); - void processStarted(); - void processOutputAvailable(const QByteArray &output); - void processErrorOutputAvailable(const QByteArray &output); - void processClosed(int exitStatus); // values are of type SshRemoteProcess::ExitStatus - private: void runInternal(const QByteArray &command, const QSsh::SshConnectionParameters &sshParams); void setState(int newState); diff --git a/src/plugins/debugger/lldb/lldbenginehost.cpp b/src/plugins/debugger/lldb/lldbenginehost.cpp index 9e36567ee8..ea0b249c03 100644 --- a/src/plugins/debugger/lldb/lldbenginehost.cpp +++ b/src/plugins/debugger/lldb/lldbenginehost.cpp @@ -70,10 +70,8 @@ SshIODevice::SshIODevice(QSsh::SshRemoteProcessRunner *r) { setOpenMode(QIODevice::ReadWrite | QIODevice::Unbuffered); connect (runner, SIGNAL(processStarted()), this, SLOT(processStarted())); - connect(runner, SIGNAL(processOutputAvailable(QByteArray)), - this, SLOT(outputAvailable(QByteArray))); - connect(runner, SIGNAL(processErrorOutputAvailable(QByteArray)), - this, SLOT(errorOutputAvailable(QByteArray))); + connect(runner, SIGNAL(readyReadStandardOutput()), this, SLOT(outputAvailable())); + connect(runner, SIGNAL(readyReadStandardError()), this, SLOT(errorOutputAvailable())); } SshIODevice::~SshIODevice() @@ -130,15 +128,15 @@ void SshIODevice::processStarted() runner->writeDataToProcess(startupbuffer); } -void SshIODevice::outputAvailable(const QByteArray &output) +void SshIODevice::outputAvailable() { - buckets.enqueue(output); + buckets.enqueue(runner->readAllStandardOutput()); emit readyRead(); } -void SshIODevice::errorOutputAvailable(const QByteArray &output) +void SshIODevice::errorOutputAvailable() { - fprintf(stderr, "%s", output.data()); + fprintf(stderr, "%s", runner->readAllStandardError().data()); } diff --git a/src/plugins/debugger/lldb/lldbenginehost.h b/src/plugins/debugger/lldb/lldbenginehost.h index 5b301b3962..9abc9e31cb 100644 --- a/src/plugins/debugger/lldb/lldbenginehost.h +++ b/src/plugins/debugger/lldb/lldbenginehost.h @@ -56,8 +56,8 @@ public: virtual qint64 readData (char * data, qint64 maxSize); private slots: void processStarted(); - void outputAvailable(const QByteArray &output); - void errorOutputAvailable(const QByteArray &output); + void outputAvailable(); + void errorOutputAvailable(); private: QSsh::SshRemoteProcessRunner *runner; QSsh::SshRemoteProcess::Ptr proc; diff --git a/src/plugins/madde/maddedevicetester.cpp b/src/plugins/madde/maddedevicetester.cpp index 5c17b76a7b..914a3da4cc 100644 --- a/src/plugins/madde/maddedevicetester.cpp +++ b/src/plugins/madde/maddedevicetester.cpp @@ -110,10 +110,6 @@ void MaddeDeviceTester::handleGenericTestFinished(TestResult result) if (!m_processRunner) m_processRunner = new SshRemoteProcessRunner(this); connect(m_processRunner, SIGNAL(connectionError()), SLOT(handleConnectionError())); - connect(m_processRunner, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleStdout(QByteArray))); - connect(m_processRunner, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(handleStderr(QByteArray))); connect(m_processRunner, SIGNAL(processClosed(int)), SLOT(handleProcessFinished(int))); QString qtInfoCmd; @@ -125,8 +121,6 @@ void MaddeDeviceTester::handleGenericTestFinished(TestResult result) } emit progressMessage(tr("Checking for Qt libraries...")); - m_stdout.clear(); - m_stderr.clear(); m_state = QtTest; m_processRunner->run(qtInfoCmd.toUtf8(), m_deviceConfiguration->sshParameters()); } @@ -141,22 +135,6 @@ void MaddeDeviceTester::handleConnectionError() setFinished(); } -void MaddeDeviceTester::handleStdout(const QByteArray &data) -{ - QTC_ASSERT(m_state == QtTest || m_state == MadDeveloperTest || m_state == QmlToolingTest, - return); - - m_stdout += data; -} - -void MaddeDeviceTester::handleStderr(const QByteArray &data) -{ - QTC_ASSERT(m_state == QtTest || m_state == MadDeveloperTest || m_state == QmlToolingTest, - return); - - m_stderr += data; -} - void MaddeDeviceTester::handleProcessFinished(int exitStatus) { switch (m_state) { @@ -178,9 +156,10 @@ void MaddeDeviceTester::handleQtTestFinished(int exitStatus) { if (exitStatus != SshRemoteProcess::NormalExit || m_processRunner->processExitCode() != 0) { - if (!m_stderr.isEmpty()) { + const QByteArray stdErr = m_processRunner->readAllStandardError(); + if (!stdErr.isEmpty()) { emit errorMessage(tr("Error checking for Qt libraries: %1\n") - .arg(QString::fromUtf8(m_stderr))); + .arg(QString::fromUtf8(stdErr))); } else { emit errorMessage(tr("Error checking for Qt libraries.\n")); } @@ -190,9 +169,6 @@ void MaddeDeviceTester::handleQtTestFinished(int exitStatus) emit progressMessage(processedQtLibsList()); } - m_stdout.clear(); - m_stderr.clear(); - emit progressMessage(tr("Checking for connectivity support...")); m_state = MadDeveloperTest; m_processRunner->run(QString(QLatin1String("test -x") + MaemoGlobal::devrootshPath()).toUtf8(), @@ -202,9 +178,10 @@ void MaddeDeviceTester::handleQtTestFinished(int exitStatus) void MaddeDeviceTester::handleMadDeveloperTestFinished(int exitStatus) { if (exitStatus != SshRemoteProcess::NormalExit) { - if (!m_stderr.isEmpty()) { + const QByteArray stdErr = m_processRunner->readAllStandardError(); + if (!stdErr.isEmpty()) { emit errorMessage(tr("Error checking for connectivity tool: %1\n") - .arg(QString::fromUtf8(m_stderr))); + .arg(QString::fromUtf8(stdErr))); } else { emit errorMessage(tr("Error checking for connectivity tool.\n")); } @@ -227,9 +204,6 @@ void MaddeDeviceTester::handleMadDeveloperTestFinished(int exitStatus) return; } - m_stdout.clear(); - m_stderr.clear(); - emit progressMessage(tr("Checking for QML tooling support...")); m_state = QmlToolingTest; m_processRunner->run(QString(QLatin1String("test -d ") @@ -239,9 +213,10 @@ void MaddeDeviceTester::handleMadDeveloperTestFinished(int exitStatus) void MaddeDeviceTester::handleQmlToolingTestFinished(int exitStatus) { if (exitStatus != SshRemoteProcess::NormalExit) { - if (!m_stderr.isEmpty()) { + const QByteArray stdErr = m_processRunner->readAllStandardError(); + if (!stdErr.isEmpty()) { emit errorMessage(tr("Error checking for QML tooling support: %1\n") - .arg(QString::fromUtf8(m_stderr))); + .arg(QString::fromUtf8(stdErr))); } else { emit errorMessage(tr("Error checking for QML tooling support.\n")); } @@ -259,7 +234,7 @@ void MaddeDeviceTester::handleQmlToolingTestFinished(int exitStatus) QString MaddeDeviceTester::processedQtLibsList() { - QString unfilteredLibs = QString::fromUtf8(m_stdout); + QString unfilteredLibs = QString::fromUtf8(m_processRunner->readAllStandardOutput()); QString filteredLibs; QString patternString; if (m_deviceConfiguration->type() == Core::Id(MeeGoOsType)) diff --git a/src/plugins/madde/maddedevicetester.h b/src/plugins/madde/maddedevicetester.h index 46248f2c64..11d1baf79b 100644 --- a/src/plugins/madde/maddedevicetester.h +++ b/src/plugins/madde/maddedevicetester.h @@ -56,8 +56,6 @@ public: private slots: void handleGenericTestFinished(RemoteLinux::AbstractLinuxDeviceTester::TestResult result); void handleConnectionError(); - void handleStdout(const QByteArray &data); - void handleStderr(const QByteArray &data); void handleProcessFinished(int exitStatus); private: @@ -75,8 +73,6 @@ private: TestResult m_result; QSsh::SshRemoteProcessRunner *m_processRunner; QSharedPointer<const RemoteLinux::LinuxDeviceConfiguration> m_deviceConfiguration; - QByteArray m_stdout; - QByteArray m_stderr; }; } // namespace Internal diff --git a/src/plugins/madde/maemopublisherfremantlefree.cpp b/src/plugins/madde/maemopublisherfremantlefree.cpp index 86d92bc971..dfab66adb9 100644 --- a/src/plugins/madde/maemopublisherfremantlefree.cpp +++ b/src/plugins/madde/maemopublisherfremantlefree.cpp @@ -396,8 +396,7 @@ void MaemoPublisherFremantleFree::uploadPackage() connect(m_uploader, SIGNAL(processStarted()), SLOT(handleScpStarted())); connect(m_uploader, SIGNAL(connectionError()), SLOT(handleConnectionError())); connect(m_uploader, SIGNAL(processClosed(int)), SLOT(handleUploadJobFinished(int))); - connect(m_uploader, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleScpStdOut(QByteArray))); + connect(m_uploader, SIGNAL(readyReadStandardOutput()), SLOT(handleScpStdOut())); emit progressReport(tr("Starting scp...")); setState(StartingScp); m_uploader->run("scp -td " + m_remoteDir.toUtf8(), m_sshParams); @@ -488,7 +487,7 @@ void MaemoPublisherFremantleFree::sendFile() m_uploader->writeDataToProcess(QByteArray(1, '\0')); } -void MaemoPublisherFremantleFree::handleScpStdOut(const QByteArray &output) +void MaemoPublisherFremantleFree::handleScpStdOut() { QTC_ASSERT(m_state == PreparingToUploadFile || m_state == UploadingFile || m_state == Inactive, return); @@ -496,7 +495,7 @@ void MaemoPublisherFremantleFree::handleScpStdOut(const QByteArray &output) if (m_state == Inactive) return; - m_scpOutput += output; + m_scpOutput += m_uploader->readAllStandardOutput(); if (m_scpOutput == QByteArray(1, '\0')) { m_scpOutput.clear(); switch (m_state) { diff --git a/src/plugins/madde/maemopublisherfremantlefree.h b/src/plugins/madde/maemopublisherfremantlefree.h index 39a692e964..621691f320 100644 --- a/src/plugins/madde/maemopublisherfremantlefree.h +++ b/src/plugins/madde/maemopublisherfremantlefree.h @@ -87,7 +87,7 @@ private slots: void handleScpStarted(); void handleConnectionError(); void handleUploadJobFinished(int exitStatus); - void handleScpStdOut(const QByteArray &output); + void handleScpStdOut(); private: enum State { diff --git a/src/plugins/madde/maemoremotecopyfacility.cpp b/src/plugins/madde/maemoremotecopyfacility.cpp index a196560f5b..6521e5a9d0 100644 --- a/src/plugins/madde/maemoremotecopyfacility.cpp +++ b/src/plugins/madde/maemoremotecopyfacility.cpp @@ -66,10 +66,8 @@ void MaemoRemoteCopyFacility::copyFiles(SshConnection *connection, if (!m_copyRunner) m_copyRunner = new SshRemoteProcessRunner(this); connect(m_copyRunner, SIGNAL(connectionError()), SLOT(handleConnectionError())); - connect(m_copyRunner, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleRemoteStdout(QByteArray))); - connect(m_copyRunner, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(handleRemoteStderr(QByteArray))); + connect(m_copyRunner, SIGNAL(readyReadStandardOutput()), SLOT(handleRemoteStdout())); + connect(m_copyRunner, SIGNAL(readyReadStandardError()), SLOT(handleRemoteStderr())); connect(m_copyRunner, SIGNAL(processClosed(int)), SLOT(handleCopyFinished(int))); m_isCopying = true; @@ -92,14 +90,14 @@ void MaemoRemoteCopyFacility::handleConnectionError() emit finished(tr("Connection failed: %1").arg(m_copyRunner->lastConnectionErrorString())); } -void MaemoRemoteCopyFacility::handleRemoteStdout(const QByteArray &output) +void MaemoRemoteCopyFacility::handleRemoteStdout() { - emit stdoutData(QString::fromUtf8(output)); + emit stdoutData(QString::fromUtf8(m_copyRunner->readAllStandardOutput())); } -void MaemoRemoteCopyFacility::handleRemoteStderr(const QByteArray &output) +void MaemoRemoteCopyFacility::handleRemoteStderr() { - emit stderrData(QString::fromUtf8(output)); + emit stderrData(QString::fromUtf8(m_copyRunner->readAllStandardError())); } void MaemoRemoteCopyFacility::handleCopyFinished(int exitStatus) diff --git a/src/plugins/madde/maemoremotecopyfacility.h b/src/plugins/madde/maemoremotecopyfacility.h index 9fedb15998..90a7a5dee2 100644 --- a/src/plugins/madde/maemoremotecopyfacility.h +++ b/src/plugins/madde/maemoremotecopyfacility.h @@ -74,8 +74,8 @@ signals: private slots: void handleConnectionError(); void handleCopyFinished(int exitStatus); - void handleRemoteStdout(const QByteArray &output); - void handleRemoteStderr(const QByteArray &output); + void handleRemoteStdout(); + void handleRemoteStderr(); private: void copyNextFile(); diff --git a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp index e9c35dab06..bbfe7cc731 100644 --- a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp +++ b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp @@ -46,7 +46,6 @@ public: QString pathToCheck; quint64 requiredSpaceInBytes; QSsh::SshRemoteProcessRunner *processRunner; - QByteArray processOutput; }; } // namespace Internal @@ -74,14 +73,9 @@ void RemoteLinuxCheckForFreeDiskSpaceService::setRequiredSpaceInBytes(quint64 si d->requiredSpaceInBytes = sizeInBytes; } -void RemoteLinuxCheckForFreeDiskSpaceService::handleStdOut(const QByteArray &output) +void RemoteLinuxCheckForFreeDiskSpaceService::handleStdErr() { - d->processOutput += output; -} - -void RemoteLinuxCheckForFreeDiskSpaceService::handleStdErr(const QByteArray &output) -{ - emit stdErrData(QString::fromUtf8(output)); + emit stdErrData(QString::fromUtf8(d->processRunner->readAllStandardError())); } void RemoteLinuxCheckForFreeDiskSpaceService::handleProcessFinished() @@ -100,11 +94,12 @@ void RemoteLinuxCheckForFreeDiskSpaceService::handleProcessFinished() } bool isNumber; - d->processOutput.chop(1); // newline - quint64 freeSpace = d->processOutput.toULongLong(&isNumber); + QByteArray processOutput = d->processRunner->readAllStandardOutput(); + processOutput.chop(1); // newline + quint64 freeSpace = processOutput.toULongLong(&isNumber); if (!isNumber) { emit errorMessage(tr("Unexpected output from remote process: '%1'.") - .arg(QString::fromUtf8(d->processOutput))); + .arg(QString::fromUtf8(processOutput))); stopDeployment(); return; } @@ -140,10 +135,7 @@ void RemoteLinuxCheckForFreeDiskSpaceService::doDeploy() { d->processRunner = new QSsh::SshRemoteProcessRunner; connect(d->processRunner, SIGNAL(processClosed(int)), SLOT(handleProcessFinished())); - connect(d->processRunner, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleStdOut(QByteArray))); - connect(d->processRunner, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(handleStdErr(QByteArray))); + connect(d->processRunner, SIGNAL(readyReadStandardError()), SLOT(handleStdErr())); const QString command = QString::fromLocal8Bit("df -k -P %1 |tail -n 1 |sed 's/ */ /g' " "|cut -d ' ' -f 4").arg(d->pathToCheck); d->processRunner->run(command.toUtf8(), deviceConfiguration()->sshParameters()); @@ -163,7 +155,6 @@ void RemoteLinuxCheckForFreeDiskSpaceService::cleanup() delete d->processRunner; d->processRunner = 0; } - d->processOutput.clear(); } } // namespace RemoteLinux diff --git a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h index 21014322cf..de212df17b 100644 --- a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h +++ b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h @@ -48,8 +48,7 @@ public: void setRequiredSpaceInBytes(quint64 sizeInBytes); private slots: - void handleStdOut(const QByteArray &output); - void handleStdErr(const QByteArray &output); + void handleStdErr(); void handleProcessFinished(); private: diff --git a/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.cpp b/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.cpp index 021755c6eb..e5595db2e3 100644 --- a/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.cpp +++ b/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.cpp @@ -99,10 +99,8 @@ void RemoteLinuxCustomCommandDeployService::doDeploy() if (!d->runner) d->runner = new SshRemoteProcessRunner(this); - connect(d->runner, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleStdout(QByteArray))); - connect(d->runner, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(handleStderr(QByteArray))); + connect(d->runner, SIGNAL(readyReadStandardOutput()), SLOT(handleStdout())); + connect(d->runner, SIGNAL(readyReadStandardError()), SLOT(handleStderr())); connect(d->runner, SIGNAL(processClosed(int)), SLOT(handleProcessClosed(int))); emit progressMessage(tr("Starting remote command '%1'...").arg(d->commandLine)); @@ -120,14 +118,14 @@ void RemoteLinuxCustomCommandDeployService::stopDeployment() handleDeploymentDone(); } -void RemoteLinuxCustomCommandDeployService::handleStdout(const QByteArray &output) +void RemoteLinuxCustomCommandDeployService::handleStdout() { - emit stdOutData(QString::fromUtf8(output)); + emit stdOutData(QString::fromUtf8(d->runner->readAllStandardOutput())); } -void RemoteLinuxCustomCommandDeployService::handleStderr(const QByteArray &output) +void RemoteLinuxCustomCommandDeployService::handleStderr() { - emit stdErrData(QString::fromUtf8(output)); + emit stdErrData(QString::fromUtf8(d->runner->readAllStandardError())); } void RemoteLinuxCustomCommandDeployService::handleProcessClosed(int exitStatus) diff --git a/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.h b/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.h index 6a31d19172..2097b96b41 100644 --- a/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.h +++ b/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.h @@ -59,8 +59,8 @@ protected: void stopDeployment(); private slots: - void handleStdout(const QByteArray &output); - void handleStderr(const QByteArray &output); + void handleStdout(); + void handleStderr(); void handleProcessClosed(int exitStatus); private: diff --git a/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp b/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp index 43aa56542f..5b51621fca 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp +++ b/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp @@ -63,13 +63,8 @@ void RemoteLinuxEnvironmentReader::start(const QString &environmentSetupCommand) m_remoteProcessRunner = new QSsh::SshRemoteProcessRunner(this); connect(m_remoteProcessRunner, SIGNAL(connectionError()), SLOT(handleConnectionFailure())); connect(m_remoteProcessRunner, SIGNAL(processClosed(int)), SLOT(remoteProcessFinished(int))); - connect(m_remoteProcessRunner, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(remoteOutput(QByteArray))); - connect(m_remoteProcessRunner, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(remoteErrorOutput(QByteArray))); const QByteArray remoteCall = QString(environmentSetupCommand + QLatin1String("; env")).toUtf8(); - m_remoteOutput.clear(); m_remoteProcessRunner->run(remoteCall, m_devConfig->sshParameters()); } @@ -112,32 +107,22 @@ void RemoteLinuxEnvironmentReader::remoteProcessFinished(int exitCode) disconnect(m_remoteProcessRunner, 0, this, 0); m_env.clear(); if (exitCode == QSsh::SshRemoteProcess::NormalExit) { - if (!m_remoteOutput.isEmpty()) { - m_env = Utils::Environment(m_remoteOutput.split(QLatin1Char('\n'), + QString remoteOutput = QString::fromUtf8(m_remoteProcessRunner->readAllStandardOutput()); + if (!remoteOutput.isEmpty()) { + m_env = Utils::Environment(remoteOutput.split(QLatin1Char('\n'), QString::SkipEmptyParts)); } } else { QString errorMsg = tr("Error running remote process: %1") .arg(m_remoteProcessRunner->processErrorString()); - if (!m_remoteErrorOutput.isEmpty()) { - errorMsg += tr("\nRemote stderr was: '%1'") - .arg(QString::fromUtf8(m_remoteErrorOutput)); - } + QString remoteStderr = m_remoteProcessRunner->readAllStandardError(); + if (!remoteStderr.isEmpty()) + errorMsg += tr("\nRemote stderr was: '%1'").arg(remoteStderr); emit error(errorMsg); } setFinished(); } -void RemoteLinuxEnvironmentReader::remoteOutput(const QByteArray &data) -{ - m_remoteOutput.append(QString::fromUtf8(data)); -} - -void RemoteLinuxEnvironmentReader::remoteErrorOutput(const QByteArray &data) -{ - m_remoteErrorOutput += data; -} - void RemoteLinuxEnvironmentReader::setFinished() { stop(); diff --git a/src/plugins/remotelinux/remotelinuxenvironmentreader.h b/src/plugins/remotelinux/remotelinuxenvironmentreader.h index 7f49be8edb..acda6147d9 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentreader.h +++ b/src/plugins/remotelinux/remotelinuxenvironmentreader.h @@ -68,15 +68,11 @@ private slots: void handleCurrentDeviceConfigChanged(); void remoteProcessFinished(int exitCode); - void remoteOutput(const QByteArray &data); - void remoteErrorOutput(const QByteArray &data); private: void setFinished(); bool m_stop; - QString m_remoteOutput; - QByteArray m_remoteErrorOutput; Utils::Environment m_env; QSharedPointer<const LinuxDeviceConfiguration> m_devConfig; RemoteLinuxRunConfiguration *m_runConfig; diff --git a/src/plugins/remotelinux/remotelinuxpackageinstaller.cpp b/src/plugins/remotelinux/remotelinuxpackageinstaller.cpp index 1ee09be145..6e41b63743 100644 --- a/src/plugins/remotelinux/remotelinuxpackageinstaller.cpp +++ b/src/plugins/remotelinux/remotelinuxpackageinstaller.cpp @@ -76,10 +76,8 @@ void AbstractRemoteLinuxPackageInstaller::installPackage(const LinuxDeviceConfig if (!d->installer) d->installer = new SshRemoteProcessRunner(this); connect(d->installer, SIGNAL(connectionError()), SLOT(handleConnectionError())); - connect(d->installer, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleInstallerOutput(QByteArray))); - connect(d->installer, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(handleInstallerErrorOutput(QByteArray))); + connect(d->installer, SIGNAL(readyReadStandardOutput()), SLOT(handleInstallerOutput())); + connect(d->installer, SIGNAL(readyReadStandardError()), SLOT(handleInstallerErrorOutput())); connect(d->installer, SIGNAL(processClosed(int)), SLOT(handleInstallationFinished(int))); QString cmdLine = installCommandLine(packageFilePath); @@ -123,14 +121,14 @@ void AbstractRemoteLinuxPackageInstaller::handleInstallationFinished(int exitSta setFinished(); } -void AbstractRemoteLinuxPackageInstaller::handleInstallerOutput(const QByteArray &output) +void AbstractRemoteLinuxPackageInstaller::handleInstallerOutput() { - emit stdoutData(QString::fromUtf8(output)); + emit stdoutData(QString::fromUtf8(d->installer->readAllStandardOutput())); } -void AbstractRemoteLinuxPackageInstaller::handleInstallerErrorOutput(const QByteArray &output) +void AbstractRemoteLinuxPackageInstaller::handleInstallerErrorOutput() { - emit stderrData(QString::fromUtf8(output)); + emit stderrData(QString::fromUtf8(d->installer->readAllStandardError())); } void AbstractRemoteLinuxPackageInstaller::setFinished() diff --git a/src/plugins/remotelinux/remotelinuxpackageinstaller.h b/src/plugins/remotelinux/remotelinuxpackageinstaller.h index ebdd0bf20d..e00755898f 100644 --- a/src/plugins/remotelinux/remotelinuxpackageinstaller.h +++ b/src/plugins/remotelinux/remotelinuxpackageinstaller.h @@ -67,8 +67,8 @@ protected: private slots: void handleConnectionError(); void handleInstallationFinished(int exitStatus); - void handleInstallerOutput(const QByteArray &output); - void handleInstallerErrorOutput(const QByteArray &output); + void handleInstallerOutput(); + void handleInstallerErrorOutput(); private: virtual QString installCommandLine(const QString &packageFilePath) const = 0; diff --git a/src/plugins/remotelinux/remotelinuxprocesslist.cpp b/src/plugins/remotelinux/remotelinuxprocesslist.cpp index e2b5cf7221..3af19dcd8e 100644 --- a/src/plugins/remotelinux/remotelinuxprocesslist.cpp +++ b/src/plugins/remotelinux/remotelinuxprocesslist.cpp @@ -67,8 +67,6 @@ public: const LinuxDeviceConfiguration::ConstPtr deviceConfiguration; SshRemoteProcessRunner process; QList<RemoteProcess> remoteProcesses; - QByteArray remoteStdout; - QByteArray remoteStderr; QString errorMsg; State state; }; @@ -152,18 +150,6 @@ QVariant AbstractRemoteLinuxProcessList::data(const QModelIndex &index, int role return QVariant(); } -void AbstractRemoteLinuxProcessList::handleRemoteStdOut(const QByteArray &output) -{ - if (d->state == Listing) - d->remoteStdout += output; -} - -void AbstractRemoteLinuxProcessList::handleRemoteStdErr(const QByteArray &output) -{ - if (d->state != Inactive) - d->remoteStderr += output; -} - void AbstractRemoteLinuxProcessList::handleConnectionError() { QTC_ASSERT(d->state != Inactive, return); @@ -192,8 +178,9 @@ void AbstractRemoteLinuxProcessList::handleRemoteProcessFinished(int exitStatus) if (d->process.processExitCode() == 0) { if (d->state == Listing) { beginResetModel(); - QList<RemoteProcess> processes = buildProcessList(QString::fromUtf8(d->remoteStdout.data(), - d->remoteStdout.count())); + const QByteArray remoteStdout = d->process.readAllStandardOutput(); + QList<RemoteProcess> processes = buildProcessList(QString::fromUtf8(remoteStdout.data(), + remoteStdout.count())); if (!processes.isEmpty()) { beginInsertRows(QModelIndex(), 0, processes.count()-1); d->remoteProcesses = processes; @@ -212,8 +199,9 @@ void AbstractRemoteLinuxProcessList::handleRemoteProcessFinished(int exitStatus) emit processListUpdated(); if (!d->errorMsg.isEmpty()) { - if (!d->remoteStderr.isEmpty()) - d->errorMsg += tr("\nRemote stderr was: %1").arg(QString::fromUtf8(d->remoteStderr)); + const QByteArray remoteStderr = d->process.readAllStandardError(); + if (!remoteStderr.isEmpty()) + d->errorMsg += tr("\nRemote stderr was: %1").arg(QString::fromUtf8(remoteStderr)); emit error(d->errorMsg); } else if (d->state == Killing) { emit processKilled(); @@ -225,14 +213,8 @@ void AbstractRemoteLinuxProcessList::handleRemoteProcessFinished(int exitStatus) void AbstractRemoteLinuxProcessList::startProcess(const QString &cmdLine) { connect(&d->process, SIGNAL(connectionError()), SLOT(handleConnectionError())); - connect(&d->process, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleRemoteStdOut(QByteArray))); - connect(&d->process, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(handleRemoteStdErr(QByteArray))); connect(&d->process, SIGNAL(processClosed(int)), SLOT(handleRemoteProcessFinished(int))); - d->remoteStdout.clear(); - d->remoteStderr.clear(); d->errorMsg.clear(); d->process.run(cmdLine.toUtf8(), d->deviceConfiguration->sshParameters()); } diff --git a/src/plugins/remotelinux/remotelinuxprocesslist.h b/src/plugins/remotelinux/remotelinuxprocesslist.h index a69e7778fc..82ff05ab99 100644 --- a/src/plugins/remotelinux/remotelinuxprocesslist.h +++ b/src/plugins/remotelinux/remotelinuxprocesslist.h @@ -78,8 +78,6 @@ protected: QSharedPointer<const LinuxDeviceConfiguration> deviceConfiguration() const; private slots: - void handleRemoteStdOut(const QByteArray &output); - void handleRemoteStdErr(const QByteArray &output); void handleConnectionError(); void handleRemoteProcessFinished(int exitStatus); diff --git a/src/plugins/remotelinux/startgdbserverdialog.cpp b/src/plugins/remotelinux/startgdbserverdialog.cpp index 9cc6d5d06c..fb4a5d279e 100644 --- a/src/plugins/remotelinux/startgdbserverdialog.cpp +++ b/src/plugins/remotelinux/startgdbserverdialog.cpp @@ -349,13 +349,14 @@ void StartGdbServerDialog::handleProcessStarted() logMessage(tr("Starting gdbserver...")); } -void StartGdbServerDialog::handleProcessOutputAvailable(const QByteArray &ba) +void StartGdbServerDialog::handleProcessOutputAvailable() { - logMessage(QString::fromUtf8(ba.trimmed())); + logMessage(QString::fromUtf8(d->runner.readAllStandardOutput().trimmed())); } -void StartGdbServerDialog::handleProcessErrorOutput(const QByteArray &ba) +void StartGdbServerDialog::handleProcessErrorOutput() { + const QByteArray ba = d->runner.readAllStandardError(); logMessage(QString::fromUtf8(ba.trimmed())); // "Attached; pid = 16740" // "Listening on port 10000" @@ -397,10 +398,8 @@ void StartGdbServerDialog::startGdbServerOnPort(int port, int pid) LinuxDeviceConfiguration::ConstPtr device = d->currentDevice(); connect(&d->runner, SIGNAL(connectionError()), SLOT(handleConnectionError())); connect(&d->runner, SIGNAL(processStarted()), SLOT(handleProcessStarted())); - connect(&d->runner, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleProcessOutputAvailable(QByteArray))); - connect(&d->runner, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(handleProcessErrorOutput(QByteArray))); + connect(&d->runner, SIGNAL(readyReadStandardOutput()), SLOT(handleProcessOutputAvailable())); + connect(&d->runner, SIGNAL(readyReadStandardError()), SLOT(handleProcessErrorOutput())); connect(&d->runner, SIGNAL(processClosed(int)), SLOT(handleProcessClosed(int))); QByteArray cmd = "/usr/bin/gdbserver --attach :" diff --git a/src/plugins/remotelinux/startgdbserverdialog.h b/src/plugins/remotelinux/startgdbserverdialog.h index e996af3669..ebff6a9332 100644 --- a/src/plugins/remotelinux/startgdbserverdialog.h +++ b/src/plugins/remotelinux/startgdbserverdialog.h @@ -67,8 +67,8 @@ private slots: void portListReady(); void handleProcessClosed(int); - void handleProcessErrorOutput(const QByteArray &data); - void handleProcessOutputAvailable(const QByteArray &data); + void handleProcessErrorOutput(); + void handleProcessOutputAvailable(); void handleProcessStarted(); void handleConnectionError(); diff --git a/tests/manual/ssh/remoteprocess/remoteprocesstest.cpp b/tests/manual/ssh/remoteprocess/remoteprocesstest.cpp index 3fc7b7e6a9..d648c53418 100644 --- a/tests/manual/ssh/remoteprocess/remoteprocesstest.cpp +++ b/tests/manual/ssh/remoteprocess/remoteprocesstest.cpp @@ -66,10 +66,8 @@ void RemoteProcessTest::run() SLOT(handleConnectionError())); connect(m_remoteRunner, SIGNAL(processStarted()), SLOT(handleProcessStarted())); - connect(m_remoteRunner, SIGNAL(processOutputAvailable(QByteArray)), - SLOT(handleProcessStdout(QByteArray))); - connect(m_remoteRunner, SIGNAL(processErrorOutputAvailable(QByteArray)), - SLOT(handleProcessStderr(QByteArray))); + connect(m_remoteRunner, SIGNAL(readyReadStandardOutput()), SLOT(handleProcessStdout())); + connect(m_remoteRunner, SIGNAL(readyReadStandardError()), SLOT(handleProcessStderr())); connect(m_remoteRunner, SIGNAL(processClosed(int)), SLOT(handleProcessClosed(int))); @@ -109,7 +107,7 @@ void RemoteProcessTest::handleProcessStarted() } } -void RemoteProcessTest::handleProcessStdout(const QByteArray &output) +void RemoteProcessTest::handleProcessStdout() { if (!m_started) { std::cerr << "Error: Remote output from non-started process." @@ -120,11 +118,11 @@ void RemoteProcessTest::handleProcessStdout(const QByteArray &output) << "." << std::endl; qApp->quit(); } else { - m_remoteStdout += output; + m_remoteStdout += m_remoteRunner->readAllStandardOutput(); } } -void RemoteProcessTest::handleProcessStderr(const QByteArray &output) +void RemoteProcessTest::handleProcessStderr() { if (!m_started) { std::cerr << "Error: Remote error output from non-started process." @@ -135,7 +133,7 @@ void RemoteProcessTest::handleProcessStderr(const QByteArray &output) << std::endl; qApp->quit(); } else { - m_remoteStderr += output; + m_remoteStderr += m_remoteRunner->readAllStandardError(); } } diff --git a/tests/manual/ssh/remoteprocess/remoteprocesstest.h b/tests/manual/ssh/remoteprocess/remoteprocesstest.h index 73dd633e1a..3aef059272 100644 --- a/tests/manual/ssh/remoteprocess/remoteprocesstest.h +++ b/tests/manual/ssh/remoteprocess/remoteprocesstest.h @@ -51,8 +51,8 @@ public: private slots: void handleConnectionError(); void handleProcessStarted(); - void handleProcessStdout(const QByteArray &output); - void handleProcessStderr(const QByteArray &output); + void handleProcessStdout(); + void handleProcessStderr(); void handleProcessClosed(int exitStatus); void handleTimeout(); void handleReadyRead(); |