RunControl: Reuse portsGatheringRecipe()

Change-Id: I20383f556b3488528758fdf886929afd3ee38a16
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2024-11-15 16:00:58 +01:00
parent 7d858ff8aa
commit cf8d108773

View File

@@ -8,7 +8,6 @@
#include "customparser.h"
#include "devicesupport/devicekitaspects.h"
#include "devicesupport/devicemanager.h"
#include "devicesupport/deviceusedportsgatherer.h"
#include "devicesupport/idevice.h"
#include "devicesupport/idevicefactory.h"
#include "devicesupport/sshparameters.h"
@@ -357,14 +356,14 @@ public:
void startTaskTree();
void checkAutoDeleteAndEmitStopped();
void enablePortsGatherer();
bool isPortsGatherer() const
{ return useDebugChannel || useQmlChannel || usePerfChannel || useWorkerChannel; }
QUrl getNextChannel(PortList *portList, const QList<Port> &usedPorts);
RunControl *q;
Id runMode;
TaskTreeRunner m_taskTreeRunner;
std::unique_ptr<DeviceUsedPortsGatherer> portsGatherer;
TaskTreeRunner m_portsGathererRunner;
};
} // Internal
@@ -592,41 +591,43 @@ void RunControlPrivate::initiateReStart()
void RunControlPrivate::startPortsGathererIfNeededAndContinueStart()
{
if (!portsGatherer) {
if (!isPortsGatherer()) {
continueStart();
return;
}
connect(portsGatherer.get(), &DeviceUsedPortsGatherer::done, this, [this](bool success) {
if (success) {
PortList portList = device->freePorts();
const QList<Port> usedPorts = portsGatherer->usedPorts();
q->appendMessage(Tr::tr("Found %n free ports.", nullptr, portList.count()) + '\n',
NormalMessageFormat);
if (useDebugChannel)
debugChannel = getNextChannel(&portList, usedPorts);
if (useQmlChannel)
qmlChannel = getNextChannel(&portList, usedPorts);
if (usePerfChannel)
perfChannel = getNextChannel(&portList, usedPorts);
if (useWorkerChannel)
workerChannel = getNextChannel(&portList, usedPorts);
const Storage<PortsOutputData> portsStorage;
continueStart();
} else {
onWorkerFailed(nullptr, portsGatherer->errorString());
const auto onDone = [this, portsStorage] {
const auto ports = *portsStorage;
if (!ports) {
onWorkerFailed(nullptr, ports.error());
return;
}
});
PortList portList = device->freePorts();
const QList<Port> usedPorts = *ports;
q->appendMessage(Tr::tr("Found %n free ports.", nullptr, portList.count()) + '\n',
NormalMessageFormat);
if (useDebugChannel)
debugChannel = getNextChannel(&portList, usedPorts);
if (useQmlChannel)
qmlChannel = getNextChannel(&portList, usedPorts);
if (usePerfChannel)
perfChannel = getNextChannel(&portList, usedPorts);
if (useWorkerChannel)
workerChannel = getNextChannel(&portList, usedPorts);
continueStart();
};
const Group recipe {
portsStorage,
device->portsGatheringRecipe(portsStorage),
onGroupDone(onDone)
};
q->appendMessage(Tr::tr("Checking available ports...") + '\n', NormalMessageFormat);
portsGatherer->setDevice(device);
portsGatherer->start();
}
void RunControlPrivate::enablePortsGatherer()
{
if (!portsGatherer)
portsGatherer = std::make_unique<DeviceUsedPortsGatherer>();
m_portsGathererRunner.start(recipe);
}
QUrl RunControlPrivate::getNextChannel(PortList *portList, const QList<Port> &usedPorts)
@@ -643,7 +644,6 @@ QUrl RunControlPrivate::getNextChannel(PortList *portList, const QList<Port> &us
void RunControl::requestDebugChannel()
{
d->enablePortsGatherer();
d->useDebugChannel = true;
}
@@ -659,7 +659,6 @@ QUrl RunControl::debugChannel() const
void RunControl::requestQmlChannel()
{
d->enablePortsGatherer();
d->useQmlChannel = true;
}
@@ -680,7 +679,6 @@ void RunControl::setQmlChannel(const QUrl &channel)
void RunControl::requestPerfChannel()
{
d->enablePortsGatherer();
d->usePerfChannel = true;
}
@@ -696,7 +694,6 @@ QUrl RunControl::perfChannel() const
void RunControl::requestWorkerChannel()
{
d->enablePortsGatherer();
d->useWorkerChannel = true;
}