fetch snapshot data on subsrciption

This commit is contained in:
2026-02-04 13:09:04 +02:00
parent c73486aaf8
commit 1f1b939af4
2 changed files with 20 additions and 5 deletions

View File

@@ -63,7 +63,7 @@ void AWDataEngineAggregator::connectSources()
auto keys = m_sensors.keys(); auto keys = m_sensors.keys();
auto newKeys = QSet(keys.cbegin(), keys.cend()) - m_subscribed; auto newKeys = QSet(keys.cbegin(), keys.cend()) - m_subscribed;
m_interface->subscribe(newKeys.values()).waitForFinished(); subscribeSources(newKeys.values());
m_subscribed.unite(newKeys); m_subscribed.unite(newKeys);
} }
@@ -106,6 +106,19 @@ void AWDataEngineAggregator::registerClient(QObject *_client)
} }
void AWDataEngineAggregator::subscribeSources(const QStringList &_sources)
{
qCDebug(LOG_AW) << "Subscribe on sources" << _sources;
// subscribe
m_interface->subscribe(_sources).waitForFinished();
// get data snapshot
auto data = m_interface->sensorData(_sources);
data.waitForFinished();
updateData(data);
}
void AWDataEngineAggregator::unregisterClient(QObject *_client) void AWDataEngineAggregator::unregisterClient(QObject *_client)
{ {
qCDebug(LOG_AW) << "Unregister client" << _client; qCDebug(LOG_AW) << "Unregister client" << _client;
@@ -159,15 +172,16 @@ void AWDataEngineAggregator::sensorAdded(const QString &_sensor)
if (!isValidSensor(info)) if (!isValidSensor(info))
return; return;
// notify about new device
emit(deviceAdded(_sensor));
// process connection
m_sensors[_sensor] = info; m_sensors[_sensor] = info;
dropSource(_sensor); // force reconnect dropSource(_sensor); // force reconnect
if (!m_subscribed.contains(_sensor)) { if (!m_subscribed.contains(_sensor)) {
m_interface->subscribe({_sensor}).waitForFinished(); subscribeSources({_sensor});
m_subscribed.insert(_sensor); m_subscribed.insert(_sensor);
} }
// notify about new device
emit(deviceAdded(_sensor));
} }

View File

@@ -54,6 +54,7 @@ public:
[[nodiscard]] static bool isValidSensor(const KSysGuard::SensorInfo &_sensor); [[nodiscard]] static bool isValidSensor(const KSysGuard::SensorInfo &_sensor);
void loadSources(); void loadSources();
void registerClient(QObject *_client); void registerClient(QObject *_client);
void subscribeSources(const QStringList &_sources);
void unregisterClient(QObject *_client); void unregisterClient(QObject *_client);
signals: signals: