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