diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index 74e8add824c..0e1ae93a25a 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -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 diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index 704894b7607..067262bcd57 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -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