forked from qt-creator/qt-creator
ProcessInterface: Get rid of ProcessProxyInterface
It doesn't seem to be useful anymore. Add some comments to the ProcessInterface API. Move virtual interface into the private section in order to not to use it directly from implementation. Task-number: QTCREATORBUG-27358 Change-Id: Idd9fd39cf153832e6e44e125fbbd5c8236a2d930 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -84,57 +84,46 @@ class QTCREATOR_UTILS_EXPORT ProcessInterface : public QObject
|
||||
|
||||
public:
|
||||
ProcessInterface(QObject *parent = nullptr) : QObject(parent), m_setup(new ProcessSetupData) {}
|
||||
ProcessInterface(ProcessSetupData::Ptr setup) : m_setup(setup) {}
|
||||
|
||||
virtual void start() = 0;
|
||||
virtual qint64 write(const QByteArray &data) = 0;
|
||||
virtual void sendControlSignal(ControlSignal controlSignal) = 0;
|
||||
|
||||
virtual QProcess::ProcessState state() const = 0;
|
||||
|
||||
virtual bool waitForStarted(int msecs) = 0;
|
||||
virtual bool waitForReadyRead(int msecs) = 0;
|
||||
virtual bool waitForFinished(int msecs) = 0;
|
||||
|
||||
signals:
|
||||
// This should be emitted when being in Starting state only.
|
||||
// After emitting this signal the process enters Running state.
|
||||
void started(qint64 processId, qint64 applicationMainThreadId = 0);
|
||||
|
||||
// This should be emitted when being in Running state only.
|
||||
void readyRead(const QByteArray &outputData, const QByteArray &errorData);
|
||||
|
||||
// This should be emitted when being in Starting or Running state.
|
||||
// When being in Starting state, the resultData should set error to FailedToStart.
|
||||
// After emitting this signal the process enters NotRunning state.
|
||||
void done(const Utils::ProcessResultData &resultData);
|
||||
|
||||
protected:
|
||||
ProcessSetupData::Ptr m_setup;
|
||||
friend class ProcessProxyInterface;
|
||||
|
||||
private:
|
||||
// It's being called only in Starting state. Just before this method is being called,
|
||||
// the process transitions from NotRunning into Starting state.
|
||||
virtual void start() = 0;
|
||||
|
||||
// It's being called only in Running state.
|
||||
virtual qint64 write(const QByteArray &data) = 0;
|
||||
|
||||
// It's being called in Starting or Running state.
|
||||
virtual void sendControlSignal(ControlSignal controlSignal) = 0;
|
||||
|
||||
virtual QProcess::ProcessState state() const = 0;
|
||||
|
||||
// It's being called only in Starting state.
|
||||
virtual bool waitForStarted(int msecs) = 0;
|
||||
|
||||
// It's being called in Starting or Running state.
|
||||
virtual bool waitForReadyRead(int msecs) = 0;
|
||||
|
||||
// It's being called in Starting or Running state.
|
||||
virtual bool waitForFinished(int msecs) = 0;
|
||||
|
||||
friend class QtcProcess;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ProcessProxyInterface : public ProcessInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProcessProxyInterface(ProcessInterface *target)
|
||||
: ProcessInterface(target->m_setup)
|
||||
, m_target(target)
|
||||
{
|
||||
m_target->setParent(this);
|
||||
connect(m_target, &ProcessInterface::started, this, &ProcessInterface::started);
|
||||
connect(m_target, &ProcessInterface::readyRead, this, &ProcessInterface::readyRead);
|
||||
connect(m_target, &ProcessInterface::done, this, &ProcessInterface::done);
|
||||
}
|
||||
|
||||
void start() override { m_target->start(); }
|
||||
|
||||
qint64 write(const QByteArray &data) override { return m_target->write(data); }
|
||||
|
||||
QProcess::ProcessState state() const override { return m_target->state(); }
|
||||
|
||||
bool waitForStarted(int msecs) override { return m_target->waitForStarted(msecs); }
|
||||
bool waitForReadyRead(int msecs) override { return m_target->waitForReadyRead(msecs); }
|
||||
bool waitForFinished(int msecs) override { return m_target->waitForFinished(msecs); }
|
||||
|
||||
protected:
|
||||
ProcessInterface *m_target;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -215,13 +215,8 @@ public:
|
||||
|
||||
class DefaultImpl : public ProcessInterface
|
||||
{
|
||||
public:
|
||||
virtual void start() final { defaultStart(); }
|
||||
|
||||
protected:
|
||||
void defaultStart();
|
||||
|
||||
private:
|
||||
virtual void start() final;
|
||||
virtual void doDefaultStart(const QString &program, const QStringList &arguments) = 0;
|
||||
bool dissolveCommand(QString *program, QStringList *arguments);
|
||||
bool ensureProgramExists(const QString &program);
|
||||
@@ -236,7 +231,7 @@ static QString blockingMessage(const QVariant &variant)
|
||||
return "blocking without event loop";
|
||||
}
|
||||
|
||||
void DefaultImpl::defaultStart()
|
||||
void DefaultImpl::start()
|
||||
{
|
||||
if (processLog().isDebugEnabled()) {
|
||||
using namespace std::chrono;
|
||||
@@ -347,6 +342,7 @@ public:
|
||||
}
|
||||
~QProcessImpl() final { ProcessReaper::reap(m_process); }
|
||||
|
||||
private:
|
||||
qint64 write(const QByteArray &data) final { return m_process->write(data); }
|
||||
void sendControlSignal(ControlSignal controlSignal) final {
|
||||
switch (controlSignal) {
|
||||
@@ -371,7 +367,6 @@ public:
|
||||
bool waitForReadyRead(int msecs) final { return m_process->waitForReadyRead(msecs); }
|
||||
bool waitForFinished(int msecs) final { return m_process->waitForFinished(msecs); }
|
||||
|
||||
private:
|
||||
void doDefaultStart(const QString &program, const QStringList &arguments) final
|
||||
{
|
||||
ProcessStartHandler *handler = m_process->processStartHandler();
|
||||
@@ -445,6 +440,7 @@ public:
|
||||
m_handle = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
qint64 write(const QByteArray &data) final { return m_handle->write(data); }
|
||||
void sendControlSignal(ControlSignal controlSignal) final {
|
||||
switch (controlSignal) {
|
||||
@@ -470,7 +466,6 @@ public:
|
||||
bool waitForReadyRead(int msecs) final { return m_handle->waitForReadyRead(msecs); }
|
||||
bool waitForFinished(int msecs) final { return m_handle->waitForFinished(msecs); }
|
||||
|
||||
private:
|
||||
void doDefaultStart(const QString &program, const QStringList &arguments) final
|
||||
{
|
||||
m_handle->start(program, arguments);
|
||||
@@ -688,13 +683,6 @@ void QtcProcess::emitFinished()
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void QtcProcess::setProcessInterface(ProcessInterface *interface)
|
||||
{
|
||||
d->setProcessInterface(interface);
|
||||
// Make a copy, don't share, until we get rid of fullCommandLine() and fullEnvironment()
|
||||
*d->m_process->m_setup = d->m_setup;
|
||||
}
|
||||
|
||||
void QtcProcess::setProcessImpl(ProcessImpl processImpl)
|
||||
{
|
||||
d->m_setup.m_processImpl = processImpl;
|
||||
@@ -810,7 +798,8 @@ void QtcProcess::start()
|
||||
}
|
||||
QTC_ASSERT(processImpl, return);
|
||||
d->clearForRun();
|
||||
setProcessInterface(processImpl);
|
||||
d->setProcessInterface(processImpl);
|
||||
*d->m_process->m_setup = d->m_setup;
|
||||
d->m_process->m_setup->m_commandLine = d->fullCommandLine();
|
||||
d->m_process->m_setup->m_environment = d->fullEnvironment();
|
||||
if (processLog().isDebugEnabled()) {
|
||||
|
@@ -205,8 +205,6 @@ protected:
|
||||
virtual void emitFinished();
|
||||
|
||||
private:
|
||||
void setProcessInterface(ProcessInterface *interface);
|
||||
|
||||
friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const QtcProcess &r);
|
||||
|
||||
friend class Internal::QtcProcessPrivate;
|
||||
|
@@ -45,6 +45,7 @@ public:
|
||||
TerminalImpl();
|
||||
~TerminalImpl() final;
|
||||
|
||||
private:
|
||||
void start() final;
|
||||
qint64 write(const QByteArray &) final { QTC_CHECK(false); return -1; }
|
||||
void sendControlSignal(ControlSignal controlSignal) final;
|
||||
@@ -57,7 +58,6 @@ public:
|
||||
|
||||
QProcess::ProcessState state() const final;
|
||||
|
||||
private:
|
||||
// OK, however, impl looks a bit different (!= NotRunning vs == Running).
|
||||
// Most probably changing it into (== Running) should be OK.
|
||||
bool isRunning() const;
|
||||
|
Reference in New Issue
Block a user