From 3a1f94ec287934afa02af2dc8031b45a90110039 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 21 Oct 2022 19:29:21 +0200 Subject: [PATCH] Add adapters for FileTransfer and DeviceUsedPortsGatherer Change-Id: I2ead2129625ae54919cf75e517e9b2180bb4bc47 Reviewed-by: hjk Reviewed-by: Qt CI Bot Reviewed-by: --- .../devicesupport/deviceusedportsgatherer.cpp | 38 +++++++++++++--- .../devicesupport/deviceusedportsgatherer.h | 16 ++++++- .../devicesupport/filetransfer.cpp | 45 +++++++++++++++---- .../devicesupport/filetransfer.h | 16 ++++++- src/plugins/remotelinux/linuxdevicetester.cpp | 7 ++- 5 files changed, 103 insertions(+), 19 deletions(-) diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp index da1e8f1887b..72421b8b9d7 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp +++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp @@ -24,6 +24,7 @@ public: QList usedPorts; IDevice::ConstPtr device; PortsGatheringMethod portsGatheringMethod; + QString m_errorString; }; } // namespace Internal @@ -39,15 +40,15 @@ DeviceUsedPortsGatherer::~DeviceUsedPortsGatherer() delete d; } -void DeviceUsedPortsGatherer::start(const IDevice::ConstPtr &device) +void DeviceUsedPortsGatherer::start() { d->usedPorts.clear(); - d->device = device; - QTC_ASSERT(d->device, emit error("No device given"); return); + d->m_errorString.clear(); + QTC_ASSERT(d->device, emitError("No device given"); return); d->portsGatheringMethod = d->device->portsGatheringMethod(); - QTC_ASSERT(d->portsGatheringMethod.commandLine, emit error("Not implemented"); return); - QTC_ASSERT(d->portsGatheringMethod.parsePorts, emit error("Not implemented"); return); + QTC_ASSERT(d->portsGatheringMethod.commandLine, emitError("Not implemented"); return); + QTC_ASSERT(d->portsGatheringMethod.parsePorts, emitError("Not implemented"); return); const QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::AnyIPProtocol; @@ -67,11 +68,21 @@ void DeviceUsedPortsGatherer::stop() } } +void DeviceUsedPortsGatherer::setDevice(const IDeviceConstPtr &device) +{ + d->device = device; +} + QList DeviceUsedPortsGatherer::usedPorts() const { return d->usedPorts; } +QString DeviceUsedPortsGatherer::errorString() const +{ + return d->m_errorString; +} + void DeviceUsedPortsGatherer::setupUsedPorts() { d->usedPorts.clear(); @@ -84,6 +95,12 @@ void DeviceUsedPortsGatherer::setupUsedPorts() emit portListReady(); } +void DeviceUsedPortsGatherer::emitError(const QString &errorString) +{ + d->m_errorString = errorString; + emitError(errorString); +} + void DeviceUsedPortsGatherer::handleProcessDone() { if (d->process->result() == ProcessResult::FinishedWithSuccess) { @@ -95,11 +112,17 @@ void DeviceUsedPortsGatherer::handleProcessDone() errMsg += QLatin1Char('\n'); errMsg += tr("Remote error output was: %1").arg(QString::fromUtf8(stdErr)); } - emit error(errMsg); + emitError(errMsg); } stop(); } +DeviceUsedPortsGathererAdapter::DeviceUsedPortsGathererAdapter() +{ + connect(task(), &DeviceUsedPortsGatherer::portListReady, this, [this] { emit done(true); }); + connect(task(), &DeviceUsedPortsGatherer::error, this, [this] { emit done(false); }); +} + // PortGatherer PortsGatherer::PortsGatherer(RunControl *runControl) @@ -120,7 +143,8 @@ PortsGatherer::~PortsGatherer() = default; void PortsGatherer::start() { appendMessage(tr("Checking available ports..."), NormalMessageFormat); - m_portsGatherer.start(device()); + m_portsGatherer.setDevice(device()); + m_portsGatherer.start(); } QUrl PortsGatherer::findEndPoint() diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h index 1f65ea00260..8409988ec78 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h +++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h @@ -8,6 +8,7 @@ #include #include +#include namespace ProjectExplorer { @@ -24,9 +25,11 @@ public: DeviceUsedPortsGatherer(QObject *parent = nullptr); ~DeviceUsedPortsGatherer() override; - void start(const IDeviceConstPtr &device); + void start(); void stop(); + void setDevice(const IDeviceConstPtr &device); QList usedPorts() const; + QString errorString() const; signals: void error(const QString &errMsg); @@ -35,10 +38,19 @@ signals: private: void handleProcessDone(); void setupUsedPorts(); + void emitError(const QString &errorString); Internal::DeviceUsedPortsGathererPrivate * const d; }; +class PROJECTEXPLORER_EXPORT DeviceUsedPortsGathererAdapter + : public Utils::Tasking::TaskAdapter +{ +public: + DeviceUsedPortsGathererAdapter(); + void start() final { task()->start(); } +}; + class PROJECTEXPLORER_EXPORT PortsGatherer : public RunWorker { Q_OBJECT @@ -92,3 +104,5 @@ private: }; } // namespace ProjectExplorer + +QTC_DECLARE_CUSTOM_TASK(PortGatherer, ProjectExplorer::DeviceUsedPortsGathererAdapter); diff --git a/src/plugins/projectexplorer/devicesupport/filetransfer.cpp b/src/plugins/projectexplorer/devicesupport/filetransfer.cpp index bfbfdcf824c..475ca783af2 100644 --- a/src/plugins/projectexplorer/devicesupport/filetransfer.cpp +++ b/src/plugins/projectexplorer/devicesupport/filetransfer.cpp @@ -67,7 +67,10 @@ class FileTransferPrivate : public QObject Q_OBJECT public: - void test(const ProjectExplorer::IDeviceConstPtr &onDevice); + IDeviceConstPtr m_testDevice; + ProcessResultData m_resultData; + + void test(); void start(); void stop(); @@ -78,18 +81,19 @@ signals: void done(const ProcessResultData &resultData); private: + void emitDone(const ProcessResultData &resultData); void startFailed(const QString &errorString); void run(const FileTransferSetupData &setup, const IDeviceConstPtr &device); std::unique_ptr m_transfer; }; -void FileTransferPrivate::test(const IDeviceConstPtr &onDevice) +void FileTransferPrivate::test() { - if (!onDevice) + if (!m_testDevice) return startFailed(tr("No device set for test transfer.")); - run({{}, m_setup.m_method, m_setup.m_rsyncFlags}, onDevice); + run({{}, m_setup.m_method, m_setup.m_rsyncFlags}, m_testDevice); } void FileTransferPrivate::start() @@ -132,13 +136,19 @@ void FileTransferPrivate::run(const FileTransferSetupData &setup, const IDeviceC connect(m_transfer.get(), &FileTransferInterface::progress, this, &FileTransferPrivate::progress); connect(m_transfer.get(), &FileTransferInterface::done, - this, &FileTransferPrivate::done); + this, &FileTransferPrivate::emitDone); m_transfer->start(); } +void FileTransferPrivate::emitDone(const ProcessResultData &resultData) +{ + m_resultData = resultData; + emit done(resultData); +} + void FileTransferPrivate::startFailed(const QString &errorString) { - emit done({0, QProcess::NormalExit, QProcess::FailedToStart, errorString}); + emitDone({0, QProcess::NormalExit, QProcess::FailedToStart, errorString}); } FileTransfer::FileTransfer() @@ -170,9 +180,14 @@ void FileTransfer::setRsyncFlags(const QString &flags) d->m_setup.m_rsyncFlags = flags; } -void FileTransfer::test(const ProjectExplorer::IDeviceConstPtr &onDevice) +void FileTransfer::setTestDevice(const ProjectExplorer::IDeviceConstPtr &device) { - d->test(onDevice); + d->m_testDevice = device; +} + +void FileTransfer::test() +{ + d->test(); } FileTransferMethod FileTransfer::transferMethod() const @@ -190,6 +205,11 @@ void FileTransfer::stop() d->stop(); } +ProcessResultData FileTransfer::resultData() const +{ + return d->m_resultData; +} + QString FileTransfer::transferMethodName(FileTransferMethod method) { switch (method) { @@ -201,6 +221,15 @@ QString FileTransfer::transferMethodName(FileTransferMethod method) return {}; } +FileTransferAdapter::FileTransferAdapter() +{ + connect(task(), &FileTransfer::done, this, [this](const ProcessResultData &result) { + emit done(result.m_exitStatus == QProcess::NormalExit + && result.m_error == QProcess::UnknownError + && result.m_exitCode == 0); + }); +} + } // namespace ProjectExplorer #include "filetransfer.moc" diff --git a/src/plugins/projectexplorer/devicesupport/filetransfer.h b/src/plugins/projectexplorer/devicesupport/filetransfer.h index 14816afee8c..75354a0df7e 100644 --- a/src/plugins/projectexplorer/devicesupport/filetransfer.h +++ b/src/plugins/projectexplorer/devicesupport/filetransfer.h @@ -7,6 +7,8 @@ #include "filetransferinterface.h" #include "idevicefwd.h" +#include + namespace Utils { class ProcessResultData; } namespace ProjectExplorer { @@ -27,10 +29,13 @@ public: FileTransferMethod transferMethod() const; - void test(const ProjectExplorer::IDeviceConstPtr &onDevice); + void setTestDevice(const ProjectExplorer::IDeviceConstPtr &device); + void test(); void start(); void stop(); + Utils::ProcessResultData resultData() const; + static QString transferMethodName(FileTransferMethod method); signals: @@ -41,4 +46,13 @@ private: FileTransferPrivate *d; }; +class PROJECTEXPLORER_EXPORT FileTransferAdapter : public Utils::Tasking::TaskAdapter +{ +public: + FileTransferAdapter(); + void start() final { task()->test(); } +}; + } // namespace ProjectExplorer + +QTC_DECLARE_CUSTOM_TASK(Transfer, ProjectExplorer::FileTransferAdapter); diff --git a/src/plugins/remotelinux/linuxdevicetester.cpp b/src/plugins/remotelinux/linuxdevicetester.cpp index e03b322bff3..19dfb74f630 100644 --- a/src/plugins/remotelinux/linuxdevicetester.cpp +++ b/src/plugins/remotelinux/linuxdevicetester.cpp @@ -14,6 +14,7 @@ #include #include #include +#include using namespace ProjectExplorer; using namespace Utils; @@ -203,7 +204,8 @@ void GenericLinuxDeviceTester::testPortsGatherer() d->state = TestingPorts; emit progressMessage(Tr::tr("Checking if specified ports are available...")); - d->portsGatherer.start(d->device); + d->portsGatherer.setDevice(d->device); + d->portsGatherer.start(); } void GenericLinuxDeviceTester::handlePortsGathererError(const QString &message) @@ -242,7 +244,8 @@ void GenericLinuxDeviceTester::testFileTransfer(FileTransferMethod method) .arg(FileTransfer::transferMethodName(method))); d->fileTransfer.setTransferMethod(method); - d->fileTransfer.test(d->device); + d->fileTransfer.setTestDevice(d->device); + d->fileTransfer.test(); } void GenericLinuxDeviceTester::handleFileTransferDone(const ProcessResultData &resultData)