aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2024-02-03 22:25:45 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2024-02-05 08:58:08 +0000
commit554f68b573f98b5f332ff456eb37c6405f61b230 (patch)
tree014aa7c02cf3993a5960f61571d8e8db55907472 /src/plugins/projectexplorer
parentf2dbd28165c901d518a8bbf18196d491f9a0a5fc (diff)
DeviceUsedPortsGatherer: Introduce done() signal
And get rid of error() and portListReady() signals. Inline some internals to have a better overview on what's happening. Change-Id: Ie8f0afc97b3315600a7fb2076208ba057aa041fa Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src/plugins/projectexplorer')
-rw-r--r--src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp71
-rw-r--r--src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h12
2 files changed, 37 insertions, 46 deletions
diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp
index df92005d4b..5312026f73 100644
--- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp
+++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp
@@ -44,6 +44,11 @@ DeviceUsedPortsGatherer::~DeviceUsedPortsGatherer()
void DeviceUsedPortsGatherer::start()
{
+ const auto emitError = [this](const QString &errorString) {
+ d->m_errorString = errorString;
+ emit done(false);
+ };
+
d->usedPorts.clear();
d->m_errorString.clear();
QTC_ASSERT(d->device, emitError("No device given"); return);
@@ -57,7 +62,25 @@ void DeviceUsedPortsGatherer::start()
d->process.reset(new Process);
d->process->setCommand(d->portsGatheringMethod.commandLine(protocol));
- connect(d->process.get(), &Process::done, this, &DeviceUsedPortsGatherer::handleProcessDone);
+ connect(d->process.get(), &Process::done, this, [this, emitError] {
+ if (d->process->result() == ProcessResult::FinishedWithSuccess) {
+ d->usedPorts.clear();
+ const QList<Port> usedPorts = d->portsGatheringMethod.parsePorts(
+ d->process->rawStdOut());
+ for (const Port port : usedPorts) {
+ if (d->device->freePorts().contains(port))
+ d->usedPorts << port;
+ }
+ emit done(true);
+ } else {
+ const QString errorString = d->process->errorString();
+ const QString stdErr = d->process->readAllStandardError();
+ const QString outputString
+ = stdErr.isEmpty() ? stdErr : Tr::tr("Remote error output was: %1").arg(stdErr);
+ emitError(Utils::joinStrings({errorString, outputString}, '\n'));
+ }
+ stop();
+ });
d->process->start();
}
@@ -84,38 +107,6 @@ QString DeviceUsedPortsGatherer::errorString() const
return d->m_errorString;
}
-void DeviceUsedPortsGatherer::setupUsedPorts()
-{
- d->usedPorts.clear();
- const QList<Port> usedPorts = d->portsGatheringMethod.parsePorts(
- d->process->rawStdOut());
- for (const Port port : usedPorts) {
- if (d->device->freePorts().contains(port))
- d->usedPorts << port;
- }
- emit portListReady();
-}
-
-void DeviceUsedPortsGatherer::emitError(const QString &errorString)
-{
- d->m_errorString = errorString;
- emit error(errorString);
-}
-
-void DeviceUsedPortsGatherer::handleProcessDone()
-{
- if (d->process->result() == ProcessResult::FinishedWithSuccess) {
- setupUsedPorts();
- } else {
- const QString errorString = d->process->errorString();
- const QString stdErr = d->process->readAllStandardError();
- const QString outputString
- = stdErr.isEmpty() ? stdErr : Tr::tr("Remote error output was: %1").arg(stdErr);
- emitError(Utils::joinStrings({errorString, outputString}, '\n'));
- }
- stop();
-}
-
// PortGatherer
PortsGatherer::PortsGatherer(RunControl *runControl)
@@ -123,11 +114,15 @@ PortsGatherer::PortsGatherer(RunControl *runControl)
{
setId("PortGatherer");
- connect(&m_portsGatherer, &DeviceUsedPortsGatherer::error, this, &PortsGatherer::reportFailure);
- connect(&m_portsGatherer, &DeviceUsedPortsGatherer::portListReady, this, [this] {
- m_portList = device()->freePorts();
- appendMessage(Tr::tr("Found %n free ports.", nullptr, m_portList.count()), NormalMessageFormat);
- reportStarted();
+ 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());
+ }
});
}
diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h
index dead5f222a..73aacdfbfe 100644
--- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h
+++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h
@@ -35,14 +35,9 @@ public:
QString errorString() const;
signals:
- void error(const QString &errMsg);
- void portListReady();
+ void done(bool success);
private:
- void handleProcessDone();
- void setupUsedPorts();
- void emitError(const QString &errorString);
-
Internal::DeviceUsedPortsGathererPrivate * const d;
};
@@ -51,8 +46,9 @@ class PROJECTEXPLORER_EXPORT DeviceUsedPortsGathererTaskAdapter
{
public:
DeviceUsedPortsGathererTaskAdapter() {
- connect(task(), &DeviceUsedPortsGatherer::portListReady, this, [this] { emit done(DoneResult::Success); });
- connect(task(), &DeviceUsedPortsGatherer::error, this, [this] { emit done(DoneResult::Error); });
+ connect(task(), &DeviceUsedPortsGatherer::done, this, [this](bool success) {
+ emit done(toDoneResult(success));
+ });
}
void start() final { task()->start(); }
};