Commit a1748e4b authored by Christian Kandeler's avatar Christian Kandeler
Browse files

RemoteLinux: Split up generic and Maemo/MeeGo-specific device tests.

Change-Id: I45154021e85727db746d33ab6ca53f8005d1c55b
Reviewed-on: http://codereview.qt.nokia.com/1935

Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent c2b9c46e
......@@ -32,19 +32,15 @@
#include "genericlinuxdeviceconfigurationfactory.h"
#include "genericlinuxdeviceconfigurationwizard.h"
#include "maemoconfigtestdialog.h"
#include "linuxdevicetestdialog.h"
#include "maemoremoteprocessesdialog.h"
#include "publickeydeploymentdialog.h"
#include "remotelinux_constants.h"
#include <utils/qtcassert.h>
namespace RemoteLinux {
namespace Internal {
namespace {
const char * const TestDeviceActionId = "TestDeviceAction";
const char * const DeployKeyToDeviceActionId = "DeployKeyToDeviceAction";
const char * const RemoteProcessesActionId = "RemoteProcessesAction";
} // anonymous namespace;
GenericLinuxDeviceConfigurationFactory::GenericLinuxDeviceConfigurationFactory(QObject *parent)
: ILinuxDeviceConfigurationFactory(parent)
......@@ -74,18 +70,20 @@ QString GenericLinuxDeviceConfigurationFactory::displayNameForOsType(const QStri
QStringList GenericLinuxDeviceConfigurationFactory::supportedDeviceActionIds() const
{
return QStringList() << QLatin1String(TestDeviceActionId)
<< QLatin1String(DeployKeyToDeviceActionId) << QLatin1String(RemoteProcessesActionId);
return QStringList() << QLatin1String(Constants::GenericTestDeviceActionId)
<< QLatin1String(Constants::GenericDeployKeyToDeviceActionId)
<< QLatin1String(Constants::GenericRemoteProcessesActionId);
}
QString GenericLinuxDeviceConfigurationFactory::displayNameForActionId(const QString &actionId) const
{
Q_ASSERT(supportedDeviceActionIds().contains(actionId));
if (actionId == QLatin1String(TestDeviceActionId))
if (actionId == QLatin1String(Constants::GenericTestDeviceActionId))
return tr("Test");
if (actionId == QLatin1String(RemoteProcessesActionId))
if (actionId == QLatin1String(Constants::GenericRemoteProcessesActionId))
return tr("Remote Processes");
if (actionId == QLatin1String(DeployKeyToDeviceActionId))
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return tr("Deploy Public Key");
return QString(); // Can't happen.
}
......@@ -94,11 +92,14 @@ QDialog *GenericLinuxDeviceConfigurationFactory::createDeviceAction(const QStrin
const LinuxDeviceConfiguration::ConstPtr &deviceConfig, QWidget *parent) const
{
Q_ASSERT(supportedDeviceActionIds().contains(actionId));
if (actionId == QLatin1String(TestDeviceActionId))
return new MaemoConfigTestDialog(deviceConfig, parent);
if (actionId == QLatin1String(RemoteProcessesActionId))
if (actionId == QLatin1String(Constants::GenericTestDeviceActionId)) {
return new LinuxDeviceTestDialog(deviceConfig, new GenericLinuxDeviceTester(parent),
parent);
}
if (actionId == QLatin1String(Constants::GenericRemoteProcessesActionId))
return new MaemoRemoteProcessesDialog(deviceConfig, parent);
if (actionId == QLatin1String(DeployKeyToDeviceActionId))
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return new PublicKeyDeploymentDialog(deviceConfig, parent);
return 0; // Can't happen.
}
......
......@@ -31,7 +31,8 @@
#include "genericlinuxdeviceconfigurationwizard.h"
#include "genericlinuxdeviceconfigurationwizardpages.h"
#include "maemoconfigtestdialog.h"
#include "linuxdevicetestdialog.h"
#include "linuxdevicetester.h"
using namespace Utils;
......@@ -84,7 +85,7 @@ LinuxDeviceConfiguration::Ptr GenericLinuxDeviceConfigurationWizard::deviceConfi
LinuxDeviceConfiguration::Ptr devConf = LinuxDeviceConfiguration::create(m_d->setupPage.configurationName(),
LinuxDeviceConfiguration::GenericLinuxOsType, LinuxDeviceConfiguration::Physical,
PortList::fromString(QLatin1String("10000-10100")), sshParams);
Internal::MaemoConfigTestDialog dlg(devConf, this);
LinuxDeviceTestDialog dlg(devConf, new GenericLinuxDeviceTester(this), this);
dlg.exec();
return devConf;
}
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "linuxdevicetestdialog.h"
#include "ui_linuxdevicetestdialog.h"
#include <QtGui/QPushButton>
namespace RemoteLinux {
LinuxDeviceTestDialog::LinuxDeviceTestDialog(const QSharedPointer<const LinuxDeviceConfiguration> &deviceConfiguration,
AbstractLinuxDeviceTester *deviceTester, QWidget *parent)
: QDialog(parent),
m_ui(new Ui::LinuxDeviceTestDialog),
m_deviceTester(deviceTester),
m_finished(false)
{
m_ui->setupUi(this);
connect(m_deviceTester, SIGNAL(progressMessage(QString)), SLOT(handleProgressMessage(QString)));
connect(m_deviceTester, SIGNAL(errorMessage(QString)), SLOT(handleErrorMessage(QString)));
connect(m_deviceTester, SIGNAL(finished(RemoteLinux::AbstractLinuxDeviceTester::TestResult)),
SLOT(handleTestFinished(RemoteLinux::AbstractLinuxDeviceTester::TestResult)));
m_deviceTester->testDevice(deviceConfiguration);
}
LinuxDeviceTestDialog::~LinuxDeviceTestDialog()
{
delete m_ui;
}
void LinuxDeviceTestDialog::reject()
{
if (!m_finished)
m_deviceTester->stopTest();
QDialog::reject();
}
void LinuxDeviceTestDialog::handleProgressMessage(const QString &message)
{
m_ui->textEdit->appendPlainText(message);
}
void LinuxDeviceTestDialog::handleErrorMessage(const QString &message)
{
m_ui->textEdit->appendHtml(QLatin1String("<font color=\"red\">") + message
+ QLatin1String("</font><p/><p/>"));
}
void LinuxDeviceTestDialog::handleTestFinished(AbstractLinuxDeviceTester::TestResult result)
{
m_finished = true;
m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Close"));
if (result == AbstractLinuxDeviceTester::TestSuccess) {
m_ui->textEdit->appendHtml(QLatin1String("<b><font color=\"blue\">")
+ tr("Device test finished successfully.") + QLatin1String("</font></b>"));
} else {
m_ui->textEdit->appendHtml(QLatin1String("<b><font color=\"red\">")
+ tr("Device test failed.") + QLatin1String("</font></b><p/>"));
}
}
} // namespace RemoteLinux
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef DEFAULTDEVICETESTDIALOG_H
#define DEFAULTDEVICETESTDIALOG_H
#include "linuxdevicetester.h"
#include "remotelinux_export.h"
#include <QtGui/QDialog>
QT_BEGIN_NAMESPACE
namespace Ui {
class LinuxDeviceTestDialog;
}
QT_END_NAMESPACE
namespace RemoteLinux {
class REMOTELINUX_EXPORT LinuxDeviceTestDialog : public QDialog
{
Q_OBJECT
public:
explicit LinuxDeviceTestDialog(const QSharedPointer<const LinuxDeviceConfiguration> &deviceConfiguration,
AbstractLinuxDeviceTester * deviceTester, QWidget *parent = 0);
~LinuxDeviceTestDialog();
void reject();
private slots:
void handleProgressMessage(const QString &message);
void handleErrorMessage(const QString &message);
void handleTestFinished(RemoteLinux::AbstractLinuxDeviceTester::TestResult result);
private:
Ui::LinuxDeviceTestDialog * const m_ui;
AbstractLinuxDeviceTester * const m_deviceTester;
bool m_finished;
};
} // namespace RemoteLinux
#endif // DEFAULTDEVICETESTDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MaemoConfigTestDialog</class>
<widget class="QDialog" name="MaemoConfigTestDialog">
<class>LinuxDeviceTestDialog</class>
<widget class="QDialog" name="LinuxDeviceTestDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>684</width>
<height>544</height>
<width>607</width>
<height>580</height>
</rect>
</property>
<property name="windowTitle">
<string>Device Configuration Test</string>
<string>Device Test</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="testResultEdit">
<widget class="QPlainTextEdit" name="textEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="errorLabel">
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>120</red>
<green>120</green>
<blue>120</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</widget>
......@@ -95,7 +38,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>MaemoConfigTestDialog</receiver>
<receiver>LinuxDeviceTestDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
......@@ -111,7 +54,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>MaemoConfigTestDialog</receiver>
<receiver>LinuxDeviceTestDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "linuxdevicetester.h"
#include "linuxdeviceconfiguration.h"
#include "maemousedportsgatherer.h"
#include <utils/qtcassert.h>
#include <utils/ssh/sshremoteprocess.h>
#include <utils/ssh/sshconnection.h>
using namespace Utils;
namespace RemoteLinux {
namespace Internal {
namespace {
enum State { Inactive, Connecting, RunningUname, TestingPorts };
} // anonymous namespace
class GenericLinuxDeviceTesterPrivate
{
public:
GenericLinuxDeviceTesterPrivate() : state(Inactive) {}
LinuxDeviceConfiguration::ConstPtr deviceConfiguration;
SshConnection::Ptr connection;
SshRemoteProcess::Ptr process;
MaemoUsedPortsGatherer portsGatherer;
QByteArray remoteStdout;
QByteArray remoteStderr;
State state;
};
} // namespace Internal
using namespace Internal;
AbstractLinuxDeviceTester::AbstractLinuxDeviceTester(QObject *parent) : QObject(parent)
{
}
GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
: AbstractLinuxDeviceTester(parent), m_d(new GenericLinuxDeviceTesterPrivate)
{
}
GenericLinuxDeviceTester::~GenericLinuxDeviceTester()
{
delete m_d;
}
void GenericLinuxDeviceTester::testDevice(const LinuxDeviceConfiguration::ConstPtr &deviceConfiguration)
{
QTC_ASSERT(m_d->state == Inactive, return);
m_d->deviceConfiguration = deviceConfiguration;
m_d->connection = SshConnection::create(deviceConfiguration->sshParameters());
connect(m_d->connection.data(), SIGNAL(connected()), SLOT(handleConnected()));
connect(m_d->connection.data(), SIGNAL(error(Utils::SshError)),
SLOT(handleConnectionFailure()));
emit progressMessage(tr("Connecting to host..."));
m_d->state = Connecting;
m_d->connection->connectToHost();
}
void GenericLinuxDeviceTester::stopTest()
{
QTC_ASSERT(m_d->state != Inactive, return);
switch (m_d->state) {
case Connecting:
m_d->connection->disconnectFromHost();
break;
case TestingPorts:
m_d->portsGatherer.stop();
break;
case RunningUname:
m_d->process->closeChannel();
break;
case Inactive:
break;
}
setFinished(TestFailure);
}
SshConnection::Ptr GenericLinuxDeviceTester::connection() const
{
return m_d->connection;
}
void GenericLinuxDeviceTester::handleConnected()
{
QTC_ASSERT(m_d->state == Connecting, return);
m_d->process = m_d->connection->createRemoteProcess("uname -rsm");
connect(m_d->process.data(), SIGNAL(outputAvailable(QByteArray)),
SLOT(handleRemoteStdOut(QByteArray)));
connect(m_d->process.data(), SIGNAL(errorOutputAvailable(QByteArray)),
SLOT(handleRemoteStdErr(QByteArray)));
connect(m_d->process.data(), SIGNAL(closed(int)), SLOT(handleProcessFinished(int)));
emit progressMessage("Checking kernel version...");
m_d->state = RunningUname;
m_d->process->start();
}
void GenericLinuxDeviceTester::handleConnectionFailure()
{
QTC_ASSERT(m_d->state != Inactive, return);
emit errorMessage(tr("SSH connection failure: %1").arg(m_d->connection->errorString()));
setFinished(TestFailure);
}
void GenericLinuxDeviceTester::handleRemoteStdOut(const QByteArray &data)
{
QTC_ASSERT(m_d->state == RunningUname, return);
m_d->remoteStdout += data;
}
void GenericLinuxDeviceTester::handleRemoteStdErr(const QByteArray &data)
{
QTC_ASSERT(m_d->state == RunningUname, return);
m_d->remoteStderr += data;
}
void GenericLinuxDeviceTester::handleProcessFinished(int exitStatus)
{
QTC_ASSERT(m_d->state == RunningUname, return);
if (exitStatus != SshRemoteProcess::ExitedNormally || m_d->process->exitCode() != 0) {
if (!m_d->remoteStderr.isEmpty())
emit errorMessage(tr("uname failed: %1").arg(QString::fromUtf8(m_d->remoteStderr)));
else
emit errorMessage(tr("uname failed."));
} else {
emit progressMessage(QString::fromUtf8(m_d->remoteStdout));
}
connect(&m_d->portsGatherer, SIGNAL(error(QString)), SLOT(handlePortsGatheringError(QString)));
connect(&m_d->portsGatherer, SIGNAL(portListReady()), SLOT(handlePortListReady()));
emit progressMessage(QLatin1String("")
+ tr("Checking if specified ports are available..."));
m_d->state = TestingPorts;
m_d->portsGatherer.start(m_d->connection, m_d->deviceConfiguration);
}
void GenericLinuxDeviceTester::handlePortsGatheringError(const QString &message)
{
QTC_ASSERT(m_d->state == TestingPorts, return);
emit errorMessage(tr("Error gathering ports: %1").arg(message));
setFinished(TestFailure);
}
void GenericLinuxDeviceTester::handlePortListReady()
{
QTC_ASSERT(m_d->state == TestingPorts, return);
if (m_d->portsGatherer.usedPorts().isEmpty()) {
emit progressMessage("All specified ports are available.\n");
} else {
QString portList;
foreach (const int port, m_d->portsGatherer.usedPorts())
portList += QString::number(port) + QLatin1String(", ");
portList.remove(portList.count() - 2, 2);
emit errorMessage(tr("The following specified ports are currently in use: %1")
.arg(portList));
}
setFinished(TestSuccess);
}
void GenericLinuxDeviceTester::setFinished(TestResult result)
{
m_d->state = Inactive;
m_d->remoteStdout.clear();
m_d->remoteStderr.clear();
disconnect(m_d->connection.data(), 0, this, 0);
disconnect(&m_d->portsGatherer, 0, this, 0);
emit finished(result);
}
} // namespace RemoteLinux
......@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**