forked from qt-creator/qt-creator
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 <christian.kandeler@qt.io>
This commit is contained in:
@@ -183,8 +183,6 @@ void QbsSession::initialize()
|
|||||||
});
|
});
|
||||||
connect(d->qbsProcess, &QtcProcess::errorOccurred, this, [this](QProcess::ProcessError e) {
|
connect(d->qbsProcess, &QtcProcess::errorOccurred, this, [this](QProcess::ProcessError e) {
|
||||||
d->eventLoop.exit(1);
|
d->eventLoop.exit(1);
|
||||||
if (state() == State::ShuttingDown || state() == State::Inactive)
|
|
||||||
return;
|
|
||||||
switch (e) {
|
switch (e) {
|
||||||
case QProcess::FailedToStart:
|
case QProcess::FailedToStart:
|
||||||
setError(Error::QbsFailedToStart);
|
setError(Error::QbsFailedToStart);
|
||||||
@@ -203,9 +201,7 @@ void QbsSession::initialize()
|
|||||||
d->qbsProcess->deleteLater();
|
d->qbsProcess->deleteLater();
|
||||||
switch (state()) {
|
switch (state()) {
|
||||||
case State::Inactive:
|
case State::Inactive:
|
||||||
break;
|
QTC_CHECK(false);
|
||||||
case State::ShuttingDown:
|
|
||||||
setInactive();
|
|
||||||
break;
|
break;
|
||||||
case State::Active:
|
case State::Active:
|
||||||
setError(Error::QbsQuit);
|
setError(Error::QbsQuit);
|
||||||
@@ -214,7 +210,6 @@ void QbsSession::initialize()
|
|||||||
setError(Error::ProtocolError);
|
setError(Error::ProtocolError);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
d->qbsProcess = nullptr;
|
|
||||||
});
|
});
|
||||||
connect(d->packetReader, &PacketReader::errorOccurred, this, [this](const QString &msg) {
|
connect(d->packetReader, &PacketReader::errorOccurred, this, [this](const QString &msg) {
|
||||||
qCDebug(qbsPmLog) << "session error" << msg;
|
qCDebug(qbsPmLog) << "session error" << msg;
|
||||||
@@ -243,7 +238,7 @@ QbsSession::~QbsSession()
|
|||||||
d->packetReader->disconnect(this);
|
d->packetReader->disconnect(this);
|
||||||
if (d->qbsProcess) {
|
if (d->qbsProcess) {
|
||||||
d->qbsProcess->disconnect(this);
|
d->qbsProcess->disconnect(this);
|
||||||
quit();
|
sendQuitPacket();
|
||||||
if (d->qbsProcess->state() == QProcess::Running)
|
if (d->qbsProcess->state() == QProcess::Running)
|
||||||
d->qbsProcess->waitForFinished(10000);
|
d->qbsProcess->waitForFinished(10000);
|
||||||
delete d->qbsProcess;
|
delete d->qbsProcess;
|
||||||
@@ -305,14 +300,6 @@ void QbsSession::cancelCurrentJob()
|
|||||||
sendRequest(QJsonObject{qMakePair(QString("type"), QJsonValue("cancel-job"))});
|
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<QString, QStringList> &sourceFilesPerProduct)
|
void QbsSession::requestFilesGeneratedFrom(const QHash<QString, QStringList> &sourceFilesPerProduct)
|
||||||
{
|
{
|
||||||
QJsonObject request;
|
QJsonObject request;
|
||||||
|
@@ -121,7 +121,7 @@ public:
|
|||||||
explicit QbsSession(QObject *parent = nullptr);
|
explicit QbsSession(QObject *parent = nullptr);
|
||||||
~QbsSession() override;
|
~QbsSession() override;
|
||||||
|
|
||||||
enum class State { Initializing, Active, ShuttingDown, Inactive };
|
enum class State { Initializing, Active, Inactive };
|
||||||
enum class Error { QbsFailedToStart, QbsQuit, ProtocolError, VersionMismatch };
|
enum class Error { QbsFailedToStart, QbsQuit, ProtocolError, VersionMismatch };
|
||||||
|
|
||||||
State state() const;
|
State state() const;
|
||||||
@@ -131,7 +131,6 @@ public:
|
|||||||
|
|
||||||
void sendRequest(const QJsonObject &request);
|
void sendRequest(const QJsonObject &request);
|
||||||
void cancelCurrentJob();
|
void cancelCurrentJob();
|
||||||
void quit();
|
|
||||||
void requestFilesGeneratedFrom(const QHash<QString, QStringList> &sourceFilesPerProduct);
|
void requestFilesGeneratedFrom(const QHash<QString, QStringList> &sourceFilesPerProduct);
|
||||||
QStringList filesGeneratedFrom(const QString &sourceFile) const;
|
QStringList filesGeneratedFrom(const QString &sourceFile) const;
|
||||||
FileChangeResult addFiles(const QStringList &files, const QString &product,
|
FileChangeResult addFiles(const QStringList &files, const QString &product,
|
||||||
|
Reference in New Issue
Block a user