forked from qt-creator/qt-creator
Use refactored ProcessMode
This patch needs to be applied together with the parent change. There are 3 basic cases: 1. The user doesn't write anything to the write channel: You don't need to call closeWriteChannel manually anymore. By default the QtcProcess you create is in ProcessMode::Reader mode. Internally it opens the process in ReadOnly mode and closes the write channel just after starting. 2. The user writes some initial data (after being started) and then closes the write channel: All what is needed now it to set the write data (QtcProcess::setWriteData) before calling start. You also use the default ProcessMode::Reader mode. Internally it opens the process in ReadWrite mode and writes the writeData asynchonously when the process already started. After writing the data it closes the write channel automatically. 3. The user writes the data also after calling start. All you need now is to create a process with ProcessMode::Writer mode. In this mode the write channel is not closed. Internally it opens the process in ReadWrite mode as some writers also read the data from the process. All the code base is adapted here to the above rules. Change-Id: Id103019d1d71a3012fd1eade226fe96b9aaa48c2 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -116,7 +116,6 @@ public:
|
||||
virtual void kill() = 0;
|
||||
virtual void close() = 0;
|
||||
virtual qint64 write(const QByteArray &data) = 0;
|
||||
virtual void closeWriteChannel() = 0;
|
||||
|
||||
virtual void setStandardInputFile(const QString &fileName) = 0;
|
||||
virtual void setProcessChannelMode(QProcess::ProcessChannelMode mode) = 0;
|
||||
@@ -230,8 +229,6 @@ public:
|
||||
{ m_process.close(); }
|
||||
qint64 write(const QByteArray &data) override
|
||||
{ return m_process.write(data); }
|
||||
void closeWriteChannel() override
|
||||
{ m_process.closeWriteChannel(); }
|
||||
|
||||
void setStandardInputFile(const QString &fileName) override
|
||||
{ m_process.setStandardInputFile(fileName); }
|
||||
@@ -327,7 +324,6 @@ public:
|
||||
void kill() override { cancel(); } // TODO: see above
|
||||
void close() override { cancel(); } // TODO: see above
|
||||
qint64 write(const QByteArray &data) override { return m_handle->write(data); }
|
||||
void closeWriteChannel() override { /*QTC_CHECK(false);*/ }
|
||||
|
||||
void setStandardInputFile(const QString &fileName) override { m_handle->setStandardInputFile(fileName); }
|
||||
void setProcessChannelMode(QProcess::ProcessChannelMode mode) override { m_handle->setProcessChannelMode(mode); }
|
||||
@@ -433,8 +429,6 @@ public:
|
||||
bool m_haveEnv = false;
|
||||
bool m_useCtrlCStub = false;
|
||||
|
||||
QProcess::OpenMode m_openMode = QProcess::ReadWrite;
|
||||
|
||||
void slotTimeout();
|
||||
void slotFinished(int exitCode, QProcess::ExitStatus e);
|
||||
void slotError(QProcess::ProcessError);
|
||||
@@ -458,7 +452,6 @@ public:
|
||||
bool m_timeOutMessageBoxEnabled = false;
|
||||
bool m_waitingForUser = false;
|
||||
bool m_processUserEvents = false;
|
||||
bool m_keepStdInOpen = false;
|
||||
};
|
||||
|
||||
void QtcProcessPrivate::clearForRun()
|
||||
@@ -512,6 +505,11 @@ QtcProcess::~QtcProcess()
|
||||
delete d;
|
||||
}
|
||||
|
||||
ProcessMode QtcProcess::processMode() const
|
||||
{
|
||||
return d->m_processMode;
|
||||
}
|
||||
|
||||
void QtcProcess::setEnvironment(const Environment &env)
|
||||
{
|
||||
d->m_environment = env;
|
||||
@@ -582,14 +580,6 @@ void QtcProcess::start()
|
||||
{
|
||||
d->clearForRun();
|
||||
|
||||
if (!d->m_writeData.isEmpty()) {
|
||||
connect(d->m_process, &ProcessInterface::started, this, [this] {
|
||||
const qint64 bytesWritten = write(d->m_writeData);
|
||||
QTC_CHECK(bytesWritten == d->m_writeData.size());
|
||||
closeWriteChannel(); // FIXME: Is this good?
|
||||
});
|
||||
}
|
||||
|
||||
if (d->m_commandLine.executable().needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.startProcessHook, return);
|
||||
s_deviceHooks.startProcessHook(*this);
|
||||
@@ -708,16 +698,6 @@ void QtcProcess::setDisableUnixTerminal()
|
||||
d->m_process->setDisableUnixTerminal();
|
||||
}
|
||||
|
||||
void QtcProcess::setKeepWriteChannelOpen()
|
||||
{
|
||||
d->m_keepStdInOpen = true;
|
||||
}
|
||||
|
||||
bool QtcProcess::keepsWriteChannelOpen() const
|
||||
{
|
||||
return d->m_keepStdInOpen;
|
||||
}
|
||||
|
||||
void QtcProcess::setStandardInputFile(const QString &inputFile)
|
||||
{
|
||||
d->m_process->setStandardInputFile(inputFile);
|
||||
@@ -728,11 +708,6 @@ void QtcProcess::setRemoteProcessHooks(const DeviceProcessHooks &hooks)
|
||||
s_deviceHooks = hooks;
|
||||
}
|
||||
|
||||
void QtcProcess::setOpenMode(QIODevice::OpenMode mode)
|
||||
{
|
||||
d->m_openMode = mode;
|
||||
}
|
||||
|
||||
bool QtcProcess::stopProcess()
|
||||
{
|
||||
if (state() == QProcess::NotRunning)
|
||||
@@ -1004,14 +979,10 @@ void QtcProcess::kill()
|
||||
|
||||
qint64 QtcProcess::write(const QByteArray &input)
|
||||
{
|
||||
QTC_ASSERT(processMode() == ProcessMode::Writer, return -1);
|
||||
return d->m_process->write(input);
|
||||
}
|
||||
|
||||
void QtcProcess::closeWriteChannel()
|
||||
{
|
||||
d->m_process->closeWriteChannel();
|
||||
}
|
||||
|
||||
void QtcProcess::close()
|
||||
{
|
||||
d->m_process->close();
|
||||
@@ -1251,7 +1222,6 @@ void QtcProcess::setExitCodeInterpreter(const ExitCodeInterpreter &interpreter)
|
||||
void QtcProcess::setWriteData(const QByteArray &writeData)
|
||||
{
|
||||
d->m_writeData = writeData;
|
||||
setKeepWriteChannelOpen();
|
||||
}
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
@@ -1276,13 +1246,6 @@ void QtcProcess::runBlocking()
|
||||
ExecuteOnDestruction logResult([this] { qCDebug(processLog) << *this; });
|
||||
|
||||
if (d->m_processUserEvents) {
|
||||
if (!d->m_writeData.isEmpty()) {
|
||||
connect(d->m_process, &ProcessInterface::started, this, [this] {
|
||||
write(d->m_writeData);
|
||||
closeWriteChannel();
|
||||
});
|
||||
}
|
||||
setOpenMode(d->m_writeData.isEmpty() ? QIODevice::ReadOnly : QIODevice::ReadWrite);
|
||||
QtcProcess::start();
|
||||
|
||||
// On Windows, start failure is triggered immediately if the
|
||||
@@ -1305,13 +1268,11 @@ void QtcProcess::runBlocking()
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
setOpenMode(QIODevice::ReadOnly);
|
||||
QtcProcess::start();
|
||||
if (!waitForStarted(d->m_maxHangTimerCount * 1000)) {
|
||||
d->m_result = QtcProcess::StartFailed;
|
||||
return;
|
||||
}
|
||||
closeWriteChannel();
|
||||
if (!waitForFinished(d->m_maxHangTimerCount * 1000)) {
|
||||
d->m_result = QtcProcess::Hang;
|
||||
terminate();
|
||||
|
||||
Reference in New Issue
Block a user