Commit 8376afd9 authored by hjk's avatar hjk

ProjectExplorer: Remove RunControl::worker<Type>()

It looks like the case where workers need talk to each other by
only knowing the type of the 'partner' does not exist in practice
anymore. With the now-common setup of a 'primary' worker that one
can introduce the 'lesser' workers to each other directly.

That's also conceptually more robust that picking a partner by
type only only from some 'pool' (all the workers in a runcontrol),
scales better (it e.g. is imaginable that a RunControl needs
more than one PortGatherer in complex setups where more than one
device is involved) saves a few cycles, and even removes the need
for workers to be qobject_cast-able.

Change-Id: Ib3d8c942c893d6c198d9813cce7df28ba3260ce8
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
Reviewed-by: default avatarhjk <hjk@qt.io>
parent 2cacf24b
...@@ -739,8 +739,8 @@ void GdbServerPortsGatherer::start() ...@@ -739,8 +739,8 @@ void GdbServerPortsGatherer::start()
// GdbServerRunner // GdbServerRunner
GdbServerRunner::GdbServerRunner(RunControl *runControl) GdbServerRunner::GdbServerRunner(RunControl *runControl, GdbServerPortsGatherer *portsGatherer)
: RunWorker(runControl) : RunWorker(runControl), m_portsGatherer(portsGatherer)
{ {
setDisplayName("GdbServerRunner"); setDisplayName("GdbServerRunner");
} }
...@@ -751,19 +751,18 @@ GdbServerRunner::~GdbServerRunner() ...@@ -751,19 +751,18 @@ GdbServerRunner::~GdbServerRunner()
void GdbServerRunner::start() void GdbServerRunner::start()
{ {
auto portsGatherer = runControl()->worker<GdbServerPortsGatherer>(); QTC_ASSERT(m_portsGatherer, reportFailure(); return);
QTC_ASSERT(portsGatherer, reportFailure(); return);
StandardRunnable r = runnable().as<StandardRunnable>(); StandardRunnable r = runnable().as<StandardRunnable>();
QStringList args = QtcProcess::splitArgs(r.commandLineArguments, OsTypeLinux); QStringList args = QtcProcess::splitArgs(r.commandLineArguments, OsTypeLinux);
QString command; QString command;
const bool isQmlDebugging = portsGatherer->useQmlServer(); const bool isQmlDebugging = m_portsGatherer->useQmlServer();
const bool isCppDebugging = portsGatherer->useGdbServer(); const bool isCppDebugging = m_portsGatherer->useGdbServer();
if (isQmlDebugging) { if (isQmlDebugging) {
args.prepend(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, args.prepend(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices,
portsGatherer->qmlServerPort())); m_portsGatherer->qmlServerPort()));
} }
if (isQmlDebugging && !isCppDebugging) { if (isQmlDebugging && !isCppDebugging) {
...@@ -774,7 +773,7 @@ void GdbServerRunner::start() ...@@ -774,7 +773,7 @@ void GdbServerRunner::start()
command = "gdbserver"; command = "gdbserver";
args.clear(); args.clear();
args.append(QString("--multi")); args.append(QString("--multi"));
args.append(QString(":%1").arg(portsGatherer->gdbServerPort().number())); args.append(QString(":%1").arg(m_portsGatherer->gdbServerPort().number()));
} }
r.executable = command; r.executable = command;
r.commandLineArguments = QtcProcess::joinArgs(args, OsTypeLinux); r.commandLineArguments = QtcProcess::joinArgs(args, OsTypeLinux);
......
...@@ -125,7 +125,8 @@ class DEBUGGER_EXPORT GdbServerRunner : public ProjectExplorer::RunWorker ...@@ -125,7 +125,8 @@ class DEBUGGER_EXPORT GdbServerRunner : public ProjectExplorer::RunWorker
Q_OBJECT Q_OBJECT
public: public:
explicit GdbServerRunner(ProjectExplorer::RunControl *runControl); explicit GdbServerRunner(ProjectExplorer::RunControl *runControl,
GdbServerPortsGatherer *portsGatherer);
~GdbServerRunner(); ~GdbServerRunner();
private: private:
...@@ -133,6 +134,7 @@ private: ...@@ -133,6 +134,7 @@ private:
void stop() override; void stop() override;
ProjectExplorer::ApplicationLauncher m_gdbServer; ProjectExplorer::ApplicationLauncher m_gdbServer;
GdbServerPortsGatherer *m_portsGatherer;
}; };
extern DEBUGGER_EXPORT const char GdbServerRunnerWorkerId[]; extern DEBUGGER_EXPORT const char GdbServerRunnerWorkerId[];
......
...@@ -771,11 +771,6 @@ void RunControl::registerWorkerCreator(Core::Id id, const WorkerCreator &workerC ...@@ -771,11 +771,6 @@ void RunControl::registerWorkerCreator(Core::Id id, const WorkerCreator &workerC
Q_UNUSED(keys); Q_UNUSED(keys);
} }
QList<QPointer<RunWorker> > RunControl::workers() const
{
return d->m_workers;
}
RunWorker *RunControl::createWorker(Core::Id id) RunWorker *RunControl::createWorker(Core::Id id)
{ {
auto keys = theWorkerCreators().keys(); auto keys = theWorkerCreators().keys();
......
...@@ -439,18 +439,6 @@ public: ...@@ -439,18 +439,6 @@ public:
const QString &cancelButtonText = QString(), const QString &cancelButtonText = QString(),
bool *prompt = nullptr); bool *prompt = nullptr);
QList<QPointer<RunWorker>> workers() const;
template <class T> T *worker() const {
for (const QPointer<RunWorker> &worker : workers()) {
if (worker) {
if (auto res = qobject_cast<T *>(worker.data()))
return res;
}
}
return nullptr;
}
RunWorker *createWorker(Core::Id id); RunWorker *createWorker(Core::Id id);
using WorkerCreator = std::function<RunWorker *(RunControl *)>; using WorkerCreator = std::function<RunWorker *(RunControl *)>;
......
...@@ -45,11 +45,11 @@ using namespace Utils; ...@@ -45,11 +45,11 @@ using namespace Utils;
namespace Qnx { namespace Qnx {
namespace Internal { namespace Internal {
class QnxAnalyzeeRunner : public ProjectExplorer::SimpleTargetRunner class QnxAnalyzeeRunner : public SimpleTargetRunner
{ {
public: public:
QnxAnalyzeeRunner(ProjectExplorer::RunControl *runControl) QnxAnalyzeeRunner(RunControl *runControl, PortsGatherer *portsGatherer)
: SimpleTargetRunner(runControl) : SimpleTargetRunner(runControl), m_portsGatherer(portsGatherer)
{ {
setDisplayName("QnxAnalyzeeRunner"); setDisplayName("QnxAnalyzeeRunner");
} }
...@@ -57,8 +57,7 @@ public: ...@@ -57,8 +57,7 @@ public:
private: private:
void start() override void start() override
{ {
auto portsGatherer = runControl()->worker<PortsGatherer>(); Utils::Port port = m_portsGatherer->findPort();
Utils::Port port = portsGatherer->findPort();
auto r = runnable().as<StandardRunnable>(); auto r = runnable().as<StandardRunnable>();
if (!r.commandLineArguments.isEmpty()) if (!r.commandLineArguments.isEmpty())
...@@ -70,6 +69,8 @@ private: ...@@ -70,6 +69,8 @@ private:
SimpleTargetRunner::start(); SimpleTargetRunner::start();
} }
PortsGatherer *m_portsGatherer;
}; };
...@@ -85,7 +86,7 @@ QnxQmlProfilerSupport::QnxQmlProfilerSupport(RunControl *runControl) ...@@ -85,7 +86,7 @@ QnxQmlProfilerSupport::QnxQmlProfilerSupport(RunControl *runControl)
auto portsGatherer = new PortsGatherer(runControl); auto portsGatherer = new PortsGatherer(runControl);
auto debuggeeRunner = new QnxAnalyzeeRunner(runControl); auto debuggeeRunner = new QnxAnalyzeeRunner(runControl, portsGatherer);
debuggeeRunner->addDependency(portsGatherer); debuggeeRunner->addDependency(portsGatherer);
auto slog2InfoRunner = new Slog2InfoRunner(runControl); auto slog2InfoRunner = new Slog2InfoRunner(runControl);
......
...@@ -56,8 +56,8 @@ namespace Internal { ...@@ -56,8 +56,8 @@ namespace Internal {
class QnxDebuggeeRunner : public ProjectExplorer::SimpleTargetRunner class QnxDebuggeeRunner : public ProjectExplorer::SimpleTargetRunner
{ {
public: public:
QnxDebuggeeRunner(ProjectExplorer::RunControl *runControl) QnxDebuggeeRunner(RunControl *runControl, GdbServerPortsGatherer *portsGatherer)
: SimpleTargetRunner(runControl) : SimpleTargetRunner(runControl), m_portsGatherer(portsGatherer)
{ {
setDisplayName("QnxDebuggeeRunner"); setDisplayName("QnxDebuggeeRunner");
} }
...@@ -65,24 +65,24 @@ public: ...@@ -65,24 +65,24 @@ public:
private: private:
void start() override void start() override
{ {
auto portsGatherer = runControl()->worker<GdbServerPortsGatherer>();
StandardRunnable r = runnable().as<StandardRunnable>(); StandardRunnable r = runnable().as<StandardRunnable>();
QStringList arguments; QStringList arguments;
if (portsGatherer->useGdbServer()) { if (m_portsGatherer->useGdbServer()) {
Utils::Port pdebugPort = portsGatherer->gdbServerPort(); Utils::Port pdebugPort = m_portsGatherer->gdbServerPort();
r.executable = Constants::QNX_DEBUG_EXECUTABLE; r.executable = Constants::QNX_DEBUG_EXECUTABLE;
arguments.append(pdebugPort.toString()); arguments.append(pdebugPort.toString());
} }
if (portsGatherer->useQmlServer()) { if (m_portsGatherer->useQmlServer()) {
arguments.append(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, arguments.append(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices,
portsGatherer->qmlServerPort())); m_portsGatherer->qmlServerPort()));
} }
arguments.append(Utils::QtcProcess::splitArgs(r.commandLineArguments)); arguments.append(Utils::QtcProcess::splitArgs(r.commandLineArguments));
r.commandLineArguments = Utils::QtcProcess::joinArgs(arguments); r.commandLineArguments = Utils::QtcProcess::joinArgs(arguments);
SimpleTargetRunner::start(); SimpleTargetRunner::start();
} }
GdbServerPortsGatherer *m_portsGatherer;
}; };
...@@ -94,12 +94,12 @@ QnxDebugSupport::QnxDebugSupport(RunControl *runControl) ...@@ -94,12 +94,12 @@ QnxDebugSupport::QnxDebugSupport(RunControl *runControl)
setDisplayName("QnxDebugSupport"); setDisplayName("QnxDebugSupport");
appendMessage(tr("Preparing remote side..."), Utils::LogMessageFormat); appendMessage(tr("Preparing remote side..."), Utils::LogMessageFormat);
auto portsGatherer = new GdbServerPortsGatherer(runControl); m_portsGatherer = new GdbServerPortsGatherer(runControl);
portsGatherer->setUseGdbServer(isCppDebugging()); m_portsGatherer->setUseGdbServer(isCppDebugging());
portsGatherer->setUseQmlServer(isQmlDebugging()); m_portsGatherer->setUseQmlServer(isQmlDebugging());
auto debuggeeRunner = new QnxDebuggeeRunner(runControl); auto debuggeeRunner = new QnxDebuggeeRunner(runControl, m_portsGatherer);
debuggeeRunner->addDependency(portsGatherer); debuggeeRunner->addDependency(m_portsGatherer);
auto slog2InfoRunner = new Slog2InfoRunner(runControl); auto slog2InfoRunner = new Slog2InfoRunner(runControl);
slog2InfoRunner->addDependency(debuggeeRunner); slog2InfoRunner->addDependency(debuggeeRunner);
...@@ -109,8 +109,7 @@ QnxDebugSupport::QnxDebugSupport(RunControl *runControl) ...@@ -109,8 +109,7 @@ QnxDebugSupport::QnxDebugSupport(RunControl *runControl)
void QnxDebugSupport::start() void QnxDebugSupport::start()
{ {
auto portsGatherer = runControl()->worker<GdbServerPortsGatherer>(); Utils::Port pdebugPort = m_portsGatherer->gdbServerPort();
Utils::Port pdebugPort = portsGatherer->gdbServerPort();
auto runConfig = qobject_cast<QnxRunConfiguration *>(runControl()->runConfiguration()); auto runConfig = qobject_cast<QnxRunConfiguration *>(runControl()->runConfiguration());
QTC_ASSERT(runConfig, return); QTC_ASSERT(runConfig, return);
...@@ -128,7 +127,7 @@ void QnxDebugSupport::start() ...@@ -128,7 +127,7 @@ void QnxDebugSupport::start()
if (isQmlDebugging()) { if (isQmlDebugging()) {
params.qmlServer.host = device()->sshParameters().host; params.qmlServer.host = device()->sshParameters().host;
params.qmlServer.port = portsGatherer->qmlServerPort(); params.qmlServer.port = m_portsGatherer->qmlServerPort();
params.inferior.commandLineArguments.replace("%qml_port%", params.qmlServer.port.toString()); params.inferior.commandLineArguments.replace("%qml_port%", params.qmlServer.port.toString());
} }
......
...@@ -40,6 +40,8 @@ public: ...@@ -40,6 +40,8 @@ public:
private: private:
void start() override; void start() override;
void stop() override; void stop() override;
Debugger::GdbServerPortsGatherer *m_portsGatherer;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -52,12 +52,12 @@ LinuxDeviceDebugSupport::LinuxDeviceDebugSupport(RunControl *runControl) ...@@ -52,12 +52,12 @@ LinuxDeviceDebugSupport::LinuxDeviceDebugSupport(RunControl *runControl)
{ {
setDisplayName("LinuxDeviceDebugSupport"); setDisplayName("LinuxDeviceDebugSupport");
auto portsGatherer = new GdbServerPortsGatherer(runControl); m_portsGatherer = new GdbServerPortsGatherer(runControl);
portsGatherer->setUseGdbServer(isCppDebugging()); m_portsGatherer->setUseGdbServer(isCppDebugging());
portsGatherer->setUseQmlServer(isQmlDebugging()); m_portsGatherer->setUseQmlServer(isQmlDebugging());
auto gdbServer = new GdbServerRunner(runControl); auto gdbServer = new GdbServerRunner(runControl, m_portsGatherer);
gdbServer->addDependency(portsGatherer); gdbServer->addDependency(m_portsGatherer);
addDependency(gdbServer); addDependency(gdbServer);
...@@ -75,12 +75,9 @@ void LinuxDeviceDebugSupport::start() ...@@ -75,12 +75,9 @@ void LinuxDeviceDebugSupport::start()
return; return;
} }
auto portsGatherer = runControl()->worker<GdbServerPortsGatherer>();
QTC_ASSERT(portsGatherer, reportFailure(); return);
const QString host = device()->sshParameters().host; const QString host = device()->sshParameters().host;
const Port gdbServerPort = portsGatherer->gdbServerPort(); const Port gdbServerPort = m_portsGatherer->gdbServerPort();
const Port qmlServerPort = portsGatherer->qmlServerPort(); const Port qmlServerPort = m_portsGatherer->qmlServerPort();
DebuggerStartParameters params; DebuggerStartParameters params;
params.startMode = AttachToRemoteServer; params.startMode = AttachToRemoteServer;
......
...@@ -43,6 +43,7 @@ private: ...@@ -43,6 +43,7 @@ private:
protected: protected:
QString m_symbolFile; QString m_symbolFile;
Debugger::GdbServerPortsGatherer *m_portsGatherer = nullptr;
}; };
} // namespace RemoteLinux } // namespace RemoteLinux
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment