Qnx: Compactify QnxDevice creation infrastructure

Change-Id: I939a435859c494f8750d62d2ca393775e01ad214
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2023-03-23 16:28:34 +01:00
parent 54b8bdc390
commit ed8f0fb03e
6 changed files with 73 additions and 145 deletions

View File

@@ -11,7 +11,6 @@ add_qtc_plugin(Qnx
qnxdeployqtlibrariesdialog.cpp qnxdeployqtlibrariesdialog.h qnxdeployqtlibrariesdialog.cpp qnxdeployqtlibrariesdialog.h
qnxdevice.cpp qnxdevice.h qnxdevice.cpp qnxdevice.h
qnxdevicetester.cpp qnxdevicetester.h qnxdevicetester.cpp qnxdevicetester.h
qnxdevicewizard.cpp qnxdevicewizard.h
qnxplugin.cpp qnxplugin.cpp
qnxqtversion.cpp qnxqtversion.h qnxqtversion.cpp qnxqtversion.h
qnxrunconfiguration.cpp qnxrunconfiguration.h qnxrunconfiguration.cpp qnxrunconfiguration.h

View File

@@ -28,8 +28,6 @@ QtcPlugin {
"qnxdebugsupport.h", "qnxdebugsupport.h",
"qnxdevice.cpp", "qnxdevice.cpp",
"qnxdevice.h", "qnxdevice.h",
"qnxdevicewizard.cpp",
"qnxdevicewizard.h",
"qnxdevicetester.cpp", "qnxdevicetester.cpp",
"qnxdevicetester.h", "qnxdevicetester.h",
"qnxconfigurationmanager.cpp", "qnxconfigurationmanager.cpp",

View File

@@ -6,19 +6,21 @@
#include "qnxconstants.h" #include "qnxconstants.h"
#include "qnxdeployqtlibrariesdialog.h" #include "qnxdeployqtlibrariesdialog.h"
#include "qnxdevicetester.h" #include "qnxdevicetester.h"
#include "qnxdevicewizard.h"
#include "qnxtr.h" #include "qnxtr.h"
#include <coreplugin/icore.h>
#include <projectexplorer/devicesupport/sshparameters.h> #include <projectexplorer/devicesupport/sshparameters.h>
#include <remotelinux/genericlinuxdeviceconfigurationwizardpages.h>
#include <remotelinux/remotelinuxsignaloperation.h> #include <remotelinux/remotelinuxsignaloperation.h>
#include <remotelinux/linuxdevice.h>
#include <utils/port.h> #include <utils/port.h>
#include <utils/portlist.h> #include <utils/portlist.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/wizard.h>
#include <QRegularExpression>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace RemoteLinux; using namespace RemoteLinux;
@@ -54,48 +56,73 @@ public:
} }
}; };
QnxDevice::QnxDevice() class QnxDevice final : public LinuxDevice
{ {
setDisplayType(Tr::tr("QNX")); public:
setDefaultDisplayName(Tr::tr("QNX Device")); QnxDevice()
setOsType(OsTypeOtherUnix); {
setupId(IDevice::ManuallyAdded); setDisplayType(Tr::tr("QNX"));
setType(Constants::QNX_QNX_OS_TYPE); setDefaultDisplayName(Tr::tr("QNX Device"));
setMachineType(IDevice::Hardware); setOsType(OsTypeOtherUnix);
SshParameters sshParams; setupId(IDevice::ManuallyAdded);
sshParams.timeout = 10; setType(Constants::QNX_QNX_OS_TYPE);
setSshParameters(sshParams); setMachineType(IDevice::Hardware);
setFreePorts(PortList::fromString("10000-10100")); SshParameters sshParams;
sshParams.timeout = 10;
setSshParameters(sshParams);
setFreePorts(PortList::fromString("10000-10100"));
addDeviceAction({Tr::tr("Deploy Qt libraries..."), [](const IDevice::Ptr &device, QWidget *parent) { addDeviceAction({Tr::tr("Deploy Qt libraries..."), [](const IDevice::Ptr &device, QWidget *parent) {
QnxDeployQtLibrariesDialog dialog(device, parent); QnxDeployQtLibrariesDialog dialog(device, parent);
dialog.exec(); dialog.exec();
}}); }});
} }
PortsGatheringMethod QnxDevice::portsGatheringMethod() const PortsGatheringMethod portsGatheringMethod() const final
{
return {
[this](QAbstractSocket::NetworkLayerProtocol) {
return CommandLine(filePath("netstat"), {"-na"});
},
&Port::parseFromNetstatOutput
};
}
DeviceProcessSignalOperation::Ptr signalOperation() const final
{
return DeviceProcessSignalOperation::Ptr(new QnxDeviceProcessSignalOperation(sharedFromThis()));
}
DeviceTester *createDeviceTester() const final { return new QnxDeviceTester; }
};
class QnxDeviceWizard : public Wizard
{ {
return { public:
// TODO: The command is probably needlessly complicated because the parsing method QnxDeviceWizard() : Wizard(Core::ICore::dialogParent())
// used to be fixed. These two can now be matched to each other. {
[this](QAbstractSocket::NetworkLayerProtocol protocol) -> CommandLine { setWindowTitle(Tr::tr("New QNX Device Configuration Setup"));
Q_UNUSED(protocol)
return {filePath("netstat"), {"-na"}};
},
&Port::parseFromNetstatOutput addPage(&m_setupPage);
}; addPage(&m_keyDeploymentPage);
} addPage(&m_finalPage);
m_finalPage.setCommitPage(true);
DeviceTester *QnxDevice::createDeviceTester() const m_device.reset(new QnxDevice);
{
return new QnxDeviceTester;
}
DeviceProcessSignalOperation::Ptr QnxDevice::signalOperation() const m_setupPage.setDevice(m_device);
{ m_keyDeploymentPage.setDevice(m_device);
return DeviceProcessSignalOperation::Ptr(new QnxDeviceProcessSignalOperation(sharedFromThis())); }
}
IDevice::Ptr device() const { return m_device; }
private:
GenericLinuxDeviceConfigurationWizardSetupPage m_setupPage;
GenericLinuxDeviceConfigurationWizardKeyDeploymentPage m_keyDeploymentPage;
GenericLinuxDeviceConfigurationWizardFinalPage m_finalPage;
LinuxDevice::Ptr m_device;
};
// Factory // Factory
@@ -105,8 +132,13 @@ QnxDeviceFactory::QnxDeviceFactory() : IDeviceFactory(Constants::QNX_QNX_OS_TYPE
setCombinedIcon(":/qnx/images/qnxdevicesmall.png", setCombinedIcon(":/qnx/images/qnxdevicesmall.png",
":/qnx/images/qnxdevice.png"); ":/qnx/images/qnxdevice.png");
setQuickCreationAllowed(true); setQuickCreationAllowed(true);
setConstructionFunction(&QnxDevice::create); setConstructionFunction([] { return IDevice::Ptr(new QnxDevice); });
setCreator(&runDeviceWizard); setCreator([] {
QnxDeviceWizard wizard;
if (wizard.exec() != QDialog::Accepted)
return IDevice::Ptr();
return wizard.device();
});
} }
} // Qnx::Internal } // Qnx::Internal

