Commit 378ad4de authored by ck's avatar ck

Maemo: Device configurations now have a list of free ports.

The device configuration widget is now the only place the user
ever has to specify ports.
parent c2da3f68
......@@ -68,8 +68,6 @@ static const QLatin1String LastDeployedTimesKey(PREFIX ".LastDeployedTimes");
static const QLatin1String ProFileKey(PREFIX ".ProFile");
static const QLatin1String ExportedLocalDirsKey(PREFIX ".ExportedLocalDirs");
static const QLatin1String RemoteMountPointsKey(PREFIX ".RemoteMountPoints");
static const QLatin1String UserDefinedMountPortsKey(PREFIX ".MountPorts");
static const QLatin1String DeployMountPortKey(PREFIX ".DeployMountPort");
static const QLatin1String BaseEnvironmentBaseKey(PREFIX ".BaseEnvironmentBase");
static const QLatin1String UserEnvironmentChangesKey(PREFIX ".UserEnvironmentChanges");
static const QLatin1String UseRemoteGdbKey(PREFIX ".UseRemoteGdb");
......
......@@ -83,7 +83,7 @@ RunControl *MaemoDebugSupport::createDebugRunControl(MaemoRunConfiguration *runC
params.executable = runConfig->localExecutableFilePath();
params.debuggerCommand = runConfig->gdbCmd();
params.remoteChannel = devConf.server.host + QLatin1Char(':')
+ gdbServerPort(runConfig, devConf);
+ QString::number(gdbServerPort(runConfig));
params.remoteArchitecture = QLatin1String("arm");
}
params.processArgs = runConfig->arguments();
......@@ -231,7 +231,7 @@ void MaemoDebugSupport::startDebugging()
const QString &remoteExe = m_runConfig->remoteExecutableFilePath();
m_runner->startExecution(QString::fromLocal8Bit("%1 gdbserver :%2 %3 %4")
.arg(MaemoGlobal::remoteCommandPrefix(remoteExe))
.arg(gdbServerPort(m_runConfig, m_deviceConfig))
.arg(gdbServerPort(m_runConfig))
.arg(remoteExe).arg(m_runConfig->arguments()
.join(QLatin1String(" "))).toUtf8());
}
......@@ -293,15 +293,9 @@ void MaemoDebugSupport::handleAdapterSetupDone()
qobject_cast<RemoteGdbServerAdapter*>(m_gdbAdapter)->handleSetupDone();
}
QString MaemoDebugSupport::gdbServerPort(const MaemoRunConfiguration *rc,
const MaemoDeviceConfig &devConf)
int MaemoDebugSupport::gdbServerPort(const MaemoRunConfiguration *rc)
{
// During configuration we don't know which port to use, so we display
// something in the config dialog, but we will make sure we use
// the right port from the information file.
return devConf.type == MaemoDeviceConfig::Physical
? QString::number(devConf.debuggingPort)
: rc->runtimeGdbServerPort();
return rc->freePorts().getNext();
}
QString MaemoDebugSupport::uploadDir(const MaemoDeviceConfig &devConf)
......
......@@ -69,8 +69,6 @@ public:
Debugger::DebuggerRunControl *runControl);
~MaemoDebugSupport();
static QString gdbServerPort(const MaemoRunConfiguration *rc,
const MaemoDeviceConfig &devConf);
static QString uploadDir(const MaemoDeviceConfig &devConf);
private slots:
......@@ -87,6 +85,8 @@ private slots:
void handleProgressReport(const QString &progressOutput);
private:
static int gdbServerPort(const MaemoRunConfiguration *rc);
void stopSsh();
void handleAdapterSetupFailed(const QString &error);
void handleAdapterSetupDone();
......
......@@ -99,7 +99,7 @@ void MaemoDeployStep::ctor()
= qobject_cast<Qt4BuildConfiguration *>(buildConfiguration());
const MaemoToolChain * const toolchain
= dynamic_cast<MaemoToolChain *>(buildConfig->toolChain());
m_mounter = new MaemoRemoteMounter(this,toolchain);
m_mounter = new MaemoRemoteMounter(this, toolchain);
connect(m_mounter, SIGNAL(mounted()), this, SLOT(handleMounted()));
connect(m_mounter, SIGNAL(unmounted()), this, SLOT(handleUnmounted()));
connect(m_mounter, SIGNAL(error(QString)), this,
......@@ -131,9 +131,6 @@ BuildStepConfigWidget *MaemoDeployStep::createConfigWidget()
QVariantMap MaemoDeployStep::toMap() const
{
QVariantMap map(BuildStep::toMap());
#ifdef DEPLOY_VIA_MOUNT
map.insert(DeployMountPortKey, m_mountPort);
#endif
addDeployTimesToMap(map);
map.unite(m_deviceConfigModel->toMap());
return map;
......@@ -162,9 +159,6 @@ bool MaemoDeployStep::fromMap(const QVariantMap &map)
{
if (!BuildStep::fromMap(map))
return false;
#ifdef DEPLOY_VIA_MOUNT
m_mountPort = map.value(DeployMountPortKey, DefaultMountPort).toInt();
#endif
getDeployTimesFromMap(map);
m_deviceConfigModel->fromMap(map);
return true;
......@@ -574,15 +568,16 @@ void MaemoDeployStep::handleUnmounted()
}
if (m_needsInstall || !m_filesToCopy.isEmpty()) {
m_mounter->setPortList(deviceConfig().freePorts());
if (m_needsInstall) {
const QString localDir = QFileInfo(packagingStep()->packageFilePath())
.absolutePath();
const MaemoMountSpecification mountSpec(localDir,
deployMountPoint(), m_mountPort);
m_mounter->addMountSpecification(mountSpec, true);
deployMountPoint());
if (!addMountSpecification(mountSpec))
return;
} else {
#ifdef Q_OS_WIN
int port = m_mountPort;
bool drivesToMount[26];
for (int i = 0; i < sizeof drivesToMount / drivesToMount[0]; ++i)
drivesToMount[i] = false;
......@@ -602,13 +597,15 @@ void MaemoDeployStep::handleUnmounted()
const QString mountPoint = deployMountPoint()
+ QLatin1Char('/') + QLatin1Char(driveLetter);
const MaemoMountSpecification mountSpec(localDir.left(3),
mountPoint, port++);
m_mounter->addMountSpecification(mountSpec, true);
mountPoint);
if (!addMountSpecification(mountSpec))
return;
drivesToMount[index] = true;
}
#else
m_mounter->addMountSpecification(MaemoMountSpecification(QLatin1String("/"),
deployMountPoint(), m_mountPort), true);
if (!addMountSpecification(MaemoMountSpecification(QLatin1String("/"),
deployMountPoint())))
return;
#endif
}
m_mounter->mount();
......@@ -660,6 +657,15 @@ void MaemoDeployStep::deployNextFile()
copyProcess->start();
}
bool MaemoDeployStep::addMountSpecification(const MaemoMountSpecification &mountSpec)
{
if (!m_mounter->addMountSpecification(mountSpec, true)) {
raiseError(tr("Device has not enough free ports for deployment."));
return false;
}
return true;
}
void MaemoDeployStep::handleCopyProcessFinished(int exitStatus)
{
if (m_stopped) {
......
......@@ -32,6 +32,7 @@
#include "maemodeployable.h"
#include "maemodeviceconfigurations.h"
#include "maemomountspecification.h"
#include <coreplugin/ssh/sftpdefs.h>
#include <projectexplorer/buildstep.h>
......@@ -81,10 +82,6 @@ public:
const MaemoDeployable &deployable) const;
void setDeployed(const QString &host, const MaemoDeployable &deployable);
MaemoDeployables *deployables() const { return m_deployables; }
#ifdef DEPLOY_VIA_MOUNT
int mountPort() const { return m_mountPort; }
void setMountPort(int port) { m_mountPort = port; }
#endif
signals:
void done();
......@@ -131,6 +128,7 @@ private:
#ifdef DEPLOY_VIA_MOUNT
QString deployMountPoint() const;
void deployNextFile();
bool addMountSpecification(const MaemoMountSpecification &mountSpec);
#else
bool deploy(const MaemoDeployable &deployable);
#endif
......@@ -150,7 +148,6 @@ private:
MaemoRemoteMounter *m_mounter;
QTimer *m_cleanupTimer;
bool m_canStart;
int m_mountPort;
#else
QSharedPointer<Core::SftpChannel> m_uploader;
typedef QPair<MaemoDeployable, QString> DeployInfo;
......
......@@ -33,20 +33,13 @@ MaemoDeployStepWidget::~MaemoDeployStepWidget()
void MaemoDeployStepWidget::init()
{
#ifdef DEPLOY_VIA_MOUNT
ui->mountPortSpinBox->setValue(m_step->mountPort());
connect(ui->mountPortSpinBox, SIGNAL(valueChanged(int)), this,
SLOT(handleMountPortEdited(int)));
#else
ui->mountPortLabel->hide();
ui->mountPortSpinBox->hide();
#endif
handleDeviceConfigModelChanged();
connect(m_step->buildConfiguration()->target(),
SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
this, SLOT(handleDeviceConfigModelChanged()));
connect(ui->deviceConfigComboBox, SIGNAL(activated(int)), this,
SLOT(setCurrentDeviceConfig(int)));
handleDeviceConfigModelChanged();
}
void MaemoDeployStepWidget::handleDeviceConfigModelChanged()
......@@ -98,14 +91,5 @@ void MaemoDeployStepWidget::setCurrentDeviceConfig(int index)
m_step->deviceConfigModel()->setCurrentIndex(index);
}
void MaemoDeployStepWidget::handleMountPortEdited(int newPort)
{
#ifdef DEPLOY_VIA_MOUNT
m_step->setMountPort(newPort);
#else
Q_UNUSED(newPort);
#endif
}
} // namespace Internal
} // namespace Qt4ProjectManager
......@@ -26,7 +26,6 @@ private:
Q_SLOT void handleModelsCreated();
Q_SLOT void handleDeviceConfigModelChanged();
Q_SLOT void setCurrentDeviceConfig(int index);
Q_SLOT void handleMountPortEdited(int newPort);
virtual void init();
virtual QString summaryText() const;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>469</width>
<height>330</height>
<width>460</width>
<height>277</height>
</rect>
</property>
<property name="windowTitle">
......@@ -43,39 +43,8 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mountPortLabel">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Mount port:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="mountPortSpinBox">
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
</item>
</layout>
</item>
......
......@@ -42,9 +42,10 @@ namespace Internal {
MaemoDeviceConfigListModel::MaemoDeviceConfigListModel(QObject *parent)
: QAbstractListModel(parent), m_currentIndex(-1)
{
setupList();
const MaemoDeviceConfigurations &devConfs
= MaemoDeviceConfigurations::instance();
if (devConfs.devConfigs().isEmpty())
if (m_devConfigs.isEmpty())
setInvalid();
else
setCurrentIndex(0);
......@@ -52,27 +53,35 @@ MaemoDeviceConfigListModel::MaemoDeviceConfigListModel(QObject *parent)
SLOT(handleDeviceConfigListChange()));
}
void MaemoDeviceConfigListModel::setupList()
{
m_devConfigs.clear();
const MaemoDeviceConfigurations &devConfs
= MaemoDeviceConfigurations::instance();
foreach (const MaemoDeviceConfig &devConfig, devConfs.devConfigs()) {
if (devConfig.freePorts().hasMore())
m_devConfigs << devConfig;
}
}
void MaemoDeviceConfigListModel::setCurrentIndex(int index)
{
if (index != m_currentIndex) {
m_currentIndex = index;
m_currentId = MaemoDeviceConfigurations::instance().devConfigs()
.at(m_currentIndex).internalId;
m_currentId = m_devConfigs.at(m_currentIndex).internalId;
emit currentChanged();
}
}
void MaemoDeviceConfigListModel::resetCurrentIndex()
{
const QList<MaemoDeviceConfig> &devConfigs
= MaemoDeviceConfigurations::instance().devConfigs();
if (devConfigs.isEmpty()) {
if (m_devConfigs.isEmpty()) {
setInvalid();
return;
}
for (int i = 0; i < devConfigs.count(); ++i) {
if (devConfigs.at(i).internalId == m_currentId) {
for (int i = 0; i < m_devConfigs.count(); ++i) {
if (m_devConfigs.at(i).internalId == m_currentId) {
setCurrentIndex(i);
return;
}
......@@ -110,6 +119,7 @@ void MaemoDeviceConfigListModel::fromMap(const QVariantMap &map)
void MaemoDeviceConfigListModel::handleDeviceConfigListChange()
{
setupList();
resetCurrentIndex();
reset();
emit currentChanged();
......@@ -117,8 +127,7 @@ void MaemoDeviceConfigListModel::handleDeviceConfigListChange()
int MaemoDeviceConfigListModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0
: MaemoDeviceConfigurations::instance().devConfigs().count();
return parent.isValid() ? 0 : m_devConfigs.count();
}
QVariant MaemoDeviceConfigListModel::data(const QModelIndex &index, int role) const
......@@ -126,7 +135,7 @@ QVariant MaemoDeviceConfigListModel::data(const QModelIndex &index, int role) co
if (!index.isValid() || index.row() >= rowCount()
|| role != Qt::DisplayRole)
return QVariant();
return MaemoDeviceConfigurations::instance().devConfigs().at(index.row()).name;
return m_devConfigs.at(index.row()).name;
}
} // namespace Internal
......
......@@ -38,6 +38,7 @@
#include "maemodeviceconfigurations.h"
#include <QtCore/QAbstractListModel>
#include <QtCore/QList>
#include <QtCore/QVariantMap>
namespace Qt4ProjectManager {
......@@ -66,7 +67,9 @@ private:
Q_SLOT void handleDeviceConfigListChange();
void resetCurrentIndex();
void setInvalid();
void setupList();
QList<MaemoDeviceConfig> m_devConfigs;
quint64 m_currentId;
int m_currentIndex;
};
......
......@@ -56,7 +56,6 @@ namespace {
const QLatin1String TypeKey("Type");
const QLatin1String HostKey("Host");
const QLatin1String SshPortKey("SshPort");
const QLatin1String DebuggingPortKey("GdbServerPort");
const QLatin1String PortsSpecKey("FreePortsSpec");
const QLatin1String UserNameKey("Uname");
const QLatin1String AuthKey("Authentication");
......@@ -177,7 +176,6 @@ private:
MaemoDeviceConfig::MaemoDeviceConfig(const QString &name, MaemoDeviceConfig::DeviceType devType)
: name(name),
type(devType),
debuggingPort(defaultDebuggingPort(type)),
portsSpec(defaultPortsSpec(type)),
internalId(MaemoDeviceConfigurations::instance().m_nextId++)
{
......@@ -193,7 +191,6 @@ MaemoDeviceConfig::MaemoDeviceConfig(const QSettings &settings,
quint64 &nextId)
: name(settings.value(NameKey).toString()),
type(static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt())),
debuggingPort(settings.value(DebuggingPortKey, defaultDebuggingPort(type)).toInt()),
portsSpec(settings.value(PortsSpecKey, defaultPortsSpec(type)).toString()),
internalId(settings.value(InternalIdKey, nextId).toULongLong())
{
......@@ -228,11 +225,6 @@ int MaemoDeviceConfig::defaultSshPort(DeviceType type) const
return type == Physical ? DefaultSshPortHW : DefaultSshPortSim;
}
int MaemoDeviceConfig::defaultDebuggingPort(DeviceType type) const
{
return type == Physical ? DefaultGdbServerPortHW : DefaultGdbServerPortSim;
}
QString MaemoDeviceConfig::defaultPortsSpec(DeviceType type) const
{
return QLatin1String(type == Physical ? "10000-10100" : "13219,14168");
......@@ -259,7 +251,6 @@ void MaemoDeviceConfig::save(QSettings &settings) const
settings.setValue(TypeKey, type);
settings.setValue(HostKey, server.host);
settings.setValue(SshPortKey, server.port);
settings.setValue(DebuggingPortKey, debuggingPort);
settings.setValue(PortsSpecKey, portsSpec);
settings.setValue(UserNameKey, server.uname);
settings.setValue(AuthKey, server.authType);
......
......@@ -94,13 +94,11 @@ public:
Core::SshConnectionParameters server;
QString name;
DeviceType type;
int debuggingPort;
QString portsSpec;
quint64 internalId;
private:
int defaultSshPort(DeviceType type) const;
int defaultDebuggingPort(DeviceType type) const;
QString defaultPortsSpec(DeviceType type) const;
QString defaultHost(DeviceType type) const;
......
......@@ -35,8 +35,8 @@ namespace Internal {
const QLatin1String MaemoMountSpecification::InvalidMountPoint("/");
MaemoMountSpecification::MaemoMountSpecification(const QString &localDir,
const QString &remoteDir, int remotePort)
: localDir(localDir), remoteMountPoint(remoteDir), remotePort(remotePort)
const QString &remoteDir)
: localDir(localDir), remoteMountPoint(remoteDir)
{
}
......
......@@ -36,16 +36,13 @@ namespace Qt4ProjectManager {
namespace Internal {
struct MaemoMountSpecification {
MaemoMountSpecification(const QString &localDir, const QString &remoteDir,
int remotePort);
MaemoMountSpecification(const QString &localDir, const QString &remoteDir);
bool isValid() const { return remoteMountPoint != InvalidMountPoint; }
static const QLatin1String InvalidMountPoint;
QString localDir;
QString remoteMountPoint;
int remotePort;
};
} // namespace Internal
......
......@@ -590,7 +590,15 @@ bool MaemoQemuManager::fillRuntimeInformation(Runtime *runtime) const
runtime->m_libPath =
libPathSpec.mid(libPathSpec.indexOf(QLatin1Char('=')) + 1);
runtime->m_sshPort = map.value(QLatin1String("sshport"));
runtime->m_gdbServerPort = map.value(QLatin1String("redirport2"));
runtime->m_freePorts = MaemoPortList();
int i = 2;
while (true) {
const QString port = map.value(QLatin1String("redirport")
+ QString::number(i++));
if (port.isEmpty())
break;
runtime->m_freePorts.addPort(port.toInt());
}
return true;
}
}
......
......@@ -31,6 +31,7 @@
#define QEMURUNTIMEMANAGER_H
#include "maemoconstants.h"
#include "maemodeviceconfigurations.h"
#include <QtCore/QMap>
#include <QtCore/QObject>
......@@ -64,7 +65,7 @@ struct Runtime
QString m_args;
QString m_libPath;
QString m_sshPort;
QString m_gdbServerPort;
MaemoPortList m_freePorts;
};
class MaemoQemuManager : public QObject
......
......@@ -57,11 +57,16 @@ void MaemoRemoteMounter::setConnection(const Core::SshConnection::Ptr &connectio
m_connection = connection;
}
void MaemoRemoteMounter::addMountSpecification(const MaemoMountSpecification &mountSpec,
bool MaemoRemoteMounter::addMountSpecification(const MaemoMountSpecification &mountSpec,
bool mountAsRoot)
{
if (mountSpec.isValid())
m_mountSpecs << MountInfo(mountSpec, mountAsRoot);
if (mountSpec.isValid()) {
if (!m_portList.hasMore())
return false;
else
m_mountSpecs << MountInfo(mountSpec, m_portList.getNext(), mountAsRoot);
}
return true;
}
void MaemoRemoteMounter::mount()
......@@ -223,16 +228,17 @@ void MaemoRemoteMounter::startUtfsClients()
const QLatin1String andOp(" && ");
QString remoteCall = chmodFuse + andOp + chmodUtfsClient;
for (int i = 0; i < m_mountSpecs.count(); ++i) {
const MaemoMountSpecification &mountSpec = m_mountSpecs.at(i).mountSpec;
const MountInfo &mountInfo = m_mountSpecs.at(i);
const MaemoMountSpecification &mountSpec = mountInfo.mountSpec;
const QString mkdir = QString::fromLocal8Bit("%1 mkdir -p %2")
.arg(MaemoGlobal::remoteSudo(), mountSpec.remoteMountPoint);
const QString chmod = QString::fromLocal8Bit("%1 chmod a+r+w+x %2")
.arg(MaemoGlobal::remoteSudo(), mountSpec.remoteMountPoint);
QString utfsClient
= QString::fromLocal8Bit("%1 --detach -l %2 -r %2 -b %2 %4")
.arg(utfsClientOnDevice()).arg(mountSpec.remotePort)
.arg(utfsClientOnDevice()).arg(mountInfo.remotePort)
.arg(mountSpec.remoteMountPoint);
if (m_mountSpecs.at(i).mountAsRoot)
if (mountInfo.mountAsRoot)
utfsClient.prepend(MaemoGlobal::remoteSudo() + QLatin1Char(' '));
remoteCall += andOp + mkdir + andOp + chmod + andOp + utfsClient;
}
......@@ -269,9 +275,10 @@ void MaemoRemoteMounter::startUtfsServers()
{
emit reportProgress(tr("Starting UTFS servers..."));
for (int i = 0; i < m_mountSpecs.count(); ++i) {
const MaemoMountSpecification &mountSpec = m_mountSpecs.at(i).mountSpec;
const MountInfo &mountInfo = m_mountSpecs.at(i);
const MaemoMountSpecification &mountSpec = mountInfo.mountSpec;
const ProcPtr utfsServerProc(new QProcess);
const QString port = QString::number(mountSpec.remotePort);
const QString port = QString::number(mountInfo.remotePort);
const QString localSecretOpt = QLatin1String("-l");
const QString remoteSecretOpt = QLatin1String("-r");
const QStringList utfsServerArgs = QStringList()
......
......@@ -30,6 +30,7 @@
#ifndef MAEMOREMOTEMOUNTER_H
#define MAEMOREMOTEMOUNTER_H
#include "maemodeviceconfigurations.h"
#include "maemomountspecification.h"
#include <coreplugin/ssh/sftpdefs.h>
......@@ -57,7 +58,8 @@ class MaemoRemoteMounter : public QObject
public:
MaemoRemoteMounter(QObject *parent, const MaemoToolChain *toolchain);
~MaemoRemoteMounter();
void addMountSpecification(const MaemoMountSpecification &mountSpec,
void setPortList(const MaemoPortList &portList) { m_portList = portList; }
bool addMountSpecification(const MaemoMountSpecification &mountSpec,
bool mountAsRoot);
void mount();
void unmount();
......@@ -91,9 +93,10 @@ private:
const MaemoToolChain * const m_toolChain;
struct MountInfo {
MountInfo(const MaemoMountSpecification &m, bool root)
: mountSpec(m), mountAsRoot(root) {}
MountInfo(const MaemoMountSpecification