maemorunfactories.cpp 8.92 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, 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, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30
#include "maemorunfactories.h"

31
#include "maemoapplicationrunnerhelperactions.h"
32
#include "maemoconstants.h"
33
#include "maemoglobal.h"
34
#include "maemoremotemountsmodel.h"
35
#include "maemorunconfiguration.h"
36

37
#include <debugger/debuggerconstants.h>
38
#include <debugger/debuggerstartparameters.h>
39 40 41
#include <debugger/debuggerplugin.h>
#include <debugger/debuggerrunner.h>
#include <projectexplorer/projectexplorerconstants.h>
Tobias Hunger's avatar
Tobias Hunger committed
42
#include <projectexplorer/kitinformation.h>
Tobias Hunger's avatar
Tobias Hunger committed
43 44
#include <projectexplorer/target.h>
#include <qt4projectmanager/qt4nodes.h>
45
#include <qt4projectmanager/qt4project.h>
Tobias Hunger's avatar
Tobias Hunger committed
46
#include <qtsupport/customexecutablerunconfiguration.h>
47 48
#include <remotelinux/remotelinuxdebugsupport.h>
#include <remotelinux/remotelinuxruncontrol.h>
49
#include <utils/qtcassert.h>
50

51
using namespace Debugger;
52
using namespace ProjectExplorer;
53
using namespace Qt4ProjectManager;
54
using namespace RemoteLinux;
55

