ProjectExplorer: Move PortsGatherer to RunControl

The PortsGatherer runworker was used in all remote setups plus local QML
tooling and injected in various ways into the tree of runworkers.

Having this centrally reduces complexity downstream.

Change-Id: I8e08a942209f5458fbdd5c9e286d05979beb8a40
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2024-09-30 09:08:43 +02:00
parent 8b86527218
commit 49db4beb7d
8 changed files with 66 additions and 86 deletions

View File

@@ -756,6 +756,7 @@ bool DebuggerRunTool::isQmlDebugging() const
void DebuggerRunTool::setUsePortsGatherer(bool useCpp, bool useQml) void DebuggerRunTool::setUsePortsGatherer(bool useCpp, bool useQml)
{ {
QTC_ASSERT(!d->portsGatherer, reportFailure(); return); QTC_ASSERT(!d->portsGatherer, reportFailure(); return);
runControl()->enablePortsGatherer();
d->portsGatherer = new DebugServerPortsGatherer(runControl()); d->portsGatherer = new DebugServerPortsGatherer(runControl());
d->portsGatherer->setUseGdbServer(useCpp); d->portsGatherer->setUseGdbServer(useCpp);
d->portsGatherer->setUseQmlServer(useQml); d->portsGatherer->setUseQmlServer(useQml);
@@ -1040,9 +1041,8 @@ namespace Internal {
class SubChannelProvider : public RunWorker class SubChannelProvider : public RunWorker
{ {
public: public:
SubChannelProvider(RunControl *runControl, PortsGatherer *portsGatherer) SubChannelProvider(RunControl *runControl)
: RunWorker(runControl) : RunWorker(runControl)
, m_portGatherer(portsGatherer)
{ {
setId("SubChannelProvider"); setId("SubChannelProvider");
} }
@@ -1054,8 +1054,7 @@ public:
m_channel.setHost("localhost"); m_channel.setHost("localhost");
else else
m_channel.setHost(device()->toolControlChannel(IDevice::ControlChannelHint()).host()); m_channel.setHost(device()->toolControlChannel(IDevice::ControlChannelHint()).host());
if (m_portGatherer) m_channel.setPort(runControl()->findEndPoint().port());
m_channel.setPort(m_portGatherer->findEndPoint().port());
reportStarted(); reportStarted();
} }
@@ -1063,7 +1062,6 @@ public:
private: private:
QUrl m_channel; QUrl m_channel;
PortsGatherer *m_portGatherer = nullptr;
}; };
} // Internal } // Internal
@@ -1108,12 +1106,11 @@ DebugServerPortsGatherer::DebugServerPortsGatherer(RunControl *runControl)
: RunWorker(runControl) : RunWorker(runControl)
{ {
setId("DebugServerPortsGatherer"); setId("DebugServerPortsGatherer");
auto portsGatherer = new PortsGatherer(runControl);
m_gdbChannelProvider = new Internal::SubChannelProvider(runControl, portsGatherer); m_gdbChannelProvider = new Internal::SubChannelProvider(runControl);
addStartDependency(m_gdbChannelProvider); addStartDependency(m_gdbChannelProvider);
m_qmlChannelProvider = new Internal::SubChannelProvider(runControl, portsGatherer); m_qmlChannelProvider = new Internal::SubChannelProvider(runControl);
addStartDependency(m_qmlChannelProvider); addStartDependency(m_qmlChannelProvider);
} }

View File

