diff --git a/src/plugins/boot2qt/qdbmakedefaultappstep.cpp b/src/plugins/boot2qt/qdbmakedefaultappstep.cpp index 9bf2fa0daa6..6041a77adc8 100644 --- a/src/plugins/boot2qt/qdbmakedefaultappstep.cpp +++ b/src/plugins/boot2qt/qdbmakedefaultappstep.cpp @@ -34,10 +34,8 @@ public: private: bool isDeploymentNecessary() const final { return true; } - void doDeploy() final + Group deployRecipe() final { - QTC_ASSERT(!m_taskTree, return); - const auto setupHandler = [this](QtcProcess &process) { QString remoteExe; if (RunConfiguration *rc = target()->activeRunConfiguration()) { @@ -63,27 +61,10 @@ private: const auto errorHandler = [this](const QtcProcess &process) { emit errorMessage(tr("Remote process failed: %1").arg(process.errorString())); }; - const auto endHandler = [this] { - m_taskTree.release()->deleteLater(); - stopDeployment(); - }; - const Group root { - Process(setupHandler, doneHandler, errorHandler), - OnGroupDone(endHandler), - OnGroupError(endHandler) - }; - m_taskTree.reset(new TaskTree(root)); - m_taskTree->start(); - } - - void stopDeployment() final - { - m_taskTree.reset(); - handleDeploymentDone(); + return Group { Process(setupHandler, doneHandler, errorHandler) }; } bool m_makeDefault = true; - std::unique_ptr m_taskTree; }; // QdbMakeDefaultAppStep diff --git a/src/plugins/boot2qt/qdbstopapplicationstep.cpp b/src/plugins/boot2qt/qdbstopapplicationstep.cpp index 4bb8716d07c..5a838df1ef2 100644 --- a/src/plugins/boot2qt/qdbstopapplicationstep.cpp +++ b/src/plugins/boot2qt/qdbstopapplicationstep.cpp @@ -30,16 +30,11 @@ class QdbStopApplicationService : public RemoteLinux::AbstractRemoteLinuxDeployS private: bool isDeploymentNecessary() const final { return true; } - void doDeploy() final; - void stopDeployment() final; - - std::unique_ptr m_taskTree; + Group deployRecipe() final; }; -void QdbStopApplicationService::doDeploy() +Group QdbStopApplicationService::deployRecipe() { - QTC_ASSERT(!m_taskTree, return); - const auto setupHandler = [this](QtcProcess &process) { const auto device = DeviceKitAspect::device(target()->kit()); QTC_CHECK(device); @@ -75,24 +70,11 @@ void QdbStopApplicationService::doDeploy() } return GroupConfig(); }; - const auto rootEndHandler = [this] { - m_taskTree.release()->deleteLater(); - stopDeployment(); - }; const Group root { DynamicSetup(rootSetupHandler), - Process(setupHandler, doneHandler, errorHandler), - OnGroupDone(rootEndHandler), - OnGroupError(rootEndHandler) + Process(setupHandler, doneHandler, errorHandler) }; - m_taskTree.reset(new TaskTree(root)); - m_taskTree->start(); -} - -void QdbStopApplicationService::stopDeployment() -{ - m_taskTree.reset(); - handleDeploymentDone(); + return root; } // QdbStopApplicationStep diff --git a/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp b/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp index 0da7bfe405b..5c66d61067d 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp +++ b/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp @@ -12,12 +12,13 @@ #include #include +#include #include -#include #include using namespace ProjectExplorer; +using namespace Utils; namespace RemoteLinux { namespace Internal { @@ -34,6 +35,7 @@ public: DeploymentTimeInfo deployTimes; State state = Inactive; + std::unique_ptr m_taskTree; }; } // namespace Internal @@ -146,4 +148,23 @@ void AbstractRemoteLinuxDeployService::handleDeploymentDone() emit finished(); } +void AbstractRemoteLinuxDeployService::doDeploy() +{ + QTC_ASSERT(!d->m_taskTree, return); + d->m_taskTree.reset(new TaskTree(deployRecipe())); + const auto endHandler = [this] { + d->m_taskTree.release()->deleteLater(); + handleDeploymentDone(); + }; + connect(d->m_taskTree.get(), &TaskTree::done, this, endHandler); + connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, endHandler); + d->m_taskTree->start(); +} + +void AbstractRemoteLinuxDeployService::stopDeployment() +{ + d->m_taskTree.reset(); + handleDeploymentDone(); +} + } // namespace RemoteLinux diff --git a/src/plugins/remotelinux/abstractremotelinuxdeployservice.h b/src/plugins/remotelinux/abstractremotelinuxdeployservice.h index fd77fc58de4..f66691971b0 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeployservice.h +++ b/src/plugins/remotelinux/abstractremotelinuxdeployservice.h @@ -16,6 +16,8 @@ class Kit; class Target; } +namespace Utils::Tasking { class Group; } + namespace RemoteLinux { namespace Internal { class AbstractRemoteLinuxDeployServicePrivate; } @@ -77,8 +79,9 @@ protected: private: virtual bool isDeploymentNecessary() const = 0; - virtual void doDeploy() = 0; - virtual void stopDeployment() = 0; + virtual Utils::Tasking::Group deployRecipe() = 0; + void doDeploy(); + void stopDeployment(); Internal::AbstractRemoteLinuxDeployServicePrivate * const d; }; diff --git a/src/plugins/remotelinux/customcommanddeploystep.cpp b/src/plugins/remotelinux/customcommanddeploystep.cpp index 1a9bd864ebb..1ce5e6e4545 100644 --- a/src/plugins/remotelinux/customcommanddeploystep.cpp +++ b/src/plugins/remotelinux/customcommanddeploystep.cpp @@ -24,17 +24,15 @@ class CustomCommandDeployService : public AbstractRemoteLinuxDeployService { public: void setCommandLine(const QString &commandLine); - CheckResult isDeploymentPossible() const override; + CheckResult isDeploymentPossible() const final; protected: - void doDeploy() override; - void stopDeployment() override; + Group deployRecipe() final; private: - bool isDeploymentNecessary() const override { return true; } + bool isDeploymentNecessary() const final { return true; } QString m_commandLine; - std::unique_ptr m_taskTree; }; void CustomCommandDeployService::setCommandLine(const QString &commandLine) @@ -50,10 +48,8 @@ CheckResult CustomCommandDeployService::isDeploymentPossible() const return AbstractRemoteLinuxDeployService::isDeploymentPossible(); } -void CustomCommandDeployService::doDeploy() +Group CustomCommandDeployService::deployRecipe() { - QTC_ASSERT(!m_taskTree, return); - const auto setupHandler = [this](QtcProcess &process) { emit progressMessage(Tr::tr("Starting remote command \"%1\"...").arg(m_commandLine)); process.setCommand({deviceConfiguration()->filePath("/bin/sh"), @@ -78,23 +74,7 @@ void CustomCommandDeployService::doDeploy() .arg(process.exitCode())); } }; - const auto endHandler = [this] { - m_taskTree.release()->deleteLater(); - stopDeployment(); - }; - const Group root { - Process(setupHandler, doneHandler, errorHandler), - OnGroupDone(endHandler), - OnGroupError(endHandler) - }; - m_taskTree.reset(new TaskTree(root)); - m_taskTree->start(); -} - -void CustomCommandDeployService::stopDeployment() -{ - m_taskTree.reset(); - handleDeploymentDone(); + return Group { Process(setupHandler, doneHandler, errorHandler) }; } class CustomCommandDeployStep : public AbstractRemoteLinuxDeployStep diff --git a/src/plugins/remotelinux/genericdirectuploadservice.cpp b/src/plugins/remotelinux/genericdirectuploadservice.cpp index c49d8cefdff..44e815a8ffc 100644 --- a/src/plugins/remotelinux/genericdirectuploadservice.cpp +++ b/src/plugins/remotelinux/genericdirectuploadservice.cpp @@ -16,7 +16,6 @@ #include #include -#include using namespace ProjectExplorer; using namespace Utils; @@ -55,7 +54,6 @@ public: IncrementalDeployment incremental = IncrementalDeployment::NotSupported; bool ignoreMissingFiles = false; QList deployableFiles; - std::unique_ptr m_taskTree; }; QList collectFilesToUpload(const DeployableFile &deployable) @@ -125,12 +123,6 @@ bool GenericDirectUploadService::isDeploymentNecessary() const return !d->deployableFiles.isEmpty(); } -void GenericDirectUploadService::stopDeployment() -{ - d->m_taskTree.reset(); - handleDeploymentDone(); -} - QDateTime GenericDirectUploadServicePrivate::timestampFromStat(const DeployableFile &file, QtcProcess *statProc) { @@ -291,19 +283,8 @@ TaskItem GenericDirectUploadServicePrivate::chmodTree(const TreeStoragem_taskTree, return); - - const auto endHandler = [this] { - d->m_taskTree.release()->deleteLater(); - stopDeployment(); - }; - const auto doneHandler = [this, endHandler] { - emit progressMessage(Tr::tr("All files successfully deployed.")); - endHandler(); - }; - const auto preFilesToStat = [this](UploadStorage *storage) { QList filesToStat; for (const DeployableFile &file : std::as_const(d->deployableFiles)) { @@ -333,6 +314,9 @@ void GenericDirectUploadService::doDeploy() if (timestamp.isValid()) saveDeploymentTimeStamp(file, timestamp); }; + const auto doneHandler = [this] { + emit progressMessage(Tr::tr("All files successfully deployed.")); + }; const TreeStorage storage; const Group root { @@ -343,12 +327,9 @@ void GenericDirectUploadService::doDeploy() d->chmodTree(storage), d->statTree(storage, postFilesToStat, postStatEndHandler) }, - OnGroupDone(doneHandler), - OnGroupError(endHandler) + OnGroupDone(doneHandler) }; - - d->m_taskTree.reset(new TaskTree(root)); - d->m_taskTree->start(); + return root; } } //namespace RemoteLinux diff --git a/src/plugins/remotelinux/genericdirectuploadservice.h b/src/plugins/remotelinux/genericdirectuploadservice.h index d7281bece68..1d85aed6d34 100644 --- a/src/plugins/remotelinux/genericdirectuploadservice.h +++ b/src/plugins/remotelinux/genericdirectuploadservice.h @@ -21,18 +21,16 @@ class REMOTELINUX_EXPORT GenericDirectUploadService : public AbstractRemoteLinux Q_OBJECT public: GenericDirectUploadService(QObject *parent = nullptr); - ~GenericDirectUploadService() override; + ~GenericDirectUploadService(); void setDeployableFiles(const QList &deployableFiles); void setIncrementalDeployment(IncrementalDeployment incremental); void setIgnoreMissingFiles(bool ignoreMissingFiles); -protected: - bool isDeploymentNecessary() const override; - void doDeploy() override; - void stopDeployment() override; - private: + bool isDeploymentNecessary() const final; + Utils::Tasking::Group deployRecipe() final; + friend class Internal::GenericDirectUploadServicePrivate; Internal::GenericDirectUploadServicePrivate * const d; }; diff --git a/src/plugins/remotelinux/killappstep.cpp b/src/plugins/remotelinux/killappstep.cpp index 17b20bc72cd..f5629e6a169 100644 --- a/src/plugins/remotelinux/killappstep.cpp +++ b/src/plugins/remotelinux/killappstep.cpp @@ -27,19 +27,14 @@ public: void setRemoteExecutable(const FilePath &filePath) { m_remoteExecutable = filePath; } private: - bool isDeploymentNecessary() const override { return !m_remoteExecutable.isEmpty(); } - - void doDeploy() override; - void stopDeployment() override; + bool isDeploymentNecessary() const final { return !m_remoteExecutable.isEmpty(); } + Group deployRecipe() final; FilePath m_remoteExecutable; - std::unique_ptr m_taskTree; }; -void KillAppService::doDeploy() +Group KillAppService::deployRecipe() { - QTC_ASSERT(!m_taskTree, return); - const auto setupHandler = [this](DeviceProcessKiller &killer) { killer.setProcessPath(m_remoteExecutable); emit progressMessage(Tr::tr("Trying to kill \"%1\" on remote device...") @@ -52,25 +47,7 @@ void KillAppService::doDeploy() 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() -{ - m_taskTree.reset(); - handleDeploymentDone(); + return Group { Killer(setupHandler, doneHandler, errorHandler) }; } class KillAppStep : public AbstractRemoteLinuxDeployStep diff --git a/src/plugins/remotelinux/rsyncdeploystep.cpp b/src/plugins/remotelinux/rsyncdeploystep.cpp index 9b4cbe591aa..3214f1cbd06 100644 --- a/src/plugins/remotelinux/rsyncdeploystep.cpp +++ b/src/plugins/remotelinux/rsyncdeploystep.cpp @@ -35,16 +35,14 @@ public: void setFlags(const QString &flags) { m_flags = flags; } private: - bool isDeploymentNecessary() const override; - void doDeploy() override; - void stopDeployment() override; + bool isDeploymentNecessary() const final; + Group deployRecipe() final; TaskItem mkdirTask(); TaskItem transferTask(); mutable FilesToTransfer m_files; bool m_ignoreMissingFiles = false; QString m_flags; - std::unique_ptr m_taskTree; }; void RsyncDeployService::setDeployableFiles(const QList &files) @@ -110,28 +108,9 @@ TaskItem RsyncDeployService::transferTask() return Transfer(setupHandler, {}, errorHandler); } -void RsyncDeployService::doDeploy() +Group RsyncDeployService::deployRecipe() { - const auto finishHandler = [this] { - m_taskTree.release()->deleteLater(); - stopDeployment(); - }; - - const Group root { - mkdirTask(), - transferTask(), - OnGroupDone(finishHandler), - OnGroupError(finishHandler), - }; - - m_taskTree.reset(new TaskTree(root)); - m_taskTree->start(); -} - -void RsyncDeployService::stopDeployment() -{ - m_taskTree.reset(); - handleDeploymentDone(); + return Group { mkdirTask(), transferTask() }; } // RsyncDeployStep diff --git a/src/plugins/remotelinux/tarpackagedeploystep.cpp b/src/plugins/remotelinux/tarpackagedeploystep.cpp index a64aeb0e4e3..4de760e5460 100644 --- a/src/plugins/remotelinux/tarpackagedeploystep.cpp +++ b/src/plugins/remotelinux/tarpackagedeploystep.cpp @@ -16,8 +16,6 @@ #include #include -#include - using namespace ProjectExplorer; using namespace Utils; using namespace Utils::Tasking; @@ -31,15 +29,12 @@ public: private: QString remoteFilePath() const; - - bool isDeploymentNecessary() const override; - void doDeploy() override; - void stopDeployment() override; + bool isDeploymentNecessary() const final; + Group deployRecipe() final; TaskItem uploadTask(); TaskItem installTask(); FilePath m_packageFilePath; - std::unique_ptr m_taskTree; }; void TarPackageDeployService::setPackageFilePath(const FilePath &filePath) @@ -102,28 +97,9 @@ TaskItem TarPackageDeployService::installTask() return Process(setupHandler, doneHandler, errorHandler); } -void TarPackageDeployService::doDeploy() +Group TarPackageDeployService::deployRecipe() { - QTC_ASSERT(!m_taskTree, return); - - const auto finishHandler = [this] { - m_taskTree.release()->deleteLater(); - stopDeployment(); - }; - const Group root { - uploadTask(), - installTask(), - OnGroupDone(finishHandler), - OnGroupError(finishHandler), - }; - m_taskTree.reset(new TaskTree(root)); - m_taskTree->start(); -} - -void TarPackageDeployService::stopDeployment() -{ - m_taskTree.reset(); - handleDeploymentDone(); + return Group { uploadTask(), installTask() }; } // TarPackageDeployStep