iOS: Dissolve IosRunControlFactory

Follows suite.

Change-Id: I2ef11d19d9a2d3d0f3f282a94f98a40478273fbc
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
hjk
2017-07-14 10:12:37 +02:00
parent cb0a09b74b
commit 6c04099601
4 changed files with 37 additions and 68 deletions

View File

@@ -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 <projectexplorer/devicesupport/devicemanager.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/runconfiguration.h>
#include <qtsupport/qtversionmanager.h>
#include <QtPlugin>
#include <projectexplorer/devicesupport/devicemanager.h>
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<Internal::IosRunConfiguration *>(runConfig) != nullptr;
};
RunControl::registerWorker<Internal::IosRunSupport>
(ProjectExplorer::Constants::NORMAL_RUN_MODE, constraint);
RunControl::registerWorker<Internal::IosDebugSupport>
(ProjectExplorer::Constants::DEBUG_RUN_MODE, constraint);
RunControl::registerWorker<Internal::IosQmlProfilerSupport>
(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, constraint);
return true;
}

View File

@@ -27,7 +27,6 @@
#include "iosconstants.h"
#include "iosrunconfiguration.h"
#include "iosrunner.h"
#include "iosmanager.h"
#include <debugger/analyzer/analyzermanager.h>
@@ -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<IosRunConfiguration *>(runConfiguration);
}
RunControl *IosRunControlFactory::create(RunConfiguration *runConfig,
Core::Id mode, QString *errorMessage)
{
Q_UNUSED(errorMessage);
Q_ASSERT(canRun(runConfig, mode));
IosRunConfiguration *rc = qobject_cast<IosRunConfiguration *>(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<RunControl> 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

View File

@@ -29,8 +29,6 @@
#include <qmakeprojectmanager/qmakerunconfigurationfactory.h>
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<Core::Id, QPointer<ProjectExplorer::RunControl> > m_activeRunControls;
};
} // namespace Internal
} // namespace Ios

View File

@@ -74,9 +74,29 @@ using namespace Utils;
namespace Ios {
namespace Internal {
static void stopRunningRunControl(RunControl *runControl)
{
static QMap<Core::Id, QPointer<RunControl>> 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<RunControl> 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<IosRunConfiguration *>(runControl->runConfiguration());
m_bundleDir = runConfig->bundleDirectory().toString();
m_arguments = QStringList(runConfig->commandLineArguments());