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