maemorunfactories.cpp 8.77 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
RunConfiguration *MaemoRunConfigurationFactory::doRestore(Target *parent,
141 142
    const QVariantMap &map)
{
Tobias Hunger's avatar
Tobias Hunger committed
143
    Core::Id id = ProjectExplorer::idFromMap(map);
144
    return new MaemoRunConfiguration(parent, id, pathFromId(id));
145 146
}

147
RunConfiguration *MaemoRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
148 149 150 151
{
    if (!canClone(parent, source))
        return 0;

152
    MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
Tobias Hunger's avatar
Tobias Hunger committed
153 154 155 156 157
    return new MaemoRunConfiguration(parent, old);
}

bool MaemoRunConfigurationFactory::canHandle(Target *t) const
{
Tobias Hunger's avatar
Tobias Hunger committed
158
    if (!t->project()->supportsKit(t->kit()))
Tobias Hunger's avatar
Tobias Hunger committed
159 160 161
        return false;
    if (!qobject_cast<Qt4Project *>(t->project()))
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
162
    Core::Id devType = DeviceTypeKitInformation::deviceTypeId(t->kit());
163
    return devType == Maemo5OsType || devType == HarmattanOsType;
Tobias Hunger's avatar
Tobias Hunger committed
164 165 166 167 168 169 170
}

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))
171
            if (mrc->projectFilePath() == n->path())
Tobias Hunger's avatar
Tobias Hunger committed
172 173
                result << rc;
    return result;
174 175 176 177 178 179 180 181 182 183 184 185
}


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

MaemoRunControlFactory::~MaemoRunControlFactory()
{
}

186
bool MaemoRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
187
{
188 189
    if (mode != NormalRunMode && mode != DebugRunMode && mode != DebugRunModeWithBreakOnMain)
        return false;
190 191
    const MaemoRunConfiguration * const maemoRunConfig
        = qobject_cast<MaemoRunConfiguration *>(runConfiguration);
192
    return maemoRunConfig && maemoRunConfig->isEnabled();
193 194
}

195 196
RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig, RunMode mode,
                                           QString *errorMessage)
197
{
198
    QTC_ASSERT(canRun(runConfig, mode), return 0);
199 200

    MaemoRunConfiguration *rc = qobject_cast<MaemoRunConfiguration *>(runConfig);
201 202 203
    QTC_ASSERT(rc, return 0);
    switch (mode) {
    case NormalRunMode: {
204 205 206 207
        RemoteLinuxRunControl * const runControl = new RemoteLinuxRunControl(rc);
        setHelperActions(runControl, rc, runControl);
        return runControl;
    }
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
    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);
    }
238

239
    QTC_ASSERT(false, return 0);
240 241 242 243 244 245 246 247
}

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

    } // namespace Internal
248
} // namespace Madde