From 38aa9704a70113aa23093cfb64127cef863f69a6 Mon Sep 17 00:00:00 2001 From: "Lamarque V. Souza" Date: Sat, 18 Jul 2015 16:36:58 -0300 Subject: [PATCH] Only deletes dbus interfaces for the same device that had created it. --- plugins/battery/batterydbusinterface.cpp | 11 ++++++----- plugins/battery/batterydbusinterface.h | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/battery/batterydbusinterface.cpp b/plugins/battery/batterydbusinterface.cpp index 950de73f0..9e06c30c2 100644 --- a/plugins/battery/batterydbusinterface.cpp +++ b/plugins/battery/batterydbusinterface.cpp @@ -24,7 +24,7 @@ #include #include -BatteryDbusInterface *BatteryDbusInterface::s_currentInterface = 0; +QMap BatteryDbusInterface::s_dbusInterfaces; BatteryDbusInterface::BatteryDbusInterface(const Device *device) : QDBusAbstractAdaptor(const_cast(device)) @@ -35,12 +35,13 @@ BatteryDbusInterface::BatteryDbusInterface(const Device *device) // 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 // destructor. - if (s_currentInterface) { - qCDebug(KDECONNECT_PLUGIN_BATTERY) << "Deleting stale BattteryDbusInterface object."; - s_currentInterface->deleteLater(); + QMap::iterator oldInterfaceIter = s_dbusInterfaces.find(device->id()); + if (oldInterfaceIter != s_dbusInterfaces.end()) { + qCDebug(KDECONNECT_PLUGIN_BATTERY) << "Deleting stale BattteryDbusInterface for" << device->name(); + oldInterfaceIter.value()->deleteLater(); } - s_currentInterface = this; + s_dbusInterfaces[device->id()] = this; } BatteryDbusInterface::~BatteryDbusInterface() diff --git a/plugins/battery/batterydbusinterface.h b/plugins/battery/batterydbusinterface.h index 434bed2d6..01d4ef7d5 100644 --- a/plugins/battery/batterydbusinterface.h +++ b/plugins/battery/batterydbusinterface.h @@ -48,7 +48,8 @@ private: int mCharge; bool mIsCharging; - static BatteryDbusInterface *s_currentInterface; + // Map to save current BatteryDbusInterface for each device. + static QMap s_dbusInterfaces; }; #endif