runconfiguration.h 10.4 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
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
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
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
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32
#ifndef RUNCONFIGURATION_H
#define RUNCONFIGURATION_H

33
#include "projectconfiguration.h"
con's avatar
con committed
34
#include "projectexplorer_export.h"
35
#include "projectexplorerconstants.h"
con's avatar
con committed
36

37
#include <utils/outputformat.h>
38
#include <utils/qtcassert.h>
con's avatar
con committed
39

40
#include <QPointer>
41
#include <QWidget>
con's avatar
con committed
42

43 44
QT_FORWARD_DECLARE_CLASS(QIcon)

45
namespace Utils { class OutputFormatter; }
con's avatar
con committed
46

47 48
namespace ProjectExplorer {
class Abi;
49
class BuildConfiguration;
50
class DebuggerRunConfigurationAspect;
51
class RunConfiguration;
52 53
class RunControl;
class Target;
con's avatar
con committed
54

55 56 57 58
// FIXME: This should also contain a handle to an remote device if used.
class PROJECTEXPLORER_EXPORT ProcessHandle
{
public:
59
    explicit ProcessHandle(quint64 pid = 0);
60

61 62 63 64 65 66
    bool isValid() const;
    void setPid(quint64 pid);
    quint64 pid() const;
    QString toString() const;

    bool equals(const ProcessHandle &) const;
67 68 69 70 71

private:
    quint64 m_pid;
};

72 73 74
inline bool operator==(const ProcessHandle &p1, const ProcessHandle &p2) { return p1.equals(p2); }
inline bool operator!=(const ProcessHandle &p1, const ProcessHandle &p2) { return !p1.equals(p2); }

75 76 77 78 79 80
class PROJECTEXPLORER_EXPORT IRunConfigurationAspect
{
public:
    virtual ~IRunConfigurationAspect() {}
    virtual QVariantMap toMap() const = 0;
    virtual QString displayName() const = 0;
81 82 83

