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

Madde: Make Maemo deployment module more self-contained.



Its old interface made outdated assumptions about data flow
and would not be able to sensibly partake in higher-level
refactorings.

Change-Id: I553c64919ba36aae39d876ade73b824f01db2767
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent 7b8eafc6
......@@ -35,7 +35,6 @@
#include <projectexplorer/target.h>
#include <projectexplorer/profileinformation.h>
#include <remotelinux/remotelinuxusedportsgatherer.h>
#include <utils/qtcassert.h>
#include <ssh/sshconnection.h>
......@@ -49,8 +48,7 @@ namespace Internal {
MaemoDeploymentMounter::MaemoDeploymentMounter(QObject *parent)
: QObject(parent),
m_state(Inactive),
m_mounter(new MaemoRemoteMounter(this)),
m_portsGatherer(new RemoteLinuxUsedPortsGatherer(this))
m_mounter(new MaemoRemoteMounter(this))
{
connect(m_mounter, SIGNAL(error(QString)), SLOT(handleMountError(QString)));
connect(m_mounter, SIGNAL(mounted()), SLOT(handleMounted()));
......@@ -59,11 +57,6 @@ MaemoDeploymentMounter::MaemoDeploymentMounter(QObject *parent)
SIGNAL(reportProgress(QString)));
connect(m_mounter, SIGNAL(debugOutput(QString)),
SIGNAL(debugOutput(QString)));
connect(m_portsGatherer, SIGNAL(error(QString)),
SLOT(handlePortsGathererError(QString)));
connect(m_portsGatherer, SIGNAL(portListReady()),
SLOT(handlePortListReady()));
}
MaemoDeploymentMounter::~MaemoDeploymentMounter() {}
......@@ -78,7 +71,7 @@ void MaemoDeploymentMounter::setupMounts(SshConnection *connection,
m_connection = connection;
m_profile = profile;
m_devConf = DeviceProfileInformation::device(profile);
m_mounter->setConnection(m_connection, m_devConf);
m_mounter->setParameters(m_devConf, MaemoGlobal::maddeRoot(profile));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
setState(UnmountingOldDirs);
unmount();
......@@ -99,7 +92,6 @@ void MaemoDeploymentMounter::setupMounter()
setState(UnmountingCurrentDirs);
m_mounter->resetMountSpecifications();
m_mounter->setProfile(m_profile);
foreach (const MaemoMountSpecification &mountSpec, m_mountSpecs)
m_mounter->addMountSpecification(mountSpec, true);
unmount();
......@@ -137,8 +129,8 @@ void MaemoDeploymentMounter::handleUnmounted()
setupMounter();
break;
case UnmountingCurrentDirs:
setState(GatheringPorts);
m_portsGatherer->start(m_devConf);
setState(Mounting);
m_mounter->mount();
break;
case UnmountingCurrentMounts:
setState(Inactive);
......@@ -150,30 +142,6 @@ void MaemoDeploymentMounter::handleUnmounted()
}
}
void MaemoDeploymentMounter::handlePortsGathererError(const QString &errorMsg)
{
QTC_ASSERT(m_state == GatheringPorts || m_state == Inactive, return);
if (m_state == Inactive)
return;
setState(Inactive);
m_mounter->resetMountSpecifications();
emit error(errorMsg);
}
void MaemoDeploymentMounter::handlePortListReady()
{
QTC_ASSERT(m_state == GatheringPorts || m_state == Inactive, return);
if (m_state == Inactive)
return;
setState(Mounting);
m_freePorts = MaemoGlobal::freePorts(m_profile);
m_mounter->mount(&m_freePorts, m_portsGatherer);
}
void MaemoDeploymentMounter::handleMountError(const QString &errorMsg)
{
QTC_ASSERT(m_state == UnmountingOldDirs || m_state == UnmountingCurrentDirs
......
......@@ -40,7 +40,7 @@
namespace ProjectExplorer { class Profile; }
namespace QSsh { class SshConnection; }
namespace RemoteLinux { class RemoteLinuxUsedPortsGatherer; }
namespace Utils { class FileName; }
namespace Madde {
namespace Internal {
......@@ -70,13 +70,11 @@ private slots:
void handleMounted();
void handleUnmounted();
void handleMountError(const QString &errorMsg);
void handlePortsGathererError(const QString &errorMsg);
void handlePortListReady();
void handleConnectionError();
private:
enum State {
Inactive, UnmountingOldDirs, UnmountingCurrentDirs, GatheringPorts,
Inactive, UnmountingOldDirs, UnmountingCurrentDirs,
Mounting, Mounted, UnmountingCurrentMounts
};
......@@ -88,8 +86,6 @@ private:
QSsh::SshConnection *m_connection;
ProjectExplorer::IDevice::ConstPtr m_devConf;
MaemoRemoteMounter * const m_mounter;
RemoteLinux::RemoteLinuxUsedPortsGatherer * const m_portsGatherer;
Utils::PortList m_freePorts;
QList<MaemoMountSpecification> m_mountSpecs;
const ProjectExplorer::Profile *m_profile;
};
......
......@@ -176,6 +176,11 @@ QString MaemoGlobal::maddeRoot(const QString &qmakePath)
return dir.absolutePath();
}
Utils::FileName MaemoGlobal::maddeRoot(const Profile *profile)
{
return SysRootProfileInformation::sysRoot(profile).parentDir().parentDir();
}
QString MaemoGlobal::targetRoot(const QString &qmakePath)
{
#ifdef Q_OS_WIN
......
......@@ -33,6 +33,7 @@
#include <coreplugin/id.h>
#include <coreplugin/idocument.h>
#include <utils/fileutils.h>
#include <utils/portlist.h>
#include <utils/environment.h>
......@@ -98,6 +99,7 @@ public:
static void addMaddeEnvironment(Utils::Environment &env, const QString &qmakePath);
static void transformMaddeCall(QString &command, QStringList &args, const QString &qmakePath);
static QString maddeRoot(const QString &qmakePath);
static Utils::FileName maddeRoot(const ProjectExplorer::Profile *profile);
static QString targetRoot(const QString &qmakePath);
static QString targetName(const QString &qmakePath);
static QString madCommand(const QString &qmakePath);
......
......@@ -33,10 +33,7 @@
#include "maemoglobal.h"
#include "maddedevice.h"
#include <projectexplorer/profileinformation.h>
#include <projectexplorer/target.h>
#include <ssh/sshconnection.h>
#include <ssh/sshremoteprocess.h>
#include <ssh/sshremoteprocessrunner.h>
#include <remotelinux/remotelinuxusedportsgatherer.h>
#include <utils/qtcassert.h>
......@@ -51,10 +48,19 @@ namespace Madde {
namespace Internal {
MaemoRemoteMounter::MaemoRemoteMounter(QObject *parent)
: QObject(parent), m_utfsServerTimer(new QTimer(this)), m_state(Inactive)
: QObject(parent),
m_utfsServerTimer(new QTimer(this)),
m_mountProcess(new SshRemoteProcessRunner(this)),
m_unmountProcess(new SshRemoteProcessRunner(this)),
m_portsGatherer(new RemoteLinuxUsedPortsGatherer(this)),
m_state(Inactive)
{
connect(m_utfsServerTimer, SIGNAL(timeout()), this,
SLOT(handleUtfsServerTimeout()));
connect(m_utfsServerTimer, SIGNAL(timeout()), SLOT(handleUtfsServerTimeout()));
connect(m_portsGatherer, SIGNAL(error(QString)),
SLOT(handlePortsGathererError(QString)));
connect(m_portsGatherer, SIGNAL(portListReady()),
SLOT(handlePortListReady()));
m_utfsServerTimer->setSingleShot(true);
}
......@@ -63,22 +69,12 @@ MaemoRemoteMounter::~MaemoRemoteMounter()
killAllUtfsServers();
}
void MaemoRemoteMounter::setConnection(SshConnection *connection,
const IDevice::ConstPtr &devConf)
void MaemoRemoteMounter::setParameters(const IDevice::ConstPtr &devConf, const FileName &maddeRoot)
{
QTC_ASSERT(m_state == Inactive, return);
m_connection = connection;
m_devConf = devConf;
}
void MaemoRemoteMounter::setProfile(const Profile *profile)
{
QTC_ASSERT(m_state == Inactive, return);
Core::Id typeId = DeviceTypeProfileInformation::deviceTypeId(profile);
m_remoteMountsAllowed = MaddeDevice::allowsRemoteMounts(typeId);
m_maddeRoot = SysRootProfileInformation::sysRoot(profile).parentDir().parentDir();
m_maddeRoot = maddeRoot;
}
void MaemoRemoteMounter::addMountSpecification(const MaemoMountSpecification &mountSpec,
......@@ -86,7 +82,7 @@ void MaemoRemoteMounter::addMountSpecification(const MaemoMountSpecification &mo
{
QTC_ASSERT(m_state == Inactive, return);
if (m_remoteMountsAllowed && mountSpec.isValid())
if (MaddeDevice::allowsRemoteMounts(m_devConf->type()) && mountSpec.isValid())
m_mountSpecs << MountInfo(mountSpec, mountAsRoot);
}
......@@ -95,22 +91,18 @@ bool MaemoRemoteMounter::hasValidMountSpecifications() const
return !m_mountSpecs.isEmpty();
}
void MaemoRemoteMounter::mount(PortList *freePorts,
const RemoteLinuxUsedPortsGatherer *portsGatherer)
void MaemoRemoteMounter::mount()
{
QTC_ASSERT(m_state == Inactive, return);
Q_ASSERT(m_utfsServers.isEmpty());
Q_ASSERT(m_connection);
if (m_mountSpecs.isEmpty()) {
setState(Inactive);
emit reportProgress(tr("No directories to mount"));
emit mounted();
} else {
m_freePorts = freePorts;
m_portsGatherer = portsGatherer;
startUtfsClients();
m_portsGatherer->start(m_devConf);
}
}
......@@ -126,17 +118,15 @@ void MaemoRemoteMounter::unmount()
QString remoteCall;
const QString remoteSudo = MaemoGlobal::remoteSudo(m_devConf->type(),
m_connection->connectionParameters().userName);
m_devConf->sshParameters().userName);
for (int i = 0; i < m_mountSpecs.count(); ++i) {
remoteCall += QString::fromLatin1("%1 umount %2 && %1 rmdir %2;")
.arg(remoteSudo, m_mountSpecs.at(i).mountSpec.remoteMountPoint);
}
m_unmountProcess = m_connection->createRemoteProcess(remoteCall.toUtf8());
connect(m_unmountProcess.data(), SIGNAL(closed(int)), this,
SLOT(handleUnmountProcessFinished(int)));
setState(Unmounting);
m_unmountProcess->start();
connect(m_unmountProcess, SIGNAL(processClosed(int)), SLOT(handleUnmountProcessFinished(int)));
m_unmountProcess->run(remoteCall.toUtf8(), m_devConf->sshParameters());
}
void MaemoRemoteMounter::handleUnmountProcessFinished(int exitStatus)
......@@ -153,8 +143,7 @@ void MaemoRemoteMounter::handleUnmountProcessFinished(int exitStatus)
errorMsg = tr("Could not execute unmount request.");
break;
case SshRemoteProcess::CrashExit:
errorMsg = tr("Failure unmounting: %1")
.arg(m_unmountProcess->errorString());
errorMsg = tr("Failure unmounting: %1").arg(m_unmountProcess->processErrorString());
break;
case SshRemoteProcess::NormalExit:
break;
......@@ -183,17 +172,19 @@ void MaemoRemoteMounter::stop()
void MaemoRemoteMounter::startUtfsClients()
{
const QString userName = m_connection->connectionParameters().userName;
QTC_ASSERT(m_state == GatheringPorts, return);
const QString userName = m_devConf->sshParameters().userName;
const QString chmodFuse = MaemoGlobal::remoteSudo(m_devConf->type(),
userName) + QLatin1String(" chmod a+r+w /dev/fuse");
const QString chmodUtfsClient
= QLatin1String("chmod a+x ") + utfsClientOnDevice();
const QLatin1String andOp(" && ");
QString remoteCall = chmodFuse + andOp + chmodUtfsClient;
PortList ports = m_devConf->freePorts();
for (int i = 0; i < m_mountSpecs.count(); ++i) {
MountInfo &mountInfo = m_mountSpecs[i];
mountInfo.remotePort
= m_portsGatherer->getNextFreePort(m_freePorts);
mountInfo.remotePort = m_portsGatherer->getNextFreePort(&ports);
if (mountInfo.remotePort == -1) {
setState(Inactive);
emit error(tr("Error: Not enough free ports on device to fulfill all mount requests."));
......@@ -221,14 +212,10 @@ void MaemoRemoteMounter::startUtfsClients()
}
emit reportProgress(tr("Starting remote UTFS clients..."));
m_mountProcess = m_connection->createRemoteProcess(remoteCall.toUtf8());
connect(m_mountProcess.data(), SIGNAL(started()), this,
SLOT(handleUtfsClientsStarted()));
connect(m_mountProcess.data(), SIGNAL(closed(int)), this,
SLOT(handleUtfsClientsFinished(int)));
m_mountProcess->start();
setState(UtfsClientsStarting);
connect(m_mountProcess, SIGNAL(processStarted()), SLOT(handleUtfsClientsStarted()));
connect(m_mountProcess, SIGNAL(processClosed(int)), SLOT(handleUtfsClientsFinished(int)));
m_mountProcess->run(remoteCall.toUtf8(), m_devConf->sshParameters());
}
void MaemoRemoteMounter::handleUtfsClientsStarted()
......@@ -250,13 +237,12 @@ void MaemoRemoteMounter::handleUtfsClientsFinished(int exitStatus)
return;
setState(Inactive);
if (exitStatus == SshRemoteProcess::NormalExit
&& m_mountProcess->exitCode() == 0) {
if (exitStatus == SshRemoteProcess::NormalExit && m_mountProcess->processExitCode() == 0) {
emit reportProgress(tr("Mount operation succeeded."));
emit mounted();
} else {
QString errMsg = tr("Failure running UTFS client: %1")
.arg(m_mountProcess->errorString());
.arg(m_mountProcess->processErrorString());
const QByteArray &mountStderr = m_mountProcess->readAllStandardError();
if (!mountStderr.isEmpty())
errMsg += tr("\nstderr was: '%1'").arg(QString::fromUtf8(mountStderr));
......@@ -282,7 +268,7 @@ void MaemoRemoteMounter::startUtfsServers()
const QString remoteSecretOpt = QLatin1String("-r");
const QStringList utfsServerArgs = QStringList() << localSecretOpt
<< port << remoteSecretOpt << port << QLatin1String("-c")
<< (m_connection->connectionParameters().host + QLatin1Char(':') + port)
<< (m_devConf->sshParameters().host + QLatin1Char(':') + port)
<< mountSpec.localDir;
connect(utfsServerProc.data(),
SIGNAL(finished(int,QProcess::ExitStatus)), this,
......@@ -298,6 +284,21 @@ void MaemoRemoteMounter::startUtfsServers()
setState(UtfsServersStarted);
}
void MaemoRemoteMounter::handlePortsGathererError(const QString &errorMsg)
{
QTC_ASSERT(m_state == GatheringPorts, return);
setState(Inactive);
emit error(errorMsg);
}
void MaemoRemoteMounter::handlePortListReady()
{
QTC_ASSERT(m_state == GatheringPorts, return);
startUtfsClients();
}
void MaemoRemoteMounter::handleUtfsServerStderr()
{
if (m_state != Inactive) {
......@@ -373,16 +374,14 @@ void MaemoRemoteMounter::handleUtfsServerTimeout()
void MaemoRemoteMounter::setState(State newState)
{
if (newState == m_state)
return;
if (newState == Inactive) {
m_utfsServerTimer->stop();
if (m_mountProcess) {
disconnect(m_mountProcess.data(), 0, this, 0);
m_mountProcess->close();
}
if (m_unmountProcess) {
disconnect(m_unmountProcess.data(), 0, this, 0);
m_unmountProcess->close();
}
disconnect(m_mountProcess, 0, this, 0);
m_mountProcess->cancel();
disconnect(m_unmountProcess, 0, this, 0);
m_unmountProcess->cancel();
}
m_state = newState;
}
......
......@@ -44,14 +44,9 @@
QT_FORWARD_DECLARE_CLASS(QTimer)
namespace QSsh {
class SshConnection;
class SshRemoteProcess;
}
namespace QSsh { class SshRemoteProcessRunner; }
namespace ProjectExplorer { class Profile; }
namespace RemoteLinux { class RemoteLinuxUsedPortsGatherer; }
namespace Utils { class PortList; }
namespace Madde {
namespace Internal {
......@@ -60,20 +55,16 @@ class MaemoRemoteMounter : public QObject
{
Q_OBJECT
public:
MaemoRemoteMounter(QObject *parent);
MaemoRemoteMounter(QObject *parent = 0);
~MaemoRemoteMounter();
// Must already be connected.
void setConnection(QSsh::SshConnection *connection,
const ProjectExplorer::IDevice::ConstPtr &devConf);
void setProfile(const ProjectExplorer::Profile *profile);
void setParameters(const ProjectExplorer::IDevice::ConstPtr &devConf,
const Utils::FileName &fileName);
void addMountSpecification(const MaemoMountSpecification &mountSpec,
bool mountAsRoot);
bool hasValidMountSpecifications() const;
void resetMountSpecifications() { m_mountSpecs.clear(); }
void mount(Utils::PortList *freePorts,
const RemoteLinux::RemoteLinuxUsedPortsGatherer *portsGatherer);
void mount();
void unmount();
void stop();
......@@ -94,11 +85,13 @@ private slots:
void handleUtfsServerTimeout();
void handleUtfsServerStderr();
void startUtfsServers();
void handlePortsGathererError(const QString &errorMsg);
void handlePortListReady();
private:
enum State {
Inactive, Unmounting, UtfsClientsStarting, UtfsClientsStarted,
UtfsServersStarted
UtfsServersStarted, GatheringPorts
};
void setState(State newState);
......@@ -119,18 +112,15 @@ private:
int remotePort;
};
QSsh::SshConnection *m_connection;
ProjectExplorer::IDevice::ConstPtr m_devConf;
QList<MountInfo> m_mountSpecs;
QSharedPointer<QSsh::SshRemoteProcess> m_mountProcess;
QSharedPointer<QSsh::SshRemoteProcess> m_unmountProcess;
QSsh::SshRemoteProcessRunner * const m_mountProcess;
QSsh::SshRemoteProcessRunner * const m_unmountProcess;
typedef QSharedPointer<QProcess> ProcPtr;
QList<ProcPtr> m_utfsServers;
Utils::PortList *m_freePorts;
const RemoteLinux::RemoteLinuxUsedPortsGatherer *m_portsGatherer;
bool m_remoteMountsAllowed;
RemoteLinux::RemoteLinuxUsedPortsGatherer * const m_portsGatherer;
Utils::FileName m_maddeRoot;
State m_state;
......
......@@ -28,6 +28,7 @@
**************************************************************************/
#include "maemosshrunner.h"
#include "maemoglobal.h"
#include "maemoqemumanager.h"
#include "maemoremotemounter.h"
#include "maemoremotemountsmodel.h"
......@@ -55,7 +56,7 @@ MaemoSshRunner::MaemoSshRunner(QObject *parent, MaemoRunConfiguration *runConfig
const BuildConfiguration * const bc = runConfig->target()->activeBuildConfiguration();
Profile *profile = bc ? bc->target()->profile() : 0;
m_qtId = QtSupport::QtProfileInformation::qtVersionId(profile);
m_mounter->setProfile(profile);
m_mounter->setParameters(devConfig(), MaemoGlobal::maddeRoot(profile));
connect(m_mounter, SIGNAL(mounted()), this, SLOT(handleMounted()));
connect(m_mounter, SIGNAL(unmounted()), this, SLOT(handleUnmounted()));
connect(m_mounter, SIGNAL(error(QString)), this,
......@@ -98,7 +99,6 @@ void MaemoSshRunner::doAdditionalInitialCleanup()
{
QTC_ASSERT(m_mountState == InactiveMountState, return);
m_mounter->setConnection(connection(), devConfig());
m_mounter->resetMountSpecifications();
for (int i = 0; i < m_mountSpecs.count(); ++i)
m_mounter->addMountSpecification(m_mountSpecs.at(i), false);
......@@ -181,7 +181,7 @@ void MaemoSshRunner::mount()
m_mountState = Mounting;
if (m_mounter->hasValidMountSpecifications()) {
emit reportProgress(tr("Mounting host directories..."));
m_mounter->mount(freePorts(), usedPortsGatherer());
m_mounter->mount();
} else {
handleMounted();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment