forked from qt-creator/qt-creator
ProjectExplorer: Base DeviceProcess on QtcProcess
... instead of having a member. Change-Id: I75e8d7600eb17c7528fe9525d2e1aa871b282ad9 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -126,8 +126,8 @@ public:
|
||||
void setAbortOnMetaChars(bool abort);
|
||||
|
||||
void start();
|
||||
void terminate();
|
||||
void interrupt();
|
||||
virtual void terminate();
|
||||
virtual void interrupt();
|
||||
|
||||
static bool startDetached(const CommandLine &cmd, const FilePath &workingDirectory = {},
|
||||
qint64 *pid = nullptr);
|
||||
@@ -175,7 +175,7 @@ public:
|
||||
|
||||
QByteArray rawStdOut() const;
|
||||
|
||||
int exitCode() const;
|
||||
virtual int exitCode() const;
|
||||
|
||||
QString exitMessage();
|
||||
|
||||
@@ -195,10 +195,10 @@ public:
|
||||
void setProcessChannelMode(QProcess::ProcessChannelMode mode);
|
||||
|
||||
QProcess::ProcessError error() const;
|
||||
QProcess::ProcessState state() const;
|
||||
virtual QProcess::ProcessState state() const;
|
||||
bool isRunning() const; // Short for state() == QProcess::Running.
|
||||
|
||||
QString errorString() const;
|
||||
virtual QString errorString() const;
|
||||
void setErrorString(const QString &str);
|
||||
|
||||
qint64 processId() const;
|
||||
@@ -207,14 +207,14 @@ public:
|
||||
bool waitForReadyRead(int msecs = 30000);
|
||||
bool waitForFinished(int msecs = 30000);
|
||||
|
||||
QByteArray readAllStandardOutput();
|
||||
QByteArray readAllStandardError();
|
||||
virtual QByteArray readAllStandardOutput();
|
||||
virtual QByteArray readAllStandardError();
|
||||
|
||||
QProcess::ExitStatus exitStatus() const;
|
||||
virtual QProcess::ExitStatus exitStatus() const;
|
||||
|
||||
void kill();
|
||||
virtual void kill();
|
||||
|
||||
qint64 write(const QByteArray &input);
|
||||
virtual qint64 write(const QByteArray &input);
|
||||
void close();
|
||||
|
||||
void setStandardInputFile(const QString &inputFile);
|
||||
|
@@ -105,20 +105,7 @@ public:
|
||||
~DockerDeviceProcess() {}
|
||||
|
||||
void start(const Runnable &runnable) override;
|
||||
|
||||
void interrupt() override;
|
||||
void terminate() override { process()->terminate(); }
|
||||
void kill() override;
|
||||
|
||||
QProcess::ProcessState state() const override;
|
||||
QProcess::ExitStatus exitStatus() const override;
|
||||
int exitCode() const override;
|
||||
QString errorString() const override;
|
||||
|
||||
QByteArray readAllStandardOutput() override;
|
||||
QByteArray readAllStandardError() override;
|
||||
|
||||
qint64 write(const QByteArray &data) override { return process()->write(data); }
|
||||
};
|
||||
|
||||
DockerDeviceProcess::DockerDeviceProcess(const QSharedPointer<const IDevice> &device,
|
||||
@@ -129,7 +116,7 @@ DockerDeviceProcess::DockerDeviceProcess(const QSharedPointer<const IDevice> &de
|
||||
|
||||
void DockerDeviceProcess::start(const Runnable &runnable)
|
||||
{
|
||||
QTC_ASSERT(process()->state() == QProcess::NotRunning, return);
|
||||
QTC_ASSERT(state() == QProcess::NotRunning, return);
|
||||
DockerDevice::ConstPtr dockerDevice = qSharedPointerCast<const DockerDevice>(device());
|
||||
QTC_ASSERT(dockerDevice, return);
|
||||
|
||||
@@ -142,68 +129,23 @@ void DockerDeviceProcess::start(const Runnable &runnable)
|
||||
MessageManager::writeDisrupting(QString::fromLocal8Bit(readAllStandardError()));
|
||||
});
|
||||
|
||||
disconnect(process());
|
||||
|
||||
CommandLine command = runnable.command;
|
||||
command.setExecutable(
|
||||
command.executable().withNewPath(dockerDevice->mapToDevicePath(command.executable())));
|
||||
process()->setCommand(command);
|
||||
process()->setEnvironment(runnable.environment);
|
||||
process()->setWorkingDirectory(runnable.workingDirectory);
|
||||
connect(process(), &QtcProcess::errorOccurred, this, &DeviceProcess::errorOccurred);
|
||||
connect(process(), &QtcProcess::finished, this, &DeviceProcess::finished);
|
||||
connect(process(), &QtcProcess::readyReadStandardOutput,
|
||||
this, &DeviceProcess::readyReadStandardOutput);
|
||||
connect(process(), &QtcProcess::readyReadStandardError,
|
||||
this, &DeviceProcess::readyReadStandardError);
|
||||
connect(process(), &QtcProcess::started, this, &DeviceProcess::started);
|
||||
setCommand(command);
|
||||
setEnvironment(runnable.environment);
|
||||
setWorkingDirectory(runnable.workingDirectory);
|
||||
|
||||
LOG("Running process:" << command.toUserOutput()
|
||||
<< "in" << runnable.workingDirectory.toUserOutput());
|
||||
dockerDevice->runProcess(*process());
|
||||
dockerDevice->runProcess(*this);
|
||||
}
|
||||
|
||||
void DockerDeviceProcess::interrupt()
|
||||
{
|
||||
device()->signalOperation()->interruptProcess(process()->processId());
|
||||
device()->signalOperation()->interruptProcess(processId());
|
||||
}
|
||||
|
||||
void DockerDeviceProcess::kill()
|
||||
{
|
||||
process()->kill();
|
||||
}
|
||||
|
||||
QProcess::ProcessState DockerDeviceProcess::state() const
|
||||
{
|
||||
return process()->state();
|
||||
}
|
||||
|
||||
QProcess::ExitStatus DockerDeviceProcess::exitStatus() const
|
||||
{
|
||||
return process()->exitStatus();
|
||||
}
|
||||
|
||||
int DockerDeviceProcess::exitCode() const
|
||||
{
|
||||
return process()->exitCode();
|
||||
}
|
||||
|
||||
QString DockerDeviceProcess::errorString() const
|
||||
{
|
||||
return process()->errorString();
|
||||
}
|
||||
|
||||
QByteArray DockerDeviceProcess::readAllStandardOutput()
|
||||
{
|
||||
return process()->readAllStandardOutput();
|
||||
}
|
||||
|
||||
QByteArray DockerDeviceProcess::readAllStandardError()
|
||||
{
|
||||
return process()->readAllStandardError();
|
||||
}
|
||||
|
||||
|
||||
class DockerPortsGatheringMethod : public PortsGatheringMethod
|
||||
{
|
||||
Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const override
|
||||
|
@@ -41,73 +41,21 @@ DesktopDeviceProcess::DesktopDeviceProcess(const QSharedPointer<const IDevice> &
|
||||
QObject *parent)
|
||||
: DeviceProcess(device, ProcessMode::Writer, parent)
|
||||
{
|
||||
connect(process(), &QtcProcess::errorOccurred, this, &DeviceProcess::errorOccurred);
|
||||
connect(process(), &QtcProcess::finished, this, &DeviceProcess::finished);
|
||||
connect(process(), &QtcProcess::readyReadStandardOutput,
|
||||
this, &DeviceProcess::readyReadStandardOutput);
|
||||
connect(process(), &QtcProcess::readyReadStandardError,
|
||||
this, &DeviceProcess::readyReadStandardError);
|
||||
connect(process(), &QtcProcess::started, this, &DeviceProcess::started);
|
||||
}
|
||||
|
||||
void DesktopDeviceProcess::start(const Runnable &runnable)
|
||||
{
|
||||
QTC_ASSERT(process()->state() == QProcess::NotRunning, return);
|
||||
QTC_ASSERT(state() == QProcess::NotRunning, return);
|
||||
if (runnable.environment.size())
|
||||
process()->setEnvironment(runnable.environment);
|
||||
process()->setWorkingDirectory(runnable.workingDirectory);
|
||||
process()->setCommand(runnable.command);
|
||||
process()->start();
|
||||
setEnvironment(runnable.environment);
|
||||
setWorkingDirectory(runnable.workingDirectory);
|
||||
setCommand(runnable.command);
|
||||
QtcProcess::start();
|
||||
}
|
||||
|
||||
void DesktopDeviceProcess::interrupt()
|
||||
{
|
||||
device()->signalOperation()->interruptProcess(process()->processId());
|
||||
}
|
||||
|
||||
void DesktopDeviceProcess::terminate()
|
||||
{
|
||||
process()->terminate();
|
||||
}
|
||||
|
||||
void DesktopDeviceProcess::kill()
|
||||
{
|
||||
process()->kill();
|
||||
}
|
||||
|
||||
QProcess::ProcessState DesktopDeviceProcess::state() const
|
||||
{
|
||||
return process()->state();
|
||||
}
|
||||
|
||||
QProcess::ExitStatus DesktopDeviceProcess::exitStatus() const
|
||||
{
|
||||
return process()->exitStatus();
|
||||
}
|
||||
|
||||
int DesktopDeviceProcess::exitCode() const
|
||||
{
|
||||
return process()->exitCode();
|
||||
}
|
||||
|
||||
QString DesktopDeviceProcess::errorString() const
|
||||
{
|
||||
return process()->errorString();
|
||||
}
|
||||
|
||||
QByteArray DesktopDeviceProcess::readAllStandardOutput()
|
||||
{
|
||||
return process()->readAllStandardOutput();
|
||||
}
|
||||
|
||||
QByteArray DesktopDeviceProcess::readAllStandardError()
|
||||
{
|
||||
return process()->readAllStandardError();
|
||||
}
|
||||
|
||||
qint64 DesktopDeviceProcess::write(const QByteArray &data)
|
||||
{
|
||||
return process()->write(data);
|
||||
device()->signalOperation()->interruptProcess(processId());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -41,18 +41,6 @@ public:
|
||||
|
||||
void start(const Runnable &runnable) override;
|
||||
void interrupt() override;
|
||||
void terminate() override;
|
||||
void kill() override;
|
||||
|
||||
QProcess::ProcessState state() const override;
|
||||
QProcess::ExitStatus exitStatus() const override;
|
||||
int exitCode() const override;
|
||||
QString errorString() const override;
|
||||
|
||||
QByteArray readAllStandardOutput() override;
|
||||
QByteArray readAllStandardError() override;
|
||||
|
||||
qint64 write(const QByteArray &data) override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -37,7 +37,7 @@ namespace ProjectExplorer {
|
||||
DeviceProcess::DeviceProcess(const IDevice::ConstPtr &device,
|
||||
const QtcProcess::Setup &setup,
|
||||
QObject *parent)
|
||||
: QObject(parent), m_process(setup), m_device(device)
|
||||
: QtcProcess(setup, parent), m_device(device)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
#include <QStringList>
|
||||
|
||||
@@ -38,47 +37,24 @@ namespace ProjectExplorer {
|
||||
class IDevice;
|
||||
class Runnable;
|
||||
|
||||
class PROJECTEXPLORER_EXPORT DeviceProcess : public QObject
|
||||
class PROJECTEXPLORER_EXPORT DeviceProcess : public Utils::QtcProcess
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Utils::QtcProcess::start;
|
||||
virtual void start(const Runnable &runnable) = 0;
|
||||
virtual void interrupt() = 0;
|
||||
virtual void terminate() = 0;
|
||||
virtual void kill() = 0;
|
||||
|
||||
virtual QProcess::ProcessState state() const = 0;
|
||||
virtual QProcess::ExitStatus exitStatus() const = 0;
|
||||
virtual int exitCode() const = 0;
|
||||
virtual QString errorString() const = 0;
|
||||
|
||||
virtual QByteArray readAllStandardOutput() = 0;
|
||||
virtual QByteArray readAllStandardError() = 0;
|
||||
|
||||
virtual qint64 write(const QByteArray &data) = 0;
|
||||
|
||||
void setRunInTerminal(bool term) { m_runInTerminal = term; }
|
||||
bool runInTerminal() const { return m_runInTerminal; }
|
||||
|
||||
signals:
|
||||
void started();
|
||||
void finished();
|
||||
void errorOccurred(QProcess::ProcessError error);
|
||||
|
||||
void readyReadStandardOutput();
|
||||
void readyReadStandardError();
|
||||
|
||||
protected:
|
||||
explicit DeviceProcess(const QSharedPointer<const IDevice> &device,
|
||||
const Utils::QtcProcess::Setup &setup,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
QSharedPointer<const IDevice> device() const;
|
||||
Utils::QtcProcess *process() { return &m_process; }
|
||||
const Utils::QtcProcess *process() const { return &m_process; }
|
||||
|
||||
private:
|
||||
Utils::QtcProcess m_process;
|
||||
const QSharedPointer<const IDevice> m_device;
|
||||
bool m_runInTerminal = false;
|
||||
};
|
||||
|
@@ -192,15 +192,11 @@ void SshDeviceProcess::handleConnected()
|
||||
if (!display.isEmpty())
|
||||
d->remoteProcess->requestX11Forwarding(display);
|
||||
if (runInTerminal()) {
|
||||
connect(process(), &QtcProcess::errorOccurred,
|
||||
this, &DeviceProcess::errorOccurred);
|
||||
connect(process(), &QtcProcess::started,
|
||||
this, &SshDeviceProcess::handleProcessStarted);
|
||||
connect(process(), &QtcProcess::finished,
|
||||
this, [this] { handleProcessFinished(process()->errorString()); });
|
||||
process()->setAbortOnMetaChars(false);
|
||||
process()->setCommand(d->remoteProcess->fullLocalCommandLine(true));
|
||||
process()->start();
|
||||
connect(this, &QtcProcess::finished,
|
||||
this, [this] { handleProcessFinished(errorString()); });
|
||||
setAbortOnMetaChars(false);
|
||||
setCommand(d->remoteProcess->fullLocalCommandLine(true));
|
||||
QtcProcess::start();
|
||||
} else {
|
||||
connect(d->remoteProcess.get(), &QSsh::SshRemoteProcess::started,
|
||||
this, &SshDeviceProcess::handleProcessStarted);
|
||||
@@ -251,7 +247,7 @@ void SshDeviceProcess::handleProcessStarted()
|
||||
void SshDeviceProcess::handleProcessFinished(const QString &error)
|
||||
{
|
||||
d->errorMessage = error;
|
||||
d->exitCode = runInTerminal() ? process()->exitCode() : d->remoteProcess->exitCode();
|
||||
d->exitCode = runInTerminal() ? QtcProcess::exitCode() : d->remoteProcess->exitCode();
|
||||
if (d->killOperation && error.isEmpty())
|
||||
d->errorMessage = tr("The process was ended forcefully.");
|
||||
d->setState(SshDeviceProcessPrivate::Inactive);
|
||||
@@ -356,10 +352,10 @@ void SshDeviceProcess::SshDeviceProcessPrivate::setState(SshDeviceProcess::SshDe
|
||||
killOperation->disconnect(q);
|
||||
killOperation.clear();
|
||||
if (q->runInTerminal())
|
||||
QMetaObject::invokeMethod(q->process(), &QtcProcess::stopProcess, Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(q, &QtcProcess::stopProcess, Qt::QueuedConnection);
|
||||
}
|
||||
killTimer.stop();
|
||||
q->process()->disconnect();
|
||||
q->disconnect();
|
||||
if (remoteProcess)
|
||||
remoteProcess->disconnect(q);
|
||||
if (connection) {
|
||||
|
Reference in New Issue
Block a user