diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-04-16 17:32:21 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-22 12:01:36 +0200 |
commit | c71404f34cc6a2fa6b52ab7adcfc72f8fa795b0e (patch) | |
tree | 72827524f0bb26d2819a1fb13fd8b527fcdc8ae4 | |
parent | 8a52d4bd4f2cf1d9a44cd1f95ad3e2d8da4c132b (diff) | |
download | qtconnectivity-c71404f34cc6a2fa6b52ab7adcfc72f8fa795b0e.tar.gz |
Bluez4: Fix incorrect list of connected devices in QBluetoothLocalDevice
ConnectionChange signals were never emitted for
remote devices which already existed at class instanciation time.
At the same time this patch removes the delayed creation of the
connectedDevices set. This simplifies the code and the caching did
not save much effort.
Task-number: QTBUG-38402
Change-Id: Ic871f919435c0d42ce2d79fd54f0da693816010a
Reviewed-by: Oleg Shparber <trollixx@gmail.com>
Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_bluez.cpp | 41 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_p.h | 2 |
2 files changed, 18 insertions, 25 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index 9f2e7fd3..ac694f34 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -347,7 +347,7 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet } QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress address) - : adapter(0), agent(0), localAddress(address), pendingHostModeChange(-1), msgConnection(0), q_ptr(q), connectedCached(false) + : adapter(0), agent(0), localAddress(address), pendingHostModeChange(-1), msgConnection(0), q_ptr(q) { initializeAdapter(); connectDeviceChanges(); @@ -356,6 +356,7 @@ QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice void QBluetoothLocalDevicePrivate::connectDeviceChanges() { if (adapter) { //invalid QBluetoothLocalDevice due to wrong local adapter address + createCache(); connect(adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(PropertyChanged(QString,QDBusVariant))); connect(adapter, SIGNAL(DeviceCreated(QDBusObjectPath)), SLOT(_q_deviceCreated(QDBusObjectPath))); connect(adapter, SIGNAL(DeviceRemoved(QDBusObjectPath)), SLOT(_q_deviceRemoved(QDBusObjectPath))); @@ -438,7 +439,7 @@ void QBluetoothLocalDevicePrivate::RequestConfirmation(const QDBusObjectPath &in void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &device) { OrgBluezDeviceInterface *deviceInterface = - new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus()); + new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus(), this); connect(deviceInterface, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(_q_devicePropertyChanged(QString,QDBusVariant))); devices << deviceInterface; QDBusPendingReply<QVariantMap> properties = deviceInterface->asyncCall(QLatin1String("GetProperties")); @@ -451,16 +452,13 @@ void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &devic const QBluetoothAddress address = QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString()); const bool connected = properties.value().value(QLatin1String("Connected")).toBool(); - if (connectedCached) { - if (connected) - connectedDevicesSet.insert(address); - else - connectedDevicesSet.remove(address); - } - if (connected) + if (connected) { + connectedDevicesSet.insert(address); emit q_ptr->deviceConnected(address); - else + } else { + connectedDevicesSet.remove(address); emit q_ptr->deviceDisconnected(address); + } } void QBluetoothLocalDevicePrivate::_q_deviceRemoved(const QDBusObjectPath &device) @@ -488,16 +486,13 @@ void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &prope const QBluetoothAddress address = QBluetoothAddress(properties.value(QLatin1String("Address")).toString()); const bool connected = value.variant().toBool(); - if (connectedCached) { - if (connected) - connectedDevicesSet.insert(address); - else - connectedDevicesSet.remove(address); - } - if (connected) + if (connected) { + connectedDevicesSet.insert(address); emit q_ptr->deviceConnected(address); - else + } else { + connectedDevicesSet.remove(address); emit q_ptr->deviceDisconnected(address); + } } } @@ -513,9 +508,12 @@ void QBluetoothLocalDevicePrivate::createCache() return; } foreach (const QDBusObjectPath &device, reply.value()) { - OrgBluezDeviceInterface deviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus()); + OrgBluezDeviceInterface *deviceInterface = + new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus(), this); + connect(deviceInterface, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(_q_devicePropertyChanged(QString,QDBusVariant))); + devices << deviceInterface; - QDBusPendingReply<QVariantMap> properties = deviceInterface.asyncCall(QLatin1String("GetProperties")); + QDBusPendingReply<QVariantMap> properties = deviceInterface->asyncCall(QLatin1String("GetProperties")); properties.waitForFinished(); if (!properties.isValid()) { qCWarning(QT_BT_BLUEZ) << "Unable to get properties for device " << device.path(); @@ -525,13 +523,10 @@ void QBluetoothLocalDevicePrivate::createCache() if (properties.value().value(QLatin1String("Connected")).toBool()) connectedDevicesSet.insert(QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString())); } - connectedCached = true; } QList<QBluetoothAddress> QBluetoothLocalDevicePrivate::connectedDevices() const { - if (!connectedCached) - const_cast<QBluetoothLocalDevicePrivate *>(this)->createCache(); return connectedDevicesSet.toList(); } diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h index 61527d31..f00c33bf 100644 --- a/src/bluetooth/qbluetoothlocaldevice_p.h +++ b/src/bluetooth/qbluetoothlocaldevice_p.h @@ -168,8 +168,6 @@ private: QBluetoothLocalDevice *q_ptr; - bool connectedCached; - void initializeAdapter(); }; |