diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index 6fef5669272..b89db25d147 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -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 &usedPorts); RunControl *q; Id runMode; TaskTreeRunner m_taskTreeRunner; - - std::unique_ptr 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 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 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 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(); + m_portsGathererRunner.start(recipe); } QUrl RunControlPrivate::getNextChannel(PortList *portList, const QList &usedPorts) @@ -643,7 +644,6 @@ QUrl RunControlPrivate::getNextChannel(PortList *portList, const QList &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; }