RunControl: Remove initiateFinish() / finished()

The only difference between initiateFinish() and initiateStop()
is that the initiateFinish() deletes the RunControl automatically
after the final state was reached.

Add setAutoDeleteOnStop() property and reuse initiateStop()
and stopped() instead.

Change-Id: I8e842978831b19587a8658b4443c96a04eb7a6df
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-03 14:27:45 +02:00
parent 418482b3e2
commit c1f6d70445
9 changed files with 56 additions and 84 deletions

View File

@@ -589,7 +589,6 @@ void TestRunner::debugTests()
runControl, &RunControl::initiateStop); runControl, &RunControl::initiateStop);
connect(runControl, &RunControl::stopped, this, &TestRunner::onFinished); connect(runControl, &RunControl::stopped, this, &TestRunner::onFinished);
m_finishDebugConnect = connect(runControl, &RunControl::finished, this, &TestRunner::onFinished);
ProjectExplorerPlugin::startRunControl(runControl); ProjectExplorerPlugin::startRunControl(runControl);
if (useOutputProcessor && TestSettings::instance()->popupOnStart()) if (useOutputProcessor && TestSettings::instance()->popupOnStart())
AutotestPlugin::popupResultsPane(); AutotestPlugin::popupResultsPane();
@@ -705,7 +704,6 @@ void TestRunner::onFinished()
if (m_taskTree) if (m_taskTree)
m_taskTree.release()->deleteLater(); m_taskTree.release()->deleteLater();
disconnect(m_stopDebugConnect); disconnect(m_stopDebugConnect);
disconnect(m_finishDebugConnect);
disconnect(m_targetConnect); disconnect(m_targetConnect);
qDeleteAll(m_selectedTests); qDeleteAll(m_selectedTests);
m_selectedTests.clear(); m_selectedTests.clear();

View File

@@ -79,7 +79,6 @@ private:
QMetaObject::Connection m_buildConnect; QMetaObject::Connection m_buildConnect;
// temporarily used when debugging // temporarily used when debugging
QMetaObject::Connection m_stopDebugConnect; QMetaObject::Connection m_stopDebugConnect;
QMetaObject::Connection m_finishDebugConnect;
// temporarily used for handling of switching the current target // temporarily used for handling of switching the current target
QMetaObject::Connection m_targetConnect; QMetaObject::Connection m_targetConnect;
QTimer m_cancelTimer; QTimer m_cancelTimer;

View File

