Commit 7183f68e authored by David Redondo's avatar David Redondo 🏎
Browse files

Restart the daemon if it is stopped

If a client is requesting data and the daemon is stopped for whatever reason,
the client will try to restart it with new call to subscribe.

(cherry picked from commit a1492cb5)
(cherry picked from commit abf848dd)
(cherry picked from commit 53b72e79)
(cherry picked from commit 70ced775)
(cherry picked from commit e905e516)
parent 21c40913
......@@ -29,7 +29,8 @@ class SensorDaemonInterface::Private
{
public:
std::unique_ptr<org::kde::KSysGuardDaemon> dbusInterface;
std::unique_ptr<QDBusServiceWatcher> serviceWatcher;
QStringList subscribedSensors;
static const QString SensorServiceName;
static const QString SensorPath;
};
......@@ -46,12 +47,19 @@ SensorDaemonInterface::SensorDaemonInterface(QObject *parent)
qDBusRegisterMetaType<SensorDataList>();
qDBusRegisterMetaType<SensorInfoMap>();
d->dbusInterface = std::make_unique<org::kde::KSysGuardDaemon>(Private::SensorServiceName, Private::SensorPath, QDBusConnection::sessionBus());
d->serviceWatcher = std::make_unique<QDBusServiceWatcher>(d->SensorServiceName, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration);
connect(d->serviceWatcher.get(), &QDBusServiceWatcher::serviceUnregistered, this, &SensorDaemonInterface::reconnect);
reconnect();
}
void KSysGuard::SensorDaemonInterface::reconnect()
{
d->dbusInterface = std::make_unique<org::kde::KSysGuardDaemon>(Private::SensorServiceName, Private::SensorPath, QDBusConnection::sessionBus());
connect(d->dbusInterface.get(), &org::kde::KSysGuardDaemon::sensorMetaDataChanged, this, &SensorDaemonInterface::onMetaDataChanged);
connect(d->dbusInterface.get(), &org::kde::KSysGuardDaemon::newSensorData, this, &SensorDaemonInterface::onValueChanged);
connect(d->dbusInterface.get(), &org::kde::KSysGuardDaemon::sensorAdded, this, &SensorDaemonInterface::sensorAdded);
connect(d->dbusInterface.get(), &org::kde::KSysGuardDaemon::sensorRemoved, this, &SensorDaemonInterface::sensorRemoved);
subscribe(d->subscribedSensors);
}
SensorDaemonInterface::~SensorDaemonInterface()
......@@ -112,6 +120,7 @@ void SensorDaemonInterface::subscribe(const QString &sensorId)
void KSysGuard::SensorDaemonInterface::subscribe(const QStringList &sensorIds)
{
d->dbusInterface->subscribe(sensorIds);
d->subscribedSensors.append(sensorIds);
}
void SensorDaemonInterface::unsubscribe(const QString &sensorId)
......
......@@ -62,6 +62,7 @@ public:
private:
void onMetaDataChanged(const QHash<QString, SensorInfo> &metaData);
void onValueChanged(const SensorDataList &values);
void reconnect();
class Private;
const std::unique_ptr<Private> d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment