diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-05-21 17:32:33 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-26 10:53:39 +0200 |
commit | 552f1a164d627720942414915fb56ae7d3b7ef22 (patch) | |
tree | 3f54608415bff6eee77cf916fe17eaeb1e00223c /src/bluetooth/qbluetoothsocket_bluez.cpp | |
parent | 01047d81fa213886a0784ff2ef567c99136f6ac7 (diff) |
Port QBluetoothSocket/QBluetoothServer to Bluez 5
Task-number: QTBUG-32085
Change-Id: I9fe63f3291a10a195d460720cd1821913a63b25b
Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src/bluetooth/qbluetoothsocket_bluez.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluez.cpp | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index c3c51e45..31a5535c 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -45,6 +45,9 @@ #include "bluez/manager_p.h" #include "bluez/adapter_p.h" #include "bluez/device_p.h" +#include "bluez/bluez5_helper_p.h" +#include "bluez/objectmanager_p.h" +#include <QtBluetooth/QBluetoothLocalDevice> #include <qplatformdefs.h> @@ -271,23 +274,8 @@ QString QBluetoothSocketPrivate::localName() const if (address.isNull()) return QString(); - OrgBluezManagerInterface manager(QStringLiteral("org.bluez"), QStringLiteral("/"), - QDBusConnection::systemBus()); - - QDBusPendingReply<QDBusObjectPath> reply = manager.FindAdapter(address.toString()); - reply.waitForFinished(); - if (reply.isError()) - return QString(); - - OrgBluezAdapterInterface adapter(QStringLiteral("org.bluez"), reply.value().path(), - QDBusConnection::systemBus()); - - QDBusPendingReply<QVariantMap> properties = adapter.GetProperties(); - properties.waitForFinished(); - if (properties.isError()) - return QString(); - - return properties.value().value(QStringLiteral("Name")).toString(); + QBluetoothLocalDevice device(address); + return device.name(); } QBluetoothAddress QBluetoothSocketPrivate::localAddress() const @@ -362,38 +350,60 @@ QString QBluetoothSocketPrivate::peerName() const const QString peerAddress = QBluetoothAddress(bdaddr).toString(); const QString localAdapter = localAddress().toString(); - OrgBluezManagerInterface manager(QStringLiteral("org.bluez"), QStringLiteral("/"), - QDBusConnection::systemBus()); + if (isBluez5()) { + OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"), + QStringLiteral("/"), + QDBusConnection::systemBus()); + QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects(); + reply.waitForFinished(); + if (reply.isError()) + return QString(); - QDBusPendingReply<QDBusObjectPath> reply = manager.FindAdapter(localAdapter); - reply.waitForFinished(); - if (reply.isError()) + foreach (const QDBusObjectPath &path, reply.value().keys()) { + const InterfaceList ifaceList = reply.value().value(path); + foreach (const QString &iface, ifaceList.keys()) { + if (iface == QStringLiteral("org.bluez.Device1")) { + if (ifaceList.value(iface).value(QStringLiteral("Address")).toString() + == peerAddress) + return ifaceList.value(iface).value(QStringLiteral("Alias")).toString(); + } + } + } return QString(); + } else { + OrgBluezManagerInterface manager(QStringLiteral("org.bluez"), QStringLiteral("/"), + QDBusConnection::systemBus()); - OrgBluezAdapterInterface adapter(QStringLiteral("org.bluez"), reply.value().path(), - QDBusConnection::systemBus()); - - QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter.CreateDevice(peerAddress); - deviceObjectPath.waitForFinished(); - if (deviceObjectPath.isError()) { - if (deviceObjectPath.error().name() != QStringLiteral("org.bluez.Error.AlreadyExists")) + QDBusPendingReply<QDBusObjectPath> reply = manager.FindAdapter(localAdapter); + reply.waitForFinished(); + if (reply.isError()) return QString(); - deviceObjectPath = adapter.FindDevice(peerAddress); + OrgBluezAdapterInterface adapter(QStringLiteral("org.bluez"), reply.value().path(), + QDBusConnection::systemBus()); + + QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter.CreateDevice(peerAddress); deviceObjectPath.waitForFinished(); - if (deviceObjectPath.isError()) - return QString(); - } + if (deviceObjectPath.isError()) { + if (deviceObjectPath.error().name() != QStringLiteral("org.bluez.Error.AlreadyExists")) + return QString(); + + deviceObjectPath = adapter.FindDevice(peerAddress); + deviceObjectPath.waitForFinished(); + if (deviceObjectPath.isError()) + return QString(); + } - OrgBluezDeviceInterface device(QStringLiteral("org.bluez"), deviceObjectPath.value().path(), - QDBusConnection::systemBus()); + OrgBluezDeviceInterface device(QStringLiteral("org.bluez"), deviceObjectPath.value().path(), + QDBusConnection::systemBus()); - QDBusPendingReply<QVariantMap> properties = device.GetProperties(); - properties.waitForFinished(); - if (properties.isError()) - return QString(); + QDBusPendingReply<QVariantMap> properties = device.GetProperties(); + properties.waitForFinished(); + if (properties.isError()) + return QString(); - return properties.value().value(QStringLiteral("Alias")).toString(); + return properties.value().value(QStringLiteral("Alias")).toString(); + } } QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const |