ProjectExplorer: Introduce DeviceProcessKiller

It will be much easier to integrate it into TaskTree,
comparing to hierarchical DeviceProcessSignalOperation.

Change-Id: I6bc9580a3d88d7bfd01e641b09094c6fa8fb94d3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2022-11-24 15:10:37 +01:00
parent d4871731bd
commit c38a00513e
2 changed files with 49 additions and 3 deletions

View File

@@ -3,10 +3,10 @@
#include "idevice.h"
#include "sshparameters.h"
#include "devicemanager.h"
#include "deviceprocesslist.h"
#include "idevicefactory.h"
#include "sshparameters.h"
#include "../kit.h"
#include "../kitinformation.h"
@@ -654,4 +654,33 @@ DeviceProcessSignalOperation::DeviceProcessSignalOperation() = default;
DeviceEnvironmentFetcher::DeviceEnvironmentFetcher() = default;
void DeviceProcessKiller::start()
{
m_signalOperation.reset();
m_errorString.clear();
const IDevice::ConstPtr device = DeviceManager::deviceForPath(m_processPath);
if (!device) {
m_errorString = tr("No device for given path: \"%1\".").arg(m_processPath.toUserOutput());
emit done(false);
return;
}
m_signalOperation = device->signalOperation();
if (!m_signalOperation) {
m_errorString = tr("Device for path \"%1\" does not support killing processes.")
.arg(m_processPath.toUserOutput());
emit done(false);
return;
}
connect(m_signalOperation.get(), &DeviceProcessSignalOperation::finished,
this, [this](const QString &errorMessage) {
m_errorString = errorMessage;
emit done(m_errorString.isEmpty());
});
m_signalOperation->killProcess(m_processPath.path());
}
} // namespace ProjectExplorer

View File

@@ -257,7 +257,6 @@ private:
friend class DeviceManager;
};
class PROJECTEXPLORER_EXPORT DeviceTester : public QObject
{
Q_OBJECT
@@ -277,4 +276,22 @@ protected:
explicit DeviceTester(QObject *parent = nullptr);
};
class PROJECTEXPLORER_EXPORT DeviceProcessKiller : public QObject
{
Q_OBJECT
public:
void setProcessPath(const Utils::FilePath &path) { m_processPath = path; }
void start();
QString errorString() const { return m_errorString; }
signals:
void done(bool success);
private:
Utils::FilePath m_processPath;
DeviceProcessSignalOperation::Ptr m_signalOperation;
QString m_errorString;
};
} // namespace ProjectExplorer