    virtual IRunConfigurationAspect *clone(RunConfiguration *parent) const = 0;

84 85
protected:
    friend class RunConfiguration;
86
    virtual void fromMap(const QVariantMap &map) = 0;
87 88
};

89
class PROJECTEXPLORER_EXPORT DebuggerRunConfigurationAspect
90 91 92 93 94
    : public QObject, public ProjectExplorer::IRunConfigurationAspect
{
    Q_OBJECT

public:
95
    DebuggerRunConfigurationAspect(RunConfiguration *runConfiguration);
96 97
    DebuggerRunConfigurationAspect(RunConfiguration *runConfiguration,
                                   const DebuggerRunConfigurationAspect *other);
98 99 100 101 102 103 104 105

    enum QmlDebuggerStatus {
        DisableQmlDebugger = 0,
        EnableQmlDebugger,
        AutoEnableQmlDebugger
    };

    QVariantMap toMap() const;
106
    void fromMap(const QVariantMap &map);
107

108 109
    DebuggerRunConfigurationAspect *clone(RunConfiguration *parent) const;

110 111 112
    QString displayName() const;

    bool useCppDebugger() const;
113
    void setUseCppDebugger(bool value);
114
    bool useQmlDebugger() const;
115
    void setUseQmlDebugger(bool value);
116
    uint qmlDebugServerPort() const;
117
    void setQmllDebugServerPort(uint port);
118 119
    bool useMultiProcess() const;
    void setUseMultiProcess(bool on);
120
    void suppressDisplay();
121
    void suppressQmlDebuggingOptions();
122
    void suppressCppDebuggingOptions();
123
    void suppressQmlDebuggingSpinbox();
124
    bool isDisplaySuppressed() const;
125
    bool areQmlDebuggingOptionsSuppressed() const;
126
    bool areCppDebuggingOptionsSuppressed() const;
127
    bool isQmlDebuggingSpinboxSuppressed() const;
128
    RunConfiguration *runConfiguration();
129 130 131 132

signals:
    void debuggersChanged();

Eike Ziller's avatar
Eike Ziller committed
133
public:
134
    RunConfiguration *m_runConfiguration;
135 136 137
    bool m_useCppDebugger;
    QmlDebuggerStatus m_useQmlDebugger;
    uint m_qmlDebugServerPort;
138 139
    bool m_useMultiProcess;

140
    bool m_suppressDisplay;
141
    bool m_suppressQmlDebuggingOptions;
142
    bool m_suppressCppDebuggingOptions;
143
    bool m_suppressQmlDebuggingSpinbox;
144 145 146
};


147
// Documentation inside.
148
class PROJECTEXPLORER_EXPORT RunConfiguration : public ProjectConfiguration
con's avatar
con committed
149 150
{
    Q_OBJECT
151

con's avatar
con committed
152
public:
Tobias Hunger's avatar
Tobias Hunger committed
153
    ~RunConfiguration();
con's avatar
con committed
154

155
    virtual bool isEnabled() const;
dt_'s avatar
dt_ committed
156
    virtual QString disabledReason() const;
157
    virtual QWidget *createConfigurationWidget() = 0;
Tobias Hunger's avatar
Tobias Hunger committed
158
    virtual bool isConfigured() const;
159 160
    // Pop up configuration dialog in case for example the executable is missing.
    virtual bool ensureConfigured(QString *errorMessage = 0);
con's avatar
con committed
161

Tobias Hunger's avatar
Tobias Hunger committed
162
    Target *target() const;
163

con's avatar
con committed
164
    virtual Utils::OutputFormatter *createOutputFormatter() const;
dt's avatar
dt committed
165

Tobias Hunger's avatar
Tobias Hunger committed
166 167
    bool fromMap(const QVariantMap &map);
    QVariantMap toMap() const;
168

169
    DebuggerRunConfigurationAspect *debuggerAspect() const { return m_debuggerAspect; }
170

171 172 173
    QList<IRunConfigurationAspect *> extraAspects() const;
    template <typename T> T *extraAspect() const
    {
174
        QTC_ASSERT(m_aspectsInitialized, return 0);
175 176 177 178 179 180 181 182 183 184
        IRunConfigurationAspect *typeCheck = static_cast<T *>(0);
        Q_UNUSED(typeCheck);
        T *result = 0;
        foreach (IRunConfigurationAspect *a, m_aspects) {
            if ((result = dynamic_cast<T *>(a)) != 0)
                break;
        }
        return result;
    }

185
    virtual ProjectExplorer::Abi abi() const;
186

187 188
    void addExtraAspects();

189
signals:
190
    void enabledChanged();
191

192
protected:
193
    RunConfiguration(Target *parent, const Core::Id id);
Tobias Hunger's avatar
Tobias Hunger committed
194
    RunConfiguration(Target *parent, RunConfiguration *source);
195

196
    /// convenience method to get current build configuration.
197
    BuildConfiguration *activeBuildConfiguration() const;
198 199

private:
200
    QList<IRunConfigurationAspect *> m_aspects;
201
    DebuggerRunConfigurationAspect *m_debuggerAspect;
202
    bool m_aspectsInitialized;
con's avatar
con committed
203 204
};

205
class PROJECTEXPLORER_EXPORT IRunConfigurationFactory : public QObject
con's avatar
con committed
206 207
{
    Q_OBJECT
208

con's avatar
con committed
209
public:
210
    explicit IRunConfigurationFactory(QObject *parent = 0);
con's avatar
con committed
211
    virtual ~IRunConfigurationFactory();
212

213 214
    virtual QList<Core::Id> availableCreationIds(Target *parent) const = 0;
    virtual QString displayNameForId(const Core::Id id) const = 0;
215

216
    virtual bool canCreate(Target *parent, const Core::Id id) const = 0;
217
    RunConfiguration *create(Target *parent, const Core::Id id);
Tobias Hunger's avatar
Tobias Hunger committed
218
    virtual bool canRestore(Target *parent, const QVariantMap &map) const = 0;
219
    RunConfiguration *restore(Target *parent, const QVariantMap &map);
Tobias Hunger's avatar
Tobias Hunger committed
220 221 222
    virtual bool canClone(Target *parent, RunConfiguration *product) const = 0;
    virtual RunConfiguration *clone(Target *parent, RunConfiguration *product) = 0;

Tobias Hunger's avatar
Tobias Hunger committed
223
    static IRunConfigurationFactory *find(Target *parent, const QVariantMap &map);
224
    static IRunConfigurationFactory *find(Target *parent, RunConfiguration *rc);
Tobias Hunger's avatar
Tobias Hunger committed
225
    static QList<IRunConfigurationFactory *> find(Target *parent);
226 227 228

signals:
    void availableCreationIdsChanged();
229 230 231

private:
    virtual RunConfiguration *doCreate(Target *parent, const Core::Id id) = 0;
232
    virtual RunConfiguration *doRestore(Target *parent, const QVariantMap &map) = 0;
con's avatar
con committed
233 234
};

235 236
class RunConfigWidget;

237
class PROJECTEXPLORER_EXPORT IRunControlFactory : public QObject
con's avatar
con committed
238 239 240
{
    Q_OBJECT
public:
241 242 243
    explicit IRunControlFactory(QObject *parent = 0);
    virtual ~IRunControlFactory();

244
    virtual bool canRun(RunConfiguration *runConfiguration, RunMode mode) const = 0;
245
    virtual RunControl *create(RunConfiguration *runConfiguration, RunMode mode, QString *errorMessage) = 0;
con's avatar
con committed
246 247 248

    virtual QString displayName() const = 0;

249
    virtual IRunConfigurationAspect *createRunConfigurationAspect(RunConfiguration *rc);
250
    virtual RunConfigWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
};

class PROJECTEXPLORER_EXPORT RunConfigWidget
    : public QWidget
{
    Q_OBJECT
public:
    RunConfigWidget()
        : QWidget(0)
    {}

    virtual QString displayName() const = 0;

signals:
    void displayNameChanged(const QString &);
con's avatar
con committed
266 267
};

268 269
class PROJECTEXPLORER_EXPORT RunControl : public QObject
{
con's avatar
con committed
270 271
    Q_OBJECT
public:
272 273
    enum StopResult {
        StoppedSynchronously, // Stopped.
274
        AsynchronousStop     // Stop sequence has been started
275 276
    };

277
    RunControl(RunConfiguration *runConfiguration, RunMode mode);
con's avatar
con committed
278 279
    virtual ~RunControl();
    virtual void start() = 0;
280 281

