diff options
author | hjk <hjk@qt.io> | 2019-04-24 14:38:01 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2019-04-25 08:09:22 +0000 |
commit | 09df30396f6b5ef13ca810a728363716d257745f (patch) | |
tree | 6637533bff50ab768f0aa3d2bfb5a5a92fe0728c /src/plugins/remotelinux | |
parent | 4fcf061e1f3c1defc1391d9a38db57eecfa56ac3 (diff) | |
download | qt-creator-09df30396f6b5ef13ca810a728363716d257745f.tar.gz |
RemoteLinux: Use a structure to return check results
Instead of the combined bool value + QString * out parameter.
Change-Id: I8840f48b74aaacd1b0c0412efd8abcdc2be12d58
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/remotelinux')
20 files changed, 68 insertions, 67 deletions
diff --git a/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp b/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp index f525f777d0..c6d184ec12 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp +++ b/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp @@ -126,9 +126,9 @@ void AbstractRemoteLinuxDeployService::start() { QTC_ASSERT(d->state == Inactive, return); - QString errorMsg; - if (!isDeploymentPossible(&errorMsg)) { - emit errorMessage(errorMsg); + const CheckResult check = isDeploymentPossible(); + if (!check) { + emit errorMessage(check.errorMessage()); emit finished(); return; } @@ -165,14 +165,11 @@ void AbstractRemoteLinuxDeployService::stop() } } -bool AbstractRemoteLinuxDeployService::isDeploymentPossible(QString *whyNot) const +CheckResult AbstractRemoteLinuxDeployService::isDeploymentPossible() const { - if (!deviceConfiguration()) { - if (whyNot) - *whyNot = tr("No device configuration set."); - return false; - } - return true; + if (!deviceConfiguration()) + return CheckResult::failure(tr("No device configuration set.")); + return CheckResult::success(); } QVariantMap AbstractRemoteLinuxDeployService::exportDeployTimes() const diff --git a/src/plugins/remotelinux/abstractremotelinuxdeployservice.h b/src/plugins/remotelinux/abstractremotelinuxdeployservice.h index 9e55708d65..6ebf2d7592 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeployservice.h +++ b/src/plugins/remotelinux/abstractremotelinuxdeployservice.h @@ -43,6 +43,22 @@ class Target; namespace RemoteLinux { namespace Internal { class AbstractRemoteLinuxDeployServicePrivate; } +class REMOTELINUX_EXPORT CheckResult +{ +public: + static CheckResult success() { return {true, {}}; } + static CheckResult failure(const QString &error = {}) { return {false, error}; } + + operator bool() const { return m_ok; } + QString errorMessage() const { return m_error; } + +private: + CheckResult(bool ok, const QString &error) : m_ok(ok), m_error(error) {} + + bool m_ok = false; + QString m_error; +}; + class REMOTELINUX_EXPORT AbstractRemoteLinuxDeployService : public QObject { Q_OBJECT @@ -60,7 +76,7 @@ public: QVariantMap exportDeployTimes() const; void importDeployTimes(const QVariantMap &map); - virtual bool isDeploymentPossible(QString *whyNot = nullptr) const; + virtual CheckResult isDeploymentPossible() const; signals: void errorMessage(const QString &message); diff --git a/src/plugins/remotelinux/abstractremotelinuxdeploystep.cpp b/src/plugins/remotelinux/abstractremotelinuxdeploystep.cpp index 5827c4fa94..c6baf0d3dd 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeploystep.cpp +++ b/src/plugins/remotelinux/abstractremotelinuxdeploystep.cpp @@ -69,11 +69,12 @@ QVariantMap AbstractRemoteLinuxDeployStep::toMap() const bool AbstractRemoteLinuxDeployStep::init() { - QString error; deployService()->setTarget(target()); - const bool canDeploy = initInternal(&error); - if (!canDeploy) - emit addOutput(tr("Cannot deploy: %1").arg(error), OutputFormat::ErrorMessage); + const CheckResult canDeploy = initInternal(); + if (!canDeploy) { + emit addOutput(tr("Cannot deploy: %1").arg(canDeploy.errorMessage()), + OutputFormat::ErrorMessage); + } return canDeploy; } diff --git a/src/plugins/remotelinux/abstractremotelinuxdeploystep.h b/src/plugins/remotelinux/abstractremotelinuxdeploystep.h index 03741d3367..e8fac039b7 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeploystep.h +++ b/src/plugins/remotelinux/abstractremotelinuxdeploystep.h @@ -27,12 +27,11 @@ #include "remotelinux_export.h" -#include <projectexplorer/buildstep.h> +#include "abstractremotelinuxdeployservice.h" -#include <QVariantMap> +#include <projectexplorer/buildstep.h> namespace RemoteLinux { -class AbstractRemoteLinuxDeployService; namespace Internal { class AbstractRemoteLinuxDeployStepPrivate; } @@ -52,7 +51,7 @@ protected: void doCancel() override; explicit AbstractRemoteLinuxDeployStep(ProjectExplorer::BuildStepList *bsl, Core::Id id); - virtual bool initInternal(QString *error = nullptr) = 0; + virtual CheckResult initInternal() = 0; private: void handleProgressMessage(const QString &message); diff --git a/src/plugins/remotelinux/genericdirectuploadstep.cpp b/src/plugins/remotelinux/genericdirectuploadstep.cpp index 54b538ab45..27668c0a50 100644 --- a/src/plugins/remotelinux/genericdirectuploadstep.cpp +++ b/src/plugins/remotelinux/genericdirectuploadstep.cpp @@ -71,11 +71,11 @@ GenericDirectUploadStep::~GenericDirectUploadStep() delete d; } -bool GenericDirectUploadStep::initInternal(QString *error) +CheckResult GenericDirectUploadStep::initInternal() { d->deployService.setIncrementalDeployment(d->incrementalAspect->value()); d->deployService.setIgnoreMissingFiles(d->ignoreMissingFilesAspect->value()); - return d->deployService.isDeploymentPossible(error); + return d->deployService.isDeploymentPossible(); } GenericDirectUploadService *GenericDirectUploadStep::deployService() const diff --git a/src/plugins/remotelinux/genericdirectuploadstep.h b/src/plugins/remotelinux/genericdirectuploadstep.h index a543134e36..fa9b98205c 100644 --- a/src/plugins/remotelinux/genericdirectuploadstep.h +++ b/src/plugins/remotelinux/genericdirectuploadstep.h @@ -40,7 +40,7 @@ public: explicit GenericDirectUploadStep(ProjectExplorer::BuildStepList *bsl); ~GenericDirectUploadStep() override; - bool initInternal(QString *error = nullptr) override; + CheckResult initInternal() override; static Core::Id stepId(); static QString displayName(); diff --git a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp index de2d43906c..8b1fb6dfe8 100644 --- a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp +++ b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp @@ -102,18 +102,15 @@ void RemoteLinuxCheckForFreeDiskSpaceService::handleProcessFinished() stopDeployment(); } -bool RemoteLinuxCheckForFreeDiskSpaceService::isDeploymentPossible(QString *whyNot) const +CheckResult RemoteLinuxCheckForFreeDiskSpaceService::isDeploymentPossible() const { - if (!AbstractRemoteLinuxDeployService::isDeploymentPossible(whyNot)) - return false; if (!d->pathToCheck.startsWith(QLatin1Char('/'))) { - if (whyNot) { - *whyNot = tr("Cannot check for free disk space: \"%1\" is not an absolute path.") - .arg(d->pathToCheck); - } - return false; + return CheckResult::failure( + tr("Cannot check for free disk space: \"%1\" is not an absolute path.") + .arg(d->pathToCheck)); } - return true; + + return AbstractRemoteLinuxDeployService::isDeploymentPossible(); } void RemoteLinuxCheckForFreeDiskSpaceService::doDeploy() diff --git a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h index 3d6e76f5fb..2819eb00c7 100644 --- a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h +++ b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h @@ -49,7 +49,7 @@ private: void doDeviceSetup() override { handleDeviceSetupDone(true); } void stopDeviceSetup() override { handleDeviceSetupDone(false); } - bool isDeploymentPossible(QString *whyNot) const override; + CheckResult isDeploymentPossible() const override; void doDeploy() override; void stopDeployment() override; diff --git a/src/plugins/remotelinux/remotelinuxcheckforfreediskspacestep.cpp b/src/plugins/remotelinux/remotelinuxcheckforfreediskspacestep.cpp index d99e386c5e..1070083eeb 100644 --- a/src/plugins/remotelinux/remotelinuxcheckforfreediskspacestep.cpp +++ b/src/plugins/remotelinux/remotelinuxcheckforfreediskspacestep.cpp @@ -80,14 +80,13 @@ RemoteLinuxCheckForFreeDiskSpaceStep::~RemoteLinuxCheckForFreeDiskSpaceStep() delete d; } -bool RemoteLinuxCheckForFreeDiskSpaceStep::initInternal(QString *error) +CheckResult RemoteLinuxCheckForFreeDiskSpaceStep::initInternal() { - Q_UNUSED(error); d->deployService.setPathToCheck( static_cast<BaseStringAspect *>(aspect(PathToCheckAspectId))->value()); d->deployService.setRequiredSpaceInBytes( static_cast<BaseIntegerAspect *>(aspect(RequiredSpaceAspectId))->value()); - return true; + return CheckResult::success(); } AbstractRemoteLinuxDeployService *RemoteLinuxCheckForFreeDiskSpaceStep::deployService() const diff --git a/src/plugins/remotelinux/remotelinuxcheckforfreediskspacestep.h b/src/plugins/remotelinux/remotelinuxcheckforfreediskspacestep.h index f02748d511..afd5887f33 100644 --- a/src/plugins/remotelinux/remotelinuxcheckforfreediskspacestep.h +++ b/src/plugins/remotelinux/remotelinuxcheckforfreediskspacestep.h @@ -41,7 +41,7 @@ public: static QString displayName(); protected: - bool initInternal(QString *error) override; + CheckResult initInternal() override; AbstractRemoteLinuxDeployService *deployService() const override; private: diff --git a/src/plugins/remotelinux/remotelinuxcustomcommanddeploymentstep.cpp b/src/plugins/remotelinux/remotelinuxcustomcommanddeploymentstep.cpp index de2dc30da4..87c82e52f8 100644 --- a/src/plugins/remotelinux/remotelinuxcustomcommanddeploymentstep.cpp +++ b/src/plugins/remotelinux/remotelinuxcustomcommanddeploymentstep.cpp @@ -58,10 +58,10 @@ RemoteLinuxCustomCommandDeploymentStep::~RemoteLinuxCustomCommandDeploymentStep( delete d; } -bool RemoteLinuxCustomCommandDeploymentStep::initInternal(QString *error) +CheckResult RemoteLinuxCustomCommandDeploymentStep::initInternal() { d->service.setCommandLine(d->commandLineAspect->value().trimmed()); - return d->service.isDeploymentPossible(error); + return d->service.isDeploymentPossible(); } AbstractRemoteLinuxDeployService *RemoteLinuxCustomCommandDeploymentStep::deployService() const diff --git a/src/plugins/remotelinux/remotelinuxcustomcommanddeploymentstep.h b/src/plugins/remotelinux/remotelinuxcustomcommanddeploymentstep.h index a8f036f8da..325ceb0ebd 100644 --- a/src/plugins/remotelinux/remotelinuxcustomcommanddeploymentstep.h +++ b/src/plugins/remotelinux/remotelinuxcustomcommanddeploymentstep.h @@ -42,7 +42,7 @@ public: static QString displayName(); private: - bool initInternal(QString *error) override; + CheckResult initInternal() override; AbstractRemoteLinuxDeployService *deployService() const override; Internal::RemoteLinuxCustomCommandDeploymentStepPrivate *d; diff --git a/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.cpp b/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.cpp index ffa1dfe6af..c385f2a4ba 100644 --- a/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.cpp +++ b/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.cpp @@ -66,19 +66,14 @@ void RemoteLinuxCustomCommandDeployService::setCommandLine(const QString &comman d->commandLine = commandLine; } -bool RemoteLinuxCustomCommandDeployService::isDeploymentPossible(QString *whyNot) const +CheckResult RemoteLinuxCustomCommandDeployService::isDeploymentPossible() const { - QTC_ASSERT(d->state == Inactive, return false); - - if (!AbstractRemoteLinuxDeployService::isDeploymentPossible(whyNot)) - return false; - if (d->commandLine.isEmpty()) { - if (whyNot) - *whyNot = tr("No command line given."); - return false; - } + QTC_ASSERT(d->state == Inactive, return CheckResult::failure()); + + if (d->commandLine.isEmpty()) + return CheckResult::failure(tr("No command line given.")); - return true; + return AbstractRemoteLinuxDeployService::isDeploymentPossible(); } void RemoteLinuxCustomCommandDeployService::doDeploy() diff --git a/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.h b/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.h index 33b0e67b1d..cc2f7fb129 100644 --- a/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.h +++ b/src/plugins/remotelinux/remotelinuxcustomcommanddeployservice.h @@ -41,7 +41,7 @@ public: void setCommandLine(const QString &commandLine); bool isDeploymentNecessary() const override { return true; } - bool isDeploymentPossible(QString *whyNot = nullptr) const override; + CheckResult isDeploymentPossible() const override; protected: void doDeviceSetup() override { handleDeviceSetupDone(true); } diff --git a/src/plugins/remotelinux/remotelinuxkillappstep.cpp b/src/plugins/remotelinux/remotelinuxkillappstep.cpp index 855cb4c2ca..f6dd121e7c 100644 --- a/src/plugins/remotelinux/remotelinuxkillappstep.cpp +++ b/src/plugins/remotelinux/remotelinuxkillappstep.cpp @@ -44,15 +44,14 @@ RemoteLinuxKillAppStep::RemoteLinuxKillAppStep(BuildStepList *bsl, Core::Id id) setWidgetExpandedByDefault(false); } -bool RemoteLinuxKillAppStep::initInternal(QString *error) +CheckResult RemoteLinuxKillAppStep::initInternal() { - Q_UNUSED(error); Target * const theTarget = target(); - QTC_ASSERT(theTarget, return false); + QTC_ASSERT(theTarget, return CheckResult::failure()); RunConfiguration * const rc = theTarget->activeRunConfiguration(); const QString remoteExe = rc ? rc->runnable().executable : QString(); m_service->setRemoteExecutable(remoteExe); - return true; + return CheckResult::success(); } AbstractRemoteLinuxDeployService *RemoteLinuxKillAppStep::deployService() const diff --git a/src/plugins/remotelinux/remotelinuxkillappstep.h b/src/plugins/remotelinux/remotelinuxkillappstep.h index e1f9b3f47e..183db57b2a 100644 --- a/src/plugins/remotelinux/remotelinuxkillappstep.h +++ b/src/plugins/remotelinux/remotelinuxkillappstep.h @@ -41,7 +41,7 @@ public: static QString displayName(); private: - bool initInternal(QString *error) override; + CheckResult initInternal() override; AbstractRemoteLinuxDeployService *deployService() const override; RemoteLinuxKillAppService * const m_service; diff --git a/src/plugins/remotelinux/rsyncdeploystep.cpp b/src/plugins/remotelinux/rsyncdeploystep.cpp index 7b872b5fa3..25c0e12207 100644 --- a/src/plugins/remotelinux/rsyncdeploystep.cpp +++ b/src/plugins/remotelinux/rsyncdeploystep.cpp @@ -199,10 +199,10 @@ RsyncDeployStep::~RsyncDeployStep() delete d; } -bool RsyncDeployStep::initInternal(QString *error) +CheckResult RsyncDeployStep::initInternal() { d->deployService.setIgnoreMissingFiles(d->ignoreMissingFilesAspect->value()); - return d->deployService.isDeploymentPossible(error); + return d->deployService.isDeploymentPossible(); } AbstractRemoteLinuxDeployService *RsyncDeployStep::deployService() const diff --git a/src/plugins/remotelinux/rsyncdeploystep.h b/src/plugins/remotelinux/rsyncdeploystep.h index ec936f6e5e..ed81646882 100644 --- a/src/plugins/remotelinux/rsyncdeploystep.h +++ b/src/plugins/remotelinux/rsyncdeploystep.h @@ -57,7 +57,7 @@ private: AbstractRemoteLinuxDeployService *deployService() const override; void doRun() override; - bool initInternal(QString *error = nullptr) override; + CheckResult initInternal() override; class RsyncDeployStepPrivate; RsyncDeployStepPrivate * const d; diff --git a/src/plugins/remotelinux/uploadandinstalltarpackagestep.cpp b/src/plugins/remotelinux/uploadandinstalltarpackagestep.cpp index ecc7eb3997..cf1c2face6 100644 --- a/src/plugins/remotelinux/uploadandinstalltarpackagestep.cpp +++ b/src/plugins/remotelinux/uploadandinstalltarpackagestep.cpp @@ -69,7 +69,7 @@ UploadAndInstallTarPackageStep::UploadAndInstallTarPackageStep(BuildStepList *bs setWidgetExpandedByDefault(false); } -bool UploadAndInstallTarPackageStep::initInternal(QString *error) +CheckResult UploadAndInstallTarPackageStep::initInternal() { const TarPackageCreationStep *pStep = nullptr; @@ -79,13 +79,11 @@ bool UploadAndInstallTarPackageStep::initInternal(QString *error) if ((pStep = dynamic_cast<TarPackageCreationStep *>(step))) break; } - if (!pStep) { - if (error) - *error = tr("No tarball creation step found."); - return false; - } + if (!pStep) + return CheckResult::failure(tr("No tarball creation step found.")); + m_deployService->setPackageFilePath(pStep->packageFilePath()); - return m_deployService->isDeploymentPossible(error); + return m_deployService->isDeploymentPossible(); } Core::Id UploadAndInstallTarPackageStep::stepId() diff --git a/src/plugins/remotelinux/uploadandinstalltarpackagestep.h b/src/plugins/remotelinux/uploadandinstalltarpackagestep.h index de1d2f487d..a613e7426f 100644 --- a/src/plugins/remotelinux/uploadandinstalltarpackagestep.h +++ b/src/plugins/remotelinux/uploadandinstalltarpackagestep.h @@ -55,7 +55,7 @@ class REMOTELINUX_EXPORT UploadAndInstallTarPackageStep : public AbstractRemoteL public: explicit UploadAndInstallTarPackageStep(ProjectExplorer::BuildStepList *bsl); - bool initInternal(QString *error = nullptr) override; + CheckResult initInternal() override; static Core::Id stepId(); static QString displayName(); |