forked from qt-creator/qt-creator
Add adapters for FileTransfer and DeviceUsedPortsGatherer
Change-Id: I2ead2129625ae54919cf75e517e9b2180bb4bc47 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -24,6 +24,7 @@ public:
|
|||||||
QList<Port> usedPorts;
|
QList<Port> usedPorts;
|
||||||
IDevice::ConstPtr device;
|
IDevice::ConstPtr device;
|
||||||
PortsGatheringMethod portsGatheringMethod;
|
PortsGatheringMethod portsGatheringMethod;
|
||||||
|
QString m_errorString;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -39,15 +40,15 @@ DeviceUsedPortsGatherer::~DeviceUsedPortsGatherer()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceUsedPortsGatherer::start(const IDevice::ConstPtr &device)
|
void DeviceUsedPortsGatherer::start()
|
||||||
{
|
{
|
||||||
d->usedPorts.clear();
|
d->usedPorts.clear();
|
||||||
d->device = device;
|
d->m_errorString.clear();
|
||||||
QTC_ASSERT(d->device, emit error("No device given"); return);
|
QTC_ASSERT(d->device, emitError("No device given"); return);
|
||||||
|
|
||||||
d->portsGatheringMethod = d->device->portsGatheringMethod();
|
d->portsGatheringMethod = d->device->portsGatheringMethod();
|
||||||
QTC_ASSERT(d->portsGatheringMethod.commandLine, emit error("Not implemented"); return);
|
QTC_ASSERT(d->portsGatheringMethod.commandLine, emitError("Not implemented"); return);
|
||||||
QTC_ASSERT(d->portsGatheringMethod.parsePorts, emit error("Not implemented"); return);
|
QTC_ASSERT(d->portsGatheringMethod.parsePorts, emitError("Not implemented"); return);
|
||||||
|
|
||||||
const QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::AnyIPProtocol;
|
const QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::AnyIPProtocol;
|
||||||
|
|
||||||
@@ -67,11 +68,21 @@ void DeviceUsedPortsGatherer::stop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceUsedPortsGatherer::setDevice(const IDeviceConstPtr &device)
|
||||||
|
{
|
||||||
|
d->device = device;
|
||||||
|
}
|
||||||
|
|
||||||
QList<Port> DeviceUsedPortsGatherer::usedPorts() const
|
QList<Port> DeviceUsedPortsGatherer::usedPorts() const
|
||||||
{
|
{
|
||||||
return d->usedPorts;
|
return d->usedPorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DeviceUsedPortsGatherer::errorString() const
|
||||||
|
{
|
||||||
|
return d->m_errorString;
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceUsedPortsGatherer::setupUsedPorts()
|
void DeviceUsedPortsGatherer::setupUsedPorts()
|
||||||
{
|
{
|
||||||
d->usedPorts.clear();
|
d->usedPorts.clear();
|
||||||
@@ -84,6 +95,12 @@ void DeviceUsedPortsGatherer::setupUsedPorts()
|
|||||||
emit portListReady();
|
emit portListReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceUsedPortsGatherer::emitError(const QString &errorString)
|
||||||
|
{
|
||||||
|
d->m_errorString = errorString;
|
||||||
|
emitError(errorString);
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceUsedPortsGatherer::handleProcessDone()
|
void DeviceUsedPortsGatherer::handleProcessDone()
|
||||||
{
|
{
|
||||||
if (d->process->result() == ProcessResult::FinishedWithSuccess) {
|
if (d->process->result() == ProcessResult::FinishedWithSuccess) {
|
||||||
@@ -95,11 +112,17 @@ void DeviceUsedPortsGatherer::handleProcessDone()
|
|||||||
errMsg += QLatin1Char('\n');
|
errMsg += QLatin1Char('\n');
|
||||||
errMsg += tr("Remote error output was: %1").arg(QString::fromUtf8(stdErr));
|
errMsg += tr("Remote error output was: %1").arg(QString::fromUtf8(stdErr));
|
||||||
}
|
}
|
||||||
emit error(errMsg);
|
emitError(errMsg);
|
||||||
}
|
}
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceUsedPortsGathererAdapter::DeviceUsedPortsGathererAdapter()
|
||||||
|
{
|
||||||
|
connect(task(), &DeviceUsedPortsGatherer::portListReady, this, [this] { emit done(true); });
|
||||||
|
connect(task(), &DeviceUsedPortsGatherer::error, this, [this] { emit done(false); });
|
||||||
|
}
|
||||||
|
|
||||||
// PortGatherer
|
// PortGatherer
|
||||||
|
|
||||||
PortsGatherer::PortsGatherer(RunControl *runControl)
|
PortsGatherer::PortsGatherer(RunControl *runControl)
|
||||||
@@ -120,7 +143,8 @@ PortsGatherer::~PortsGatherer() = default;
|
|||||||
void PortsGatherer::start()
|
void PortsGatherer::start()
|
||||||
{
|
{
|
||||||
appendMessage(tr("Checking available ports..."), NormalMessageFormat);
|
appendMessage(tr("Checking available ports..."), NormalMessageFormat);
|
||||||
m_portsGatherer.start(device());
|
m_portsGatherer.setDevice(device());
|
||||||
|
m_portsGatherer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl PortsGatherer::findEndPoint()
|
QUrl PortsGatherer::findEndPoint()
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#include <projectexplorer/runcontrol.h>
|
#include <projectexplorer/runcontrol.h>
|
||||||
|
|
||||||
#include <utils/portlist.h>
|
#include <utils/portlist.h>
|
||||||
|
#include <utils/tasktree.h>
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
@@ -24,9 +25,11 @@ public:
|
|||||||
DeviceUsedPortsGatherer(QObject *parent = nullptr);
|
DeviceUsedPortsGatherer(QObject *parent = nullptr);
|
||||||
~DeviceUsedPortsGatherer() override;
|
~DeviceUsedPortsGatherer() override;
|
||||||
|
|
||||||
void start(const IDeviceConstPtr &device);
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
void setDevice(const IDeviceConstPtr &device);
|
||||||
QList<Utils::Port> usedPorts() const;
|
QList<Utils::Port> usedPorts() const;
|
||||||
|
QString errorString() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void error(const QString &errMsg);
|
void error(const QString &errMsg);
|
||||||
@@ -35,10 +38,19 @@ signals:
|
|||||||
private:
|
private:
|
||||||
void handleProcessDone();
|
void handleProcessDone();
|
||||||
void setupUsedPorts();
|
void setupUsedPorts();
|
||||||
|
void emitError(const QString &errorString);
|
||||||
|
|
||||||
Internal::DeviceUsedPortsGathererPrivate * const d;
|
Internal::DeviceUsedPortsGathererPrivate * const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PROJECTEXPLORER_EXPORT DeviceUsedPortsGathererAdapter
|
||||||
|
: public Utils::Tasking::TaskAdapter<DeviceUsedPortsGatherer>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeviceUsedPortsGathererAdapter();
|
||||||
|
void start() final { task()->start(); }
|
||||||
|
};
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT PortsGatherer : public RunWorker
|
class PROJECTEXPLORER_EXPORT PortsGatherer : public RunWorker
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -92,3 +104,5 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
|
QTC_DECLARE_CUSTOM_TASK(PortGatherer, ProjectExplorer::DeviceUsedPortsGathererAdapter);
|
||||||
|
@@ -67,7 +67,10 @@ class FileTransferPrivate : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void test(const ProjectExplorer::IDeviceConstPtr &onDevice);
|
IDeviceConstPtr m_testDevice;
|
||||||
|
ProcessResultData m_resultData;
|
||||||
|
|
||||||
|
void test();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
@@ -78,18 +81,19 @@ signals:
|
|||||||
void done(const ProcessResultData &resultData);
|
void done(const ProcessResultData &resultData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void emitDone(const ProcessResultData &resultData);
|
||||||
void startFailed(const QString &errorString);
|
void startFailed(const QString &errorString);
|
||||||
void run(const FileTransferSetupData &setup, const IDeviceConstPtr &device);
|
void run(const FileTransferSetupData &setup, const IDeviceConstPtr &device);
|
||||||
|
|
||||||
std::unique_ptr<FileTransferInterface> m_transfer;
|
std::unique_ptr<FileTransferInterface> 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."));
|
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()
|
void FileTransferPrivate::start()
|
||||||
@@ -132,13 +136,19 @@ void FileTransferPrivate::run(const FileTransferSetupData &setup, const IDeviceC
|
|||||||
connect(m_transfer.get(), &FileTransferInterface::progress,
|
connect(m_transfer.get(), &FileTransferInterface::progress,
|
||||||
this, &FileTransferPrivate::progress);
|
this, &FileTransferPrivate::progress);
|
||||||
connect(m_transfer.get(), &FileTransferInterface::done,
|
connect(m_transfer.get(), &FileTransferInterface::done,
|
||||||
this, &FileTransferPrivate::done);
|
this, &FileTransferPrivate::emitDone);
|
||||||
m_transfer->start();
|
m_transfer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileTransferPrivate::emitDone(const ProcessResultData &resultData)
|
||||||
|
{
|
||||||
|
m_resultData = resultData;
|
||||||
|
emit done(resultData);
|
||||||
|
}
|
||||||
|
|
||||||
void FileTransferPrivate::startFailed(const QString &errorString)
|
void FileTransferPrivate::startFailed(const QString &errorString)
|
||||||
{
|
{
|
||||||
emit done({0, QProcess::NormalExit, QProcess::FailedToStart, errorString});
|
emitDone({0, QProcess::NormalExit, QProcess::FailedToStart, errorString});
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTransfer::FileTransfer()
|
FileTransfer::FileTransfer()
|
||||||
@@ -170,9 +180,14 @@ void FileTransfer::setRsyncFlags(const QString &flags)
|
|||||||
d->m_setup.m_rsyncFlags = 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
|
FileTransferMethod FileTransfer::transferMethod() const
|
||||||
@@ -190,6 +205,11 @@ void FileTransfer::stop()
|
|||||||
d->stop();
|
d->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProcessResultData FileTransfer::resultData() const
|
||||||
|
{
|
||||||
|
return d->m_resultData;
|
||||||
|
}
|
||||||
|
|
||||||
QString FileTransfer::transferMethodName(FileTransferMethod method)
|
QString FileTransfer::transferMethodName(FileTransferMethod method)
|
||||||
{
|
{
|
||||||
switch (method) {
|
switch (method) {
|
||||||
@@ -201,6 +221,15 @@ QString FileTransfer::transferMethodName(FileTransferMethod method)
|
|||||||
return {};
|
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
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
#include "filetransfer.moc"
|
#include "filetransfer.moc"
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
#include "filetransferinterface.h"
|
#include "filetransferinterface.h"
|
||||||
#include "idevicefwd.h"
|
#include "idevicefwd.h"
|
||||||
|
|
||||||
|
#include <utils/tasktree.h>
|
||||||
|
|
||||||
namespace Utils { class ProcessResultData; }
|
namespace Utils { class ProcessResultData; }
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
@@ -27,10 +29,13 @@ public:
|
|||||||
|
|
||||||
FileTransferMethod transferMethod() const;
|
FileTransferMethod transferMethod() const;
|
||||||
|
|
||||||
void test(const ProjectExplorer::IDeviceConstPtr &onDevice);
|
void setTestDevice(const ProjectExplorer::IDeviceConstPtr &device);
|
||||||
|
void test();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
Utils::ProcessResultData resultData() const;
|
||||||
|
|
||||||
static QString transferMethodName(FileTransferMethod method);
|
static QString transferMethodName(FileTransferMethod method);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -41,4 +46,13 @@ private:
|
|||||||
FileTransferPrivate *d;
|
FileTransferPrivate *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PROJECTEXPLORER_EXPORT FileTransferAdapter : public Utils::Tasking::TaskAdapter<FileTransfer>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FileTransferAdapter();
|
||||||
|
void start() final { task()->test(); }
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
|
QTC_DECLARE_CUSTOM_TASK(Transfer, ProjectExplorer::FileTransferAdapter);
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
#include <utils/processinterface.h>
|
#include <utils/processinterface.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
#include <utils/tasktree.h>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -203,7 +204,8 @@ void GenericLinuxDeviceTester::testPortsGatherer()
|
|||||||
d->state = TestingPorts;
|
d->state = TestingPorts;
|
||||||
emit progressMessage(Tr::tr("Checking if specified ports are available..."));
|
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)
|
void GenericLinuxDeviceTester::handlePortsGathererError(const QString &message)
|
||||||
@@ -242,7 +244,8 @@ void GenericLinuxDeviceTester::testFileTransfer(FileTransferMethod method)
|
|||||||
.arg(FileTransfer::transferMethodName(method)));
|
.arg(FileTransfer::transferMethodName(method)));
|
||||||
|
|
||||||
d->fileTransfer.setTransferMethod(method);
|
d->fileTransfer.setTransferMethod(method);
|
||||||
d->fileTransfer.test(d->device);
|
d->fileTransfer.setTestDevice(d->device);
|
||||||
|
d->fileTransfer.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericLinuxDeviceTester::handleFileTransferDone(const ProcessResultData &resultData)
|
void GenericLinuxDeviceTester::handleFileTransferDone(const ProcessResultData &resultData)
|
||||||
|
Reference in New Issue
Block a user