56
namespace Madde {
57
namespace Internal {
58 59 60

namespace {

61
QString pathFromId(Core::Id id)
62
{
Tobias Hunger's avatar
Tobias Hunger committed
63
    QString idStr = id.toString();
64 65
    const QString prefix = QLatin1String(MAEMO_RC_ID_PREFIX);
    if (!idStr.startsWith(prefix))
66
        return QString();
67
    return idStr.mid(prefix.size());
68 69
}

70 71 72
template<class Receiver> void setHelperActions(Receiver *receiver, MaemoRunConfiguration *runConfig,
        RunControl *runControl)
{
Tobias Hunger's avatar
Tobias Hunger committed
73
    const Kit * const k = runConfig->target()->kit();
74
    MaemoPreRunAction * const preRunAction = new MaemoPreRunAction(
Tobias Hunger's avatar
Tobias Hunger committed
75
            DeviceKitInformation::device(k), MaemoGlobal::maddeRoot(k),
76 77 78 79 80 81 82
            runConfig->remoteMounts()->mountSpecs(), runControl);
    MaemoPostRunAction * const postRunAction
            = new MaemoPostRunAction(preRunAction->mounter(), runControl);
    receiver->setApplicationRunnerPreRunAction(preRunAction);
    receiver->setApplicationRunnerPostRunAction(postRunAction);
}

83 84 85
} // namespace

MaemoRunConfigurationFactory::MaemoRunConfigurationFactory(QObject *parent)
Tobias Hunger's avatar
Tobias Hunger committed
86 87
    : QmakeRunConfigurationFactory(parent)
{ setObjectName(QLatin1String("MaemoRunConfigurationFactory")); }
88 89 90 91 92

MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
93
bool MaemoRunConfigurationFactory::canCreate(Target *parent, const Core::Id id) const
94
{
Tobias Hunger's avatar
Tobias Hunger committed
95 96 97
    if (!canHandle(parent))
        return false;
    return static_cast<Qt4Project *>(parent->project())->hasApplicationProFile(pathFromId(id));
98 99 100 101 102
}

bool MaemoRunConfigurationFactory::canRestore(Target *parent,
    const QVariantMap &map) const
{
Tobias Hunger's avatar
Tobias Hunger committed
103 104
    return canHandle(parent)
        && ProjectExplorer::idFromMap(map).toString().startsWith(QLatin1String(MAEMO_RC_ID_PREFIX));
105 106 107 108 109
}

bool MaemoRunConfigurationFactory::canClone(Target *parent,
    RunConfiguration *source) const
{
Tobias Hunger's avatar
Tobias Hunger committed
110 111
    if (!canHandle(parent))
        return false;
112 113
    const RemoteLinuxRunConfiguration * const rlrc
            = qobject_cast<RemoteLinuxRunConfiguration *>(source);
114 115
    Core::Id id = source->id().withSuffix(QLatin1Char('.') + rlrc->projectFilePath());
    return rlrc && canCreate(parent, id);
116 117
}

118
QList<Core::Id> MaemoRunConfigurationFactory::availableCreationIds(Target *parent) const
119
{
120
    QList<Core::Id> result;
Tobias Hunger's avatar
Tobias Hunger committed
121 122 123 124
    if (!canHandle(parent))
        return result;
    QStringList proFiles = static_cast<Qt4Project *>(parent->project())->applicationProFilePathes(QLatin1String(MAEMO_RC_ID_PREFIX));
    foreach (const QString &pf, proFiles)
125
        result << Core::Id::fromString(pf);
126
    return result;
127 128
}

Tobias Hunger's avatar
Tobias Hunger committed
129
QString MaemoRunConfigurationFactory::displayNameForId(const Core::Id id) const
130
{
Christian Kandeler's avatar
Christian Kandeler committed
131
    return QFileInfo(pathFromId(id)).completeBaseName()
132
        + QLatin1String(" (on remote Maemo device)");
133 134
}

135
RunConfiguration *MaemoRunConfigurationFactory::doCreate(Target *parent, const Core::Id id)
136
{
Tobias Hunger's avatar
Tobias Hunger committed
137
    return new MaemoRunConfiguration(parent, id, pathFromId(id));
138 139 140 141 142 143 144
}

RunConfiguration *MaemoRunConfigurationFactory::restore(Target *parent,
    const QVariantMap &map)
{
    if (!canRestore(parent, map))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
145 146

    Core::Id id = ProjectExplorer::idFromMap(map);
147
    MaemoRunConfiguration *rc
Tobias Hunger's avatar
Tobias Hunger committed
148
        = new MaemoRunConfiguration(parent, id, pathFromId(id));
149 150 151 152 153
    if (rc->fromMap(map))
        return rc;

    delete rc;
    return 0;
154 155
}

156
RunConfiguration *MaemoRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
157 158 159 160
{
    if (!canClone(parent, source))
        return 0;

161
    MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
Tobias Hunger's avatar
Tobias Hunger committed
162 163 164 165 166
    return new MaemoRunConfiguration(parent, old);
}

bool MaemoRunConfigurationFactory::canHandle(Target *t) const
{
Tobias Hunger's avatar
Tobias Hunger committed
167
    if (!t->project()->supportsKit(t->kit()))
Tobias Hunger's avatar
Tobias Hunger committed
168 169 170
        return false;
    if (!qobject_cast<Qt4Project *>(t->project()))
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
171
    Core::Id devType = DeviceTypeKitInformation::deviceTypeId(t->kit());
172
    return devType == Maemo5OsType || devType == HarmattanOsType;
Tobias Hunger's avatar
Tobias Hunger committed
173 174 175 176 177 178 179
}

QList<RunConfiguration *> MaemoRunConfigurationFactory::runConfigurationsForNode(Target *t, Node *n)
{
    QList<ProjectExplorer::RunConfiguration *> result;
    foreach (ProjectExplorer::RunConfiguration *rc, t->runConfigurations())
        if (MaemoRunConfiguration *mrc = qobject_cast<MaemoRunConfiguration *>(rc))
180
            if (mrc->projectFilePath() == n->path())
Tobias Hunger's avatar
Tobias Hunger committed
181 182
                result << rc;
    return result;
183 184 185 186 187 188 189 190 191 192 193 194
}


MaemoRunControlFactory::MaemoRunControlFactory(QObject *parent)
    : IRunControlFactory(parent)
{
}

MaemoRunControlFactory::~MaemoRunControlFactory()
{
}

195
bool MaemoRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
196
{
197 198
    if (mode != NormalRunMode && mode != DebugRunMode && mode != DebugRunModeWithBreakOnMain)
        return false;
199 200
    const MaemoRunConfiguration * const maemoRunConfig
        = qobject_cast<MaemoRunConfiguration *>(runConfiguration);
201
    return maemoRunConfig && maemoRunConfig->isEnabled();
202 203
}

204 205
RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig, RunMode mode,
                                           QString *errorMessage)
206
{
207
    QTC_ASSERT(canRun(runConfig, mode), return 0);
208 209

    MaemoRunConfiguration *rc = qobject_cast<MaemoRunConfiguration *>(runConfig);
210 211 212
    QTC_ASSERT(rc, return 0);
    switch (mode) {
    case NormalRunMode: {
213 214 215 216
        RemoteLinuxRunControl * const runControl = new RemoteLinuxRunControl(rc);
        setHelperActions(runControl, rc, runControl);
        return runControl;
    }
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
    case DebugRunMode:
    case DebugRunModeWithBreakOnMain: {
        IDevice::ConstPtr dev = DeviceKitInformation::device(rc->target()->kit());
        if (!dev) {
            *errorMessage = tr("Cannot debug: Kit has no device.");
            return 0;
        }
        if (rc->portsUsedByDebuggers() > dev->freePorts().count()) {
            *errorMessage = tr("Cannot debug: Not enough free ports available.");
            return 0;
        }
        DebuggerStartParameters params = LinuxDeviceDebugSupport::startParameters(rc);
        if (mode == ProjectExplorer::DebugRunModeWithBreakOnMain)
            params.breakOnMain = true;
        DebuggerRunControl * const runControl
                = DebuggerPlugin::createDebugger(params, rc, errorMessage);
        if (!runControl)
            return 0;
        LinuxDeviceDebugSupport * const debugSupport =
                new LinuxDeviceDebugSupport(rc, runControl->engine());
        setHelperActions(debugSupport, rc, runControl);
        connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
        return runControl;
    }
    case NoRunMode:
    case QmlProfilerRunMode:
    case CallgrindRunMode:
    case MemcheckRunMode:
        QTC_ASSERT(false, return 0);
    }
247

248
    QTC_ASSERT(false, return 0);
249 250 251 252 253 254 255 256
}

QString MaemoRunControlFactory::displayName() const
{
    return tr("Run on device");
}

    } // namespace Internal
257
} // namespace Madde