Commit a1492cb5 authored by David Redondo's avatar David Redondo 🏎

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.
parent 90548f3e
......@@ -29,7 +29,8 @@ class SensorDaemonInterface::Private
{
public:
std::unique_ptr<org::kde::KSysGuardDaemon> dbusInterface;
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 = new QDBusServiceWatcher(d->SensorServiceName, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration, this);
connect(d->serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &SensorDaemonInterface::reconnect);
reconnect();
}
void KSysGuard::SensorDaemonInterface::reconnect()
{
d->dbusInterface.reset(new 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