Skip to content

Commit

Permalink
MQTT: refactor the producer as a finite state machine
Browse files Browse the repository at this point in the history
Contributes to issue #1385
  • Loading branch information
chriadam committed Aug 8, 2024
1 parent 34c7e48 commit f08c332
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Global.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ QtObject {
}

function reset() {
// unload the gui.
dataManagerLoaded = false

// note: we don't reset `main` or `changingLanguage`
// as main will never be destroyed during the ui rebuild,
// and we handle changingLanguage specially.
Expand Down Expand Up @@ -131,7 +134,6 @@ QtObject {

// The last thing we do is set the splash screen visible.
allPagesLoaded = false
dataManagerLoaded = false
splashScreenVisible = true
}

Expand Down
15 changes: 11 additions & 4 deletions src/backendconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void BackendConnection::setState(VeQItemMqttProducer::ConnectionState backendCon
setState(BackendConnection::State::Idle);
break;
}
case VeQItemMqttProducer::WaitingToConnect: // fall through
case VeQItemMqttProducer::TransportConnecting: // fall through
case VeQItemMqttProducer::TransportConnected: // fall through
case VeQItemMqttProducer::Connecting:
{
setState(BackendConnection::State::Connecting);
Expand All @@ -72,6 +75,7 @@ void BackendConnection::setState(VeQItemMqttProducer::ConnectionState backendCon
setState(BackendConnection::State::Connected);
break;
}
case VeQItemMqttProducer::Identified: // fall through
case VeQItemMqttProducer::Initializing:
{
setState(BackendConnection::State::Initializing);
Expand All @@ -87,6 +91,9 @@ void BackendConnection::setState(VeQItemMqttProducer::ConnectionState backendCon
setState(BackendConnection::State::Disconnected);
break;
}
case VeQItemMqttProducer::WaitingToReconnect: // fall through
case VeQItemMqttProducer::TransportReconnecting: // fall through
case VeQItemMqttProducer::TransportReconnected: // fall through
case VeQItemMqttProducer::Reconnecting:
{
setState(BackendConnection::State::Reconnecting);
Expand Down Expand Up @@ -161,12 +168,12 @@ void BackendConnection::initDBusConnection(const QString &address)
#if defined(VENUS_WEBASSEMBLY_BUILD)
void BackendConnection::onNetworkConfigChanged(const QVariant var)
{
qWarning() << "onNetworkConfigChanged" << var;

if (var.toInt() > 0 && !mRestartDelayTimer) {
if (var.isValid() && var.toInt() > 0 && !mRestartDelayTimer) {
qWarning() << "Closing MQTT connection and reloading due to network config change";
VeQItemMqttProducer *mqtt = qobject_cast<VeQItemMqttProducer *>(m_producer);
if (mqtt)
if (mqtt) {
mqtt->close();
}

mRestartDelayTimer = new QTimer();
connect(mRestartDelayTimer, &QTimer::timeout, this, &BackendConnection::onReloadPageTimerExpired);
Expand Down
2 changes: 1 addition & 1 deletion src/veutil

0 comments on commit f08c332

Please sign in to comment.