forked from qt-creator/qt-creator
PE: Replace QString with Utils::Result
Inside DeviceProcessSignalOperation::finished() signal. Task-number: QTCREATORBUG-27363 Change-Id: Iea1aced1105daf8f60e23d35466e0173d4e3669b Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -20,7 +20,7 @@ void AndroidSignalOperation::signalOperationViaADB(qint64 pid, int signal)
|
||||
struct InternalStorage {
|
||||
FilePath adbPath;
|
||||
QString runAs = {};
|
||||
QString errorMessage = {};
|
||||
Result result = Result::Ok;
|
||||
};
|
||||
|
||||
const Storage<InternalStorage> storage({AndroidConfig::adbToolPath()});
|
||||
@@ -33,16 +33,15 @@ void AndroidSignalOperation::signalOperationViaADB(qint64 pid, int signal)
|
||||
storage->runAs = process.stdOut();
|
||||
if (!storage->runAs.isEmpty())
|
||||
return true;
|
||||
storage->errorMessage = QLatin1String("Cannot find User for process: ")
|
||||
+ QString::number(pid);
|
||||
storage->result = Result::Error("Cannot find User for process: " + QString::number(pid));
|
||||
} else if (result == DoneWith::Error) {
|
||||
storage->errorMessage = QLatin1String(" adb process exit code: ")
|
||||
+ QString::number(process.exitCode());
|
||||
QString result = " adb process exit code: " + QString::number(process.exitCode());
|
||||
const QString adbError = process.errorString();
|
||||
if (!adbError.isEmpty())
|
||||
storage->errorMessage += QLatin1String(" adb process error: ") + adbError;
|
||||
result += " adb process error: " + adbError;
|
||||
storage->result = Result::Error(result);
|
||||
} else {
|
||||
storage->errorMessage = QLatin1String("adb process timed out");
|
||||
storage->result = Result::Error("adb process timed out");
|
||||
}
|
||||
return false;
|
||||
};
|
||||
@@ -53,14 +52,14 @@ void AndroidSignalOperation::signalOperationViaADB(qint64 pid, int signal)
|
||||
};
|
||||
const auto onKillDone = [storage, pid](const Process &process, DoneWith result) {
|
||||
if (result == DoneWith::Error) {
|
||||
storage->errorMessage = QLatin1String("Cannot kill process: ") + QString::number(pid)
|
||||
+ process.stdErr();
|
||||
storage->result = Result::Error("Cannot kill process: " + QString::number(pid)
|
||||
+ process.stdErr());
|
||||
} else if (result == DoneWith::Cancel) {
|
||||
storage->errorMessage = QLatin1String("adb process timed out");
|
||||
storage->result = Result::Error("adb process timed out");
|
||||
}
|
||||
};
|
||||
|
||||
const auto onDone = [this, storage] { emit finished(storage->errorMessage); };
|
||||
const auto onDone = [this, storage] { emit finished(storage->result); };
|
||||
|
||||
const Group recipe {
|
||||
ProcessTask(onCatSetup, onCatDone).withTimeout(5s),
|
||||
@@ -78,9 +77,8 @@ void AndroidSignalOperation::killProcess(qint64 pid)
|
||||
void AndroidSignalOperation::killProcess(const QString &filePath)
|
||||
{
|
||||
Q_UNUSED(filePath)
|
||||
m_errorMessage = QLatin1String("The android signal operation does "
|
||||
"not support killing by filepath.");
|
||||
emit finished(m_errorMessage);
|
||||
m_result = Result::Error("The android signal operation does not support killing by filepath.");
|
||||
emit finished(m_result);
|
||||
}
|
||||
|
||||
void AndroidSignalOperation::interruptProcess(qint64 pid)
|
||||
|
@@ -684,12 +684,12 @@ void GdbEngine::interruptInferior()
|
||||
DeviceProcessSignalOperation::Ptr signalOperation = dev->signalOperation();
|
||||
QTC_ASSERT(signalOperation, notifyInferiorStopFailed(); return);
|
||||
connect(signalOperation.get(), &DeviceProcessSignalOperation::finished,
|
||||
this, [this, signalOperation](const QString &error) {
|
||||
if (error.isEmpty()) {
|
||||
this, [this, signalOperation](const Result &result) {
|
||||
if (result) {
|
||||
showMessage("Interrupted " + QString::number(inferiorPid()));
|
||||
notifyInferiorStopOk();
|
||||
} else {
|
||||
showMessage(error, LogError);
|
||||
showMessage(result.error(), LogError);
|
||||
notifyInferiorStopFailed();
|
||||
}
|
||||
});
|
||||
|
@@ -30,41 +30,45 @@ namespace ProjectExplorer {
|
||||
void DesktopProcessSignalOperation::killProcess(qint64 pid)
|
||||
{
|
||||
killProcessSilently(pid);
|
||||
emit finished(m_errorMessage);
|
||||
emit finished(m_result);
|
||||
}
|
||||
|
||||
void DesktopProcessSignalOperation::killProcess(const QString &filePath)
|
||||
{
|
||||
m_errorMessage.clear();
|
||||
m_result = Result::Ok;
|
||||
const QList<ProcessInfo> processInfoList = ProcessInfo::processInfoList();
|
||||
for (const ProcessInfo &processInfo : processInfoList) {
|
||||
if (processInfo.commandLine == filePath)
|
||||
killProcessSilently(processInfo.processId);
|
||||
}
|
||||
emit finished(m_errorMessage);
|
||||
emit finished(m_result);
|
||||
}
|
||||
|
||||
void DesktopProcessSignalOperation::interruptProcess(qint64 pid)
|
||||
{
|
||||
m_errorMessage.clear();
|
||||
m_result = Result::Ok;
|
||||
interruptProcessSilently(pid);
|
||||
emit finished(m_errorMessage);
|
||||
emit finished(m_result);
|
||||
}
|
||||
|
||||
void DesktopProcessSignalOperation::appendMsgCannotKill(qint64 pid, const QString &why)
|
||||
{
|
||||
if (!m_errorMessage.isEmpty())
|
||||
m_errorMessage += QChar::fromLatin1('\n');
|
||||
m_errorMessage += Tr::tr("Cannot kill process with pid %1: %2").arg(pid).arg(why);
|
||||
m_errorMessage += QLatin1Char(' ');
|
||||
QString result = m_result.error();
|
||||
if (!result.isEmpty())
|
||||
result += QChar::fromLatin1('\n');
|
||||
result += Tr::tr("Cannot kill process with pid %1: %2").arg(pid).arg(why);
|
||||
result += QLatin1Char(' ');
|
||||
m_result = Result::Error(result);
|
||||
}
|
||||
|
||||
void DesktopProcessSignalOperation::appendMsgCannotInterrupt(qint64 pid, const QString &why)
|
||||
{
|
||||
if (!m_errorMessage.isEmpty())
|
||||
m_errorMessage += QChar::fromLatin1('\n');
|
||||
m_errorMessage += Tr::tr("Cannot interrupt process with pid %1: %2").arg(pid).arg(why);
|
||||
m_errorMessage += QLatin1Char(' ');
|
||||
QString result = m_result.error();
|
||||
if (!result.isEmpty())
|
||||
result += QChar::fromLatin1('\n');
|
||||
result += Tr::tr("Cannot interrupt process with pid %1: %2").arg(pid).arg(why);
|
||||
result += QLatin1Char(' ');
|
||||
m_result = Result::Error(result);
|
||||
}
|
||||
|
||||
void DesktopProcessSignalOperation::killProcessSilently(qint64 pid)
|
||||
|
@@ -766,8 +766,8 @@ void DeviceProcessKiller::start()
|
||||
}
|
||||
|
||||
connect(m_signalOperation.get(), &DeviceProcessSignalOperation::finished,
|
||||
this, [this](const QString &errorMessage) {
|
||||
m_errorString = errorMessage;
|
||||
this, [this](const Result &result) {
|
||||
m_errorString = result.error();
|
||||
emit done(toDoneResult(m_errorString.isEmpty()));
|
||||
});
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/id.h>
|
||||
#include <utils/portlist.h>
|
||||
#include <utils/result.h>
|
||||
#include <utils/store.h>
|
||||
|
||||
#include <QAbstractSocket>
|
||||
@@ -67,13 +68,13 @@ public:
|
||||
|
||||
signals:
|
||||
// If the error message is empty the operation was successful
|
||||
void finished(const QString &errorMessage);
|
||||
void finished(const Utils::Result &result);
|
||||
|
||||
protected:
|
||||
explicit DeviceProcessSignalOperation();
|
||||
|
||||
Utils::FilePath m_debuggerCommand;
|
||||
QString m_errorMessage;
|
||||
Utils::Result m_result = Utils::Result::Ok;
|
||||
};
|
||||
|
||||
// See cpp file for documentation.
|
||||
@@ -316,7 +317,7 @@ signals:
|
||||
private:
|
||||
Utils::FilePath m_processPath;
|
||||
DeviceProcessSignalOperation::Ptr m_signalOperation;
|
||||
QString m_errorString;
|
||||
QString m_errorString; // TODO: Replace with Result
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT DeviceProcessKillerTaskAdapter final
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <utils/processinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/result.h>
|
||||
#include <utils/treemodel.h>
|
||||
|
||||
#include <QTimer>
|
||||
@@ -96,7 +97,18 @@ void ProcessList::killProcess(int row)
|
||||
const ProcessInfo processInfo = at(row);
|
||||
d->signalOperation = d->device->signalOperation();
|
||||
connect(d->signalOperation.get(), &DeviceProcessSignalOperation::finished,
|
||||
this, &ProcessList::reportDelayedKillStatus);
|
||||
this, [this](const Result &result) {
|
||||
if (result) {
|
||||
QTC_CHECK(d->state == Killing);
|
||||
setFinished();
|
||||
emit processKilled();
|
||||
} else {
|
||||
QTC_CHECK(d->state != Inactive);
|
||||
setFinished();
|
||||
emit error(result.error());
|
||||
}
|
||||
d->signalOperation.reset();
|
||||
});
|
||||
d->signalOperation->killProcess(processInfo.processId);
|
||||
}
|
||||
|
||||
@@ -142,19 +154,4 @@ void ProcessList::handleUpdate()
|
||||
emit processListUpdated();
|
||||
}
|
||||
|
||||
void ProcessList::reportDelayedKillStatus(const QString &errorMessage)
|
||||
{
|
||||
if (errorMessage.isEmpty()) {
|
||||
QTC_CHECK(d->state == Killing);
|
||||
setFinished();
|
||||
emit processKilled();
|
||||
} else {
|
||||
QTC_CHECK(d->state != Inactive);
|
||||
setFinished();
|
||||
emit error(errorMessage);
|
||||
}
|
||||
|
||||
d->signalOperation.reset();
|
||||
}
|
||||
|
||||
} // ProjectExplorer
|
||||
|
@@ -38,8 +38,6 @@ signals:
|
||||
|
||||
private:
|
||||
void handleUpdate();
|
||||
void reportDelayedKillStatus(const QString &errorMessage);
|
||||
|
||||
void setFinished();
|
||||
|
||||
const std::unique_ptr<Internal::DeviceProcessListPrivate> d;
|
||||
|
@@ -77,15 +77,15 @@ void RemoteLinuxSignalOperation::interruptProcess(qint64 pid)
|
||||
|
||||
void RemoteLinuxSignalOperation::runnerDone()
|
||||
{
|
||||
m_errorMessage.clear();
|
||||
m_result = Result::Ok;
|
||||
if (m_process->exitStatus() != QProcess::NormalExit) {
|
||||
m_errorMessage = m_process->errorString();
|
||||
m_result = Result::Error(m_process->errorString());
|
||||
} else if (m_process->exitCode() != 0) {
|
||||
m_errorMessage = Tr::tr("Exit code is %1. stderr:").arg(m_process->exitCode())
|
||||
+ QLatin1Char(' ') + QString::fromLatin1(m_process->rawStdErr());
|
||||
m_result = Result::Error(Tr::tr("Exit code is %1. stderr:").arg(m_process->exitCode())
|
||||
+ ' ' + QString::fromLatin1(m_process->rawStdErr()));
|
||||
}
|
||||
m_process.release()->deleteLater();
|
||||
emit finished(m_errorMessage);
|
||||
emit finished(m_result);
|
||||
}
|
||||
|
||||
} // RemoteLinux
|
||||
|
Reference in New Issue
Block a user