consoleprocess.h 3.51 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6 7 8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
25 26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

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

33 34
#include "abstractprocess.h"

con's avatar
con committed
35 36 37 38 39
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QProcess>

40 41
#include <QtNetwork/QLocalServer>

con's avatar
con committed
42 43 44
#ifdef Q_OS_WIN
#include <windows.h>
class QWinEventNotifier;
45
class QTemporaryFile;
con's avatar
con committed
46 47
#endif

48 49
namespace Core {
namespace Utils {
con's avatar
con committed
50

51
class QWORKBENCH_UTILS_EXPORT ConsoleProcess : public QObject, public AbstractProcess
con's avatar
con committed
52 53 54 55
{
    Q_OBJECT

public:
56
    ConsoleProcess(QObject *parent = 0);
con's avatar
con committed
57 58 59 60 61
    ~ConsoleProcess();

    bool start(const QString &program, const QStringList &args);
    void stop();

62 63 64 65 66 67 68 69 70 71 72 73 74
    void setDebug(bool on) { m_debug = on; }
    bool isDebug() const { return m_debug; }

    bool isRunning() const; // This reflects the state of the console+stub
    qint64 applicationPID() const { return m_appPid; }
    int exitCode() const { return m_appCode; } // This will be the signal number if exitStatus == CrashExit
    QProcess::ExitStatus exitStatus() const { return m_appStatus; }

#ifdef Q_OS_WIN
    // These are public for WinGuiProcess. Should be in AbstractProcess, but it has no .cpp so far.
    static QString createCommandline(const QString &program, const QStringList &args);
    static QStringList fixEnvironment(const QStringList &env);
#endif
con's avatar
con committed
75 76 77

signals:
    void processError(const QString &error);
78
    // These reflect the state of the actual client process
con's avatar
con committed
79 80 81
    void processStarted();
    void processStopped();

82 83 84
    // These reflect the state of the console+stub
    void wrapperStarted();
    void wrapperStopped();
con's avatar
con committed
85 86

private slots:
87 88 89 90 91 92
    void stubConnectionAvailable();
    void readStubOutput();
    void stubExited();
#ifdef Q_OS_WIN
    void inferiorExited();
#endif
con's avatar
con committed
93 94

private:
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    QString stubServerListen();
    void stubServerShutdown();
#ifdef Q_OS_WIN
    void cleanupStub();
    void cleanupInferior();
#endif

    bool m_debug;
    qint64 m_appPid;
    int m_appCode;
    QString m_executable;
    QProcess::ExitStatus m_appStatus;
    QLocalServer m_stubServer;
    QLocalSocket *m_stubSocket;
#ifdef Q_OS_WIN
con's avatar
con committed
110
    PROCESS_INFORMATION *m_pid;
111 112
    HANDLE m_hInferior;
    QWinEventNotifier *inferiorFinishedNotifier;
con's avatar
con committed
113
    QWinEventNotifier *processFinishedNotifier;
114
    QTemporaryFile *m_tempFile;
115
#else
116
    QProcess m_process;
117
    QByteArray m_stubServerDir;
con's avatar
con committed
118 119 120 121
#endif

};

122 123
} //namespace Utils
} //namespace Core
con's avatar
con committed
124 125

#endif