2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2022-05-26 15:10:06 +02:00
|
|
|
|
|
|
|
|
#include "killappstep.h"
|
|
|
|
|
|
2022-07-01 15:59:17 +02:00
|
|
|
#include "abstractremotelinuxdeploystep.h"
|
2022-05-27 15:41:57 +02:00
|
|
|
#include "abstractremotelinuxdeployservice.h"
|
2022-05-26 15:10:06 +02:00
|
|
|
#include "remotelinux_constants.h"
|
2022-07-01 15:59:17 +02:00
|
|
|
#include "remotelinuxtr.h"
|
2022-05-26 15:10:06 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2022-07-01 15:59:17 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2022-05-26 15:10:06 +02:00
|
|
|
#include <projectexplorer/runcontrol.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2022-07-01 15:59:17 +02:00
|
|
|
|
2022-05-26 15:10:06 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-07-01 15:59:17 +02:00
|
|
|
namespace RemoteLinux::Internal {
|
2022-05-26 15:10:06 +02:00
|
|
|
|
|
|
|
|
class KillAppService : public AbstractRemoteLinuxDeployService
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-09-01 08:00:21 +02:00
|
|
|
void setRemoteExecutable(const FilePath &filePath);
|
2022-05-26 15:10:06 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void handleStdErr();
|
|
|
|
|
void handleProcessFinished();
|
|
|
|
|
|
|
|
|
|
bool isDeploymentNecessary() const override;
|
|
|
|
|
|
|
|
|
|
void doDeploy() override;
|
|
|
|
|
void stopDeployment() override;
|
|
|
|
|
|
|
|
|
|
void handleSignalOpFinished(const QString &errorMessage);
|
|
|
|
|
void cleanup();
|
|
|
|
|
void finishDeployment();
|
|
|
|
|
|
2022-09-01 08:00:21 +02:00
|
|
|
FilePath m_remoteExecutable;
|
2022-07-01 15:59:17 +02:00
|
|
|
DeviceProcessSignalOperation::Ptr m_signalOperation;
|
2022-05-26 15:10:06 +02:00
|
|
|
};
|
|
|
|
|
|
2022-09-01 08:00:21 +02:00
|
|
|
void KillAppService::setRemoteExecutable(const FilePath &filePath)
|
2022-05-26 15:10:06 +02:00
|
|
|
{
|
|
|
|
|
m_remoteExecutable = filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool KillAppService::isDeploymentNecessary() const
|
|
|
|
|
{
|
|
|
|
|
return !m_remoteExecutable.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KillAppService::doDeploy()
|
|
|
|
|
{
|
|
|
|
|
m_signalOperation = deviceConfiguration()->signalOperation();
|
|
|
|
|
if (!m_signalOperation) {
|
|
|
|
|
handleDeploymentDone();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-01 15:59:17 +02:00
|
|
|
connect(m_signalOperation.data(), &DeviceProcessSignalOperation::finished,
|
2022-11-22 10:48:42 +01:00
|
|
|
this, &KillAppService::handleSignalOpFinished, Qt::QueuedConnection);
|
2022-09-01 08:00:21 +02:00
|
|
|
emit progressMessage(Tr::tr("Trying to kill \"%1\" on remote device...")
|
|
|
|
|
.arg(m_remoteExecutable.path()));
|
|
|
|
|
m_signalOperation->killProcess(m_remoteExecutable.path());
|
2022-05-26 15:10:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KillAppService::cleanup()
|
|
|
|
|
{
|
|
|
|
|
if (m_signalOperation) {
|
|
|
|
|
disconnect(m_signalOperation.data(), nullptr, this, nullptr);
|
|
|
|
|
m_signalOperation.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KillAppService::finishDeployment()
|
|
|
|
|
{
|
|
|
|
|
cleanup();
|
|
|
|
|
handleDeploymentDone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KillAppService::stopDeployment()
|
|
|
|
|
{
|
|
|
|
|
finishDeployment();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KillAppService::handleSignalOpFinished(const QString &errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (errorMessage.isEmpty())
|
2022-07-01 15:59:17 +02:00
|
|
|
emit progressMessage(Tr::tr("Remote application killed."));
|
2022-05-26 15:10:06 +02:00
|
|
|
else
|
2022-07-01 15:59:17 +02:00
|
|
|
emit progressMessage(Tr::tr("Failed to kill remote application. Assuming it was not running."));
|
2022-05-26 15:10:06 +02:00
|
|
|
finishDeployment();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 15:59:17 +02:00
|
|
|
class KillAppStep : public AbstractRemoteLinuxDeployStep
|
2022-05-26 15:10:06 +02:00
|
|
|
{
|
2022-07-01 15:59:17 +02:00
|
|
|
public:
|
|
|
|
|
KillAppStep(BuildStepList *bsl, Id id) : AbstractRemoteLinuxDeployStep(bsl, id)
|
|
|
|
|
{
|
2022-10-13 14:35:25 +02:00
|
|
|
auto service = new Internal::KillAppService;
|
|
|
|
|
setDeployService(service);
|
2022-07-01 15:59:17 +02:00
|
|
|
|
|
|
|
|
setWidgetExpandedByDefault(false);
|
|
|
|
|
|
|
|
|
|
setInternalInitializer([this, service] {
|
|
|
|
|
Target * const theTarget = target();
|
|
|
|
|
QTC_ASSERT(theTarget, return CheckResult::failure());
|
|
|
|
|
RunConfiguration * const rc = theTarget->activeRunConfiguration();
|
2022-09-01 08:00:21 +02:00
|
|
|
const FilePath remoteExe = rc ? rc->runnable().command.executable() : FilePath();
|
2022-07-01 15:59:17 +02:00
|
|
|
service->setRemoteExecutable(remoteExe);
|
|
|
|
|
return CheckResult::success();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-05-26 15:10:06 +02:00
|
|
|
|
2022-07-01 15:59:17 +02:00
|
|
|
KillAppStepFactory::KillAppStepFactory()
|
2022-05-26 15:10:06 +02:00
|
|
|
{
|
2022-07-01 15:59:17 +02:00
|
|
|
registerStep<KillAppStep>(Constants::KillAppStepId);
|
|
|
|
|
setDisplayName(Tr::tr("Kill current application instance"));
|
|
|
|
|
setSupportedConfiguration(RemoteLinux::Constants::DeployToGenericLinux);
|
|
|
|
|
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY);
|
2022-05-26 15:10:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-01 15:59:17 +02:00
|
|
|
} // RemoteLinux::Internal
|