forked from qt-creator/qt-creator
Core: ProcessReaper code cosmetics
- Rename ReaperPrivate to ProcessReapers - drop the used ProcessReaper::m_futureInterface - sprinkle some private and final - remove unnecessary Q_OBJECT - remove unnecessary #include, fix accidental user Change-Id: I2787815975dc80cb93db2132bbfe7ce9a74ebd5f Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -87,7 +87,7 @@ private:
|
||||
MainWindow *m_mainWindow = nullptr;
|
||||
EditMode *m_editMode = nullptr;
|
||||
Locator *m_locator = nullptr;
|
||||
ReaperPrivate m_reaper;
|
||||
ProcessReapers m_reaper;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -26,19 +26,20 @@
|
||||
#include "reaper.h"
|
||||
#include "reaper_p.h"
|
||||
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
static ReaperPrivate *d = nullptr;
|
||||
static ProcessReapers *d = nullptr;
|
||||
|
||||
namespace {
|
||||
void killProcess(QProcess *process)
|
||||
static void killProcess(QProcess *process)
|
||||
{
|
||||
if (auto qtcProcess = qobject_cast<Utils::QtcProcess*>(process))
|
||||
qtcProcess->kill();
|
||||
@@ -46,14 +47,30 @@ void killProcess(QProcess *process)
|
||||
process->kill();
|
||||
}
|
||||
|
||||
void terminateProcess(QProcess *process)
|
||||
static void terminateProcess(QProcess *process)
|
||||
{
|
||||
if (auto qtcProcess = qobject_cast<Utils::QtcProcess*>(process))
|
||||
qtcProcess->terminate();
|
||||
else
|
||||
process->terminate();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
class ProcessReaper final : public QObject
|
||||
{
|
||||
public:
|
||||
ProcessReaper(QProcess *p, int timeoutMs);
|
||||
~ProcessReaper() final;
|
||||
|
||||
int timeoutMs() const;
|
||||
bool isFinished() const;
|
||||
void nextIteration();
|
||||
|
||||
private:
|
||||
mutable QTimer m_iterationTimer;
|
||||
QProcess *m_process;
|
||||
int m_emergencyCounter = 0;
|
||||
QProcess::ProcessState m_lastState = QProcess::NotRunning;
|
||||
};
|
||||
|
||||
ProcessReaper::ProcessReaper(QProcess *p, int timeoutMs) : m_process(p)
|
||||
{
|
||||
@@ -64,7 +81,6 @@ ProcessReaper::ProcessReaper(QProcess *p, int timeoutMs) : m_process(p)
|
||||
connect(&m_iterationTimer, &QTimer::timeout, this, &ProcessReaper::nextIteration);
|
||||
|
||||
QTimer::singleShot(0, this, &ProcessReaper::nextIteration);
|
||||
m_futureInterface.reportStarted();
|
||||
}
|
||||
|
||||
ProcessReaper::~ProcessReaper()
|
||||
@@ -92,7 +108,6 @@ void ProcessReaper::nextIteration()
|
||||
if (state == QProcess::NotRunning || m_emergencyCounter > 5) {
|
||||
delete m_process;
|
||||
m_process = nullptr;
|
||||
m_futureInterface.reportFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,12 +127,12 @@ void ProcessReaper::nextIteration()
|
||||
++m_emergencyCounter;
|
||||
}
|
||||
|
||||
ReaperPrivate::ReaperPrivate()
|
||||
ProcessReapers::ProcessReapers()
|
||||
{
|
||||
d = this;
|
||||
}
|
||||
|
||||
ReaperPrivate::~ReaperPrivate()
|
||||
ProcessReapers::~ProcessReapers()
|
||||
{
|
||||
while (!m_reapers.isEmpty()) {
|
||||
int alreadyWaited = 0;
|
||||
|
||||
@@ -25,46 +25,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QFutureInterface>
|
||||
#include <QProcess>
|
||||
#include <QTimer>
|
||||
#include <QList>
|
||||
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
class CorePlugin;
|
||||
class ProcessReaper;
|
||||
|
||||
class ProcessReaper : public QObject
|
||||
class ProcessReapers final
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProcessReaper(QProcess *p, int timeoutMs);
|
||||
~ProcessReaper() override;
|
||||
|
||||
int timeoutMs() const;
|
||||
bool isFinished() const;
|
||||
void nextIteration();
|
||||
|
||||
private:
|
||||
mutable QTimer m_iterationTimer;
|
||||
QFutureInterface<void> m_futureInterface;
|
||||
QProcess *m_process;
|
||||
int m_emergencyCounter = 0;
|
||||
QProcess::ProcessState m_lastState = QProcess::NotRunning;
|
||||
};
|
||||
|
||||
class ReaperPrivate {
|
||||
public:
|
||||
~ReaperPrivate();
|
||||
~ProcessReapers();
|
||||
ProcessReapers();
|
||||
|
||||
QList<ProcessReaper *> m_reapers;
|
||||
|
||||
private:
|
||||
ReaperPrivate();
|
||||
|
||||
friend class CorePlugin;
|
||||
friend class ProcessReaper;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -59,16 +59,17 @@
|
||||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTimerEvent>
|
||||
#include <QDir>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFormLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QMenu>
|
||||
#include <QSpinBox>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QCheckBox>
|
||||
#include <QFormLayout>
|
||||
#include <QMenu>
|
||||
#include <QTimer>
|
||||
#include <QTimerEvent>
|
||||
|
||||
using namespace Core;
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
Reference in New Issue
Block a user