Only deletes dbus interfaces for the same device that had created it.
This commit is contained in:
parent
208c11de1a
commit
38aa9704a7
2 changed files with 8 additions and 6 deletions
|
@ -24,7 +24,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <core/device.h>
|
#include <core/device.h>
|
||||||
|
|
||||||
BatteryDbusInterface *BatteryDbusInterface::s_currentInterface = 0;
|
QMap<QString, BatteryDbusInterface *> BatteryDbusInterface::s_dbusInterfaces;
|
||||||
|
|
||||||
BatteryDbusInterface::BatteryDbusInterface(const Device *device)
|
BatteryDbusInterface::BatteryDbusInterface(const Device *device)
|
||||||
: QDBusAbstractAdaptor(const_cast<Device*>(device))
|
: QDBusAbstractAdaptor(const_cast<Device*>(device))
|
||||||
|
@ -35,12 +35,13 @@ BatteryDbusInterface::BatteryDbusInterface(const Device *device)
|
||||||
// This makes the old BatteryDdbusInterface be deleted only after the new one is
|
// This makes the old BatteryDdbusInterface be deleted only after the new one is
|
||||||
// fully operational. That seems to prevent the crash mentioned in BatteryPlugin's
|
// fully operational. That seems to prevent the crash mentioned in BatteryPlugin's
|
||||||
// destructor.
|
// destructor.
|
||||||
if (s_currentInterface) {
|
QMap<QString, BatteryDbusInterface *>::iterator oldInterfaceIter = s_dbusInterfaces.find(device->id());
|
||||||
qCDebug(KDECONNECT_PLUGIN_BATTERY) << "Deleting stale BattteryDbusInterface object.";
|
if (oldInterfaceIter != s_dbusInterfaces.end()) {
|
||||||
s_currentInterface->deleteLater();
|
qCDebug(KDECONNECT_PLUGIN_BATTERY) << "Deleting stale BattteryDbusInterface for" << device->name();
|
||||||
|
oldInterfaceIter.value()->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
s_currentInterface = this;
|
s_dbusInterfaces[device->id()] = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
BatteryDbusInterface::~BatteryDbusInterface()
|
BatteryDbusInterface::~BatteryDbusInterface()
|
||||||
|
|
|
@ -48,7 +48,8 @@ private:
|
||||||
int mCharge;
|
int mCharge;
|
||||||
bool mIsCharging;
|
bool mIsCharging;
|
||||||
|
|
||||||
static BatteryDbusInterface *s_currentInterface;
|
// Map to save current BatteryDbusInterface for each device.
|
||||||
|
static QMap<QString, BatteryDbusInterface *> s_dbusInterfaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue