forked from qt-creator/qt-creator
KillAppService: Reuse TaskTree
Change-Id: I250542724d537219a8c1ce222d7e941474671adf Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -17,68 +17,62 @@
|
|||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
using namespace Utils::Tasking;
|
||||||
|
|
||||||
namespace RemoteLinux::Internal {
|
namespace RemoteLinux::Internal {
|
||||||
|
|
||||||
class KillAppService : public AbstractRemoteLinuxDeployService
|
class KillAppService : public AbstractRemoteLinuxDeployService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void setRemoteExecutable(const FilePath &filePath);
|
void setRemoteExecutable(const FilePath &filePath) { m_remoteExecutable = filePath; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isDeploymentNecessary() const override;
|
bool isDeploymentNecessary() const override { return !m_remoteExecutable.isEmpty(); }
|
||||||
|
|
||||||
void doDeploy() override;
|
void doDeploy() override;
|
||||||
void stopDeployment() override;
|
void stopDeployment() override;
|
||||||
|
|
||||||
void handleSignalOpFinished(const QString &errorMessage);
|
|
||||||
|
|
||||||
FilePath m_remoteExecutable;
|
FilePath m_remoteExecutable;
|
||||||
DeviceProcessSignalOperation::Ptr m_signalOperation;
|
std::unique_ptr<TaskTree> m_taskTree;
|
||||||
};
|
};
|
||||||
|
|
||||||
void KillAppService::setRemoteExecutable(const FilePath &filePath)
|
|
||||||
{
|
|
||||||
m_remoteExecutable = filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KillAppService::isDeploymentNecessary() const
|
|
||||||
{
|
|
||||||
return !m_remoteExecutable.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void KillAppService::doDeploy()
|
void KillAppService::doDeploy()
|
||||||
{
|
{
|
||||||
m_signalOperation = deviceConfiguration()->signalOperation();
|
QTC_ASSERT(!m_taskTree, return);
|
||||||
if (!m_signalOperation) {
|
|
||||||
handleDeploymentDone();
|
const auto setupHandler = [this](DeviceProcessKiller &killer) {
|
||||||
return;
|
killer.setProcessPath(m_remoteExecutable);
|
||||||
}
|
|
||||||
connect(m_signalOperation.data(), &DeviceProcessSignalOperation::finished,
|
|
||||||
this, &KillAppService::handleSignalOpFinished, Qt::QueuedConnection);
|
|
||||||
emit progressMessage(Tr::tr("Trying to kill \"%1\" on remote device...")
|
emit progressMessage(Tr::tr("Trying to kill \"%1\" on remote device...")
|
||||||
.arg(m_remoteExecutable.path()));
|
.arg(m_remoteExecutable.path()));
|
||||||
m_signalOperation->killProcess(m_remoteExecutable.path());
|
};
|
||||||
|
const auto doneHandler = [this](const DeviceProcessKiller &) {
|
||||||
|
emit progressMessage(Tr::tr("Remote application killed."));
|
||||||
|
};
|
||||||
|
const auto errorHandler = [this](const DeviceProcessKiller &) {
|
||||||
|
emit progressMessage(Tr::tr("Failed to kill remote application. "
|
||||||
|
"Assuming it was not running."));
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto endHandler = [this] {
|
||||||
|
m_taskTree.release()->deleteLater();
|
||||||
|
stopDeployment();
|
||||||
|
};
|
||||||
|
|
||||||
|
const Group root {
|
||||||
|
Killer(setupHandler, doneHandler, errorHandler),
|
||||||
|
OnGroupDone(endHandler),
|
||||||
|
OnGroupError(endHandler)
|
||||||
|
};
|
||||||
|
m_taskTree.reset(new TaskTree(root));
|
||||||
|
m_taskTree->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KillAppService::stopDeployment()
|
void KillAppService::stopDeployment()
|
||||||
{
|
{
|
||||||
if (m_signalOperation) {
|
m_taskTree.reset();
|
||||||
disconnect(m_signalOperation.data(), nullptr, this, nullptr);
|
|
||||||
m_signalOperation.clear();
|
|
||||||
}
|
|
||||||
handleDeploymentDone();
|
handleDeploymentDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KillAppService::handleSignalOpFinished(const QString &errorMessage)
|
|
||||||
{
|
|
||||||
if (errorMessage.isEmpty())
|
|
||||||
emit progressMessage(Tr::tr("Remote application killed."));
|
|
||||||
else
|
|
||||||
emit progressMessage(Tr::tr("Failed to kill remote application. Assuming it was not running."));
|
|
||||||
stopDeployment();
|
|
||||||
}
|
|
||||||
|
|
||||||
class KillAppStep : public AbstractRemoteLinuxDeployStep
|
class KillAppStep : public AbstractRemoteLinuxDeployStep
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Reference in New Issue
Block a user