Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT: refactor the producer as a finite state machine #1392

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading