Boot2Qt: Merge qdbstopapplicationservice into build step files

Change-Id: I1e7756305cdce77ffabf093fbdb49c2d12037f91
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-05-04 13:54:45 +02:00
parent bef1bd18f7
commit e304a25c31
5 changed files with 100 additions and 191 deletions

View File

@@ -26,34 +26,123 @@
#include "qdbstopapplicationstep.h"
#include "qdbconstants.h"
#include "qdbstopapplicationservice.h"
#include <projectexplorer/applicationlauncher.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/target.h>
#include <remotelinux/abstractremotelinuxdeploystep.h>
using namespace ProjectExplorer;
using namespace Utils;
namespace Qdb {
namespace Internal {
// QdbStopApplicationService
class QdbStopApplicationService : public RemoteLinux::AbstractRemoteLinuxDeployService
{
Q_DECLARE_TR_FUNCTIONS(Qdb::Internal::QdbStopApplicationService)
public:
QdbStopApplicationService() {}
~QdbStopApplicationService() { cleanup(); }
private:
void handleProcessFinished();
void handleAppendMessage(const QString &message, OutputFormat format);
bool isDeploymentNecessary() const final { return true; }
void doDeploy() final;
void stopDeployment() final;
void cleanup();
ApplicationLauncher m_applicationLauncher;
QString m_errorOutput;
};
void QdbStopApplicationService::handleProcessFinished()
{
const QString failureMessage = tr("Could not check and possibly stop running application.");
if (m_applicationLauncher.exitStatus() == QProcess::CrashExit) {
emit errorMessage(failureMessage);
stopDeployment();
return;
}
if (m_errorOutput.contains("Could not connect: Connection refused")) {
emit progressMessage(tr("Checked that there is no running application."));
} else if (!m_errorOutput.isEmpty()) {
emit stdErrData(m_errorOutput);
emit errorMessage(failureMessage);
} else {
emit progressMessage(tr("Stopped the running application."));
}
stopDeployment();
}
void QdbStopApplicationService::handleAppendMessage(const QString &message, OutputFormat format)
{
if (format == StdErrFormat)
m_errorOutput.append(message);
else
emit stdOutData(message);
}
void QdbStopApplicationService::doDeploy()
{
connect(&m_applicationLauncher, &ApplicationLauncher::errorOccurred,
this, [this] { emit stdErrData(m_applicationLauncher.errorString()); });
connect(&m_applicationLauncher, &ApplicationLauncher::finished,
this, &QdbStopApplicationService::handleProcessFinished);
connect(&m_applicationLauncher, &ApplicationLauncher::appendMessage,
this, &QdbStopApplicationService::handleAppendMessage);
Runnable runnable;
runnable.command = {Constants::AppcontrollerFilepath, {"--stop"}};
runnable.workingDirectory = "/usr/bin";
runnable.device = DeviceKitAspect::device(target()->kit());
m_applicationLauncher.setRunnable(runnable);
m_applicationLauncher.start();
}
void QdbStopApplicationService::stopDeployment()
{
cleanup();
handleDeploymentDone();
}
void QdbStopApplicationService::cleanup()
{
m_applicationLauncher.disconnect(this);
}
// QdbStopApplicationStep
class QdbStopApplicationStep final : public RemoteLinux::AbstractRemoteLinuxDeployStep
{
Q_DECLARE_TR_FUNCTIONS(Qdb::Internal::QdbStopApplicationStep)
public:
QdbStopApplicationStep(BuildStepList *bsl, Utils::Id id);
QdbStopApplicationStep(BuildStepList *bsl, Id id)
: AbstractRemoteLinuxDeployStep(bsl, id)
{
auto service = createDeployService<QdbStopApplicationService>();
setWidgetExpandedByDefault(false);
setInternalInitializer([service] { return service->isDeploymentPossible(); });
}
};
QdbStopApplicationStep::QdbStopApplicationStep(BuildStepList *bsl, Utils::Id id)
: AbstractRemoteLinuxDeployStep(bsl, id)
{
auto service = createDeployService<QdbStopApplicationService>();
setWidgetExpandedByDefault(false);
setInternalInitializer([service] { return service->isDeploymentPossible(); });
}
// QdbStopApplicationStepFactory