From 6c040996018bbcd32d17e45b82945fecb37352e1 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 14 Jul 2017 10:12:37 +0200 Subject: [PATCH] iOS: Dissolve IosRunControlFactory Follows suite. Change-Id: I2ef11d19d9a2d3d0f3f282a94f98a40478273fbc Reviewed-by: Vikas Pachdha --- src/plugins/ios/iosplugin.cpp | 19 +++++++++-- src/plugins/ios/iosrunfactories.cpp | 49 ----------------------------- src/plugins/ios/iosrunfactories.h | 17 ---------- src/plugins/ios/iosrunner.cpp | 20 ++++++++++++ 4 files changed, 37 insertions(+), 68 deletions(-) diff --git a/src/plugins/ios/iosplugin.cpp b/src/plugins/ios/iosplugin.cpp index 28e590167e0..b2b33d8ae32 100644 --- a/src/plugins/ios/iosplugin.cpp +++ b/src/plugins/ios/iosplugin.cpp @@ -36,17 +36,22 @@ #include "iosdsymbuildstep.h" #include "iosqtversionfactory.h" #include "iosrunfactories.h" +#include "iosrunner.h" #include "iossettingspage.h" #include "iossimulator.h" #include "iossimulatorfactory.h" #include "iostoolhandler.h" +#include "iosrunconfiguration.h" +#include #include +#include + #include #include -#include +using namespace ProjectExplorer; namespace Ios { namespace Internal { @@ -67,7 +72,6 @@ bool IosPlugin::initialize(const QStringList &arguments, QString *errorMessage) addAutoReleasedObject(new Internal::IosBuildConfigurationFactory); addAutoReleasedObject(new Internal::IosToolChainFactory); - addAutoReleasedObject(new Internal::IosRunControlFactory); addAutoReleasedObject(new Internal::IosRunConfigurationFactory); addAutoReleasedObject(new Internal::IosSettingsPage); addAutoReleasedObject(new Internal::IosQtVersionFactory); @@ -78,6 +82,17 @@ bool IosPlugin::initialize(const QStringList &arguments, QString *errorMessage) addAutoReleasedObject(new Internal::IosDsymBuildStepFactory); addAutoReleasedObject(new Internal::IosDeployConfigurationFactory); + auto constraint = [](RunConfiguration *runConfig) { + return qobject_cast(runConfig) != nullptr; + }; + + RunControl::registerWorker + (ProjectExplorer::Constants::NORMAL_RUN_MODE, constraint); + RunControl::registerWorker + (ProjectExplorer::Constants::DEBUG_RUN_MODE, constraint); + RunControl::registerWorker + (ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, constraint); + return true; } diff --git a/src/plugins/ios/iosrunfactories.cpp b/src/plugins/ios/iosrunfactories.cpp index b2d42b671b5..c41dcb8263f 100644 --- a/src/plugins/ios/iosrunfactories.cpp +++ b/src/plugins/ios/iosrunfactories.cpp @@ -27,7 +27,6 @@ #include "iosconstants.h" #include "iosrunconfiguration.h" -#include "iosrunner.h" #include "iosmanager.h" #include @@ -143,53 +142,5 @@ RunConfiguration *IosRunConfigurationFactory::doRestore(Target *parent, const QV return new IosRunConfiguration(parent, id, pathFromId(id)); } -IosRunControlFactory::IosRunControlFactory(QObject *parent) - : IRunControlFactory(parent) -{ -} - -bool IosRunControlFactory::canRun(RunConfiguration *runConfiguration, - Core::Id mode) const -{ - if (mode != ProjectExplorer::Constants::NORMAL_RUN_MODE - && mode != ProjectExplorer::Constants::DEBUG_RUN_MODE - && mode != ProjectExplorer::Constants::QML_PROFILER_RUN_MODE) { - return false; - } - - return qobject_cast(runConfiguration); -} - -RunControl *IosRunControlFactory::create(RunConfiguration *runConfig, - Core::Id mode, QString *errorMessage) -{ - Q_UNUSED(errorMessage); - Q_ASSERT(canRun(runConfig, mode)); - IosRunConfiguration *rc = qobject_cast(runConfig); - Q_ASSERT(rc); - Target *target = runConfig->target(); - QTC_ASSERT(target, return 0); - - Core::Id devId = DeviceKitInformation::deviceId(rc->target()->kit()); - // The device can only run an application at a time, if an app is running stop it. - if (m_activeRunControls.contains(devId)) { - if (QPointer activeRunControl = m_activeRunControls[devId]) - activeRunControl->initiateStop(); - m_activeRunControls.remove(devId); - } - auto runControl = new RunControl(runConfig, mode); - if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE) { - (void) new Ios::Internal::IosRunSupport(runControl); - } else if (mode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE) { - (void) new IosQmlProfilerSupport(runControl); - } else { - (void) new IosDebugSupport(runControl); - } - - if (devId.isValid()) - m_activeRunControls[devId] = runControl; - return runControl; -} - } // namespace Internal } // namespace Ios diff --git a/src/plugins/ios/iosrunfactories.h b/src/plugins/ios/iosrunfactories.h index 8e9b072639e..318e57e04ea 100644 --- a/src/plugins/ios/iosrunfactories.h +++ b/src/plugins/ios/iosrunfactories.h @@ -29,8 +29,6 @@ #include namespace ProjectExplorer { -class RunControl; -class RunConfigWidget; class Target; class Node; } // namespace ProjectExplorer @@ -68,20 +66,5 @@ private: const QVariantMap &map) override; }; -class IosRunControlFactory : public ProjectExplorer::IRunControlFactory -{ - Q_OBJECT - -public: - explicit IosRunControlFactory(QObject *parent = 0); - - bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, - Core::Id mode) const override; - ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration, - Core::Id mode, QString *) override; -private: - mutable QMap > m_activeRunControls; -}; - } // namespace Internal } // namespace Ios diff --git a/src/plugins/ios/iosrunner.cpp b/src/plugins/ios/iosrunner.cpp index 23400d34c74..0a09efe9336 100644 --- a/src/plugins/ios/iosrunner.cpp +++ b/src/plugins/ios/iosrunner.cpp @@ -74,9 +74,29 @@ using namespace Utils; namespace Ios { namespace Internal { +static void stopRunningRunControl(RunControl *runControl) +{ + static QMap> activeRunControls; + + RunConfiguration *runConfig = runControl->runConfiguration(); + Target *target = runConfig->target(); + Core::Id devId = DeviceKitInformation::deviceId(target->kit()); + + // The device can only run an application at a time, if an app is running stop it. + if (activeRunControls.contains(devId)) { + if (QPointer activeRunControl = activeRunControls[devId]) + activeRunControl->initiateStop(); + activeRunControls.remove(devId); + } + + if (devId.isValid()) + activeRunControls[devId] = runControl; +} + IosRunner::IosRunner(RunControl *runControl) : RunWorker(runControl) { + stopRunningRunControl(runControl); auto runConfig = qobject_cast(runControl->runConfiguration()); m_bundleDir = runConfig->bundleDirectory().toString(); m_arguments = QStringList(runConfig->commandLineArguments());