View File

@@ -3,30 +3,10 @@
#pragma once #pragma once
#include <remotelinux/linuxdevice.h> #include <projectexplorer/devicesupport/idevicefactory.h>
namespace Qnx::Internal { namespace Qnx::Internal {
class QnxDevice final : public RemoteLinux::LinuxDevice
{
public:
using Ptr = QSharedPointer<QnxDevice>;
using ConstPtr = QSharedPointer<const QnxDevice>;
static Ptr create() { return Ptr(new QnxDevice); }
ProjectExplorer::PortsGatheringMethod portsGatheringMethod() const override;
ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override;
ProjectExplorer::DeviceTester *createDeviceTester() const override;
private:
QnxDevice();
QString interruptProcessByNameCommandLine(const QString &filePath) const;
QString killProcessByNameCommandLine(const QString &filePath) const;
};
class QnxDeviceFactory final : public ProjectExplorer::IDeviceFactory class QnxDeviceFactory final : public ProjectExplorer::IDeviceFactory
{ {
public: public:

View File

@@ -1,69 +0,0 @@
// Copyright (C) 2016 BlackBerry Limited. All rights reserved.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qnxdevicewizard.h"
#include "qnxconstants.h"
#include "qnxdevice.h"
#include "qnxtr.h"
#include <coreplugin/icore.h>
#include <projectexplorer/devicesupport/sshparameters.h>
#include <remotelinux/genericlinuxdeviceconfigurationwizardpages.h>
#include <utils/portlist.h>
#include <utils/wizard.h>
using namespace ProjectExplorer;
using namespace RemoteLinux;
using namespace Utils;
namespace Qnx::Internal {
class QnxDeviceWizard : public Wizard
{
public:
QnxDeviceWizard() : Wizard(Core::ICore::dialogParent())
{
setWindowTitle(Tr::tr("New QNX Device Configuration Setup"));
addPage(&m_setupPage);
addPage(&m_keyDeploymentPage);
addPage(&m_finalPage);
m_finalPage.setCommitPage(true);
SshParameters sshParams;
sshParams.timeout = 10;
m_device = QnxDevice::create();
m_device->setupId(IDevice::ManuallyAdded);
m_device->setType(Constants::QNX_QNX_OS_TYPE);
m_device->setMachineType(IDevice::Hardware);
m_device->setSshParameters(sshParams);
m_device->setFreePorts(PortList::fromString("10000-10100"));
m_setupPage.setDevice(m_device);
m_keyDeploymentPage.setDevice(m_device);
}
IDevice::Ptr device() const { return m_device; }
private:
GenericLinuxDeviceConfigurationWizardSetupPage m_setupPage;
GenericLinuxDeviceConfigurationWizardKeyDeploymentPage m_keyDeploymentPage;
GenericLinuxDeviceConfigurationWizardFinalPage m_finalPage;
LinuxDevice::Ptr m_device;
};
IDevice::Ptr runDeviceWizard()
{
QnxDeviceWizard wizard;
if (wizard.exec() != QDialog::Accepted)
return IDevice::Ptr();
return wizard.device();
}
} // Qnx::Internal

View File

@@ -1,12 +0,0 @@
// Copyright (C) 2016 BlackBerry Limited. All rights reserved.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <projectexplorer/devicesupport/idevice.h>
namespace Qnx::Internal {
ProjectExplorer::IDevice::Ptr runDeviceWizard();
} // Qnx::Internal