@@ -545,10 +545,12 @@ void DebuggerRunTool::start()
m_engine->setRunId(d->runId); m_engine->setRunId(d->runId);
m_engine->setRunTool(this); m_engine->setRunTool(this);
m_engine->setCompanionEngine(m_engine2); m_engine->setCompanionEngine(m_engine2);
connect(m_engine, &DebuggerEngine::requestRunControlFinish, auto rc = runControl();
runControl(), &RunControl::initiateFinish); connect(m_engine, &DebuggerEngine::requestRunControlFinish, rc, [rc] {
connect(m_engine, &DebuggerEngine::requestRunControlStop, rc->setAutoDeleteOnStop(true);
runControl(), &RunControl::initiateStop); rc->initiateStop();
}, Qt::QueuedConnection);
connect(m_engine, &DebuggerEngine::requestRunControlStop, rc, &RunControl::initiateStop);
connect(m_engine, &DebuggerEngine::engineStarted, connect(m_engine, &DebuggerEngine::engineStarted,
this, [this] { handleEngineStarted(m_engine); }); this, [this] { handleEngineStarted(m_engine); });
connect(m_engine, &DebuggerEngine::engineFinished, connect(m_engine, &DebuggerEngine::engineFinished,
@@ -575,10 +577,11 @@ void DebuggerRunTool::start()
m_engine2->setRunTool(this); m_engine2->setRunTool(this);
m_engine2->setCompanionEngine(m_engine); m_engine2->setCompanionEngine(m_engine);
m_engine2->setSecondaryEngine(); m_engine2->setSecondaryEngine();
connect(m_engine2, &DebuggerEngine::requestRunControlFinish, connect(m_engine2, &DebuggerEngine::requestRunControlFinish, rc, [rc] {
runControl(), &RunControl::initiateFinish); rc->setAutoDeleteOnStop(true);
connect(m_engine2, &DebuggerEngine::requestRunControlStop, rc->initiateStop();
runControl(), &RunControl::initiateStop); }, Qt::QueuedConnection);
connect(m_engine2, &DebuggerEngine::requestRunControlStop, rc, &RunControl::initiateStop);
connect(m_engine2, &DebuggerEngine::engineStarted, connect(m_engine2, &DebuggerEngine::engineStarted,
this, [this] { handleEngineStarted(m_engine2); }); this, [this] { handleEngineStarted(m_engine2); });
connect(m_engine2, &DebuggerEngine::engineFinished, connect(m_engine2, &DebuggerEngine::engineFinished,

View File

@@ -185,8 +185,6 @@ void PerfProfilerRunner::start()
&PerfProfilerTool::onRunControlStarted); &PerfProfilerTool::onRunControlStarted);
connect(runControl(), &RunControl::stopped, PerfProfilerTool::instance(), connect(runControl(), &RunControl::stopped, PerfProfilerTool::instance(),
&PerfProfilerTool::onRunControlFinished); &PerfProfilerTool::onRunControlFinished);
connect(runControl(), &RunControl::finished, PerfProfilerTool::instance(),
&PerfProfilerTool::onRunControlFinished);
PerfDataReader *reader = m_perfParserWorker->reader(); PerfDataReader *reader = m_perfParserWorker->reader();
if (auto prw = qobject_cast<LocalPerfRecordWorker *>(m_perfRecordWorker)) { if (auto prw = qobject_cast<LocalPerfRecordWorker *>(m_perfRecordWorker)) {

View File

@@ -406,8 +406,10 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
}); });
if (tab != m_runControlTabs.end()) { if (tab != m_runControlTabs.end()) {
// Reuse this tab // Reuse this tab
if (tab->runControl) if (tab->runControl) {
tab->runControl->initiateFinish(); tab->runControl->setAutoDeleteOnStop(true);
tab->runControl->initiateStop();
}
tab->runControl = rc; tab->runControl = rc;
tab->window->reset(); tab->window->reset();
rc->setupFormatter(tab->window->outputFormatter()); rc->setupFormatter(tab->window->outputFormatter());
@@ -642,8 +644,10 @@ void AppOutputPane::closeTab(int tabIndex, CloseTabMode closeTabMode)
m_tabWidget->removeTab(tabIndex); m_tabWidget->removeTab(tabIndex);
delete window; delete window;
if (runControl) if (runControl) {
runControl->initiateFinish(); // Will self-destruct. runControl->setAutoDeleteOnStop(true);
runControl->initiateStop();
}
Utils::erase(m_runControlTabs, [tab](const RunControlTab &t) { Utils::erase(m_runControlTabs, [tab](const RunControlTab &t) {
return t.runControl == tab->runControl; }); return t.runControl == tab->runControl; });
updateCloseActions(); updateCloseActions();

View File

@@ -211,9 +211,7 @@ enum class RunControlState
Starting, // Actual process/tool starts. Starting, // Actual process/tool starts.
Running, // All good and running. Running, // All good and running.
Stopping, // initiateStop() was called, stop application/tool Stopping, // initiateStop() was called, stop application/tool
Stopped, // all good, but stopped. Can possibly be re-started Stopped // all good, but stopped. Can possibly be re-started
Finishing, // Application tab manually closed
Finished // Final state, will self-destruct with deleteLater()
}; };
static QString stateName(RunControlState s) static QString stateName(RunControlState s)
@@ -225,8 +223,6 @@ static QString stateName(RunControlState s)
SN(RunControlState::Running) SN(RunControlState::Running)
SN(RunControlState::Stopping) SN(RunControlState::Stopping)
SN(RunControlState::Stopped) SN(RunControlState::Stopped)
SN(RunControlState::Finishing)
SN(RunControlState::Finished)
} }
return QString("<unknown: %1>").arg(int(s)); return QString("<unknown: %1>").arg(int(s));
# undef SN # undef SN
@@ -259,6 +255,7 @@ public:
QList<QPointer<RunWorker>> m_workers; QList<QPointer<RunWorker>> m_workers;
RunControlState state = RunControlState::Initialized; RunControlState state = RunControlState::Initialized;
bool printEnvironment = false; bool printEnvironment = false;
bool autoDelete = false;
}; };
class RunControlPrivate : public QObject, public RunControlPrivateData class RunControlPrivate : public QObject, public RunControlPrivateData
@@ -274,7 +271,7 @@ public:
~RunControlPrivate() override ~RunControlPrivate() override
{ {
QTC_CHECK(state == RunControlState::Finished || state == RunControlState::Initialized); QTC_CHECK(state == RunControlState::Stopped || state == RunControlState::Initialized);
disconnect(); disconnect();
q = nullptr; q = nullptr;
qDeleteAll(m_workers); qDeleteAll(m_workers);
@@ -407,6 +404,11 @@ RunControl::~RunControl()
#endif #endif
} }
void RunControl::setAutoDeleteOnStop(bool autoDelete)
{
d->autoDelete = autoDelete;
}
void RunControl::initiateStart() void RunControl::initiateStart()
{ {
emit aboutToStart(); emit aboutToStart();
@@ -429,11 +431,6 @@ void RunControl::forceStop()
d->forceStop(); d->forceStop();
} }
void RunControl::initiateFinish()
{
QTimer::singleShot(0, d.get(), &RunControlPrivate::initiateFinish);
}
RunWorker *RunControl::createWorker(Id workerId) RunWorker *RunControl::createWorker(Id workerId)
{ {
const Id deviceType = DeviceTypeKitAspect::deviceTypeId(d->kit); const Id deviceType = DeviceTypeKitAspect::deviceTypeId(d->kit);
@@ -542,7 +539,7 @@ void RunControlPrivate::continueStart()
void RunControlPrivate::initiateStop() void RunControlPrivate::initiateStop()
{ {
if (state != RunControlState::Starting && state != RunControlState::Running) if (state == RunControlState::Initialized)
qDebug() << "Unexpected initiateStop() in state" << stateName(state); qDebug() << "Unexpected initiateStop() in state" << stateName(state);
setState(RunControlState::Stopping); setState(RunControlState::Stopping);
@@ -596,12 +593,8 @@ void RunControlPrivate::continueStopOrFinish()
} }
RunControlState targetState; RunControlState targetState;
if (state == RunControlState::Finishing) { if (state == RunControlState::Stopping)
targetState = RunControlState::Finished;
} else {
checkState(RunControlState::Stopping);
targetState = RunControlState::Stopped; targetState = RunControlState::Stopped;
}
if (allDone) { if (allDone) {
debugMessage("All Stopped"); debugMessage("All Stopped");
@@ -613,7 +606,7 @@ void RunControlPrivate::continueStopOrFinish()
void RunControlPrivate::forceStop() void RunControlPrivate::forceStop()
{ {
if (state == RunControlState::Finished) { if (state == RunControlState::Stopped) {
debugMessage("Was finished, too late to force Stop"); debugMessage("Was finished, too late to force Stop");
return; return;
} }
@@ -648,14 +641,6 @@ void RunControlPrivate::forceStop()
debugMessage("All Stopped"); debugMessage("All Stopped");
} }
void RunControlPrivate::initiateFinish()
{
setState(RunControlState::Finishing);
debugMessage("Ramping down");
continueStopOrFinish();
}
void RunControlPrivate::onWorkerStarted(RunWorker *worker) void RunControlPrivate::onWorkerStarted(RunWorker *worker)
{ {
worker->d->state = RunWorkerState::Running; worker->d->state = RunWorkerState::Running;
@@ -688,11 +673,9 @@ void RunControlPrivate::onWorkerFailed(RunWorker *worker, const QString &msg)
initiateStop(); initiateStop();
break; break;
case RunControlState::Stopping: case RunControlState::Stopping:
case RunControlState::Finishing:
continueStopOrFinish(); continueStopOrFinish();
break; break;
case RunControlState::Stopped: case RunControlState::Stopped:
case RunControlState::Finished:
QTC_CHECK(false); // Should not happen. QTC_CHECK(false); // Should not happen.
continueStopOrFinish(); continueStopOrFinish();
break; break;
@@ -723,7 +706,7 @@ void RunControlPrivate::onWorkerStopped(RunWorker *worker)
break; break;
} }
if (state == RunControlState::Finishing || state == RunControlState::Stopping) { if (state == RunControlState::Stopping) {
continueStopOrFinish(); continueStopOrFinish();
return; return;
} else if (worker->isEssential()) { } else if (worker->isEssential()) {
@@ -1078,26 +1061,15 @@ bool RunControlPrivate::isAllowedTransition(RunControlState from, RunControlStat
{ {
switch (from) { switch (from) {
case RunControlState::Initialized: case RunControlState::Initialized:
return to == RunControlState::Starting return to == RunControlState::Starting;
|| to == RunControlState::Finishing;
case RunControlState::Starting: case RunControlState::Starting:
return to == RunControlState::Running return to == RunControlState::Running || to == RunControlState::Stopping;
|| to == RunControlState::Stopping
|| to == RunControlState::Finishing;
case RunControlState::Running: case RunControlState::Running:
return to == RunControlState::Stopping return to == RunControlState::Stopping || to == RunControlState::Stopped;
|| to == RunControlState::Stopped
|| to == RunControlState::Finishing;
case RunControlState::Stopping: case RunControlState::Stopping:
return to == RunControlState::Stopped return to == RunControlState::Stopped;
|| to == RunControlState::Finishing;
case RunControlState::Stopped: case RunControlState::Stopped:
return to == RunControlState::Starting return to != RunControlState::Initialized;
|| to == RunControlState::Finishing;
case RunControlState::Finishing:
return to == RunControlState::Finished;
case RunControlState::Finished:
return false;
} }
return false; return false;
} }
@@ -1125,13 +1097,13 @@ void RunControlPrivate::setState(RunControlState newState)
emit q->started(); emit q->started();
break; break;
case RunControlState::Stopped: case RunControlState::Stopped:
q->setApplicationProcessHandle(Utils::ProcessHandle()); if (autoDelete) {
emit q->stopped();
break;
case RunControlState::Finished:
emit q->finished();
debugMessage("All finished. Deleting myself"); debugMessage("All finished. Deleting myself");
q->deleteLater(); q->deleteLater();
} else {
q->setApplicationProcessHandle(Utils::ProcessHandle());
}
emit q->stopped();
break; break;
default: default:
break; break;

View File

@@ -156,11 +156,12 @@ public:
void copyDataFromRunConfiguration(RunConfiguration *runConfig); void copyDataFromRunConfiguration(RunConfiguration *runConfig);
void copyDataFromRunControl(RunControl *runControl); void copyDataFromRunControl(RunControl *runControl);
void setAutoDeleteOnStop(bool autoDelete);
void initiateStart(); void initiateStart();
void initiateReStart(); void initiateReStart();
void initiateStop(); void initiateStop();
void forceStop(); void forceStop();
void initiateFinish();
bool promptToStop(bool *optionalPrompt = nullptr) const; bool promptToStop(bool *optionalPrompt = nullptr) const;
void setPromptToStop(const std::function<bool(bool *)> &promptToStop); void setPromptToStop(const std::function<bool(bool *)> &promptToStop);
@@ -237,7 +238,6 @@ signals:
void aboutToStart(); void aboutToStart();
void started(); void started();
void stopped(); void stopped();
void finished();
void applicationProcessHandleChanged(QPrivateSignal); // Use setApplicationProcessHandle void applicationProcessHandleChanged(QPrivateSignal); // Use setApplicationProcessHandle
private: private:

View File

@@ -297,7 +297,10 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
} }
} }
auto handleStop = [this, runControl]() { auto handleStop = [this, runControl] {
if (!d->m_toolBusy)
return;
d->m_toolBusy = false; d->m_toolBusy = false;
updateRunActions(); updateRunActions();
disconnect(d->m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop); disconnect(d->m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop);
@@ -311,11 +314,6 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
}; };
connect(runControl, &RunControl::stopped, this, handleStop); connect(runControl, &RunControl::stopped, this, handleStop);
connect(runControl, &RunControl::finished, this, [this, handleStop] {
if (d->m_toolBusy)
handleStop();
});
connect(d->m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop); connect(d->m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop);
updateRunActions(); updateRunActions();

View File

@@ -66,10 +66,6 @@ void LocalQmlProfilerRunnerTest::testRunner()
running = false; running = false;
started = false; started = false;
}); });
connect(runControl, &RunControl::finished, this, [&]{
running = false;
started = false;
});
}; };
connectRunner(); connectRunner();
@@ -84,7 +80,8 @@ void LocalQmlProfilerRunnerTest::testRunner()
QCOMPARE(stopCount, 1); QCOMPARE(stopCount, 1);
QCOMPARE(runCount, 0); QCOMPARE(runCount, 0);
runControl->initiateFinish(); runControl->setAutoDeleteOnStop(true);
runControl->initiateStop();
QTRY_VERIFY(runControl.isNull()); QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull()); QVERIFY(profiler.isNull());
@@ -104,7 +101,8 @@ void LocalQmlProfilerRunnerTest::testRunner()
QCOMPARE(stopCount, 2); QCOMPARE(stopCount, 2);
QCOMPARE(runCount, 1); QCOMPARE(runCount, 1);
runControl->initiateFinish(); runControl->setAutoDeleteOnStop(true);
runControl->initiateStop();
QTRY_VERIFY(runControl.isNull()); QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull()); QVERIFY(profiler.isNull());
@@ -123,7 +121,8 @@ void LocalQmlProfilerRunnerTest::testRunner()
QCOMPARE(stopCount, 3); QCOMPARE(stopCount, 3);
QCOMPARE(runCount, 2); QCOMPARE(runCount, 2);
runControl->initiateFinish(); runControl->setAutoDeleteOnStop(true);
runControl->initiateStop();
QTRY_VERIFY(runControl.isNull()); QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull()); QVERIFY(profiler.isNull());
@@ -146,7 +145,8 @@ void LocalQmlProfilerRunnerTest::testRunner()
QCOMPARE(stopCount, 4); QCOMPARE(stopCount, 4);
QCOMPARE(runCount, 3); QCOMPARE(runCount, 3);
runControl->initiateFinish(); runControl->setAutoDeleteOnStop(true);
runControl->initiateStop();
QTRY_VERIFY(runControl.isNull()); QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull()); QVERIFY(profiler.isNull());
} }