    virtual bool promptToStop(bool *optionalPrompt = 0) const;
282
    virtual StopResult stop() = 0;
con's avatar
con committed
283
    virtual bool isRunning() const = 0;
284
    virtual QString displayName() const;
285
    virtual QIcon icon() const = 0;
286

287 288
    ProcessHandle applicationProcessHandle() const;
    void setApplicationProcessHandle(const ProcessHandle &handle);
289
    Abi abi() const;
290

291
    RunConfiguration *runConfiguration() const;
292
    bool sameRunConfiguration(const RunControl *other) const;
293

con's avatar
con committed
294
    Utils::OutputFormatter *outputFormatter();
295
    RunMode runMode() const;
296

297 298
public slots:
    void bringApplicationToForeground(qint64 pid);
con's avatar
con committed
299
    void appendMessage(const QString &msg, Utils::OutputFormat format);
300

con's avatar
con committed
301
signals:
302
    void appendMessage(ProjectExplorer::RunControl *runControl,
con's avatar
con committed
303
        const QString &msg, Utils::OutputFormat format);
con's avatar
con committed
304 305
    void started();
    void finished();
306
    void applicationProcessHandleChanged();
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
307

con's avatar
con committed
308 309 310
private slots:
    void bringApplicationToForegroundInternal();

311 312 313 314 315 316
protected:
    bool showPromptToStopDialog(const QString &title, const QString &text,
                                const QString &stopButtonText = QString(),
                                const QString &cancelButtonText = QString(),
                                bool *prompt = 0) const;

con's avatar
con committed
317
private:
318
    QString m_displayName;
319
    RunMode m_runMode;
320
    const QPointer<RunConfiguration> m_runConfiguration;
con's avatar
con committed
321
    Utils::OutputFormatter *m_outputFormatter;
con's avatar
con committed
322

323 324 325
    // A handle to the actual application process.
    ProcessHandle m_applicationProcessHandle;

con's avatar
con committed
326 327 328 329 330 331 332 333 334 335 336
#ifdef Q_OS_MAC
    //these two are used to bring apps in the foreground on Mac
    qint64 m_internalPid;
    int m_foregroundCount;
#endif
};

} // namespace ProjectExplorer

// Allow a RunConfiguration to be stored in a QVariant
Q_DECLARE_METATYPE(ProjectExplorer::RunConfiguration*)
337
Q_DECLARE_METATYPE(ProjectExplorer::RunControl*)
con's avatar
con committed
338 339

#endif // RUNCONFIGURATION_H