iosrunner.cpp 7.42 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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.
**
** GNU Lesser General Public License Usage
** 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
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "iosbuildstep.h"
#include "iosconfigurations.h"
#include "iosdevice.h"
#include "iosmanager.h"
#include "iosrunconfiguration.h"
#include "iosrunner.h"
#include "iossimulator.h"

#include <projectexplorer/devicesupport/deviceapplicationrunner.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/target.h>

#include <QDir>
#include <QTime>
#include <QMessageBox>

namespace Ios {
namespace Internal {

IosRunner::IosRunner(QObject *parent, IosRunConfiguration *runConfig, bool debuggingMode)
    : QObject(parent), m_toolHandler(0), m_bundleDir(runConfig->bundleDir().toString()),
      m_arguments(runConfig->commandLineArguments()),
      m_device(ProjectExplorer::DeviceKitInformation::device(runConfig->target()->kit())),
53
      m_debuggingMode(debuggingMode), m_cleanExit(false)
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{
}

IosRunner::~IosRunner()
{
    stop();
}

QString IosRunner::bundlePath()
{
    return m_bundleDir;
}

QStringList IosRunner::extraArgs()
{
    return m_arguments;
}

QString IosRunner::deviceId()
{
    IosDevice::ConstPtr dev = m_device.dynamicCast<const IosDevice>();
    if (!dev)
        return QString();
    return dev->uniqueDeviceID();
}

IosToolHandler::RunKind IosRunner::runType()
{
    if (m_debuggingMode)
        return IosToolHandler::DebugRun;
    return IosToolHandler::NormalRun;
}

void IosRunner::start()
{
    if (m_toolHandler) {
        m_toolHandler->stop();
        emit finished(m_cleanExit);
    }
    m_cleanExit = false;
    IosToolHandler::DeviceType devType = IosToolHandler::IosDeviceType;
    if (m_device->type() != Ios::Constants::IOS_DEVICE_TYPE) {
        IosSimulator::ConstPtr sim = m_device.dynamicCast<const IosSimulator>();
        if (sim.isNull()) {
            emit finished(m_cleanExit);
            return;
        }
        devType = IosToolHandler::IosSimulatedIphoneRetina4InchType; // store type in sim?
    }
    m_toolHandler = new IosToolHandler(devType, this);
    connect(m_toolHandler, SIGNAL(appOutput(Ios::IosToolHandler*,QString)),
            SLOT(handleAppOutput(Ios::IosToolHandler*,QString)));
    connect(m_toolHandler,
            SIGNAL(didStartApp(Ios::IosToolHandler*,QString,QString,Ios::IosToolHandler::OpStatus)),
            SLOT(handleDidStartApp(Ios::IosToolHandler*,QString,QString,Ios::IosToolHandler::OpStatus)));
    connect(m_toolHandler, SIGNAL(errorMsg(Ios::IosToolHandler*,QString)),
            SLOT(handleErrorMsg(Ios::IosToolHandler*,QString)));
    connect(m_toolHandler, SIGNAL(gotGdbserverSocket(Ios::IosToolHandler*,QString,QString,int)),
            SLOT(handleGotGdbserverSocket(Ios::IosToolHandler*,QString,QString,int)));
113
114
    connect(m_toolHandler, SIGNAL(gotInferiorPid(Ios::IosToolHandler*,QString,QString,Q_PID)),
            SLOT(handleGotInferiorPid(Ios::IosToolHandler*,QString,QString,Q_PID)));
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    connect(m_toolHandler, SIGNAL(toolExited(Ios::IosToolHandler*,int)),
            SLOT(handleToolExited(Ios::IosToolHandler*,int)));
    connect(m_toolHandler, SIGNAL(finished(Ios::IosToolHandler*)),
            SLOT(handleFinished(Ios::IosToolHandler*)));
    m_toolHandler->requestRunApp(bundlePath(), extraArgs(), runType(), deviceId());
}

void IosRunner::stop()
{
    if (m_toolHandler)
        m_toolHandler->stop();
}

void IosRunner::handleDidStartApp(IosToolHandler *handler, const QString &bundlePath,
                                  const QString &deviceId, IosToolHandler::OpStatus status)
{
    Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
    if (m_toolHandler == handler)
        emit didStartApp(status);
}

void IosRunner::handleGotGdbserverSocket(IosToolHandler *handler, const QString &bundlePath,
                                         const QString &deviceId, int gdbFd)
{
    Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
    if (m_toolHandler == handler)
        emit gotGdbserverSocket(gdbFd);
}

void IosRunner::handleGotInferiorPid(IosToolHandler *handler, const QString &bundlePath,
145
                                     const QString &deviceId, Q_PID pid)
146
147
148
149
150
151
152
153
154
155
156
157
{
    Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
    if (m_toolHandler == handler)
        emit gotInferiorPid(pid);
}

void IosRunner::handleAppOutput(IosToolHandler *handler, const QString &output)
{
    Q_UNUSED(handler);
    emit appOutput(output);
}

158
159
160
161
162
163
164
165
166
167
168
void IosRunner::warnAboutRunFail()
{
    QMessageBox mBox;
    mBox.setText(tr("Running on iOS device failed."));
    mBox.setInformativeText(tr("The certificates in Xcode or the device might be outdated. Check the certificates in the organizer window of Xcode, and try again."));
    mBox.setStandardButtons(QMessageBox::Ok);
    mBox.setDefaultButton(QMessageBox::Ok);
    mBox.setIcon(QMessageBox::Information);
    mBox.exec();
}

169
170
171
172
173
174
175
176
177
178
179
void IosRunner::warnAboutDeployFail()
{
    QMessageBox mBox;
    mBox.setText(tr("Deploying to iOS device failed."));
    mBox.setInformativeText(tr("This might be due to an incorrect Info.plist or outdated certificates in Xcode or device (see organizer window of Xcode)."));
    mBox.setStandardButtons(QMessageBox::Ok);
    mBox.setDefaultButton(QMessageBox::Ok);
    mBox.setIcon(QMessageBox::Information);
    mBox.exec();
}

180
181
182
void IosRunner::handleErrorMsg(IosToolHandler *handler, const QString &msg)
{
    Q_UNUSED(handler);
183
184
    if (msg.contains(QLatin1String("AMDeviceStartService returned -402653150")))
        QTimer::singleShot(0, this, SLOT(warnAboutRunFail()));
185
186
    else if (msg.contains(QLatin1String("AMDeviceInstallApplication returned -402653103")))
        QTimer::singleShot(0, this, SLOT(warnAboutDeployFail()));
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
    emit errorMsg(msg);
}

void IosRunner::handleToolExited(IosToolHandler *handler, int code)
{
    Q_UNUSED(handler);
    m_cleanExit = (code == 0);
}

void IosRunner::handleFinished(IosToolHandler *handler)
{
    if (m_toolHandler == handler) {
        emit finished(m_cleanExit);
        m_toolHandler = 0;
    }
    handler->deleteLater();
}

QString IosRunner::displayName() const
{
    return QString::fromLatin1("Run on %1").arg(m_device.isNull() ? QString()
                                                                  : m_device->displayName());
}

} // namespace Internal
} // namespace Qt4ProjectManager