mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
correct subscription processing
This commit is contained in:
parent
b6ade7310a
commit
115bef3dbe
@ -17,15 +17,17 @@
|
|||||||
|
|
||||||
#include "awdataengineaggregator.h"
|
#include "awdataengineaggregator.h"
|
||||||
|
|
||||||
#include <QDBusConnection>
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
#include <ksysguard/formatter/Unit.h>
|
||||||
#include <ksysguard/systemstats/DBusInterface.h>
|
#include <ksysguard/systemstats/DBusInterface.h>
|
||||||
|
|
||||||
|
#include <QDBusConnection>
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
AWDataEngineAggregator::AWDataEngineAggregator(QObject *_parent)
|
AWDataEngineAggregator::AWDataEngineAggregator(QObject *_parent)
|
||||||
: QObject(_parent)
|
: QObject(_parent)
|
||||||
|
, m_interface(new KSysGuard::SystemStats::DBusInterface())
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
@ -34,12 +36,14 @@ AWDataEngineAggregator::AWDataEngineAggregator(QObject *_parent)
|
|||||||
qDBusRegisterMetaType<KSysGuard::SensorDataList>();
|
qDBusRegisterMetaType<KSysGuard::SensorDataList>();
|
||||||
qDBusRegisterMetaType<QHash<QString, KSysGuard::SensorInfo>>();
|
qDBusRegisterMetaType<QHash<QString, KSysGuard::SensorInfo>>();
|
||||||
|
|
||||||
m_interface = new KSysGuard::SystemStats::DBusInterface();
|
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::newSensorData, this,
|
||||||
|
&AWDataEngineAggregator::updateData);
|
||||||
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::newSensorData, this, &AWDataEngineAggregator::updateData);
|
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorMetaDataChanged, this,
|
||||||
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorMetaDataChanged, this, &AWDataEngineAggregator::updateSensors);
|
&AWDataEngineAggregator::updateSensors);
|
||||||
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorAdded, this, &AWDataEngineAggregator::sensorAdded);
|
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorAdded, this,
|
||||||
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorRemoved, this, &AWDataEngineAggregator::sensorRemoved);
|
&AWDataEngineAggregator::sensorAdded);
|
||||||
|
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorRemoved, this,
|
||||||
|
&AWDataEngineAggregator::sensorRemoved);
|
||||||
|
|
||||||
loadSources();
|
loadSources();
|
||||||
}
|
}
|
||||||
@ -54,9 +58,20 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDataEngineAggregator::connectSources()
|
||||||
|
{
|
||||||
|
auto keys = m_sensors.keys();
|
||||||
|
auto newKeys = QSet(keys.cbegin(), keys.cend()) - m_subscribed;
|
||||||
|
|
||||||
|
m_interface->subscribe(newKeys.values()).waitForFinished();
|
||||||
|
m_subscribed.unite(newKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWDataEngineAggregator::disconnectSources()
|
void AWDataEngineAggregator::disconnectSources()
|
||||||
{
|
{
|
||||||
m_interface->unsubscribe(m_sensors.keys());
|
m_interface->unsubscribe(m_subscribed.values()).waitForFinished();
|
||||||
|
m_subscribed.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -73,15 +88,7 @@ void AWDataEngineAggregator::loadSources()
|
|||||||
|
|
||||||
auto sensors = response.value();
|
auto sensors = response.value();
|
||||||
updateSensors(sensors);
|
updateSensors(sensors);
|
||||||
}
|
connectSources();
|
||||||
|
|
||||||
|
|
||||||
void AWDataEngineAggregator::reconnectSources(const int interval)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Reconnect all sensors with update interval" << interval;
|
|
||||||
|
|
||||||
disconnectSources();
|
|
||||||
m_interface->subscribe(m_sensors.keys());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,7 +96,10 @@ void AWDataEngineAggregator::dropSource(const QString &_source)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Disconnect sensor" << _source;
|
qCDebug(LOG_AW) << "Disconnect sensor" << _source;
|
||||||
|
|
||||||
m_interface->unsubscribe({_source});
|
if (m_subscribed.contains(_source)) {
|
||||||
|
m_interface->unsubscribe({_source}).waitForFinished();
|
||||||
|
m_subscribed.remove(_source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -100,13 +110,17 @@ void AWDataEngineAggregator::sensorAdded(const QString &_sensor)
|
|||||||
// check if sensor is actually valid
|
// check if sensor is actually valid
|
||||||
auto response = m_interface->sensors({_sensor});
|
auto response = m_interface->sensors({_sensor});
|
||||||
response.waitForFinished();
|
response.waitForFinished();
|
||||||
auto info = response.value();
|
|
||||||
if (info.count() != 1)
|
auto info = response.value().value(_sensor);
|
||||||
|
if (!isValidSensor(info))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qCWarning(LOG_AW) << info.keys();
|
m_sensors[_sensor] = info;
|
||||||
|
dropSource(_sensor); // force reconnect
|
||||||
m_interface->subscribe({_sensor});
|
if (!m_subscribed.contains(_sensor)) {
|
||||||
|
m_interface->subscribe({_sensor}).waitForFinished();
|
||||||
|
m_subscribed.insert(_sensor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -115,9 +129,10 @@ void AWDataEngineAggregator::sensorRemoved(const QString &_sensor)
|
|||||||
qCDebug(LOG_AW) << "Sensor" << _sensor << "has been removed";
|
qCDebug(LOG_AW) << "Sensor" << _sensor << "has been removed";
|
||||||
|
|
||||||
m_sensors.remove(_sensor);
|
m_sensors.remove(_sensor);
|
||||||
m_interface->unsubscribe({_sensor});
|
dropSource(_sensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWDataEngineAggregator::updateData(KSysGuard::SensorDataList _data)
|
void AWDataEngineAggregator::updateData(KSysGuard::SensorDataList _data)
|
||||||
{
|
{
|
||||||
emit(dataUpdated(m_sensors, _data));
|
emit(dataUpdated(m_sensors, _data));
|
||||||
|
@ -15,9 +15,7 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
#ifndef AWDATAENGINEAGGREGATOR_H
|
|
||||||
#define AWDATAENGINEAGGREGATOR_H
|
|
||||||
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
#include <ksysguard/systemstats/SensorInfo.h>
|
||||||
|
|
||||||
@ -31,7 +29,6 @@ namespace KSysGuard::SystemStats
|
|||||||
class DBusInterface;
|
class DBusInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class AWDataEngineAggregator : public QObject
|
class AWDataEngineAggregator : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -39,10 +36,10 @@ class AWDataEngineAggregator : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit AWDataEngineAggregator(QObject *_parent = nullptr);
|
explicit AWDataEngineAggregator(QObject *_parent = nullptr);
|
||||||
~AWDataEngineAggregator() override;
|
~AWDataEngineAggregator() override;
|
||||||
|
void connectSources();
|
||||||
void disconnectSources();
|
void disconnectSources();
|
||||||
[[nodiscard]] bool isValidSensor(const KSysGuard::SensorInfo &_sensor);
|
[[nodiscard]] static bool isValidSensor(const KSysGuard::SensorInfo &_sensor);
|
||||||
void loadSources();
|
void loadSources();
|
||||||
void reconnectSources(const int interval);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data);
|
void dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data);
|
||||||
@ -58,7 +55,5 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
KSysGuard::SystemStats::DBusInterface *m_interface = nullptr;
|
KSysGuard::SystemStats::DBusInterface *m_interface = nullptr;
|
||||||
QHash<QString, KSysGuard::SensorInfo> m_sensors;
|
QHash<QString, KSysGuard::SensorInfo> m_sensors;
|
||||||
|
QSet<QString> m_subscribed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* AWDATAENGINEAGGREGATOR_H */
|
|
||||||
|
@ -347,7 +347,8 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
|||||||
// gb
|
// gb
|
||||||
m_map.insert(_source, "swapgb");
|
m_map.insert(_source, "swapgb");
|
||||||
m_formatter["swapgb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
m_formatter["swapgb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||||
} else if (_source.startsWith("lmsensors/") || _source.contains(cpuTempRegExp) || _source == "cpu/all/averageTemperature") {
|
} else if (_source.startsWith("lmsensors/") || _source.contains(cpuTempRegExp)
|
||||||
|
|| _source == "cpu/all/averageTemperature") {
|
||||||
// temperature
|
// temperature
|
||||||
auto index = m_devices["temp"].indexOf(_source);
|
auto index = m_devices["temp"].indexOf(_source);
|
||||||
// HACK on DE initialization there are no units key
|
// HACK on DE initialization there are no units key
|
||||||
|
@ -314,7 +314,8 @@ void AWKeyOperations::addDevice(const QString &_source)
|
|||||||
QString device = _source;
|
QString device = _source;
|
||||||
device.remove("partitions").remove("/filllevel");
|
device.remove("partitions").remove("/filllevel");
|
||||||
addKeyToCache("mount", device);
|
addKeyToCache("mount", device);
|
||||||
} else if (_source.startsWith("lmsensors") || _source.contains(cpuTempRegExp) || _source == "cpu/all/averageTemperature") {
|
} else if (_source.startsWith("lmsensors") || _source.contains(cpuTempRegExp)
|
||||||
|
|| _source == "cpu/all/averageTemperature") {
|
||||||
addKeyToCache("temp", _source);
|
addKeyToCache("temp", _source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,8 @@ AWKeys::AWKeys(QObject *_parent)
|
|||||||
connect(m_timer, &QTimer::timeout, this, &AWKeys::updateTextData);
|
connect(m_timer, &QTimer::timeout, this, &AWKeys::updateTextData);
|
||||||
|
|
||||||
// transfer signal from AWDataAggregator object to QML ui
|
// transfer signal from AWDataAggregator object to QML ui
|
||||||
connect(m_dataAggregator, &AWDataAggregator::toolTipPainted, [this](const QString &_tooltip) { emit(needToolTipToBeUpdated(_tooltip)); });
|
connect(m_dataAggregator, &AWDataAggregator::toolTipPainted,
|
||||||
|
[this](const QString &_tooltip) { emit(needToolTipToBeUpdated(_tooltip)); });
|
||||||
|
|
||||||
connect(this, &AWKeys::dropSourceFromDataengine, m_dataEngineAggregator, &AWDataEngineAggregator::dropSource);
|
connect(this, &AWKeys::dropSourceFromDataengine, m_dataEngineAggregator, &AWDataEngineAggregator::dropSource);
|
||||||
connect(m_dataEngineAggregator, &AWDataEngineAggregator::dataUpdated, this, &AWKeys::dataUpdated);
|
connect(m_dataEngineAggregator, &AWDataEngineAggregator::dataUpdated, this, &AWKeys::dataUpdated);
|
||||||
@ -102,7 +103,6 @@ void AWKeys::initKeys(const QString &_currentPattern, const int _interval, const
|
|||||||
m_aggregator->initFormatters();
|
m_aggregator->initFormatters();
|
||||||
m_keyOperator->setPattern(_currentPattern);
|
m_keyOperator->setPattern(_currentPattern);
|
||||||
m_keyOperator->updateCache();
|
m_keyOperator->updateCache();
|
||||||
m_dataEngineAggregator->reconnectSources(_interval);
|
|
||||||
|
|
||||||
// timer
|
// timer
|
||||||
m_timer->setInterval(_interval);
|
m_timer->setInterval(_interval);
|
||||||
|
@ -67,7 +67,6 @@ void ExtSysMonSensor::update()
|
|||||||
continue; // skip properties which are not explicitly subscribed
|
continue; // skip properties which are not explicitly subscribed
|
||||||
|
|
||||||
auto value = m_source->data(source);
|
auto value = m_source->data(source);
|
||||||
qCWarning(LOG_ESS) << source << value;
|
|
||||||
property->setValue(value);
|
property->setValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ NetworkSource::~NetworkSource()
|
|||||||
|
|
||||||
QVariant NetworkSource::data(const QString &_source)
|
QVariant NetworkSource::data(const QString &_source)
|
||||||
{
|
{
|
||||||
qCWarning(LOG_ESS) << "Source" << _source;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
if (!m_values.contains(_source))
|
if (!m_values.contains(_source))
|
||||||
run();
|
run();
|
||||||
@ -82,8 +82,10 @@ KSysGuard::SensorInfo *NetworkSource::initialData(const QString &_source) const
|
|||||||
void NetworkSource::run()
|
void NetworkSource::run()
|
||||||
{
|
{
|
||||||
m_values["device"] = NetworkSource::getCurrentDevice();
|
m_values["device"] = NetworkSource::getCurrentDevice();
|
||||||
|
if (m_process->state() == QProcess::ProcessState::NotRunning) {
|
||||||
m_process->start("iwgetid", {"-r"});
|
m_process->start("iwgetid", {"-r"});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList NetworkSource::sources() const
|
QStringList NetworkSource::sources() const
|
||||||
|
@ -49,12 +49,10 @@ QVariant WeatherSource::data(const QString &_source)
|
|||||||
|
|
||||||
int ind = index(_source);
|
int ind = index(_source);
|
||||||
if (!m_values.contains(_source)) {
|
if (!m_values.contains(_source)) {
|
||||||
QVariantHash data = m_extWeather->itemByTagNumber(ind)->run();
|
auto data = m_extWeather->itemByTagNumber(ind)->run();
|
||||||
for (auto &key : data.keys())
|
m_values.insert(data);
|
||||||
m_values[key] = data[key];
|
|
||||||
}
|
}
|
||||||
QVariant value = m_values.take(_source);
|
return m_values.take(_source);
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -94,7 +92,7 @@ KSysGuard::SensorInfo *WeatherSource::initialData(const QString &_source) const
|
|||||||
data->unit = KSysGuard::UnitCelsius;
|
data->unit = KSysGuard::UnitCelsius;
|
||||||
} else if (_source.startsWith("timestamp")) {
|
} else if (_source.startsWith("timestamp")) {
|
||||||
data->name = QString("Timestamp for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
data->name = QString("Timestamp for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||||
data->variantType = QVariant::String;
|
data->variantType = QVariant::DateTime;
|
||||||
data->unit = KSysGuard::UnitNone;
|
data->unit = KSysGuard::UnitNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user