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;
|
MainWindow *m_mainWindow = nullptr;
|
||||||
EditMode *m_editMode = nullptr;
|
EditMode *m_editMode = nullptr;
|
||||||
Locator *m_locator = nullptr;
|
Locator *m_locator = nullptr;
|
||||||
ReaperPrivate m_reaper;
|
ProcessReapers m_reaper;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -26,19 +26,20 @@
|
|||||||
#include "reaper.h"
|
#include "reaper.h"
|
||||||
#include "reaper_p.h"
|
#include "reaper_p.h"
|
||||||
|
|
||||||
#include <utils/qtcprocess.h>
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
static ReaperPrivate *d = nullptr;
|
static ProcessReapers *d = nullptr;
|
||||||
|
|
||||||
namespace {
|
static void killProcess(QProcess *process)
|
||||||
void killProcess(QProcess *process)
|
|
||||||
{
|
{
|
||||||
if (auto qtcProcess = qobject_cast<Utils::QtcProcess*>(process))
|
if (auto qtcProcess = qobject_cast<Utils::QtcProcess*>(process))
|
||||||
qtcProcess->kill();
|
qtcProcess->kill();
|
||||||
@@ -46,14 +47,30 @@ void killProcess(QProcess *process)
|
|||||||
process->kill();
|
process->kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminateProcess(QProcess *process)
|
static void terminateProcess(QProcess *process)
|
||||||
{
|
{
|
||||||
if (auto qtcProcess = qobject_cast<Utils::QtcProcess*>(process))
|
if (auto qtcProcess = qobject_cast<Utils::QtcProcess*>(process))
|
||||||
qtcProcess->terminate();
|
qtcProcess->terminate();
|
||||||
else
|
else
|
||||||
process->terminate();
|
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)
|
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);
|
connect(&m_iterationTimer, &QTimer::timeout, this, &ProcessReaper::nextIteration);
|
||||||
|
|
||||||
QTimer::singleShot(0, this, &ProcessReaper::nextIteration);
|
QTimer::singleShot(0, this, &ProcessReaper::nextIteration);
|
||||||
m_futureInterface.reportStarted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessReaper::~ProcessReaper()
|
ProcessReaper::~ProcessReaper()
|
||||||
@@ -92,7 +108,6 @@ void ProcessReaper::nextIteration()
|
|||||||
if (state == QProcess::NotRunning || m_emergencyCounter > 5) {
|
if (state == QProcess::NotRunning || m_emergencyCounter > 5) {
|
||||||
delete m_process;
|
delete m_process;
|
||||||
m_process = nullptr;
|
m_process = nullptr;
|
||||||
m_futureInterface.reportFinished();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,12 +127,12 @@ void ProcessReaper::nextIteration()
|
|||||||
++m_emergencyCounter;
|
++m_emergencyCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReaperPrivate::ReaperPrivate()
|
ProcessReapers::ProcessReapers()
|
||||||
{
|
{
|
||||||
d = this;
|
d = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReaperPrivate::~ReaperPrivate()
|
ProcessReapers::~ProcessReapers()
|
||||||
{
|
{
|
||||||
while (!m_reapers.isEmpty()) {
|
while (!m_reapers.isEmpty()) {
|
||||||
int alreadyWaited = 0;
|
int alreadyWaited = 0;
|
||||||
|
|||||||
@@ -25,46 +25,24 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QList>
|
||||||
#include <QFutureInterface>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CorePlugin;
|
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:
|
private:
|
||||||
mutable QTimer m_iterationTimer;
|
~ProcessReapers();
|
||||||
QFutureInterface<void> m_futureInterface;
|
ProcessReapers();
|
||||||
QProcess *m_process;
|
|
||||||
int m_emergencyCounter = 0;
|
|
||||||
QProcess::ProcessState m_lastState = QProcess::NotRunning;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ReaperPrivate {
|
|
||||||
public:
|
|
||||||
~ReaperPrivate();
|
|
||||||
|
|
||||||
QList<ProcessReaper *> m_reapers;
|
QList<ProcessReaper *> m_reapers;
|
||||||
|
|
||||||
private:
|
|
||||||
ReaperPrivate();
|
|
||||||
|
|
||||||
friend class CorePlugin;
|
friend class CorePlugin;
|
||||||
|
friend class ProcessReaper;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -59,16 +59,17 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTimerEvent>
|
#include <QCheckBox>
|
||||||
#include <QDir>
|
#include <QComboBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QMenu>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <QComboBox>
|
#include <QTimer>
|
||||||
#include <QGroupBox>
|
#include <QTimerEvent>
|
||||||
#include <QCheckBox>
|
|
||||||
#include <QFormLayout>
|
|
||||||
#include <QMenu>
|
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|||||||
Reference in New Issue
Block a user