forked from qt-creator/qt-creator
ProjectExplorer: Start transferring RunWorkerFactory ownership
... to the plugins providing them. To allow this being done one-by-one in the plugins, allow both central and per-plugin ownership, and clean up the central instances centrally. This step will be removed again once the transition is complete. Change-Id: Ica7786012e05ab83a0784448f2f8b3b781fe2167 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -524,6 +524,8 @@ ProjectExplorerPlugin::~ProjectExplorerPlugin()
|
|||||||
delete dd->m_toolChainManager;
|
delete dd->m_toolChainManager;
|
||||||
ProjectPanelFactory::destroyFactories();
|
ProjectPanelFactory::destroyFactories();
|
||||||
delete dd;
|
delete dd;
|
||||||
|
|
||||||
|
RunWorkerFactory::destroyRemainingRunWorkerFactories();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorerPlugin *ProjectExplorerPlugin::instance()
|
ProjectExplorerPlugin *ProjectExplorerPlugin::instance()
|
||||||
|
|||||||
@@ -683,17 +683,18 @@ FixedRunConfigurationFactory::availableCreators(Target *parent) const
|
|||||||
|
|
||||||
// RunWorkerFactory
|
// RunWorkerFactory
|
||||||
|
|
||||||
using RunWorkerFactories = std::vector<RunWorkerFactory>;
|
static QList<RunWorkerFactory *> g_runWorkerFactories;
|
||||||
|
|
||||||
static RunWorkerFactories &theWorkerFactories()
|
|
||||||
{
|
|
||||||
static RunWorkerFactories factories;
|
|
||||||
return factories;
|
|
||||||
}
|
|
||||||
|
|
||||||
RunWorkerFactory::RunWorkerFactory(Core::Id mode, Constraint constr, const WorkerCreator &prod, int prio)
|
RunWorkerFactory::RunWorkerFactory(Core::Id mode, Constraint constr, const WorkerCreator &prod, int prio)
|
||||||
: m_runMode(mode), m_constraint(constr), m_producer(prod), m_priority(prio)
|
: m_runMode(mode), m_constraint(constr), m_producer(prod), m_priority(prio)
|
||||||
{}
|
{
|
||||||
|
g_runWorkerFactories.append(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
RunWorkerFactory::~RunWorkerFactory()
|
||||||
|
{
|
||||||
|
g_runWorkerFactories.removeOne(this);
|
||||||
|
}
|
||||||
|
|
||||||
bool RunWorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
|
bool RunWorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
|
||||||
{
|
{
|
||||||
@@ -704,7 +705,10 @@ bool RunWorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMo
|
|||||||
return m_constraint(runConfiguration);
|
return m_constraint(runConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RunWorkerFactory::destroyRemainingRunWorkerFactories()
|
||||||
|
{
|
||||||
|
qDeleteAll(g_runWorkerFactories);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class ProjectExplorer::RunControl
|
\class ProjectExplorer::RunControl
|
||||||
@@ -1003,7 +1007,7 @@ RunWorker *RunControl::createWorker(Core::Id id)
|
|||||||
RunWorkerFactory::WorkerCreator RunControl::producer(RunConfiguration *runConfig, Core::Id runMode)
|
RunWorkerFactory::WorkerCreator RunControl::producer(RunConfiguration *runConfig, Core::Id runMode)
|
||||||
{
|
{
|
||||||
const auto canRun = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1, runConfig, runMode);
|
const auto canRun = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1, runConfig, runMode);
|
||||||
const RunWorkerFactories candidates = Utils::filtered(theWorkerFactories(), canRun);
|
const QList<RunWorkerFactory *> candidates = Utils::filtered(g_runWorkerFactories, canRun);
|
||||||
|
|
||||||
if (candidates.empty())
|
if (candidates.empty())
|
||||||
return {};
|
return {};
|
||||||
@@ -1013,12 +1017,7 @@ RunWorkerFactory::WorkerCreator RunControl::producer(RunConfiguration *runConfig
|
|||||||
std::bind(&RunWorkerFactory::priority, std::placeholders::_2));
|
std::bind(&RunWorkerFactory::priority, std::placeholders::_2));
|
||||||
const auto bestFactory = std::max_element(candidates.begin(), candidates.end(), higherPriority);
|
const auto bestFactory = std::max_element(candidates.begin(), candidates.end(), higherPriority);
|
||||||
|
|
||||||
return bestFactory->producer();
|
return (*bestFactory)->producer();
|
||||||
}
|
|
||||||
|
|
||||||
void RunControl::addWorkerFactory(const RunWorkerFactory &workerFactory)
|
|
||||||
{
|
|
||||||
theWorkerFactories().push_back(workerFactory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunControlPrivate::initiateStart()
|
void RunControlPrivate::initiateStart()
|
||||||
|
|||||||
@@ -456,12 +456,19 @@ public:
|
|||||||
RunWorkerFactory(Core::Id mode, Constraint constr, const WorkerCreator &prod,
|
RunWorkerFactory(Core::Id mode, Constraint constr, const WorkerCreator &prod,
|
||||||
int prio = 0);
|
int prio = 0);
|
||||||
|
|
||||||
|
virtual ~RunWorkerFactory();
|
||||||
|
|
||||||
bool canRun(RunConfiguration *runConfiguration, Core::Id m_runMode) const;
|
bool canRun(RunConfiguration *runConfiguration, Core::Id m_runMode) const;
|
||||||
|
|
||||||
int priority() const { return m_priority; }
|
int priority() const { return m_priority; }
|
||||||
WorkerCreator producer() const { return m_producer; }
|
WorkerCreator producer() const { return m_producer; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// FIXME: That's temporary until ownership has been transferred to
|
||||||
|
// the individual plugins.
|
||||||
|
friend class ProjectExplorerPlugin;
|
||||||
|
static void destroyRemainingRunWorkerFactories();
|
||||||
|
|
||||||
Core::Id m_runMode;
|
Core::Id m_runMode;
|
||||||
Constraint m_constraint;
|
Constraint m_constraint;
|
||||||
WorkerCreator m_producer;
|
WorkerCreator m_producer;
|
||||||
@@ -539,20 +546,20 @@ public:
|
|||||||
static void registerWorker(Core::Id runMode, const WorkerCreator &producer,
|
static void registerWorker(Core::Id runMode, const WorkerCreator &producer,
|
||||||
const Constraint &constraint = {})
|
const Constraint &constraint = {})
|
||||||
{
|
{
|
||||||
addWorkerFactory({runMode, constraint, producer});
|
(void) new RunWorkerFactory(runMode, constraint, producer);
|
||||||
}
|
}
|
||||||
template <class Worker>
|
template <class Worker>
|
||||||
static void registerWorker(Core::Id runMode, const Constraint &constraint, int priority = 0)
|
static void registerWorker(Core::Id runMode, const Constraint &constraint, int priority = 0)
|
||||||
{
|
{
|
||||||
auto producer = [](RunControl *rc) { return new Worker(rc); };
|
auto producer = [](RunControl *rc) { return new Worker(rc); };
|
||||||
addWorkerFactory({runMode, constraint, producer, priority});
|
(void) new RunWorkerFactory(runMode, constraint, producer, priority);
|
||||||
}
|
}
|
||||||
template <class Config, class Worker>
|
template <class Config, class Worker>
|
||||||
static void registerWorker(Core::Id runMode, int priority = 0)
|
static void registerWorker(Core::Id runMode, int priority = 0)
|
||||||
{
|
{
|
||||||
auto constraint = [](RunConfiguration *runConfig) { return qobject_cast<Config *>(runConfig) != nullptr; };
|
auto constraint = [](RunConfiguration *runConfig) { return qobject_cast<Config *>(runConfig) != nullptr; };
|
||||||
auto producer = [](RunControl *rc) { return new Worker(rc); };
|
auto producer = [](RunControl *rc) { return new Worker(rc); };
|
||||||
addWorkerFactory({runMode, constraint, producer, priority});
|
(void) new RunWorkerFactory(runMode, constraint, producer, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WorkerCreator producer(RunConfiguration *runConfiguration, Core::Id runMode);
|
static WorkerCreator producer(RunConfiguration *runConfiguration, Core::Id runMode);
|
||||||
@@ -570,7 +577,6 @@ private:
|
|||||||
friend class RunWorker;
|
friend class RunWorker;
|
||||||
friend class Internal::RunWorkerPrivate;
|
friend class Internal::RunWorkerPrivate;
|
||||||
|
|
||||||
static void addWorkerFactory(const RunWorkerFactory &workerFactory);
|
|
||||||
Internal::RunControlPrivate *d;
|
Internal::RunControlPrivate *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user