runconfiguration.h 10.2 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>
con's avatar
con committed
38

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

42 43
QT_FORWARD_DECLARE_CLASS(QIcon)

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

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

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

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

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

private:
    quint64 m_pid;
};

71 72 73
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); }

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

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

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

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

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

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

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

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

109 110 111
    QString displayName() const;

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

signals:
    void debuggersChanged();

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

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


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

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

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

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

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

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

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

170 171 172 173 174 175 176 177 178 179 180 181 182
    QList<IRunConfigurationAspect *> extraAspects() const;
    template <typename T> T *extraAspect() const
    {
        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;
    }

183
    virtual ProjectExplorer::Abi abi() const;
184

185
signals:
186
    void enabledChanged();
187

188
protected:
189
    RunConfiguration(Target *parent, const Core::Id id);
Tobias Hunger's avatar
Tobias Hunger committed
190
    RunConfiguration(Target *parent, RunConfiguration *source);
191

192
    /// convenience method to get current build configuration.
193
    BuildConfiguration *activeBuildConfiguration() const;
194 195

private:
196 197 198
    void addExtraAspects();

    QList<IRunConfigurationAspect *> m_aspects;
199
    DebuggerRunConfigurationAspect *m_debuggerAspect;
con's avatar
con committed
200 201
};

202
class PROJECTEXPLORER_EXPORT IRunConfigurationFactory : public QObject
con's avatar
con committed
203 204
{
    Q_OBJECT
205

con's avatar
con committed
206
public:
207
    explicit IRunConfigurationFactory(QObject *parent = 0);
con's avatar
con committed
208
    virtual ~IRunConfigurationFactory();
209

210 211
    virtual QList<Core::Id> availableCreationIds(Target *parent) const = 0;
    virtual QString displayNameForId(const Core::Id id) const = 0;
212

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

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

signals:
    void availableCreationIdsChanged();
con's avatar
con committed
226 227
};

228 229
class RunConfigWidget;

230
class PROJECTEXPLORER_EXPORT IRunControlFactory : public QObject
con's avatar
con committed
231 232 233
{
    Q_OBJECT
public:
234 235 236
    explicit IRunControlFactory(QObject *parent = 0);
    virtual ~IRunControlFactory();

237
    virtual bool canRun(RunConfiguration *runConfiguration, RunMode mode) const = 0;
238
    virtual RunControl *create(RunConfiguration *runConfiguration, RunMode mode, QString *errorMessage) = 0;
con's avatar
con committed
239 240 241

    virtual QString displayName() const = 0;

242
    virtual IRunConfigurationAspect *createRunConfigurationAspect();
243
    virtual RunConfigWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
};

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
259 260
};

261 262
class PROJECTEXPLORER_EXPORT RunControl : public QObject
{
con's avatar
con committed
263 264
    Q_OBJECT
public:
265 266
    enum StopResult {
        StoppedSynchronously, // Stopped.
267
        AsynchronousStop     // Stop sequence has been started
268 269
    };

270
    RunControl(RunConfiguration *runConfiguration, RunMode mode);
con's avatar
con committed
271 272
    virtual ~RunControl();
    virtual void start() = 0;
273 274

    virtual bool promptToStop(bool *optionalPrompt = 0) const;
275
    virtual StopResult stop() = 0;
con's avatar
con committed
276
    virtual bool isRunning() const = 0;
277
    virtual QString displayName() const;
278
    virtual QIcon icon() const = 0;
279

280 281
    ProcessHandle applicationProcessHandle() const;
    void setApplicationProcessHandle(const ProcessHandle &handle);
282
    Abi abi() const;
283

284
    RunConfiguration *runConfiguration() const;
285
    bool sameRunConfiguration(const RunControl *other) const;
286

con's avatar
con committed
287
    Utils::OutputFormatter *outputFormatter();
288
    RunMode runMode() const;
289

290 291
public slots:
    void bringApplicationToForeground(qint64 pid);
con's avatar
con committed
292
    void appendMessage(const QString &msg, Utils::OutputFormat format);
293

con's avatar
con committed
294
signals:
295
    void appendMessage(ProjectExplorer::RunControl *runControl,
con's avatar
con committed
296
        const QString &msg, Utils::OutputFormat format);
con's avatar
con committed
297 298
    void started();
    void finished();
299
    void applicationProcessHandleChanged();
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
300

con's avatar
con committed
301 302 303
private slots:
    void bringApplicationToForegroundInternal();

304 305 306 307 308 309
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
310
private:
311
    QString m_displayName;
312
    RunMode m_runMode;
313
    const QPointer<RunConfiguration> m_runConfiguration;
con's avatar
con committed
314
    Utils::OutputFormatter *m_outputFormatter;
con's avatar
con committed
315

316 317 318
    // A handle to the actual application process.
    ProcessHandle m_applicationProcessHandle;

con's avatar
con committed
319 320 321 322 323 324 325 326 327 328 329
#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*)
330
Q_DECLARE_METATYPE(ProjectExplorer::RunControl*)
con's avatar
con committed
331 332

#endif // RUNCONFIGURATION_H