From b21ed19903d88f79967355d408aabfc6f9ab2af4 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 28 Apr 2022 23:33:55 +0200 Subject: [PATCH] QbsSession: Simplify the logic QbsSession::quit() is called only from QbsSession d'tor. Move this method into private section. Since QbsSession::quit() body was the only place in code where we potentially set the m_state into State::ShuttingDown, there is no need to check whether the m_state is set to State::ShuttingDown, as that's impossible, since quit() can only be called once during the lifetime of QbsSession. Replace a call to quit() in d'tor with quit() body. Since the ShuttingDown state was set only in d'tor, after disconnecting from qbsProcess signals, it's not possible that any signal handler would be called when being in ShuttingDown state. That's why the SettingDown state is removed in this patch as being no-op. Change-Id: Iff77f4119d7122a9723de4a5cd0bb98f4dce8506 Reviewed-by: Christian Kandeler --- src/plugins/qbsprojectmanager/qbssession.cpp | 17 ++--------------- src/plugins/qbsprojectmanager/qbssession.h | 3 +-- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/plugins/qbsprojectmanager/qbssession.cpp b/src/plugins/qbsprojectmanager/qbssession.cpp index 67c77c7bf97..b5bf7bb3820 100644 --- a/src/plugins/qbsprojectmanager/qbssession.cpp +++ b/src/plugins/qbsprojectmanager/qbssession.cpp @@ -183,8 +183,6 @@ void QbsSession::initialize() }); connect(d->qbsProcess, &QtcProcess::errorOccurred, this, [this](QProcess::ProcessError e) { d->eventLoop.exit(1); - if (state() == State::ShuttingDown || state() == State::Inactive) - return; switch (e) { case QProcess::FailedToStart: setError(Error::QbsFailedToStart); @@ -203,9 +201,7 @@ void QbsSession::initialize() d->qbsProcess->deleteLater(); switch (state()) { case State::Inactive: - break; - case State::ShuttingDown: - setInactive(); + QTC_CHECK(false); break; case State::Active: setError(Error::QbsQuit); @@ -214,7 +210,6 @@ void QbsSession::initialize() setError(Error::ProtocolError); break; } - d->qbsProcess = nullptr; }); connect(d->packetReader, &PacketReader::errorOccurred, this, [this](const QString &msg) { qCDebug(qbsPmLog) << "session error" << msg; @@ -243,7 +238,7 @@ QbsSession::~QbsSession() d->packetReader->disconnect(this); if (d->qbsProcess) { d->qbsProcess->disconnect(this); - quit(); + sendQuitPacket(); if (d->qbsProcess->state() == QProcess::Running) d->qbsProcess->waitForFinished(10000); delete d->qbsProcess; @@ -305,14 +300,6 @@ void QbsSession::cancelCurrentJob() sendRequest(QJsonObject{qMakePair(QString("type"), QJsonValue("cancel-job"))}); } -void QbsSession::quit() -{ - if (d->state == State::ShuttingDown || d->state == State::Inactive) - return; - d->state = State::ShuttingDown; - sendQuitPacket(); -} - void QbsSession::requestFilesGeneratedFrom(const QHash &sourceFilesPerProduct) { QJsonObject request; diff --git a/src/plugins/qbsprojectmanager/qbssession.h b/src/plugins/qbsprojectmanager/qbssession.h index 8829085f9df..cea2fc42891 100644 --- a/src/plugins/qbsprojectmanager/qbssession.h +++ b/src/plugins/qbsprojectmanager/qbssession.h @@ -121,7 +121,7 @@ public: explicit QbsSession(QObject *parent = nullptr); ~QbsSession() override; - enum class State { Initializing, Active, ShuttingDown, Inactive }; + enum class State { Initializing, Active, Inactive }; enum class Error { QbsFailedToStart, QbsQuit, ProtocolError, VersionMismatch }; State state() const; @@ -131,7 +131,6 @@ public: void sendRequest(const QJsonObject &request); void cancelCurrentJob(); - void quit(); void requestFilesGeneratedFrom(const QHash &sourceFilesPerProduct); QStringList filesGeneratedFrom(const QString &sourceFile) const; FileChangeResult addFiles(const QStringList &files, const QString &product,