Fixed crash: OMG QDbusAdaptors can not be removed!

Added a fixme for future reference
reloadPlugins() now recycles plugins already present
Lots of debug messages and minor changes added trying to fix the bug
This commit is contained in:
Albert Vaca 2013-08-14 01:35:12 +02:00
parent 2a1996cbf7
commit 0f38eb34a4
9 changed files with 64 additions and 35 deletions

View file

@ -68,9 +68,9 @@ bool Device::hasPlugin(const QString& name)
void Device::reloadPlugins()
{
QMap< QString, KdeConnectPlugin* > newPluginMap;
qDeleteAll(m_plugins);
m_plugins.clear();
if (paired()) { //Do not load any plugin for unpaired devices
QString path = KStandardDirs().resourceDirs("config").first()+"kdeconnect/";
QMap<QString,QString> pluginStates = KSharedConfig::openConfig(path + id())->group("Plugins").entryMap();
@ -84,20 +84,30 @@ void Device::reloadPlugins()
KPluginInfo info = loader->getPluginInfo(pluginName);
bool enabled = (value.isNull() ? info.isPluginEnabledByDefault() : QVariant(value).toBool());
qDebug() << pluginName << "enabled:" << enabled;
if (enabled) {
if (m_plugins.contains(pluginName)) {
//Already loaded, reuse it
newPluginMap[pluginName] = m_plugins[pluginName];
m_plugins.remove(pluginName);
} else {
KdeConnectPlugin* plugin = loader->instantiatePluginForDevice(pluginName, this);
connect(this, SIGNAL(receivedPackage(const NetworkPackage&)),
plugin, SLOT(receivePackage(const NetworkPackage&)));
// connect(plugin, SIGNAL(sendPackage(const NetworkPackage&)),
// device, SLOT(sendPackage(const NetworkPackage&)));
m_plugins[pluginName] = plugin;
newPluginMap[pluginName] = plugin;
}
}
}
}
//Erase all the plugins left in the original map (it means that we don't want
//them anymore, otherways they would have been moved to the newPluginMap)
qDeleteAll(m_plugins);
m_plugins.clear();
m_plugins = newPluginMap;
Q_EMIT pluginsChanged();
@ -106,7 +116,6 @@ void Device::reloadPlugins()
void Device::setPair(bool b)
{
qDebug() << "setPair" << b;
m_paired = b;
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
if (b) {
@ -116,6 +125,7 @@ void Device::setPair(bool b)
qDebug() << name() << "unpaired";
config->group("devices").group("paired").deleteGroup(id());
}
reloadPlugins();
}
static bool lessThan(DeviceLink* p1, DeviceLink* p2)

View file

@ -25,7 +25,11 @@
BatteryDbusInterface::BatteryDbusInterface(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
}
BatteryDbusInterface::~BatteryDbusInterface()
{
qDebug() << "Destroying BatteryDbusInterface";
}
void BatteryDbusInterface::updateValues(bool isCharging, int currentCharge)

View file

@ -33,6 +33,7 @@ class BatteryDbusInterface
public:
explicit BatteryDbusInterface(QObject *parent);
virtual ~BatteryDbusInterface();
int charge() { return mCharge; }
bool isCharging() { return mIsCharging; }

View file

@ -32,6 +32,7 @@ K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_battery", "kdeconnect_batte
BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args)
: KdeConnectPlugin(parent, args)
{
batteryDbusInterface = new BatteryDbusInterface(parent);
NetworkPackage np(PACKAGE_TYPE_BATTERY);
@ -42,7 +43,14 @@ BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args)
BatteryPlugin::~BatteryPlugin()
{
batteryDbusInterface->deleteLater();
//FIXME: Qt dbus does not allow to remove an adaptor! (it causes a crash in
// the next access to device via dbus). The implication of not deleting this
// is that disabling the plugin does not remove the interface (that will
// return outdated values) and that enabling it again instantiates a second
// adaptor. This is a partial memory leak (the memory will be freed when the
// device is destroyed anyway)
//batteryDbusInterface->deleteLater();
}
bool BatteryPlugin::receivePackage(const NetworkPackage& np)

View file

@ -12,4 +12,4 @@ X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=preferences-desktop-notification
Name=Notification sync
Comment=Show every notification in KDE and keep them in sync
Comment=Show phone notifications in KDE and keep them in sync

View file

@ -11,5 +11,5 @@ X-KDE-PluginInfo-Website=http://albertvaka.wordpress.com
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=speaker
Name=Pause music on call
Comment=Pause music during a phone call
Name=Pause media during calls
Comment=Pause music/videos during a phone call

View file

@ -33,6 +33,11 @@ PingPlugin::PingPlugin(QObject* parent, const QVariantList& args)
qDebug() << "Ping plugin constructor for device" << device()->name();
}
PingPlugin::~PingPlugin()
{
qDebug() << "Ping plugin destructor for device" << device()->name();
}
bool PingPlugin::receivePackage(const NetworkPackage& np)
{

View file

@ -32,6 +32,7 @@ class KDE_EXPORT PingPlugin
public:
explicit PingPlugin(QObject *parent, const QVariantList &args);
virtual ~PingPlugin();
public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np);

View file

@ -12,4 +12,4 @@ X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=call-start
Name=Telephony integration
Comment=Currently it only shows notifications for calls and SMS
Comment=Show notifications for calls and SMS (answering coming soon)