@@ -109,45 +109,4 @@ QString DeviceUsedPortsGatherer::errorString() const
return d->m_errorString; return d->m_errorString;
} }
// PortGatherer
PortsGatherer::PortsGatherer(RunControl *runControl)
: RunWorker(runControl)
{
setId("PortGatherer");
connect(&m_portsGatherer, &DeviceUsedPortsGatherer::done, this, [this](bool success) {
if (success) {
m_portList = device()->freePorts();
appendMessage(Tr::tr("Found %n free ports.", nullptr, m_portList.count()),
NormalMessageFormat);
reportStarted();
} else {
reportFailure(m_portsGatherer.errorString());
}
});
}
void PortsGatherer::start()
{
appendMessage(Tr::tr("Checking available ports..."), NormalMessageFormat);
m_portsGatherer.setDevice(device());
m_portsGatherer.start();
}
QUrl PortsGatherer::findEndPoint()
{
QUrl result;
result.setScheme(urlTcpScheme());
result.setHost(device()->sshParameters().host());
result.setPort(m_portList.getNextFreePort(m_portsGatherer.usedPorts()).number());
return result;
}
void PortsGatherer::stop()
{
m_portsGatherer.stop();
reportStopped();
}
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -50,24 +50,6 @@ public:
void start() final { task()->start(); } void start() final { task()->start(); }
}; };
class PROJECTEXPLORER_EXPORT PortsGatherer : public RunWorker
{
Q_OBJECT
public:
explicit PortsGatherer(RunControl *runControl);
QUrl findEndPoint();
protected:
void start() override;
void stop() override;
private:
DeviceUsedPortsGatherer m_portsGatherer;
Utils::PortList m_portList;
};
using DeviceUsedPortsGathererTask = CustomTask<DeviceUsedPortsGathererTaskAdapter>; using DeviceUsedPortsGathererTask = CustomTask<DeviceUsedPortsGathererTaskAdapter>;
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -7,8 +7,10 @@
#include "buildconfiguration.h" #include "buildconfiguration.h"
#include "customparser.h" #include "customparser.h"
#include "devicesupport/devicemanager.h" #include "devicesupport/devicemanager.h"
#include "devicesupport/deviceusedportsgatherer.h"
#include "devicesupport/idevice.h" #include "devicesupport/idevice.h"
#include "devicesupport/idevicefactory.h" #include "devicesupport/idevicefactory.h"
#include "devicesupport/sshparameters.h"
#include "devicesupport/sshsettings.h" #include "devicesupport/sshsettings.h"
#include "kitaspects.h" #include "kitaspects.h"
#include "project.h" #include "project.h"
@@ -18,6 +20,7 @@
#include "projectexplorertr.h" #include "projectexplorertr.h"
#include "runconfigurationaspects.h" #include "runconfigurationaspects.h"
#include "target.h" #include "target.h"
#include "utils/url.h"
#include "windebuginterface.h" #include "windebuginterface.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -326,6 +329,7 @@ public:
void debugMessage(const QString &msg) const; void debugMessage(const QString &msg) const;
void initiateStart(); void initiateStart();
void startPortsGathererIfNeededAndContinueStart();
void initiateReStart(); void initiateReStart();
void continueStart(); void continueStart();
void initiateStop(); void initiateStop();
@@ -348,6 +352,9 @@ public:
RunControl *q; RunControl *q;
Id runMode; Id runMode;
TaskTreeRunner m_taskTreeRunner; TaskTreeRunner m_taskTreeRunner;
std::unique_ptr<DeviceUsedPortsGatherer> portsGatherer;
PortList portList;
}; };
} // Internal } // Internal
@@ -552,7 +559,7 @@ void RunControlPrivate::initiateStart()
setState(RunControlState::Starting); setState(RunControlState::Starting);
debugMessage("Queue: Starting"); debugMessage("Queue: Starting");
continueStart(); startPortsGathererIfNeededAndContinueStart();
} }
void RunControlPrivate::initiateReStart() void RunControlPrivate::initiateReStart()
@@ -568,7 +575,45 @@ void RunControlPrivate::initiateReStart()
setState(RunControlState::Starting); setState(RunControlState::Starting);
debugMessage("Queue: ReStarting"); debugMessage("Queue: ReStarting");
startPortsGathererIfNeededAndContinueStart();
}
void RunControlPrivate::startPortsGathererIfNeededAndContinueStart()
{
if (!portsGatherer) {
continueStart(); continueStart();
return;
}
connect(portsGatherer.get(), &DeviceUsedPortsGatherer::done, this, [this](bool success) {
if (success) {
portList = device->freePorts();
q->appendMessage(Tr::tr("Found %n free ports.", nullptr, portList.count()) + '\n',
NormalMessageFormat);
continueStart();
} else {
onWorkerFailed(nullptr, portsGatherer->errorString());
}
});
q->appendMessage(Tr::tr("Checking available ports...") + '\n', NormalMessageFormat);
portsGatherer->setDevice(device);
portsGatherer->start();
}
void RunControl::enablePortsGatherer()
{
d->portsGatherer = std::make_unique<DeviceUsedPortsGatherer>();
}
QUrl RunControl::findEndPoint()
{
QTC_ASSERT(d->portsGatherer, return {});
QUrl result;
result.setScheme(urlTcpScheme());
result.setHost(device()->sshParameters().host());
result.setPort(d->portList.getNextFreePort(d->portsGatherer->usedPorts()).number());
return result;
} }
void RunControlPrivate::continueStart() void RunControlPrivate::continueStart()
@@ -734,6 +779,7 @@ void RunControlPrivate::onWorkerStarted(RunWorker *worker)
void RunControlPrivate::onWorkerFailed(RunWorker *worker, const QString &msg) void RunControlPrivate::onWorkerFailed(RunWorker *worker, const QString &msg)
{ {
if (worker)
worker->d->state = RunWorkerState::Done; worker->d->state = RunWorkerState::Done;
showError(msg); showError(msg);

View File

@@ -234,6 +234,9 @@ public:
static bool canRun(Utils::Id runMode, Utils::Id deviceType, Utils::Id runConfigId); static bool canRun(Utils::Id runMode, Utils::Id deviceType, Utils::Id runConfigId);
void postMessage(const QString &msg, Utils::OutputFormat format, bool appendNewLine = true); void postMessage(const QString &msg, Utils::OutputFormat format, bool appendNewLine = true);
void enablePortsGatherer();
QUrl findEndPoint();
signals: signals:
void appendMessage(const QString &msg, Utils::OutputFormat format); void appendMessage(const QString &msg, Utils::OutputFormat format);
void aboutToStart(); void aboutToStart();

View File

@@ -27,8 +27,7 @@ public:
setId("QnxQmlProfilerSupport"); setId("QnxQmlProfilerSupport");
appendMessage(Tr::tr("Preparing remote side..."), LogMessageFormat); appendMessage(Tr::tr("Preparing remote side..."), LogMessageFormat);
auto portsGatherer = new PortsGatherer(runControl); runControl->enablePortsGatherer();
addStartDependency(portsGatherer);
auto slog2InfoRunner = new Slog2InfoRunner(runControl); auto slog2InfoRunner = new Slog2InfoRunner(runControl);
addStartDependency(slog2InfoRunner); addStartDependency(slog2InfoRunner);
@@ -37,8 +36,8 @@ public:
profiler->addStartDependency(this); profiler->addStartDependency(this);
addStopDependency(profiler); addStopDependency(profiler);
setStartModifier([this, portsGatherer, profiler] { setStartModifier([this, runControl, profiler] {
const QUrl serverUrl = portsGatherer->findEndPoint(); const QUrl serverUrl = runControl->findEndPoint();
profiler->recordData("QmlServerUrl", serverUrl); profiler->recordData("QmlServerUrl", serverUrl);
CommandLine cmd = commandLine(); CommandLine cmd = commandLine();

View File

@@ -50,19 +50,14 @@ public:
{ {
setId("RemoteLinuxQmlToolingSupport"); setId("RemoteLinuxQmlToolingSupport");
auto portsGatherer = new PortsGatherer(runControl); runControl->enablePortsGatherer();
addStartDependency(portsGatherer);
// The ports gatherer can safely be stopped once the process is running, even though it has to
// be started before.
addStopDependency(portsGatherer);
auto runworker = runControl->createWorker(QmlDebug::runnerIdForRunMode(runControl->runMode())); auto runworker = runControl->createWorker(QmlDebug::runnerIdForRunMode(runControl->runMode()));
runworker->addStartDependency(this); runworker->addStartDependency(this);
addStopDependency(runworker); addStopDependency(runworker);
setStartModifier([this, runControl, portsGatherer, runworker] { setStartModifier([this, runControl, runworker] {
const QUrl serverUrl = portsGatherer->findEndPoint(); const QUrl serverUrl = runControl->findEndPoint();
runworker->recordData("QmlServerUrl", serverUrl); runworker->recordData("QmlServerUrl", serverUrl);
QmlDebug::QmlDebugServicesPreset services = QmlDebug::servicesForRunMode(runControl->runMode()); QmlDebug::QmlDebugServicesPreset services = QmlDebug::servicesForRunMode(runControl->runMode());

View File

@@ -205,16 +205,15 @@ public:
EmrunRunWorker(RunControl *runControl) EmrunRunWorker(RunControl *runControl)
: SimpleTargetRunner(runControl) : SimpleTargetRunner(runControl)
{ {
auto portsGatherer = new PortsGatherer(runControl); runControl->enablePortsGatherer();
addStartDependency(portsGatherer);
setStartModifier([this, runControl, portsGatherer] { setStartModifier([this, runControl] {
const QString browserId = const QString browserId =
runControl->aspectData<WebBrowserSelectionAspect>()->currentBrowser; runControl->aspectData<WebBrowserSelectionAspect>()->currentBrowser;
setCommandLine(emrunCommand(runControl->target(), setCommandLine(emrunCommand(runControl->target(),
runControl->buildKey(), runControl->buildKey(),
browserId, browserId,
QString::number(portsGatherer->findEndPoint().port()))); QString::number(runControl->findEndPoint().port())));
setEnvironment(runControl->buildEnvironment()); setEnvironment(runControl->buildEnvironment());
}); });
} }