forked from qt-creator/qt-creator
ProcessInterface: Place the class in separate header file
Change-Id: I9f3924f7cf69af58f93fc19f0af25c6fa9cfb55e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -123,6 +123,7 @@ add_qtc_library(Utils
|
||||
predicates.h
|
||||
processenums.h
|
||||
processhandle.cpp processhandle.h
|
||||
processinterface.h
|
||||
processreaper.cpp processreaper.h
|
||||
processutils.cpp processutils.h
|
||||
progressindicator.cpp progressindicator.h
|
||||
|
116
src/libs/utils/processinterface.h
Normal file
116
src/libs/utils/processinterface.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2022 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include "environment.h"
|
||||
#include "commandline.h"
|
||||
#include "processenums.h"
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ProcessSetupData
|
||||
{
|
||||
public:
|
||||
ProcessImpl m_processImpl = ProcessImpl::Default;
|
||||
ProcessMode m_processMode = ProcessMode::Reader;
|
||||
TerminalMode m_terminalMode = TerminalMode::Off;
|
||||
|
||||
CommandLine m_commandLine;
|
||||
FilePath m_workingDirectory;
|
||||
Environment m_environment;
|
||||
QByteArray m_writeData;
|
||||
QProcess::ProcessChannelMode m_processChannelMode = QProcess::SeparateChannels;
|
||||
QVariantHash m_extraData;
|
||||
QString m_standardInputFile;
|
||||
QString m_errorString; // partial internal
|
||||
QString m_nativeArguments; // internal, dependent on specific code path
|
||||
|
||||
bool m_abortOnMetaChars = true;
|
||||
bool m_runAsRoot = false;
|
||||
bool m_haveEnv = false;
|
||||
bool m_lowPriority = false;
|
||||
bool m_unixTerminalDisabled = false;
|
||||
bool m_useCtrlCStub = false; // debug only
|
||||
bool m_belowNormalPriority = false; // internal, dependent on other fields and specific code path
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ProcessInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProcessInterface(QObject *parent) : QObject(parent) {}
|
||||
|
||||
virtual void start() { defaultStart(); }
|
||||
virtual void terminate() = 0;
|
||||
virtual void kill() = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
virtual QByteArray readAllStandardOutput() = 0;
|
||||
virtual QByteArray readAllStandardError() = 0;
|
||||
virtual qint64 write(const QByteArray &data) = 0;
|
||||
|
||||
virtual qint64 processId() const = 0;
|
||||
virtual QProcess::ProcessState state() const = 0;
|
||||
virtual int exitCode() const = 0;
|
||||
virtual QProcess::ExitStatus exitStatus() const = 0;
|
||||
|
||||
virtual QProcess::ProcessError error() const = 0;
|
||||
virtual QString errorString() const = 0;
|
||||
virtual void setErrorString(const QString &str) = 0;
|
||||
|
||||
virtual bool waitForStarted(int msecs) = 0;
|
||||
virtual bool waitForReadyRead(int msecs) = 0;
|
||||
virtual bool waitForFinished(int msecs) = 0;
|
||||
|
||||
virtual void kickoffProcess();
|
||||
virtual void interruptProcess();
|
||||
virtual qint64 applicationMainThreadID() const;
|
||||
|
||||
signals:
|
||||
void started();
|
||||
void finished();
|
||||
void errorOccurred(QProcess::ProcessError error);
|
||||
void readyReadStandardOutput();
|
||||
void readyReadStandardError();
|
||||
|
||||
protected:
|
||||
void defaultStart();
|
||||
|
||||
ProcessSetupData m_setup;
|
||||
|
||||
private:
|
||||
virtual void doDefaultStart(const QString &program, const QStringList &arguments);
|
||||
bool dissolveCommand(QString *program, QStringList *arguments);
|
||||
bool ensureProgramExists(const QString &program);
|
||||
friend class QtcProcess;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
@@ -580,6 +580,21 @@ static QString blockingMessage(const QVariant &variant)
|
||||
return "(blocking without event loop):";
|
||||
}
|
||||
|
||||
void ProcessInterface::kickoffProcess()
|
||||
{
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
|
||||
void ProcessInterface::interruptProcess()
|
||||
{
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
|
||||
qint64 ProcessInterface::applicationMainThreadID() const
|
||||
{
|
||||
QTC_CHECK(false); return -1;
|
||||
}
|
||||
|
||||
void ProcessInterface::defaultStart()
|
||||
{
|
||||
if (processLog().isDebugEnabled()) {
|
||||
@@ -600,6 +615,13 @@ void ProcessInterface::defaultStart()
|
||||
s_start.measureAndRun(&ProcessInterface::doDefaultStart, this, program, arguments);
|
||||
}
|
||||
|
||||
void ProcessInterface::doDefaultStart(const QString &program, const QStringList &arguments)
|
||||
{
|
||||
Q_UNUSED(program)
|
||||
Q_UNUSED(arguments)
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
|
||||
bool ProcessInterface::dissolveCommand(QString *program, QStringList *arguments)
|
||||
{
|
||||
const CommandLine &commandLine = m_setup.m_commandLine;
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "environment.h"
|
||||
#include "commandline.h"
|
||||
#include "processenums.h"
|
||||
#include "processinterface.h"
|
||||
#include "qtcassert.h"
|
||||
|
||||
#include <QProcess>
|
||||
@@ -45,86 +46,6 @@ namespace Utils {
|
||||
|
||||
namespace Internal { class QtcProcessPrivate; }
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ProcessSetupData
|
||||
{
|
||||
public:
|
||||
ProcessImpl m_processImpl = ProcessImpl::Default;
|
||||
ProcessMode m_processMode = ProcessMode::Reader;
|
||||
TerminalMode m_terminalMode = TerminalMode::Off;
|
||||
|
||||
CommandLine m_commandLine;
|
||||
FilePath m_workingDirectory;
|
||||
Environment m_environment;
|
||||
QByteArray m_writeData;
|
||||
QProcess::ProcessChannelMode m_processChannelMode = QProcess::SeparateChannels;
|
||||
QVariantHash m_extraData;
|
||||
QString m_standardInputFile;
|
||||
QString m_errorString; // partial internal
|
||||
QString m_nativeArguments; // internal, dependent on specific code path
|
||||
|
||||
// TODO: Make below bools a one common flag enum?
|
||||
bool m_abortOnMetaChars = true;
|
||||
bool m_runAsRoot = false;
|
||||
bool m_haveEnv = false;
|
||||
bool m_lowPriority = false;
|
||||
bool m_unixTerminalDisabled = false;
|
||||
bool m_useCtrlCStub = false; // debug only
|
||||
bool m_belowNormalPriority = false; // internal, dependent on other fields and specific code path
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ProcessInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProcessInterface(QObject *parent) : QObject(parent) {}
|
||||
|
||||
virtual void start() { defaultStart(); }
|
||||
virtual void terminate() = 0;
|
||||
virtual void kill() = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
virtual QByteArray readAllStandardOutput() = 0;
|
||||
virtual QByteArray readAllStandardError() = 0;
|
||||
virtual qint64 write(const QByteArray &data) = 0;
|
||||
|
||||
virtual qint64 processId() const = 0;
|
||||
virtual QProcess::ProcessState state() const = 0;
|
||||
virtual int exitCode() const = 0;
|
||||
virtual QProcess::ExitStatus exitStatus() const = 0;
|
||||
|
||||
virtual QProcess::ProcessError error() const = 0;
|
||||
virtual QString errorString() const = 0;
|
||||
virtual void setErrorString(const QString &str) = 0;
|
||||
|
||||
virtual bool waitForStarted(int msecs) = 0;
|
||||
virtual bool waitForReadyRead(int msecs) = 0;
|
||||
virtual bool waitForFinished(int msecs) = 0;
|
||||
|
||||
virtual void kickoffProcess() { QTC_CHECK(false); }
|
||||
virtual void interruptProcess() { QTC_CHECK(false); }
|
||||
virtual qint64 applicationMainThreadID() const { QTC_CHECK(false); return -1; }
|
||||
|
||||
signals:
|
||||
void started();
|
||||
void finished();
|
||||
void errorOccurred(QProcess::ProcessError error);
|
||||
void readyReadStandardOutput();
|
||||
void readyReadStandardError();
|
||||
|
||||
protected:
|
||||
void defaultStart();
|
||||
|
||||
ProcessSetupData m_setup;
|
||||
|
||||
private:
|
||||
virtual void doDefaultStart(const QString &program, const QStringList &arguments)
|
||||
{ Q_UNUSED(program) Q_UNUSED(arguments) QTC_CHECK(false); }
|
||||
bool dissolveCommand(QString *program, QStringList *arguments);
|
||||
bool ensureProgramExists(const QString &program);
|
||||
friend class QtcProcess;
|
||||
};
|
||||
|
||||
class DeviceProcessHooks;
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT QtcProcess : public ProcessInterface
|
||||
|
@@ -221,6 +221,7 @@ Project {
|
||||
"processenums.h",
|
||||
"processhandle.cpp",
|
||||
"processhandle.h",
|
||||
"processinterface.h",
|
||||
"processreaper.cpp",
|
||||
"processreaper.h",
|
||||
"processutils.cpp",
|
||||
|
Reference in New Issue
Block a user