summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-05-26 14:56:49 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-05-26 14:56:49 +0200
commitf334ea4b196950c4074e7513626aabeef3d99d7f (patch)
treeccb07d59afbb60a92b80a061645c8013aab9b96c /src
parent3910d9ffcc11db7b3beb7f2b6f0c1754103cfacb (diff)
parent552f1a164d627720942414915fb56ae7d3b7ef22 (diff)
Merge branch 'dev' into btle
Conflicts: examples/bluetooth/bluetooth.pro src/bluetooth/bluez/bluez.pri src/bluetooth/doc/src/bluetooth-index.qdoc src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp src/bluetooth/qbluetoothdeviceinfo.cpp src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp src/bluetooth/qbluetoothservicediscoveryagent_p.h src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp Change-Id: I88b22c51a4ee95b067ef8d2b2fddb5cbff4566f8
Diffstat (limited to 'src')
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java52
-rw-r--r--src/bluetooth/android/servicediscoverybroadcastreceiver.cpp6
-rw-r--r--src/bluetooth/bluetooth.pro6
-rw-r--r--src/bluetooth/bluez/adapter1_bluez5.cpp26
-rw-r--r--src/bluetooth/bluez/adapter1_bluez5_p.h126
-rw-r--r--src/bluetooth/bluez/bluez.pri14
-rw-r--r--src/bluetooth/bluez/bluez5_helper.cpp460
-rw-r--r--src/bluetooth/bluez/bluez5_helper_p.h93
-rw-r--r--src/bluetooth/bluez/device1_bluez5.cpp26
-rw-r--r--src/bluetooth/bluez/device1_bluez5_p.h151
-rw-r--r--src/bluetooth/bluez/objectmanager.cpp26
-rw-r--r--src/bluetooth/bluez/objectmanager_p.h58
-rw-r--r--src/bluetooth/bluez/org.bluez.Adapter1.xml23
-rw-r--r--src/bluetooth/bluez/org.bluez.Device1.xml31
-rw-r--r--src/bluetooth/bluez/org.freedesktop.dbus.objectmanager.xml19
-rw-r--r--src/bluetooth/bluez/org.freedesktop.dbus.properties.xml27
-rw-r--r--src/bluetooth/bluez/properties.cpp26
-rw-r--r--src/bluetooth/bluez/properties_p.h71
-rw-r--r--src/bluetooth/doc/qtbluetooth.qdocconf2
-rw-r--r--src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp34
-rw-r--r--src/bluetooth/doc/src/bluetooth-index.qdoc22
-rw-r--r--src/bluetooth/doc/src/bluetooth-overview.qdoc4
-rw-r--r--src/bluetooth/doc/src/examples.qdoc14
-rw-r--r--src/bluetooth/qbluetooth.cpp1
-rw-r--r--src/bluetooth/qbluetooth.h19
-rw-r--r--src/bluetooth/qbluetoothaddress.cpp33
-rw-r--r--src/bluetooth/qbluetoothaddress.h9
-rw-r--r--src/bluetooth/qbluetoothaddress_p.h2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.cpp31
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.h14
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp46
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp352
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp7
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.h38
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp78
-rw-r--r--src/bluetooth/qbluetoothdeviceinfo.cpp36
-rw-r--r--src/bluetooth/qbluetoothdeviceinfo.h3
-rw-r--r--src/bluetooth/qbluetoothhostinfo.cpp8
-rw-r--r--src/bluetooth/qbluetoothhostinfo.h1
-rw-r--r--src/bluetooth/qbluetoothhostinfo_p.h4
-rw-r--r--src/bluetooth/qbluetoothlocaldevice.cpp21
-rw-r--r--src/bluetooth/qbluetoothlocaldevice.h7
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_android.cpp233
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_bluez.cpp997
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_p.cpp10
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_p.h51
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_qnx.cpp115
-rw-r--r--src/bluetooth/qbluetoothserver_p.h8
-rw-r--r--src/bluetooth/qbluetoothserver_qnx.cpp61
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp26
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.h1
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_android.cpp133
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp474
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_p.cpp4
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_p.h17
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp19
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_bluez.cpp94
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_qnx.cpp31
-rw-r--r--src/bluetooth/qbluetoothsocket.cpp9
-rw-r--r--src/bluetooth/qbluetoothsocket_android.cpp9
-rw-r--r--src/bluetooth/qbluetoothsocket_bluez.cpp115
-rw-r--r--src/bluetooth/qbluetoothsocket_p.h6
-rw-r--r--src/bluetooth/qbluetoothsocket_qnx.cpp86
-rw-r--r--src/bluetooth/qbluetoothtransferreply.cpp2
-rw-r--r--src/bluetooth/qbluetoothtransferreply.h4
-rw-r--r--src/bluetooth/qbluetoothtransferreply_bluez.cpp18
-rw-r--r--src/bluetooth/qbluetoothtransferreply_bluez_p.h2
-rw-r--r--src/bluetooth/qbluetoothtransferreply_qnx.cpp76
-rw-r--r--src/bluetooth/qbluetoothtransferreply_qnx_p.h13
-rw-r--r--src/bluetooth/qbluetoothuuid.cpp127
-rw-r--r--src/bluetooth/qbluetoothuuid.h8
-rw-r--r--src/bluetooth/qnx/ppshelpers_p.h2
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp13
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothservice.cpp67
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothservice_p.h1
-rw-r--r--src/imports/bluetooth/qmldir1
-rw-r--r--src/imports/nfc/qdeclarativendeffilter.cpp2
-rw-r--r--src/imports/nfc/qmldir1
-rw-r--r--src/nfc/doc/src/nfc-index.qdoc9
-rw-r--r--src/nfc/qllcpserver_p.h2
-rw-r--r--src/nfc/qllcpsocket_p.h2
-rw-r--r--src/nfc/qllcpsocket_qnx_p.h4
-rw-r--r--src/nfc/qnearfieldmanager_qnx.cpp2
-rw-r--r--src/nfc/qnearfieldmanager_qnx_p.h2
-rw-r--r--src/nfc/qnearfieldsharemanager_qnx_p.h2
-rw-r--r--src/nfc/qnearfieldsharetarget_qnx_p.h2
-rw-r--r--src/nfc/qnearfieldtarget_emulator.cpp6
-rw-r--r--src/nfc/qnearfieldtarget_qnx_p.h12
-rw-r--r--src/nfc/qnx/qnxnfceventfilter.cpp2
-rw-r--r--src/nfc/qnx/qnxnfceventfilter_p.h2
-rw-r--r--src/nfc/qnx/qnxnfcmanager.cpp6
-rw-r--r--src/nfc/qnx/qnxnfcmanager_p.h4
-rw-r--r--src/nfc/qnx/qnxnfcsharemanager_p.h2
-rw-r--r--src/nfc/qqmlndefrecord.cpp6
-rw-r--r--src/nfc/targetemulator.cpp12
-rw-r--r--src/src.pro14
96 files changed, 3922 insertions, 1032 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java
index ba96c0cf..20dbd78f 100644
--- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java
@@ -49,7 +49,10 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.List;
public class QtBluetoothBroadcastReceiver extends BroadcastReceiver
{
@@ -126,4 +129,53 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver
return true;
}
+ /*
+ * Returns a list of remote devices confirmed to be connected.
+ *
+ * This list is not complete as it only detects GATT/BtLE related connections.
+ * Unfortunately there is no API that provides the complete list.
+ *
+ * The function uses Android API v11 & v18. We need to use reflection.
+ */
+ static public String[] getConnectedDevices()
+ {
+ try {
+ //Bluetooth service name
+ Field f = Context.class.getField("BLUETOOTH_SERVICE");
+ String serviceValueString = (String)f.get(qtactivity);
+
+ Class btProfileClz = Class.forName("android.bluetooth.BluetoothProfile");
+
+ //value of BluetoothProfile.GATT
+ f = btProfileClz.getField("GATT");
+ int gatt = f.getInt(null);
+
+ //value of BluetoothProfile.GATT_SERVER
+ f = btProfileClz.getField("GATT_SERVER");
+ int gattServer = f.getInt(null);
+
+ //get BluetoothManager instance
+ Object bluetoothManager = qtactivity.getSystemService(serviceValueString);
+
+ Class[] cArg = new Class[1];
+ cArg[0] = int.class;
+ Method m = bluetoothManager.getClass().getMethod("getConnectedDevices", cArg);
+
+ List gattConnections = (List) m.invoke(bluetoothManager, gatt);
+ List gattServerConnections = (List) m.invoke(bluetoothManager, gattServer);
+
+ //process found remote connections but avoid duplications
+ HashSet<String> set = new HashSet<String>();
+ for (int i = 0; i < gattConnections.size(); i++)
+ set.add(gattConnections.get(i).toString());
+
+ for (int i = 0; i < gattServerConnections.size(); i++)
+ set.add(gattServerConnections.get(i).toString());
+
+ return set.toArray(new String[set.size()]);
+ } catch (Exception ex) {
+ //API is less than 18
+ return new String[0];
+ }
+ }
}
diff --git a/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp b/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp
index 0a3f97f9..87564ce6 100644
--- a/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp
+++ b/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp
@@ -76,8 +76,10 @@ void ServiceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context,
"getParcelableArrayExtra",
"(Ljava/lang/String;)[Landroid/os/Parcelable;",
keyExtra.object<jstring>());
- if (!parcelableUuids.isValid())
+ if (!parcelableUuids.isValid()) {
+ emit uuidFetchFinished(QBluetoothAddress(), QList<QBluetoothUuid>());
return;
+ }
const QList<QBluetoothUuid> result = ServiceDiscoveryBroadcastReceiver::convertParcelableArray(parcelableUuids);
keyExtra = valueForStaticField(JavaNames::BluetoothDevice, JavaNames::ExtraDevice);
@@ -89,6 +91,8 @@ void ServiceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context,
if (bluetoothDevice.isValid()) {
address = QBluetoothAddress(bluetoothDevice.callObjectMethod<jstring>("getAddress").toString());
emit uuidFetchFinished(address, result);
+ } else {
+ emit uuidFetchFinished(QBluetoothAddress(), QList<QBluetoothUuid>());
}
}
}
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 2220ced1..b6b61ee6 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -90,6 +90,8 @@ config_bluez:qtHaveModule(dbus) {
qlowenergycharacteristicinfo_bluez.cpp \
qlowenergycontroller_bluez.cpp
+ CONFIG += link_pkgconfig
+ PKGCONFIG_PRIVATE += bluez
} else:CONFIG(blackberry) {
DEFINES += QT_QNX_BLUETOOTH
@@ -142,8 +144,8 @@ config_bluez:qtHaveModule(dbus) {
qlowenergycontroller_p.cpp
} else {
- message("Unsupported bluetooth platform, will not build a working QBluetooth library")
- message("Either no Qt dBus found or no Bluez headers")
+ message("Unsupported Bluetooth platform, will not build a working QtBluetooth library.")
+ message("Either no Qt D-Bus found or no BlueZ headers.")
SOURCES += \
qbluetoothdevicediscoveryagent_p.cpp \
qbluetoothlocaldevice_p.cpp \
diff --git a/src/bluetooth/bluez/adapter1_bluez5.cpp b/src/bluetooth/bluez/adapter1_bluez5.cpp
new file mode 100644
index 00000000..8de63d32
--- /dev/null
+++ b/src/bluetooth/bluez/adapter1_bluez5.cpp
@@ -0,0 +1,26 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -p adapter1 -v org.bluez.Adapter1.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * This file may have been hand-edited. Look for HAND-EDIT comments
+ * before re-generating it.
+ */
+
+#include "adapter1_bluez5_p.h"
+
+/*
+ * Implementation of interface class OrgBluezAdapter1Interface
+ */
+
+OrgBluezAdapter1Interface::OrgBluezAdapter1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+OrgBluezAdapter1Interface::~OrgBluezAdapter1Interface()
+{
+}
+
diff --git a/src/bluetooth/bluez/adapter1_bluez5_p.h b/src/bluetooth/bluez/adapter1_bluez5_p.h
new file mode 100644
index 00000000..32a70b3d
--- /dev/null
+++ b/src/bluetooth/bluez/adapter1_bluez5_p.h
@@ -0,0 +1,126 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -p adapter1 -v org.bluez.Adapter1.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * Do not edit! All changes made to it will be lost.
+ */
+
+#ifndef ADAPTER1_H_1396951555
+#define ADAPTER1_H_1396951555
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * Proxy class for interface org.bluez.Adapter1
+ */
+class OrgBluezAdapter1Interface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "org.bluez.Adapter1"; }
+
+public:
+ OrgBluezAdapter1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~OrgBluezAdapter1Interface();
+
+ Q_PROPERTY(QString Address READ address)
+ inline QString address() const
+ { return qvariant_cast< QString >(property("Address")); }
+
+ Q_PROPERTY(QString Alias READ alias WRITE setAlias)
+ inline QString alias() const
+ { return qvariant_cast< QString >(property("Alias")); }
+ inline void setAlias(const QString &value)
+ { setProperty("Alias", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(uint Class READ classProperty)
+ inline uint classProperty() const
+ { return qvariant_cast< uint >(property("Class")); }
+
+ Q_PROPERTY(bool Discoverable READ discoverable WRITE setDiscoverable)
+ inline bool discoverable() const
+ { return qvariant_cast< bool >(property("Discoverable")); }
+ inline void setDiscoverable(bool value)
+ { setProperty("Discoverable", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(uint DiscoverableTimeout READ discoverableTimeout WRITE setDiscoverableTimeout)
+ inline uint discoverableTimeout() const
+ { return qvariant_cast< uint >(property("DiscoverableTimeout")); }
+ inline void setDiscoverableTimeout(uint value)
+ { setProperty("DiscoverableTimeout", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(bool Discovering READ discovering)
+ inline bool discovering() const
+ { return qvariant_cast< bool >(property("Discovering")); }
+
+ Q_PROPERTY(QString Modalias READ modalias)
+ inline QString modalias() const
+ { return qvariant_cast< QString >(property("Modalias")); }
+
+ Q_PROPERTY(QString Name READ name)
+ inline QString name() const
+ { return qvariant_cast< QString >(property("Name")); }
+
+ Q_PROPERTY(bool Pairable READ pairable WRITE setPairable)
+ inline bool pairable() const
+ { return qvariant_cast< bool >(property("Pairable")); }
+ inline void setPairable(bool value)
+ { setProperty("Pairable", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(uint PairableTimeout READ pairableTimeout WRITE setPairableTimeout)
+ inline uint pairableTimeout() const
+ { return qvariant_cast< uint >(property("PairableTimeout")); }
+ inline void setPairableTimeout(uint value)
+ { setProperty("PairableTimeout", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(bool Powered READ powered WRITE setPowered)
+ inline bool powered() const
+ { return qvariant_cast< bool >(property("Powered")); }
+ inline void setPowered(bool value)
+ { setProperty("Powered", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(QStringList UUIDs READ uUIDs)
+ inline QStringList uUIDs() const
+ { return qvariant_cast< QStringList >(property("UUIDs")); }
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<> RemoveDevice(const QDBusObjectPath &device)
+ {
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(device);
+ return asyncCallWithArgumentList(QLatin1String("RemoveDevice"), argumentList);
+ }
+
+ inline QDBusPendingReply<> StartDiscovery()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("StartDiscovery"), argumentList);
+ }
+
+ inline QDBusPendingReply<> StopDiscovery()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("StopDiscovery"), argumentList);
+ }
+
+Q_SIGNALS: // SIGNALS
+};
+
+namespace org {
+ namespace bluez {
+ typedef ::OrgBluezAdapter1Interface Adapter1;
+ }
+}
+#endif
diff --git a/src/bluetooth/bluez/bluez.pri b/src/bluetooth/bluez/bluez.pri
index a4b597a0..0fa4e5c9 100644
--- a/src/bluetooth/bluez/bluez.pri
+++ b/src/bluetooth/bluez/bluez.pri
@@ -21,7 +21,12 @@ HEADERS += bluez/manager_p.h \
bluez/obex_agent_p.h \
bluez/obex_transfer_p.h \
bluez/obex_manager_p.h \
- bluez/characteristic_p.h
+ bluez/characteristic_p.h \
+ bluez/bluez5_helper_p.h \
+ bluez/objectmanager_p.h \
+ bluez/properties_p.h \
+ bluez/adapter1_bluez5_p.h \
+ bluez/device1_bluez5_p.h
SOURCES += bluez/manager.cpp \
@@ -34,4 +39,9 @@ SOURCES += bluez/manager.cpp \
bluez/obex_agent.cpp \
bluez/obex_transfer.cpp \
bluez/obex_manager.cpp \
- bluez/characteristic.cpp
+ bluez/characteristic.cpp \
+ bluez/objectmanager.cpp \
+ bluez/properties.cpp \
+ bluez/adapter1_bluez5.cpp \
+ bluez/device1_bluez5.cpp \
+ bluez/bluez5_helper.cpp
diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp
new file mode 100644
index 00000000..c995d948
--- /dev/null
+++ b/src/bluetooth/bluez/bluez5_helper.cpp
@@ -0,0 +1,460 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QGlobalStatic>
+#include <QtCore/QLoggingCategory>
+#include <QtCore/QMap>
+#include "bluez5_helper_p.h"
+#include "objectmanager_p.h"
+#include "properties_p.h"
+#include "adapter1_bluez5_p.h"
+#include <bluetooth/sdp_lib.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
+
+typedef enum Bluez5TestResultType
+{
+ Unknown,
+ Bluez4,
+ Bluez5
+} Bluez5TestResult;
+
+Q_GLOBAL_STATIC_WITH_ARGS(Bluez5TestResult, bluezVersion, (Bluez5TestResult::Unknown));
+
+bool isBluez5()
+{
+ if (*bluezVersion() == Bluez5TestResultType::Unknown) {
+ OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"),
+ QStringLiteral("/"),
+ QDBusConnection::systemBus());
+
+ qDBusRegisterMetaType<InterfaceList>();
+ qDBusRegisterMetaType<ManagedObjectList>();
+
+ QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError()) {
+ *bluezVersion() = Bluez5TestResultType::Bluez4;
+ qCDebug(QT_BT_BLUEZ) << "Bluez 4 detected.";
+ } else {
+ *bluezVersion() = Bluez5TestResultType::Bluez5;
+ qCDebug(QT_BT_BLUEZ) << "Bluez 5 detected.";
+ }
+ }
+
+ return (*bluezVersion() == Bluez5TestResultType::Bluez5);
+}
+
+struct AdapterData
+{
+public:
+ AdapterData() : reference(1), wasListeningAlready(false), propteryListener(0) {}
+
+ int reference;
+ bool wasListeningAlready;
+ OrgFreedesktopDBusPropertiesInterface *propteryListener;
+};
+
+class QtBluezDiscoveryManagerPrivate
+{
+public:
+ QMap<QString, AdapterData *> references;
+ OrgFreedesktopDBusObjectManagerInterface *manager;
+};
+
+Q_GLOBAL_STATIC(QtBluezDiscoveryManager, discoveryManager)
+
+/*!
+ \internal
+ \class QtBluezDiscoveryManager
+
+ This class manages the access to "org.bluez.Adapter1::Start/StopDiscovery.
+
+ The flag is a system flag. We want to ensure that the various Qt classes don't turn
+ the flag on and off and thereby get into their way. If some other system component
+ changes the flag (e.g. adapter removed) we notify all Qt classes about the change by emitting
+ \l discoveryInterrupted(QString). Classes should indicate this via an appropriate
+ error message to the user.
+
+ Once the signal was emitted, all existing requests for discovery mode on the same adapter
+ have to be renewed via \l registerDiscoveryInterest(QString).
+*/
+
+QtBluezDiscoveryManager::QtBluezDiscoveryManager(QObject *parent) :
+ QObject(parent)
+{
+ qCDebug(QT_BT_BLUEZ) << "Creating QtBluezDiscoveryManager";
+ d = new QtBluezDiscoveryManagerPrivate();
+
+ d->manager = new OrgFreedesktopDBusObjectManagerInterface(
+ QStringLiteral("org.bluez"), QStringLiteral("/"),
+ QDBusConnection::systemBus(), this);
+ connect(d->manager, SIGNAL(InterfacesRemoved(QDBusObjectPath,QStringList)),
+ SLOT(InterfacesRemoved(QDBusObjectPath,QStringList)));
+}
+
+QtBluezDiscoveryManager::~QtBluezDiscoveryManager()
+{
+ qCDebug(QT_BT_BLUEZ) << "Destroying QtBluezDiscoveryManager";
+
+ foreach (const QString &adapterPath, d->references.keys()) {
+ AdapterData *data = d->references.take(adapterPath);
+ delete data->propteryListener;
+
+ // turn discovery off if it wasn't on already
+ if (!data->wasListeningAlready) {
+ OrgBluezAdapter1Interface iface(QStringLiteral("org.bluez"), adapterPath,
+ QDBusConnection::systemBus());
+ iface.StopDiscovery();
+ }
+
+ delete data;
+ }
+
+ delete d;
+}
+
+QtBluezDiscoveryManager *QtBluezDiscoveryManager::instance()
+{
+ if (isBluez5())
+ return discoveryManager();
+
+ Q_ASSERT(false);
+ return 0;
+}
+
+bool QtBluezDiscoveryManager::registerDiscoveryInterest(const QString &adapterPath)
+{
+ if (adapterPath.isEmpty())
+ return false;
+
+ // already monitored adapter? -> increase ref count -> done
+ if (d->references.contains(adapterPath)) {
+ d->references[adapterPath]->reference++;
+ return true;
+ }
+
+ AdapterData *data = new AdapterData();
+
+ OrgFreedesktopDBusPropertiesInterface *propIface = new OrgFreedesktopDBusPropertiesInterface(
+ QStringLiteral("org.bluez"), adapterPath, QDBusConnection::systemBus());
+ connect(propIface, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)),
+ SLOT(PropertiesChanged(QString,QVariantMap,QStringList)));
+ data->propteryListener = propIface;
+
+ OrgBluezAdapter1Interface iface(QStringLiteral("org.bluez"), adapterPath,
+ QDBusConnection::systemBus());
+ data->wasListeningAlready = iface.discovering();
+
+ d->references[adapterPath] = data;
+
+ if (!data->wasListeningAlready)
+ iface.StartDiscovery();
+
+ return true;
+}
+
+void QtBluezDiscoveryManager::unregisterDiscoveryInterest(const QString &adapterPath)
+{
+ if (!d->references.contains(adapterPath))
+ return;
+
+ AdapterData *data = d->references[adapterPath];
+ data->reference--;
+
+ if (data->reference > 0) // more than one client requested discovery mode
+ return;
+
+ d->references.remove(adapterPath);
+ if (!data->wasListeningAlready) { // Qt turned discovery mode on, Qt has to turn it off again
+ OrgBluezAdapter1Interface iface(QStringLiteral("org.bluez"), adapterPath,
+ QDBusConnection::systemBus());
+ iface.StopDiscovery();
+ }
+
+ delete data->propteryListener;
+ delete data;
+}
+
+//void QtBluezDiscoveryManager::dumpState() const
+//{
+// qCDebug(QT_BT_BLUEZ) << "-------------------------";
+// if (d->references.isEmpty()) {
+// qCDebug(QT_BT_BLUEZ) << "No running registration";
+// } else {
+// foreach (const QString &path, d->references.keys()) {
+// qCDebug(QT_BT_BLUEZ) << path << "->" << d->references[path]->reference;
+// }
+// }
+// qCDebug(QT_BT_BLUEZ) << "-------------------------";
+//}
+
+void QtBluezDiscoveryManager::InterfacesRemoved(const QDBusObjectPath &object_path,
+ const QStringList &interfaces)
+{
+ if (!d->references.contains(object_path.path())
+ || !interfaces.contains(QStringLiteral("org.bluez.Adapter1")))
+ return;
+
+ removeAdapterFromMonitoring(object_path.path());
+}
+
+void QtBluezDiscoveryManager::PropertiesChanged(const QString &interface,
+ const QVariantMap &changed_properties,
+ const QStringList &invalidated_properties)
+{
+ Q_UNUSED(invalidated_properties);
+
+ OrgFreedesktopDBusPropertiesInterface *propIface =
+ qobject_cast<OrgFreedesktopDBusPropertiesInterface *>(sender());
+
+ if (!propIface)
+ return;
+
+ if (interface == QStringLiteral("org.bluez.Adapter1")
+ && d->references.contains(propIface->path())
+ && changed_properties.contains(QStringLiteral("Discovering"))) {
+ bool isDiscovering = changed_properties.value(QStringLiteral("Discovering")).toBool();
+ if (!isDiscovering)
+ removeAdapterFromMonitoring(propIface->path());
+ }
+}
+
+void QtBluezDiscoveryManager::removeAdapterFromMonitoring(const QString &dbusPath)
+{
+ // remove adapter from monitoring
+ AdapterData *data = d->references.take(dbusPath);
+ delete data->propteryListener;
+ delete data;
+
+ emit discoveryInterrupted(dbusPath);
+}
+
+#define BUFFER_SIZE 1024
+
+static void parseAttributeValues(sdp_data_t *data, int indentation, QByteArray &xmlOutput)
+{
+ if (!data)
+ return;
+
+ const int length = indentation*2 + 1;
+ QByteArray indentString(length, ' ');
+
+ char snBuffer[BUFFER_SIZE];
+
+ xmlOutput.append(indentString);
+
+ // deal with every dtd type
+ switch (data->dtd) {
+ case SDP_DATA_NIL:
+ xmlOutput.append("<nil/>\n");
+ break;
+ case SDP_UINT8:
+ qsnprintf(snBuffer, BUFFER_SIZE, "<uint8 value=\"0x%02x\"/>\n", data->val.uint8);
+ xmlOutput.append(snBuffer);
+ break;
+ case SDP_UINT16:
+ qsnprintf(snBuffer, BUFFER_SIZE, "<uint16 value=\"0x%04x\"/>\n", data->val.uint16);
+ xmlOutput.append(snBuffer);
+ break;
+ case SDP_UINT32:
+ qsnprintf(snBuffer, BUFFER_SIZE, "<uint32 value=\"0x%08x\"/>\n", data->val.uint32);
+ xmlOutput.append(snBuffer);
+ break;
+ case SDP_UINT64:
+ qsnprintf(snBuffer, BUFFER_SIZE, "<uint64 value=\"0x%016x\"/>\n", data->val.uint64);
+ xmlOutput.append(snBuffer);
+ break;
+ case SDP_UINT128:
+ xmlOutput.append("<uint128 value=\"0x");
+ for (int i = 0; i < 16; i++)
+ ::sprintf(&snBuffer[i * 2], "%02x", data->val.uint128.data[i]);
+ xmlOutput.append(snBuffer);
+ xmlOutput.append("\"/>\n");
+ break;
+ case SDP_INT8:
+ qsnprintf(snBuffer, BUFFER_SIZE, "<int8 value=\"%d\"/>/n", data->val.int8);
+ xmlOutput.append(snBuffer);
+ break;
+ case SDP_INT16:
+ qsnprintf(snBuffer, BUFFER_SIZE, "<int16 value=\"%d\"/>/n", data->val.int16);
+ xmlOutput.append(snBuffer);
+ break;
+ case SDP_INT32:
+ qsnprintf(snBuffer, BUFFER_SIZE, "<int32 value=\"%d\"/>/n", data->val.int32);
+ xmlOutput.append(snBuffer);
+ break;
+ case SDP_INT64:
+ qsnprintf(snBuffer, BUFFER_SIZE, "<int64 value=\"%d\"/>/n", data->val.int64);
+ xmlOutput.append(snBuffer);
+ break;
+ case SDP_INT128:
+ xmlOutput.append("<int128 value=\"0x");
+ for (int i = 0; i < 16; i++)
+ ::sprintf(&snBuffer[i * 2], "%02x", data->val.int128.data[i]);
+ xmlOutput.append(snBuffer);
+ xmlOutput.append("\"/>\n");
+ break;
+ case SDP_UUID_UNSPEC:
+ break;
+ case SDP_UUID16:
+ case SDP_UUID32:
+ xmlOutput.append("<uuid value=\"0x");
+ sdp_uuid2strn(&(data->val.uuid), snBuffer, BUFFER_SIZE);
+ xmlOutput.append(snBuffer);
+ xmlOutput.append("\"/>\n");
+ break;
+ case SDP_UUID128:
+ xmlOutput.append("<uuid value=\"");
+ sdp_uuid2strn(&(data->val.uuid), snBuffer, BUFFER_SIZE);
+ xmlOutput.append(snBuffer);
+ xmlOutput.append("\"/>\n");
+ break;
+ case SDP_TEXT_STR_UNSPEC:
+ break;
+ case SDP_TEXT_STR8:
+ case SDP_TEXT_STR16:
+ case SDP_TEXT_STR32:
+ {
+ xmlOutput.append("<text ");
+ QByteArray text = QByteArray::fromRawData(data->val.str, data->unitSize);
+
+ bool hasNonPrintableChar = false;
+ for (int i = 0; i < text.count() && !hasNonPrintableChar; i++) {
+ if (!isprint(text[i])) {
+ hasNonPrintableChar = true;
+ break;
+ }
+ }
+
+ if (hasNonPrintableChar) {
+ xmlOutput.append("encoding=\"hex\" value=\"");
+ xmlOutput.append(text.toHex());
+ } else {
+ text.replace("&", "&amp");
+ text.replace("<", "&lt");
+ text.replace(">", "&gt");
+ text.replace("\"", "&quot");
+
+ xmlOutput.append("value=\"");
+ xmlOutput.append(text);
+ }
+
+ xmlOutput.append("\"/>\n");
+ break;
+ }
+ case SDP_BOOL:
+ if (data->val.uint8)
+ xmlOutput.append("<boolean value=\"true\"/>\n");
+ else
+ xmlOutput.append("<boolean value=\"false\"/>\n");
+ break;
+ case SDP_SEQ_UNSPEC:
+ break;
+ case SDP_SEQ8:
+ case SDP_SEQ16:
+ case SDP_SEQ32:
+ xmlOutput.append("<sequence>\n");
+ parseAttributeValues(data->val.dataseq, indentation + 1, xmlOutput);
+ xmlOutput.append(indentString);
+ xmlOutput.append("</sequence>\n");
+ break;
+ case SDP_ALT_UNSPEC:
+ break;
+ case SDP_ALT8:
+ case SDP_ALT16:
+ case SDP_ALT32:
+ xmlOutput.append("<alternate>\n");
+ parseAttributeValues(data->val.dataseq, indentation + 1, xmlOutput);
+ xmlOutput.append(indentString);
+ xmlOutput.append("</alternate>\n");
+ break;
+ case SDP_URL_STR_UNSPEC:
+ break;
+ case SDP_URL_STR8:
+ case SDP_URL_STR16:
+ case SDP_URL_STR32:
+ strncpy(snBuffer, data->val.str, data->unitSize - 1);
+ xmlOutput.append("<url value=\"");
+ xmlOutput.append(snBuffer);
+ xmlOutput.append("\"/>\n");
+ break;
+ default:
+ qDebug(QT_BT_BLUEZ) << "Unknown dtd type";
+ }
+
+ parseAttributeValues(data->next, indentation, xmlOutput);
+}
+
+static void parseAttribute(void *value, void *extraData)
+{
+ sdp_data_t *data = (sdp_data_t *) value;
+ QByteArray *xmlOutput = static_cast<QByteArray *>(extraData);
+
+ char buffer[BUFFER_SIZE];
+
+ ::qsnprintf(buffer, BUFFER_SIZE, " <attribute id=\"0x%04x\">\n", data->attrId);
+ xmlOutput->append(buffer);
+
+ parseAttributeValues(data, 2, *xmlOutput);
+
+ xmlOutput->append(" </attribute>\n");
+}
+
+// the resulting xml output is based on the already used xml parser
+QByteArray parseSdpRecord(sdp_record_t *record)
+{
+ if (!record || !record->attrlist)
+ return QByteArray();
+
+ QByteArray xmlOutput;
+
+ xmlOutput.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<record>\n");
+
+ sdp_list_foreach(record->attrlist, parseAttribute, &xmlOutput);
+ xmlOutput.append("</record>");
+
+ return xmlOutput;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/bluez/bluez5_helper_p.h b/src/bluetooth/bluez/bluez5_helper_p.h
new file mode 100644
index 00000000..2429c09c
--- /dev/null
+++ b/src/bluetooth/bluez/bluez5_helper_p.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BLUEZ5_HELPER_H
+#define BLUEZ5_HELPER_H
+
+#include <QtCore/QObject>
+#include <QtDBus/QtDBus>
+#include <bluetooth/sdp.h>
+
+typedef QMap<QString, QVariantMap> InterfaceList;
+typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList;
+
+Q_DECLARE_METATYPE(InterfaceList)
+Q_DECLARE_METATYPE(ManagedObjectList)
+
+QT_BEGIN_NAMESPACE
+
+bool isBluez5();
+
+QByteArray parseSdpRecord(sdp_record_t *record);
+
+class QtBluezDiscoveryManagerPrivate;
+class QtBluezDiscoveryManager : public QObject
+{
+ Q_OBJECT
+public:
+ QtBluezDiscoveryManager(QObject* parent = 0);
+ ~QtBluezDiscoveryManager();
+ static QtBluezDiscoveryManager *instance();
+
+ bool registerDiscoveryInterest(const QString &adapterPath);
+ void unregisterDiscoveryInterest(const QString &adapterPath);
+
+ //void dumpState() const;
+
+signals:
+ void discoveryInterrupted(const QString &adapterPath);
+
+private slots:
+ void InterfacesRemoved(const QDBusObjectPath &object_path,
+ const QStringList &interfaces);
+ void PropertiesChanged(const QString &interface,
+ const QVariantMap &changed_properties,
+ const QStringList &invalidated_properties);
+
+private:
+ void removeAdapterFromMonitoring(const QString &dbusPath);
+
+ QtBluezDiscoveryManagerPrivate *d;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/bluetooth/bluez/device1_bluez5.cpp b/src/bluetooth/bluez/device1_bluez5.cpp
new file mode 100644
index 00000000..50bef4cb
--- /dev/null
+++ b/src/bluetooth/bluez/device1_bluez5.cpp
@@ -0,0 +1,26 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -p device1_bluez5 -v org.bluez.Device1.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * This file may have been hand-edited. Look for HAND-EDIT comments
+ * before re-generating it.
+ */
+
+#include "device1_bluez5_p.h"
+
+/*
+ * Implementation of interface class OrgBluezDevice1Interface
+ */
+
+OrgBluezDevice1Interface::OrgBluezDevice1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+OrgBluezDevice1Interface::~OrgBluezDevice1Interface()
+{
+}
+
diff --git a/src/bluetooth/bluez/device1_bluez5_p.h b/src/bluetooth/bluez/device1_bluez5_p.h
new file mode 100644
index 00000000..4caae28a
--- /dev/null
+++ b/src/bluetooth/bluez/device1_bluez5_p.h
@@ -0,0 +1,151 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -p device1_bluez5 -v org.bluez.Device1.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * Do not edit! All changes made to it will be lost.
+ */
+
+#ifndef DEVICE1_BLUEZ5_H_1396951960
+#define DEVICE1_BLUEZ5_H_1396951960
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * Proxy class for interface org.bluez.Device1
+ */
+class OrgBluezDevice1Interface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "org.bluez.Device1"; }
+
+public:
+ OrgBluezDevice1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~OrgBluezDevice1Interface();
+
+ Q_PROPERTY(QDBusObjectPath Adapter READ adapter)
+ inline QDBusObjectPath adapter() const
+ { return qvariant_cast< QDBusObjectPath >(property("Adapter")); }
+
+ Q_PROPERTY(QString Address READ address)
+ inline QString address() const
+ { return qvariant_cast< QString >(property("Address")); }
+
+ Q_PROPERTY(QString Alias READ alias WRITE setAlias)
+ inline QString alias() const
+ { return qvariant_cast< QString >(property("Alias")); }
+ inline void setAlias(const QString &value)
+ { setProperty("Alias", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(ushort Appearance READ appearance)
+ inline ushort appearance() const
+ { return qvariant_cast< ushort >(property("Appearance")); }
+
+ Q_PROPERTY(bool Blocked READ blocked WRITE setBlocked)
+ inline bool blocked() const
+ { return qvariant_cast< bool >(property("Blocked")); }
+ inline void setBlocked(bool value)
+ { setProperty("Blocked", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(uint Class READ classProperty)
+ inline uint classProperty() const
+ { return qvariant_cast< uint >(property("Class")); }
+
+ Q_PROPERTY(bool Connected READ connected)
+ inline bool connected() const
+ { return qvariant_cast< bool >(property("Connected")); }
+
+ Q_PROPERTY(QString Icon READ icon)
+ inline QString icon() const
+ { return qvariant_cast< QString >(property("Icon")); }
+
+ Q_PROPERTY(bool LegacyPairing READ legacyPairing)
+ inline bool legacyPairing() const
+ { return qvariant_cast< bool >(property("LegacyPairing")); }
+
+ Q_PROPERTY(QString Modalias READ modalias)
+ inline QString modalias() const
+ { return qvariant_cast< QString >(property("Modalias")); }
+
+ Q_PROPERTY(QString Name READ name)
+ inline QString name() const
+ { return qvariant_cast< QString >(property("Name")); }
+
+ Q_PROPERTY(bool Paired READ paired)
+ inline bool paired() const
+ { return qvariant_cast< bool >(property("Paired")); }
+
+ Q_PROPERTY(short RSSI READ rSSI)
+ inline short rSSI() const
+ { return qvariant_cast< short >(property("RSSI")); }
+
+ Q_PROPERTY(bool Trusted READ trusted WRITE setTrusted)
+ inline bool trusted() const
+ { return qvariant_cast< bool >(property("Trusted")); }
+ inline void setTrusted(bool value)
+ { setProperty("Trusted", QVariant::fromValue(value)); }
+
+ Q_PROPERTY(QStringList UUIDs READ uUIDs)
+ inline QStringList uUIDs() const
+ { return qvariant_cast< QStringList >(property("UUIDs")); }
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<> CancelPairing()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("CancelPairing"), argumentList);
+ }
+
+ inline QDBusPendingReply<> Connect()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("Connect"), argumentList);
+ }
+
+ inline QDBusPendingReply<> ConnectProfile(const QString &UUID)
+ {
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(UUID);
+ return asyncCallWithArgumentList(QLatin1String("ConnectProfile"), argumentList);
+ }
+
+ inline QDBusPendingReply<> Disconnect()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("Disconnect"), argumentList);
+ }
+
+ inline QDBusPendingReply<> DisconnectProfile(const QString &UUID)
+ {
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(UUID);
+ return asyncCallWithArgumentList(QLatin1String("DisconnectProfile"), argumentList);
+ }
+
+ inline QDBusPendingReply<> Pair()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("Pair"), argumentList);
+ }
+
+Q_SIGNALS: // SIGNALS
+};
+
+namespace org {
+ namespace bluez {
+ typedef ::OrgBluezDevice1Interface Device1;
+ }
+}
+#endif
diff --git a/src/bluetooth/bluez/objectmanager.cpp b/src/bluetooth/bluez/objectmanager.cpp
new file mode 100644
index 00000000..521012f6
--- /dev/null
+++ b/src/bluetooth/bluez/objectmanager.cpp
@@ -0,0 +1,26 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -p objectmanager -v -i bluez5_helper.h org.freedesktop.dbus.objectmanager.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * This file may have been hand-edited. Look for HAND-EDIT comments
+ * before re-generating it.
+ */
+
+#include "objectmanager_p.h"
+
+/*
+ * Implementation of interface class OrgFreedesktopDBusObjectManagerInterface
+ */
+
+OrgFreedesktopDBusObjectManagerInterface::OrgFreedesktopDBusObjectManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+OrgFreedesktopDBusObjectManagerInterface::~OrgFreedesktopDBusObjectManagerInterface()
+{
+}
+
diff --git a/src/bluetooth/bluez/objectmanager_p.h b/src/bluetooth/bluez/objectmanager_p.h
new file mode 100644
index 00000000..6acf3d6d
--- /dev/null
+++ b/src/bluetooth/bluez/objectmanager_p.h
@@ -0,0 +1,58 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -p objectmanager -v -i bluez5_helper.h org.freedesktop.dbus.objectmanager.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * Do not edit! All changes made to it will be lost.
+ */
+
+#ifndef OBJECTMANAGER_H_1396883000
+#define OBJECTMANAGER_H_1396883000
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+#include "bluez5_helper_p.h"
+
+/*
+ * Proxy class for interface org.freedesktop.DBus.ObjectManager
+ */
+class OrgFreedesktopDBusObjectManagerInterface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "org.freedesktop.DBus.ObjectManager"; }
+
+public:
+ OrgFreedesktopDBusObjectManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~OrgFreedesktopDBusObjectManagerInterface();
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<ManagedObjectList> GetManagedObjects()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("GetManagedObjects"), argumentList);
+ }
+
+Q_SIGNALS: // SIGNALS
+ void InterfacesAdded(const QDBusObjectPath &object_path, InterfaceList interfaces_and_properties);
+ void InterfacesRemoved(const QDBusObjectPath &object_path, const QStringList &interfaces);
+};
+
+namespace org {
+ namespace freedesktop {
+ namespace DBus {
+ typedef ::OrgFreedesktopDBusObjectManagerInterface ObjectManager;
+ }
+ }
+}
+#endif
diff --git a/src/bluetooth/bluez/org.bluez.Adapter1.xml b/src/bluetooth/bluez/org.bluez.Adapter1.xml
new file mode 100644
index 00000000..a1e6babe
--- /dev/null
+++ b/src/bluetooth/bluez/org.bluez.Adapter1.xml
@@ -0,0 +1,23 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.bluez.Adapter1">
+ <method name="StartDiscovery"></method>
+ <method name="StopDiscovery"></method>
+ <method name="RemoveDevice">
+ <arg name="device" type="o" direction="in"/>
+ </method>
+ <property name="Address" type="s" access="read"></property>
+ <property name="Name" type="s" access="read"></property>
+ <property name="Alias" type="s" access="readwrite"></property>
+ <property name="Class" type="u" access="read"></property>
+ <property name="Powered" type="b" access="readwrite"></property>
+ <property name="Discoverable" type="b" access="readwrite"></property>
+ <property name="DiscoverableTimeout" type="u" access="readwrite"></property>
+ <property name="Pairable" type="b" access="readwrite"></property>
+ <property name="PairableTimeout" type="u" access="readwrite"></property>
+ <property name="Discovering" type="b" access="read"></property>
+ <property name="UUIDs" type="as" access="read"></property>
+ <property name="Modalias" type="s" access="read"></property>
+ </interface>
+</node>
diff --git a/src/bluetooth/bluez/org.bluez.Device1.xml b/src/bluetooth/bluez/org.bluez.Device1.xml
new file mode 100644
index 00000000..1f8fd2c1
--- /dev/null
+++ b/src/bluetooth/bluez/org.bluez.Device1.xml
@@ -0,0 +1,31 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.bluez.Device1">
+ <method name="Disconnect"></method>
+ <method name="Connect"></method>
+ <method name="ConnectProfile">
+ <arg name="UUID" type="s" direction="in"/>
+ </method>
+ <method name="DisconnectProfile">
+ <arg name="UUID" type="s" direction="in"/>
+ </method>
+ <method name="Pair"></method>
+ <method name="CancelPairing"></method>
+ <property name="Address" type="s" access="read"></property>
+ <property name="Name" type="s" access="read"></property>
+ <property name="Alias" type="s" access="readwrite"></property>
+ <property name="Class" type="u" access="read"></property>
+ <property name="Appearance" type="q" access="read"></property>
+ <property name="Icon" type="s" access="read"></property>
+ <property name="Paired" type="b" access="read"></property>
+ <property name="Trusted" type="b" access="readwrite"></property>
+ <property name="Blocked" type="b" access="readwrite"></property>
+ <property name="LegacyPairing" type="b" access="read"></property>
+ <property name="RSSI" type="n" access="read"></property>
+ <property name="Connected" type="b" access="read"></property>
+ <property name="UUIDs" type="as" access="read"></property>
+ <property name="Modalias" type="s" access="read"></property>
+ <property name="Adapter" type="o" access="read"></property>
+ </interface>
+</node>
diff --git a/src/bluetooth/bluez/org.freedesktop.dbus.objectmanager.xml b/src/bluetooth/bluez/org.freedesktop.dbus.objectmanager.xml
new file mode 100644
index 00000000..8ab2a6e1
--- /dev/null
+++ b/src/bluetooth/bluez/org.freedesktop.dbus.objectmanager.xml
@@ -0,0 +1,19 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
+ <interface name="org.freedesktop.DBus.ObjectManager">
+ <method name="GetManagedObjects">
+ <arg type="a{oa{sa{sv}}}" name="object_paths_interfaces_and_properties" direction="out"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ManagedObjectList"/>
+ </method>
+ <signal name="InterfacesAdded">
+ <arg type="o" name="object_path"/>
+ <arg type="a{sa{sv}}" name="interfaces_and_properties"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="InterfaceList"/>
+ </signal>
+ <signal name="InterfacesRemoved">
+ <arg type="o" name="object_path"/>
+ <arg type="as" name="interfaces"/>
+ </signal>
+ </interface>
+</node>
diff --git a/src/bluetooth/bluez/org.freedesktop.dbus.properties.xml b/src/bluetooth/bluez/org.freedesktop.dbus.properties.xml
new file mode 100644
index 00000000..5dc94f5d
--- /dev/null
+++ b/src/bluetooth/bluez/org.freedesktop.dbus.properties.xml
@@ -0,0 +1,27 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.freedesktop.DBus.Properties">
+ <method name="Get">
+ <arg name="interface" type="s" direction="in"/>
+ <arg name="name" type="s" direction="in"/>
+ <arg name="value" type="v" direction="out"/>
+ </method>
+ <method name="Set">
+ <arg name="interface" type="s" direction="in"/>
+ <arg name="name" type="s" direction="in"/>
+ <arg name="value" type="v" direction="in"/>
+ </method>
+ <method name="GetAll">
+ <arg name="interface" type="s" direction="in"/>
+ <arg name="properties" type="a{sv}" direction="out"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
+ </method>
+ <signal name="PropertiesChanged">
+ <arg name="interface" type="s"/>
+ <arg name="changed_properties" type="a{sv}"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
+ <arg name="invalidated_properties" type="as"/>
+ </signal>
+ </interface>
+</node>
diff --git a/src/bluetooth/bluez/properties.cpp b/src/bluetooth/bluez/properties.cpp
new file mode 100644
index 00000000..53c9021c
--- /dev/null
+++ b/src/bluetooth/bluez/properties.cpp
@@ -0,0 +1,26 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -p properties -v org.freedesktop.dbus.properties.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * This file may have been hand-edited. Look for HAND-EDIT comments
+ * before re-generating it.
+ */
+
+#include "properties_p.h"
+
+/*
+ * Implementation of interface class OrgFreedesktopDBusPropertiesInterface
+ */
+
+OrgFreedesktopDBusPropertiesInterface::OrgFreedesktopDBusPropertiesInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+OrgFreedesktopDBusPropertiesInterface::~OrgFreedesktopDBusPropertiesInterface()
+{
+}
+
diff --git a/src/bluetooth/bluez/properties_p.h b/src/bluetooth/bluez/properties_p.h
new file mode 100644
index 00000000..44a79664
--- /dev/null
+++ b/src/bluetooth/bluez/properties_p.h
@@ -0,0 +1,71 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -p properties -v org.freedesktop.dbus.properties.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * Do not edit! All changes made to it will be lost.
+ */
+
+#ifndef PROPERTIES_H_1396952220
+#define PROPERTIES_H_1396952220
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * Proxy class for interface org.freedesktop.DBus.Properties
+ */
+class OrgFreedesktopDBusPropertiesInterface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "org.freedesktop.DBus.Properties"; }
+
+public:
+ OrgFreedesktopDBusPropertiesInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~OrgFreedesktopDBusPropertiesInterface();
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<QDBusVariant> Get(const QString &interface, const QString &name)
+ {
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(interface) << QVariant::fromValue(name);
+ return asyncCallWithArgumentList(QLatin1String("Get"), argumentList);
+ }
+
+ inline QDBusPendingReply<QVariantMap> GetAll(const QString &interface)
+ {
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(interface);
+ return asyncCallWithArgumentList(QLatin1String("GetAll"), argumentList);
+ }
+
+ inline QDBusPendingReply<> Set(const QString &interface, const QString &name, const QDBusVariant &value)
+ {
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(interface) << QVariant::fromValue(name) << QVariant::fromValue(value);
+ return asyncCallWithArgumentList(QLatin1String("Set"), argumentList);
+ }
+
+Q_SIGNALS: // SIGNALS
+ void PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties);
+};
+
+namespace org {
+ namespace freedesktop {
+ namespace DBus {
+ typedef ::OrgFreedesktopDBusPropertiesInterface Properties;
+ }
+ }
+}
+#endif
diff --git a/src/bluetooth/doc/qtbluetooth.qdocconf b/src/bluetooth/doc/qtbluetooth.qdocconf
index 36e8cb6f..171310cb 100644
--- a/src/bluetooth/doc/qtbluetooth.qdocconf
+++ b/src/bluetooth/doc/qtbluetooth.qdocconf
@@ -36,7 +36,7 @@ qhp.QtBluetooth.subprojects.examples.selectors = fake:example
tagfile = ../../../doc/qtbluetooth/qtbluetooth.tags
-depends += qtcore qtdoc
+depends += qtcore qtdoc qtquick
headerdirs += .. \
../../imports/bluetooth
diff --git a/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp b/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp
index 88520c35..c0c0f61a 100644
--- a/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp
+++ b/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp
@@ -46,6 +46,7 @@
#include <QtCore/QFile>
#include <QtCore/QObject>
#include <QtBluetooth/QBluetoothDeviceDiscoveryAgent>
+#include <QtBluetooth/QBluetoothServiceDiscoveryAgent>
#include <QtBluetooth/QBluetoothTransferManager>
#include <QtBluetooth/QBluetoothTransferRequest>
#include <QtBluetooth/QBluetoothTransferReply>
@@ -60,11 +61,13 @@ class MyClass : public QObject
public:
MyClass() : QObject() {}
void localDevice();
- void startDiscovery();
+ void startDeviceDiscovery();
+ void startServiceDiscovery();
void objectPush();
public slots:
void deviceDiscovered(const QBluetoothDeviceInfo &device);
+ void serviceDiscovered(const QBluetoothServiceInfo &service);
void transferFinished(QBluetoothTransferReply* reply);
};
@@ -94,8 +97,8 @@ if (localDevice.isValid()) {
}
-//! [discovery]
-void MyClass::startDiscovery()
+//! [device_discovery]
+void MyClass::startDeviceDiscovery()
{
// Create a discovery agent and connect to its signals
@@ -114,7 +117,30 @@ void MyClass::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')';
}
-//! [discovery]
+//! [device_discovery]
+
+//! [service_discovery]
+void MyClass::startServiceDiscovery()
+{
+
+ // Create a discovery agent and connect to its signals
+ QBluetoothServiceDiscoveryAgent *discoveryAgent = new QBluetoothServiceDiscoveryAgent(this);
+ connect(discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
+ this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
+
+ // Start a discovery
+ discoveryAgent->start();
+
+ //...
+}
+
+// In your local slot, read information about the found devices
+void MyClass::serviceDiscovered(const QBluetoothServiceInfo &service)
+{
+ qDebug() << "Found new service:" << service.serviceName()
+ << '(' << service.device().address().toString() << ')';
+}
+//! [service_discovery]
void MyClass::objectPush()
{
diff --git a/src/bluetooth/doc/src/bluetooth-index.qdoc b/src/bluetooth/doc/src/bluetooth-index.qdoc
index e9575db1..afdf2600 100644
--- a/src/bluetooth/doc/src/bluetooth-index.qdoc
+++ b/src/bluetooth/doc/src/bluetooth-index.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -29,15 +29,21 @@
\page qtbluetooth-index.html
\title Qt Bluetooth
\brief Qt Bluetooth enables connectivity between Bluetooth enabled devices.
+\ingroup technology-apis
+
+The Bluetooth API provides connectivity between Bluetooth enabled devices.
+
+Currently the API is supported on \l{Qt for Android}{Android},
+\l{Qt for BlackBerry}{BlackBerry 10} and
+\l{Qt for Linux/X11}{Linux} (\l{http://www.bluez.org}{Bluez 4.x}).
+
+\section1 Overview
Bluetooth is a short-range (less than 100 meters) wireless technology. It
has a reasonably high data transfer rate of 2.1 Mbit/s, which makes it ideal
-for transferring data between devices. Currently the API is supported on
-Linux (Bluez 4.x), Android and BlackBerry 10.
-
-Bluetooth connectivity is based on basic device management, such as scanning
-for devices, gathering information about them, and exchanging data between
-them.
+for transferring data between devices. Bluetooth connectivity is based on
+basic device management, such as scanning for devices, gathering information
+about them, and exchanging data between them.
\section1 Getting started
@@ -70,6 +76,7 @@ import statement in your \c .qml file:
\list
\li \l {scanner}{QML Bluetooth Scanner}
\li \l {picturetransfer}{QML Bluetooth Picture Push}
+ \li \l {pingpong}{QML Bluetooth PingPong}
\li \l {lowenergyscanner}{Bluetooth Low Energy Scanner}
\li \l {heartlistener}{Heart Listener}
\endlist
@@ -77,7 +84,6 @@ import statement in your \c .qml file:
\list
\li \l {btchat}{Bluetooth Chat}
\li \l {btscanner}{Bluetooth Scanner}
- \li \l {bttennis}{Bluetooth Tennis}
\li \l {btfiletransfer}{Bluetooth File Transfer}
\endlist
\endlist
diff --git a/src/bluetooth/doc/src/bluetooth-overview.qdoc b/src/bluetooth/doc/src/bluetooth-overview.qdoc
index 8842f483..2a5d8de2 100644
--- a/src/bluetooth/doc/src/bluetooth-overview.qdoc
+++ b/src/bluetooth/doc/src/bluetooth-overview.qdoc
@@ -55,7 +55,7 @@
\section1 Retrieving Local Device Information
The Qt Bluetooth API has three main purposes. The first one is to
- obtain local and remote device information. The first steps in retrieving device information is
+ obtain local and remote device information. The first steps in retrieving device information are
to check if Bluetooth is available on the device and read the local device address and name.
QBluetoothLocalDevice is the class that provides all of this information. Additionally you can use it
to turn Bluetooth on/off, set the visibility of the device and determine the current connections.
@@ -69,7 +69,7 @@
your own and fill them with data, the easier way is to use the QBluetoothDeviceDiscoveryAgent to
start an automated search for visible Bluetooth devices within the connectable range.
- \snippet doc_src_qtbluetooth.cpp discovery
+ \snippet doc_src_qtbluetooth.cpp device_discovery
\section1 Pushing Files to Remote Devices
diff --git a/src/bluetooth/doc/src/examples.qdoc b/src/bluetooth/doc/src/examples.qdoc
index 08759874..f53d7127 100644
--- a/src/bluetooth/doc/src/examples.qdoc
+++ b/src/bluetooth/doc/src/examples.qdoc
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the documentation of the Qt local connectivty modules.
+** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
@@ -45,9 +45,8 @@
\li Example
\li Description
\row
- \li \l{bttennis}{Bluetooth Tennis}
- \li The classic game of \l {http://en.wikipedia.org/wiki/Pong}{Pong}. Supports multiplayer
- over Bluetooth and touch-to-play functionality on devices that support NFC.
+ \li \l{btchat}{Bluetooth Chat}
+ \li Simple chat server and client via Bluetooth.
\row
\li \l{btfiletransfer}{Bluetooth File Transfer}
\li Transfer files between Bluetooth devices.
@@ -62,9 +61,8 @@
\li Example
\li Description
\row
- \li \l{bttennis}{QML Bluetooth Tennis}
- \li The tennis game using a QML interface to the Bluetooth API. It
- must connect to an instance of the C++ \l{bttennis}{Bluetooth Tennis} game to play.
+ \li \l{pingpong}{QML Bluetooth PingPong}
+ \li A QML ping pong game demonstrating Bluetooth socket communication between two devices.
\row
\li \l{scanner}{QML Bluetooth Scanner}
\li A QML implementation of the Bluetooth device scanner.
diff --git a/src/bluetooth/qbluetooth.cpp b/src/bluetooth/qbluetooth.cpp
index 4ba14dba..de1e5629 100644
--- a/src/bluetooth/qbluetooth.cpp
+++ b/src/bluetooth/qbluetooth.cpp
@@ -45,7 +45,6 @@
QT_BEGIN_NAMESPACE
namespace QBluetooth {
-
/*!
\namespace QBluetooth
\inmodule QtBluetooth
diff --git a/src/bluetooth/qbluetooth.h b/src/bluetooth/qbluetooth.h
index b13c0043..3d92e1f8 100644
--- a/src/bluetooth/qbluetooth.h
+++ b/src/bluetooth/qbluetooth.h
@@ -39,7 +39,6 @@
**
****************************************************************************/
-
#ifndef QBLUETOOTH_H
#define QBLUETOOTH_H
@@ -48,16 +47,16 @@
QT_BEGIN_NAMESPACE
namespace QBluetooth {
- enum Security {
- NoSecurity = 0x00,
- Authorization = 0x01,
- Authentication = 0x02,
- Encryption = 0x04,
- Secure = 0x08
- };
+enum Security {
+ NoSecurity = 0x00,
+ Authorization = 0x01,
+ Authentication = 0x02,
+ Encryption = 0x04,
+ Secure = 0x08
+};
- Q_DECLARE_FLAGS(SecurityFlags, Security)
- Q_DECLARE_OPERATORS_FOR_FLAGS(SecurityFlags)
+Q_DECLARE_FLAGS(SecurityFlags, Security)
+Q_DECLARE_OPERATORS_FOR_FLAGS(SecurityFlags)
}
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothaddress.cpp b/src/bluetooth/qbluetoothaddress.cpp
index 9213a431..cd1eab4c 100644
--- a/src/bluetooth/qbluetoothaddress.cpp
+++ b/src/bluetooth/qbluetoothaddress.cpp
@@ -42,6 +42,10 @@
#include "qbluetoothaddress.h"
#include "qbluetoothaddress_p.h"
+#ifndef QT_NO_DEBUG_STREAM
+#include <QDebug>
+#endif
+
QT_BEGIN_NAMESPACE
/*!
@@ -62,8 +66,7 @@ QT_BEGIN_NAMESPACE
Returns true if the Bluetooth addresses are not equal, otherwise returns false.
*/
-namespace
-{
+namespace {
class BluetoothAddressRegisterMetaTypes
{
public:
@@ -77,16 +80,16 @@ public:
/*!
Constructs an null Bluetooth address.
*/
-QBluetoothAddress::QBluetoothAddress()
- : d_ptr(new QBluetoothAddressPrivate)
+QBluetoothAddress::QBluetoothAddress() :
+ d_ptr(new QBluetoothAddressPrivate)
{
}
/*!
Constructs a new Bluetooth address and assigns \a address to it.
*/
-QBluetoothAddress::QBluetoothAddress(quint64 address)
- : d_ptr(new QBluetoothAddressPrivate)
+QBluetoothAddress::QBluetoothAddress(quint64 address) :
+ d_ptr(new QBluetoothAddressPrivate)
{
Q_D(QBluetoothAddress);
d->m_address = address;
@@ -98,8 +101,8 @@ QBluetoothAddress::QBluetoothAddress(quint64 address)
The format of \a address can be either XX:XX:XX:XX:XX:XX or XXXXXXXXXXXX,
where X is a hexadecimal digit. Case is not important.
*/
-QBluetoothAddress::QBluetoothAddress(const QString &address)
- : d_ptr(new QBluetoothAddressPrivate)
+QBluetoothAddress::QBluetoothAddress(const QString &address) :
+ d_ptr(new QBluetoothAddressPrivate)
{
Q_D(QBluetoothAddress);
@@ -121,8 +124,8 @@ QBluetoothAddress::QBluetoothAddress(const QString &address)
/*!
Constructs a new Bluetooth address which is a copy of \a other.
*/
-QBluetoothAddress::QBluetoothAddress(const QBluetoothAddress &other)
- : d_ptr(new QBluetoothAddressPrivate)
+QBluetoothAddress::QBluetoothAddress(const QBluetoothAddress &other) :
+ d_ptr(new QBluetoothAddressPrivate)
{
*this = other;
}
@@ -200,7 +203,7 @@ quint64 QBluetoothAddress::toUInt64() const
*/
QString QBluetoothAddress::toString() const
{
- QString s(QLatin1String("%1:%2:%3:%4:%5:%6"));
+ QString s(QStringLiteral("%1:%2:%3:%4:%5:%6"));
Q_D(const QBluetoothAddress);
for (int i = 5; i >= 0; --i) {
@@ -216,4 +219,12 @@ QBluetoothAddressPrivate::QBluetoothAddressPrivate()
m_address = 0;
}
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug debug, const QBluetoothAddress &address)
+{
+ debug << address.toString();
+ return debug;
+}
+#endif
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothaddress.h b/src/bluetooth/qbluetoothaddress.h
index db9e0a1a..d10946db 100644
--- a/src/bluetooth/qbluetoothaddress.h
+++ b/src/bluetooth/qbluetoothaddress.h
@@ -69,7 +69,10 @@ public:
bool operator<(const QBluetoothAddress &other) const;
bool operator==(const QBluetoothAddress &other) const;
- inline bool operator!=(const QBluetoothAddress &other) const { return !operator==(other); }
+ inline bool operator!=(const QBluetoothAddress &other) const
+ {
+ return !operator==(other);
+ }
quint64 toUInt64() const;
QString toString() const;
@@ -79,6 +82,10 @@ private:
QBluetoothAddressPrivate *d_ptr;
};
+#ifndef QT_NO_DEBUG_STREAM
+Q_BLUETOOTH_EXPORT QDebug operator<<(QDebug, const QBluetoothAddress &address);
+#endif
+
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QBluetoothAddress)
diff --git a/src/bluetooth/qbluetoothaddress_p.h b/src/bluetooth/qbluetoothaddress_p.h
index bb25629e..20408b05 100644
--- a/src/bluetooth/qbluetoothaddress_p.h
+++ b/src/bluetooth/qbluetoothaddress_p.h
@@ -51,9 +51,7 @@ class QBluetoothAddressPrivate
public:
QBluetoothAddressPrivate();
-
quint64 m_address;
-
};
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
index eeac8f11..ab0643d6 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
\li and call start().
\endlist
- \snippet doc_src_qtbluetooth.cpp discovery
+ \snippet doc_src_qtbluetooth.cpp device_discovery
To retrieve results asynchronously, connect to the deviceDiscovered() signal. To get a list of
all discovered devices, call discoveredDevices() after the finished() signal.
@@ -91,14 +91,24 @@ QT_BEGIN_NAMESPACE
support it, GeneralUnlimitedInquiry will be used instead. Setting LimitedInquiry is useful
for multi-player Bluetooth-based games that needs faster communication between the devices.
The phone scans for devices in LimitedInquiry and Service Discovery is done on one or two devices
- to speed up the service scan. After the game has connected to the device it intends to,the device
- returns to GeneralUnilimitedInquiry.
+ to speed up the service scan. After the game has connected to the device it intended to,
+ the device returns to GeneralUnlimitedInquiry.
*/
/*!
\fn void QBluetoothDeviceDiscoveryAgent::deviceDiscovered(const QBluetoothDeviceInfo &info)
This signal is emitted when the Bluetooth device described by \a info is discovered.
+
+ The signal is emitted as soon as the most important device information
+ has been collected. However, as long as the \l finished() signal has not
+ been emitted the information collection continues even for already discovered
+ devices. This is particularly true for signal strength information (RSSI). If
+ signal strength information is required it is advisable to retrieve the device
+ information via \l discoveredDevices() once the discovery has finished. This
+ will yield the most recent RSSI information.
+
+ \sa QBluetoothDeviceInfo::rssi()
*/
/*!
@@ -132,10 +142,10 @@ QT_BEGIN_NAMESPACE
/*!
Constructs a new Bluetooth device discovery agent with parent \a parent.
*/
-QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject *parent)
- : QObject(parent), d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(QBluetoothAddress()))
+QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject *parent) :
+ QObject(parent),
+ d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(QBluetoothAddress(), this))
{
- d_ptr->q_ptr = this;
}
/*!
@@ -150,10 +160,11 @@ QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject *parent)
\sa error()
*/
-QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent)
- : QObject(parent), d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(deviceAdapter))
+QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(
+ const QBluetoothAddress &deviceAdapter, QObject *parent) :
+ QObject(parent),
+ d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(deviceAdapter, this))
{
- d_ptr->q_ptr = this;
if (!deviceAdapter.isNull()) {
const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
foreach (const QBluetoothHostInfo &hostInfo, localDevices) {
@@ -238,7 +249,6 @@ bool QBluetoothDeviceDiscoveryAgent::isActive() const
return d->isActive();
}
-
/*!
Returns the last error.
*/
@@ -261,4 +271,3 @@ QString QBluetoothDeviceDiscoveryAgent::errorString() const
#include "moc_qbluetoothdevicediscoveryagent.cpp"
QT_END_NAMESPACE
-
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h
index 4ac1685e..45615e74 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h
@@ -45,9 +45,7 @@
#include <QtBluetooth/qbluetoothglobal.h>
#include <QObject>
-
#include <QtBluetooth/QBluetoothDeviceInfo>
-
#include <QtBluetooth/QBluetoothAddress>
QT_BEGIN_NAMESPACE
@@ -57,7 +55,8 @@ class QBluetoothDeviceDiscoveryAgentPrivate;
class Q_BLUETOOTH_EXPORT QBluetoothDeviceDiscoveryAgent : public QObject
{
Q_OBJECT
- Q_PROPERTY(QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType READ inquiryType WRITE setInquiryType)
+ Q_PROPERTY(QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType
+ READ inquiryType WRITE setInquiryType)
public:
// FIXME: add more errors
@@ -67,7 +66,7 @@ public:
InputOutputError,
PoweredOffError,
InvalidBluetoothAdapterError,
- UnknownError = 100 //New errors must be added before Unknown error
+ UnknownError = 100 // New errors must be added before Unknown error
};
enum InquiryType {
@@ -76,7 +75,8 @@ public:
};
QBluetoothDeviceDiscoveryAgent(QObject *parent = 0);
- explicit QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent = 0);
+ explicit QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter,
+ QObject *parent = 0);
~QBluetoothDeviceDiscoveryAgent();
QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType() const;
@@ -106,6 +106,10 @@ private:
#ifdef QT_BLUEZ_BLUETOOTH
Q_PRIVATE_SLOT(d_func(), void _q_deviceFound(const QString &address, const QVariantMap &dict))
Q_PRIVATE_SLOT(d_func(), void _q_propertyChanged(const QString &name, const QDBusVariant &value))
+ Q_PRIVATE_SLOT(d_func(), void _q_InterfacesAdded(const QDBusObjectPath &path, InterfaceList interfaceList))
+ Q_PRIVATE_SLOT(d_func(), void _q_discoveryFinished())
+ Q_PRIVATE_SLOT(d_func(), void _q_discoveryInterrupted(const QString &path))
+ Q_PRIVATE_SLOT(d_func(), void _q_PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties))
#endif
};
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index 4f8ecdff..c889d051 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -51,14 +51,16 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(
- const QBluetoothAddress &deviceAdapter)
- : inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry),
- lastError(QBluetoothDeviceDiscoveryAgent::NoError), errorString(QStringLiteral()),
- receiver(0),
- m_adapterAddress(deviceAdapter),
- m_active(false),
- pendingCancel(false),
- pendingStart(false)
+ const QBluetoothAddress &deviceAdapter, QBluetoothDeviceDiscoveryAgent *parent) :
+ inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry),
+ lastError(QBluetoothDeviceDiscoveryAgent::NoError),
+ errorString(QStringLiteral()),
+ receiver(0),
+ m_adapterAddress(deviceAdapter),
+ m_active(false),
+ pendingCancel(false),
+ pendingStart(false),
+ q_ptr(parent)
{
adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter",
"getDefaultAdapter",
@@ -102,8 +104,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
return;
}
- if (!m_adapterAddress.isNull() &&
- adapter.callObjectMethod<jstring>("getAddress").toString() != m_adapterAddress.toString()) {
+ if (!m_adapterAddress.isNull()
+ && adapter.callObjectMethod<jstring>("getAddress").toString()
+ != m_adapterAddress.toString()) {
qCWarning(QT_BT_ANDROID) << "Incorrect local adapter passed.";
lastError = QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError;
errorString = QBluetoothDeviceDiscoveryAgent::tr("Passed address is not a local device.");
@@ -112,14 +115,14 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
}
const int state = adapter.callMethod<jint>("getState");
- if (state != 12 ) { //BluetoothAdapter.STATE_ON
+ if (state != 12) { // BluetoothAdapter.STATE_ON
lastError = QBluetoothDeviceDiscoveryAgent::PoweredOffError;
errorString = QBluetoothDeviceDiscoveryAgent::tr("Device is powered off");
emit q->error(lastError);
return;
}
- //install Java BroadcastReceiver
+ // install Java BroadcastReceiver
if (!receiver) {
receiver = new DeviceDiscoveryBroadcastReceiver();
qRegisterMetaType<QBluetoothDeviceInfo>("QBluetoothDeviceInfo");
@@ -140,7 +143,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
m_active = true;
- qCDebug(QT_BT_ANDROID) << "QBluetoothDeviceDiscoveryAgentPrivate::start() - successfully executed.";
+ qCDebug(QT_BT_ANDROID)
+ << "QBluetoothDeviceDiscoveryAgentPrivate::start() - successfully executed.";
}
void QBluetoothDeviceDiscoveryAgentPrivate::stop()
@@ -163,9 +167,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop()
void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveryFinished()
{
- //We need to guard because Android sends two DISCOVERY_FINISHED when cancelling
- //Also if we have two active agents both receive the same signal.
- //If this one is not active ignore the device information
+ // We need to guard because Android sends two DISCOVERY_FINISHED when cancelling
+ // Also if we have two active agents both receive the same signal.
+ // If this one is not active ignore the device information
if (!m_active)
return;
@@ -180,9 +184,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveryFinished()
pendingStart = pendingCancel = false;
start();
} else {
- //check that it didn't finish due to turned off Bluetooth Device
+ // check that it didn't finish due to turned off Bluetooth Device
const int state = adapter.callMethod<jint>("getState");
- if (state != 12 ) { //BluetoothAdapter.STATE_ON
+ if (state != 12) { // BluetoothAdapter.STATE_ON
lastError = QBluetoothDeviceDiscoveryAgent::PoweredOffError;
errorString = QBluetoothDeviceDiscoveryAgent::tr("Device is powered off");
emit q->error(lastError);
@@ -192,9 +196,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveryFinished()
}
}
-void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices(const QBluetoothDeviceInfo &info)
+void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices(
+ const QBluetoothDeviceInfo &info)
{
- //If we have two active agents both receive the same signal.
+ // If we have two active agents both receive the same signal.
// If this one is not active ignore the device information
if (!m_active)
return;
@@ -205,4 +210,5 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices(const QBlue
qCDebug(QT_BT_ANDROID) << "Device found: " << info.name() << info.address().toString();
emit q->deviceDiscovered(info);
}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index f866b477..fd2c5703 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -48,44 +48,76 @@
#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 "bluez/adapter1_bluez5_p.h"
+#include "bluez/device1_bluez5_p.h"
+#include "bluez/properties_p.h"
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
-QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter)
- : lastError(QBluetoothDeviceDiscoveryAgent::NoError), m_adapterAddress(deviceAdapter), pendingCancel(false), pendingStart(false),
- adapter(0)
+QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(
+ const QBluetoothAddress &deviceAdapter, QBluetoothDeviceDiscoveryAgent *parent) :
+ lastError(QBluetoothDeviceDiscoveryAgent::NoError),
+ m_adapterAddress(deviceAdapter),
+ pendingCancel(false),
+ pendingStart(false),
+ manager(0),
+ adapter(0),
+ managerBluez5(0),
+ adapterBluez5(0),
+ discoveryTimer(0),
+ q_ptr(parent)
{
- manager = new OrgBluezManagerInterface(QLatin1String("org.bluez"), QLatin1String("/"),
- QDBusConnection::systemBus());
+ if (isBluez5()) {
+ Q_Q(QBluetoothDeviceDiscoveryAgent);
+ managerBluez5 = new OrgFreedesktopDBusObjectManagerInterface(
+ QStringLiteral("org.bluez"),
+ QStringLiteral("/"),
+ QDBusConnection::systemBus(), parent);
+ QObject::connect(managerBluez5,
+ SIGNAL(InterfacesAdded(QDBusObjectPath,InterfaceList)),
+ q, SLOT(_q_InterfacesAdded(QDBusObjectPath,InterfaceList)));
+
+ } else {
+ manager = new OrgBluezManagerInterface(QStringLiteral("org.bluez"), QStringLiteral("/"),
+ QDBusConnection::systemBus(), parent);
+ }
inquiryType = QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry;
}
QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate()
{
- delete manager;
delete adapter;
+ delete adapterBluez5;
}
bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const
{
- if(pendingStart)
+ if (pendingStart)
return true;
- if(pendingCancel)
+ if (pendingCancel)
return false;
- return adapter != 0;
+
+ return (adapter || adapterBluez5);
}
void QBluetoothDeviceDiscoveryAgentPrivate::start()
{
-
- if(pendingCancel == true) {
+ if (pendingCancel == true) {
pendingStart = true;
return;
}
discoveredDevices.clear();
+
+ if (managerBluez5) {
+ startBluez5();
+ return;
+ }
+
QDBusPendingReply<QDBusObjectPath> reply;
if (m_adapterAddress.isNull())
@@ -103,18 +135,18 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
return;
}
- adapter = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), reply.value().path(),
+ adapter = new OrgBluezAdapterInterface(QStringLiteral("org.bluez"), reply.value().path(),
QDBusConnection::systemBus());
Q_Q(QBluetoothDeviceDiscoveryAgent);
- QObject::connect(adapter, SIGNAL(DeviceFound(QString,QVariantMap)),
- q, SLOT(_q_deviceFound(QString,QVariantMap)));
- QObject::connect(adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)),
- q, SLOT(_q_propertyChanged(QString,QDBusVariant)));
+ QObject::connect(adapter, SIGNAL(DeviceFound(QString, QVariantMap)),
+ q, SLOT(_q_deviceFound(QString, QVariantMap)));
+ QObject::connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)),
+ q, SLOT(_q_propertyChanged(QString, QDBusVariant)));
QDBusPendingReply<QVariantMap> propertiesReply = adapter->GetProperties();
propertiesReply.waitForFinished();
- if(propertiesReply.isError()) {
+ if (propertiesReply.isError()) {
errorString = propertiesReply.error().message();
delete adapter;
adapter = 0;
@@ -150,14 +182,106 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
}
}
+void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5()
+{
+ Q_Q(QBluetoothDeviceDiscoveryAgent);
+
+ QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError()) {
+ errorString = reply.error().message();
+ lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
+ emit q->error(lastError);
+ return;
+ }
+
+
+ OrgBluezAdapter1Interface *tempAdapter = 0;
+ QMap<QString, QVariantMap> devicesForAdapter; // dbus path for devices for matching adapter
+
+ 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.Adapter1")) {
+ if (tempAdapter)
+ continue;
+
+ if (m_adapterAddress.isNull()) {
+ // use the first found adapter as default
+ tempAdapter = new OrgBluezAdapter1Interface(QStringLiteral("org.bluez"),
+ path.path(),
+ QDBusConnection::systemBus());
+ } else {
+ const QString addressString = ifaceList.value(iface).
+ value(QStringLiteral("Address")).toString();
+ if (m_adapterAddress == QBluetoothAddress(addressString)) {
+ tempAdapter = new OrgBluezAdapter1Interface(
+ QStringLiteral("org.bluez"),
+ path.path(),
+ QDBusConnection::systemBus());
+ }
+ }
+ } else if (iface == QStringLiteral("org.bluez.Device1")) {
+ devicesForAdapter.insert(path.path(), ifaceList.value(iface));
+ }
+ }
+ }
+
+ if (!tempAdapter) {
+ qCDebug(QT_BT_BLUEZ) << "Cannot find Bluez 5 adapter for device search";
+ lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
+ errorString = QBluetoothDeviceDiscoveryAgent::tr("Cannot find valid Bluetooth adapter.");
+ q->error(lastError);
+ return;
+ }
+
+ if (!tempAdapter->powered()) {
+ qCDebug(QT_BT_BLUEZ) << "Aborting device discovery due to offline Bluetooth Adapter";
+ lastError = QBluetoothDeviceDiscoveryAgent::PoweredOffError;
+ errorString = QBluetoothDeviceDiscoveryAgent::tr("Device is powered off");
+ delete tempAdapter;
+ emit q->error(lastError);
+ return;
+ }
+
+ adapterBluez5 = tempAdapter;
+ QtBluezDiscoveryManager::instance()->registerDiscoveryInterest(adapterBluez5->path());
+ QObject::connect(QtBluezDiscoveryManager::instance(), SIGNAL(discoveryInterrupted(QString)),
+ q, SLOT(_q_discoveryInterrupted(QString)));
+
+ // collect initial set of information
+ foreach (const QString &path, devicesForAdapter.keys()) {
+ if (path.indexOf(adapterBluez5->path()) != 0)
+ continue; //devices path doesnt start with same path as adapter
+
+ deviceFoundBluez5(path);
+ }
+
+ // wait 20s and sum up what was found
+ if (!discoveryTimer) {
+ discoveryTimer = new QTimer(q);
+ discoveryTimer->setSingleShot(true);
+ discoveryTimer->setInterval(20000); // 20s
+ QObject::connect(discoveryTimer, SIGNAL(timeout()),
+ q, SLOT(_q_discoveryFinished()));
+ }
+
+ discoveryTimer->start();
+}
+
void QBluetoothDeviceDiscoveryAgentPrivate::stop()
{
+ if (!adapter && !adapterBluez5)
+ return;
+
+ qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO;
+ pendingCancel = true;
+ pendingStart = false;
if (adapter) {
- qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO;
- pendingCancel = true;
- pendingStart = false;
QDBusPendingReply<> reply = adapter->StopDiscovery();
reply.waitForFinished();
+ } else {
+ _q_discoveryFinished();
}
}
@@ -165,24 +289,24 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres
const QVariantMap &dict)
{
const QBluetoothAddress btAddress(address);
- const QString btName = dict.value(QLatin1String("Name")).toString();
- quint32 btClass = dict.value(QLatin1String("Class")).toUInt();
+ const QString btName = dict.value(QStringLiteral("Name")).toString();
+ quint32 btClass = dict.value(QStringLiteral("Class")).toUInt();
qCDebug(QT_BT_BLUEZ) << "Discovered: " << address << btName
- << "Num UUIDs" << dict.value(QLatin1String("UUIDs")).toStringList().count()
- << "total device" << discoveredDevices.count() << "cached"
- << dict.value(QLatin1String("Cached")).toBool()
- << "RSSI" << dict.value(QLatin1String("RSSI")).toInt();
+ << "Num UUIDs" << dict.value(QStringLiteral("UUIDs")).toStringList().count()
+ << "total device" << discoveredDevices.count() << "cached"
+ << dict.value(QStringLiteral("Cached")).toBool()
+ << "RSSI" << dict.value(QStringLiteral("RSSI")).toInt();
QBluetoothDeviceInfo device(btAddress, btName, btClass);
- if(dict.value(QLatin1String("RSSI")).isValid())
- device.setRssi(dict.value(QLatin1String("RSSI")).toInt());
+ if (dict.value(QStringLiteral("RSSI")).isValid())
+ device.setRssi(dict.value(QStringLiteral("RSSI")).toInt());
QList<QBluetoothUuid> uuids;
- foreach (const QString &u, dict.value(QLatin1String("UUIDs")).toStringList()) {
+ foreach (const QString &u, dict.value(QLatin1String("UUIDs")).toStringList())
uuids.append(QBluetoothUuid(u));
- }
device.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete);
- device.setCached(dict.value(QLatin1String("Cached")).toBool());
+ device.setCached(dict.value(QStringLiteral("Cached")).toBool());
+
/*
* Bluez v4.1 does not have extra bit which gives information if device is Bluetooth
@@ -193,9 +317,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres
device.setCoreConfiguration(QBluetoothDeviceInfo::LowEnergyCoreConfiguration);
else
device.setCoreConfiguration(QBluetoothDeviceInfo::BaseRateCoreConfiguration);
- for(int i = 0; i < discoveredDevices.size(); i++){
- if(discoveredDevices[i].address() == device.address()) {
- if(discoveredDevices[i] == device) {
+ for (int i = 0; i < discoveredDevices.size(); i++) {
+ if (discoveredDevices[i].address() == device.address()) {
+ if (discoveredDevices[i] == device) {
qCDebug(QT_BT_BLUEZ) << "Duplicate: " << address;
return;
}
@@ -213,6 +337,63 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres
emit q->deviceDiscovered(device);
}
+void QBluetoothDeviceDiscoveryAgentPrivate::deviceFoundBluez5(const QString& devicePath)
+{
+ Q_Q(QBluetoothDeviceDiscoveryAgent);
+
+ if (!q->isActive())
+ return;
+
+ OrgBluezDevice1Interface device(QStringLiteral("org.bluez"), devicePath,
+ QDBusConnection::systemBus());
+
+ if (device.adapter().path() != adapterBluez5->path())
+ return;
+
+ const QBluetoothAddress btAddress(device.address());
+ if (btAddress.isNull()) // no point reporting an empty address
+ return;
+
+ const QString btName = device.alias();
+ quint32 btClass = device.classProperty();
+
+ qCDebug(QT_BT_BLUEZ) << "Discovered: " << btAddress.toString() << btName
+ << "Num UUIDs" << device.uUIDs().count()
+ << "total device" << discoveredDevices.count() << "cached"
+ << "RSSI" << device.rSSI();
+
+ OrgFreedesktopDBusPropertiesInterface *prop = new OrgFreedesktopDBusPropertiesInterface(
+ QStringLiteral("org.bluez"), devicePath, QDBusConnection::systemBus(), q);
+ QObject::connect(prop, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)),
+ q, SLOT(_q_PropertiesChanged(QString,QVariantMap,QStringList)));
+ // remember what we have to cleanup
+ propertyMonitors.append(prop);
+
+ // read information
+ QBluetoothDeviceInfo deviceInfo(btAddress, btName, btClass);
+ deviceInfo.setRssi(device.rSSI());
+ QList<QBluetoothUuid> uuids;
+ foreach (const QString &u, device.uUIDs())
+ uuids.append(QBluetoothUuid(u));
+ deviceInfo.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete);
+
+ for (int i = 0; i < discoveredDevices.size(); i++) {
+ if (discoveredDevices[i].address() == deviceInfo.address()) {
+ if (discoveredDevices[i] == deviceInfo) {
+ qCDebug(QT_BT_BLUEZ) << "Duplicate: " << btAddress.toString();
+ return;
+ }
+ discoveredDevices.replace(i, deviceInfo);
+
+ emit q->deviceDiscovered(deviceInfo);
+ return; // this works if the list doesn't contain duplicates. Don't let it.
+ }
+ }
+
+ discoveredDevices.append(deviceInfo);
+ emit q->deviceDiscovered(deviceInfo);
+}
+
void QBluetoothDeviceDiscoveryAgentPrivate::_q_propertyChanged(const QString &name,
const QDBusVariant &value)
{
@@ -222,19 +403,112 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_propertyChanged(const QString &na
Q_Q(QBluetoothDeviceDiscoveryAgent);
adapter->deleteLater();
adapter = 0;
- if(pendingCancel && !pendingStart){
+ if (pendingCancel && !pendingStart) {
emit q->canceled();
pendingCancel = false;
- }
- else if(pendingStart){
+ } else if (pendingStart) {
pendingStart = false;
pendingCancel = false;
start();
- }
- else {
+ } else {
emit q->finished();
}
}
}
+void QBluetoothDeviceDiscoveryAgentPrivate::_q_InterfacesAdded(const QDBusObjectPath &object_path,
+ InterfaceList interfaces_and_properties)
+{
+ Q_Q(QBluetoothDeviceDiscoveryAgent);
+
+ if (!q->isActive())
+ return;
+
+ if (interfaces_and_properties.contains(QStringLiteral("org.bluez.Device1"))) {
+ // device interfaces belonging to different adapter
+ // will be filtered out by deviceFoundBluez5();
+ deviceFoundBluez5(object_path.path());
+ }
+}
+
+void QBluetoothDeviceDiscoveryAgentPrivate::_q_discoveryFinished()
+{
+ Q_Q(QBluetoothDeviceDiscoveryAgent);
+
+ if (discoveryTimer)
+ discoveryTimer->stop();
+
+ QtBluezDiscoveryManager::instance()->disconnect(q);
+ QtBluezDiscoveryManager::instance()->unregisterDiscoveryInterest(adapterBluez5->path());
+
+ qDeleteAll(propertyMonitors);
+ propertyMonitors.clear();
+
+ delete adapterBluez5;
+ adapterBluez5 = 0;
+
+ if (pendingCancel && !pendingStart) {
+ emit q->canceled();
+ pendingCancel = false;
+ } else if (pendingStart) {
+ pendingStart = false;
+ pendingCancel = false;
+ start();
+ } else {
+ emit q->finished();
+ }
+}
+
+void QBluetoothDeviceDiscoveryAgentPrivate::_q_discoveryInterrupted(const QString &path)
+{
+ Q_Q(QBluetoothDeviceDiscoveryAgent);
+
+ if (!q->isActive())
+ return;
+
+ if (path == adapterBluez5->path()) {
+ qCWarning(QT_BT_BLUEZ) << "Device discovery aborted due to unexpected adapter changes";
+
+ if (discoveryTimer)
+ discoveryTimer->stop();
+
+ QtBluezDiscoveryManager::instance()->disconnect(q);
+ // no need to call unregisterDiscoveryInterest since QtBluezDiscoveryManager
+ // does this automatically when emitting discoveryInterrupted(QString) signal
+
+ delete adapterBluez5;
+ adapterBluez5 = 0;
+
+ errorString = QBluetoothDeviceDiscoveryAgent::tr("Bluetooth adapter error");
+ lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
+ emit q->error(lastError);
+ }
+}
+
+void QBluetoothDeviceDiscoveryAgentPrivate::_q_PropertiesChanged(const QString &interface,
+ const QVariantMap &changed_properties,
+ const QStringList &)
+{
+ Q_Q(QBluetoothDeviceDiscoveryAgent);
+ if (interface == QStringLiteral("org.bluez.Device1")
+ && changed_properties.contains(QStringLiteral("RSSI"))) {
+ OrgFreedesktopDBusPropertiesInterface *props =
+ qobject_cast<OrgFreedesktopDBusPropertiesInterface *>(q->sender());
+ if (!props)
+ return;
+
+ OrgBluezDevice1Interface device(QStringLiteral("org.bluez"), props->path(),
+ QDBusConnection::systemBus());
+ for (int i = 0; i < discoveredDevices.size(); i++) {
+ if (discoveredDevices[i].address().toString() == device.address()) {
+ qCDebug(QT_BT_BLUEZ) << "Updating RSSI for" << device.address()
+ << changed_properties.value(QStringLiteral("RSSI"));
+ discoveredDevices[i].setRssi(
+ changed_properties.value(QStringLiteral("RSSI")).toInt());
+ return;
+ }
+ }
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp
index 72a3e853..181586bd 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp
@@ -48,7 +48,10 @@
QT_BEGIN_NAMESPACE
-QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter)
+QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(
+ const QBluetoothAddress &deviceAdapter,
+ QBluetoothDeviceDiscoveryAgent *parent)
+ : q_ptr(parent)
{
Q_UNUSED(deviceAdapter);
inquiryType = QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry;
@@ -75,6 +78,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
void QBluetoothDeviceDiscoveryAgentPrivate::stop()
{
}
+
#ifdef QT_BLUEZ_BLUETOOTH
void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &address,
const QVariantMap &dict)
@@ -89,6 +93,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_propertyChanged(const QString &na
Q_UNUSED(name);
Q_UNUSED(value);
}
+
#endif
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
index 71dec409..168b6c0c 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
@@ -54,8 +54,14 @@
#include <QtBluetooth/QBluetoothLocalDevice>
#ifdef QT_BLUEZ_BLUETOOTH
+#include "bluez/bluez5_helper_p.h"
+
class OrgBluezManagerInterface;
class OrgBluezAdapterInterface;
+class OrgFreedesktopDBusObjectManagerInterface;
+class OrgFreedesktopDBusPropertiesInterface;
+class OrgBluezAdapter1Interface;
+class OrgBluezDevice1Interface;
QT_BEGIN_NAMESPACE
class QDBusVariant;
@@ -69,14 +75,17 @@ QT_BEGIN_NAMESPACE
class QBluetoothDeviceDiscoveryAgentPrivate
#if defined(QT_QNX_BLUETOOTH) || defined(QT_ANDROID_BLUETOOTH)
-: public QObject {
+ : public QObject
+{
Q_OBJECT
#else
{
#endif
Q_DECLARE_PUBLIC(QBluetoothDeviceDiscoveryAgent)
public:
- QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter);
+ QBluetoothDeviceDiscoveryAgentPrivate(
+ const QBluetoothAddress &deviceAdapter,
+ QBluetoothDeviceDiscoveryAgent *parent);
~QBluetoothDeviceDiscoveryAgentPrivate();
void start();
@@ -86,6 +95,13 @@ public:
#ifdef QT_BLUEZ_BLUETOOTH
void _q_deviceFound(const QString &address, const QVariantMap &dict);
void _q_propertyChanged(const QString &name, const QDBusVariant &value);
+ void _q_InterfacesAdded(const QDBusObjectPath &object_path,
+ InterfaceList interfaces_and_properties);
+ void _q_discoveryFinished();
+ void _q_discoveryInterrupted(const QString &path);
+ void _q_PropertiesChanged(const QString &interface,
+ const QVariantMap &changed_properties,
+ const QStringList &invalidated_properties);
#endif
private:
@@ -96,12 +112,12 @@ private:
QString errorString;
#ifdef QT_ANDROID_BLUETOOTH
-private Q_SLOTS:
+private slots:
void processDiscoveryFinished();
- void processDiscoveredDevices(const QBluetoothDeviceInfo& info);
+ void processDiscoveredDevices(const QBluetoothDeviceInfo &info);
private:
- DeviceDiscoveryBroadcastReceiver* receiver;
+ DeviceDiscoveryBroadcastReceiver *receiver;
QBluetoothAddress m_adapterAddress;
bool m_active;
QAndroidJniObject adapter;
@@ -113,8 +129,15 @@ private:
bool pendingStart;
OrgBluezManagerInterface *manager;
OrgBluezAdapterInterface *adapter;
+ OrgFreedesktopDBusObjectManagerInterface *managerBluez5;
+ OrgBluezAdapter1Interface *adapterBluez5;
+ QTimer *discoveryTimer;
+ QList<OrgFreedesktopDBusPropertiesInterface *> propertyMonitors;
+
+ void deviceFoundBluez5(const QString& devicePath);
+ void startBluez5();
#elif defined(QT_QNX_BLUETOOTH)
- private Q_SLOTS:
+private slots:
void finished();
void remoteDevicesChanged(int);
void controlReply(ppsResult result);
@@ -127,7 +150,7 @@ private:
int m_rdfd;
bool m_active;
- enum Ops{
+ enum Ops {
None,
Cancel,
Start
@@ -139,7 +162,6 @@ private:
#endif
QBluetoothDeviceDiscoveryAgent *q_ptr;
-
};
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
index 42b6ceff..4132fe76 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
@@ -46,12 +46,17 @@
#include <QtCore/private/qcore_unix_p.h>
-
QT_BEGIN_NAMESPACE
-QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter):
- QObject(0), lastError(QBluetoothDeviceDiscoveryAgent::NoError),
- m_rdfd(-1), m_active(false), m_nextOp(None), m_currentOp(None)
+QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(
+ const QBluetoothAddress &deviceAdapter, QBluetoothDeviceDiscoveryAgent *parent) :
+ QObject(parent),
+ lastError(QBluetoothDeviceDiscoveryAgent::NoError),
+ m_rdfd(-1),
+ m_active(false),
+ m_nextOp(None),
+ m_currentOp(None),
+ q_ptr(parent)
{
Q_UNUSED(deviceAdapter);
inquiryType = QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry;
@@ -86,16 +91,18 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
m_nextOp = Start;
return;
}
- if (m_nextOp == Cancel) {
+ if (m_nextOp == Cancel)
m_nextOp = None;
- }
m_currentOp = Start;
if (m_rdfd != -1) {
qCDebug(QT_BT_QNX) << "RDev FD still open";
- } else if ((m_rdfd = qt_safe_open("/pps/services/bluetooth/remote_devices/.all", O_RDONLY)) == -1) {
- qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "rdfd - failed to open /pps/services/bluetooth/remote_devices/.all"
- << m_rdfd;
+ } else if ((m_rdfd
+ = qt_safe_open("/pps/services/bluetooth/remote_devices/.all",
+ O_RDONLY)) == -1) {
+ qCWarning(QT_BT_QNX) << Q_FUNC_INFO
+ << "rdfd - failed to open /pps/services/bluetooth/remote_devices/.all"
+ << m_rdfd;
lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
errorString = QBluetoothDeviceDiscoveryAgent::tr("Cannot open remote device socket");
emit q->error(lastError);
@@ -106,7 +113,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
if (!m_rdNotifier) {
qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "failed to connect to m_rdNotifier";
lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
- errorString = QBluetoothDeviceDiscoveryAgent::tr("Cannot connect to Bluetooth socket notifier");
+ errorString = QBluetoothDeviceDiscoveryAgent::tr(
+ "Cannot connect to Bluetooth socket notifier");
emit q->error(lastError);
stop();
return;
@@ -114,7 +122,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
}
if (ppsSendControlMessage("device_search", this)) {
- //If there is no new results after 7 seconds, the device inquire will be stopped
+ // If there is no new results after 7 seconds, the device inquire will be stopped
m_finishedTimer.start(10000);
connect(m_rdNotifier, SIGNAL(activated(int)), this, SLOT(remoteDevicesChanged(int)));
} else {
@@ -138,7 +146,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop()
m_currentOp = Cancel;
qCDebug(QT_BT_QNX) << "Stopping device search";
- ppsSendControlMessage("cancel_device_search",this);
+ ppsSendControlMessage("cancel_device_search", this);
if (m_rdNotifier) {
delete m_rdNotifier;
@@ -160,9 +168,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
QBluetoothAddress deviceAddr;
QString deviceName;
- if (!ppsReadRemoteDevice(fd, &ppsDecoder, &deviceAddr, &deviceName)) {
+ if (!ppsReadRemoteDevice(fd, &ppsDecoder, &deviceAddr, &deviceName))
return;
- }
bool paired = false;
int cod = 0;
@@ -186,8 +193,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
deviceInfo.setRssi(rssi);
bool updated = false;
- //Prevent a device from being listed twice
- for (int i=0; i < discoveredDevices.size(); i++) {
+ // Prevent a device from being listed twice
+ for (int i = 0; i < discoveredDevices.size(); i++) {
if (discoveredDevices.at(i).address() == deviceInfo.address()) {
updated = true;
if (discoveredDevices.at(i) == deviceInfo) {
@@ -198,7 +205,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
}
}
}
- //Starts the timer again
+ // Starts the timer again
m_finishedTimer.start(7000);
if (!deviceAddr.isNull()) {
qCDebug(QT_BT_QNX) << "Device discovered: " << deviceName << deviceAddr.toString();
@@ -217,7 +224,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
deviceInfo.setCoreConfiguration(QBluetoothDeviceInfo::BaseRateCoreConfiguration);
}
discoveredDevices.append(deviceInfo);
- if (!updated)//We are not allowed to emit a signal with the updated version
+ if (!updated) // We are not allowed to emit a signal with the updated version
emit q_ptr->deviceDiscovered(discoveredDevices.last());
}
}
@@ -227,11 +234,11 @@ void QBluetoothDeviceDiscoveryAgentPrivate::controlReply(ppsResult result)
Q_Q(QBluetoothDeviceDiscoveryAgent);
if (result.msg == QStringLiteral("device_search") && m_currentOp == Start) {
if (result.dat.size() > 0 && result.dat.first() == QStringLiteral("EOK")) {
- //Do nothing. We can not be certain, that the device search is over yet
+ // Do nothing. We can not be certain, that the device search is over yet
} else if (result.error == 16) {
qCDebug(QT_BT_QNX) << "Could not start device inquire bc resource is busy";
- if (m_nextOp == None) { //We try again
- ppsSendControlMessage("cancel_device_search",this);
+ if (m_nextOp == None) { // We try again
+ ppsSendControlMessage("cancel_device_search", this);
QTimer::singleShot(5000, this, SLOT(startDeviceSearch()));
m_finishedTimer.start(20000);
}
@@ -240,17 +247,18 @@ void QBluetoothDeviceDiscoveryAgentPrivate::controlReply(ppsResult result)
qCWarning(QT_BT_QNX) << "A PPS Bluetooth error occurred:";
lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
errorString = result.errorMsg;
- Q_EMIT q_ptr->error(QBluetoothDeviceDiscoveryAgent::InputOutputError);
+ emit q_ptr->error(QBluetoothDeviceDiscoveryAgent::InputOutputError);
stop();
}
processNextOp();
- } else if (result.msg == QStringLiteral("cancel_device_search") && m_currentOp == Cancel && !isFinished) {
+ } else if (result.msg == QStringLiteral("cancel_device_search") && m_currentOp == Cancel
+ && !isFinished) {
qCDebug(QT_BT_QNX) << "Cancel device search";
-// if (!result.errorMsg.isEmpty()) {
-// lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
-// errorString = result.errorMsg;
-// q_ptr->error(QBluetoothDeviceDiscoveryAgent::InputOutputError);
-// }
+// if (!result.errorMsg.isEmpty()) {
+// lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
+// errorString = result.errorMsg;
+// q_ptr->error(QBluetoothDeviceDiscoveryAgent::InputOutputError);
+// }
emit q->canceled();
processNextOp();
}
@@ -258,9 +266,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::controlReply(ppsResult result)
void QBluetoothDeviceDiscoveryAgentPrivate::controlEvent(ppsResult result)
{
- if (result.msg == QStringLiteral("device_added")) {
+ if (result.msg == QStringLiteral("device_added"))
qCDebug(QT_BT_QNX) << "Device was added" << result.dat.first();
- }
}
void QBluetoothDeviceDiscoveryAgentPrivate::finished()
@@ -275,9 +282,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::finished()
void QBluetoothDeviceDiscoveryAgentPrivate::startDeviceSearch()
{
- if (m_currentOp == Start) {
- ppsSendControlMessage("device_search", this); //Try again
- }
+ if (m_currentOp == Start)
+ ppsSendControlMessage("device_search", this); // Try again
}
void QBluetoothDeviceDiscoveryAgentPrivate::processNextOp()
@@ -289,12 +295,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processNextOp()
m_currentOp = m_nextOp;
m_nextOp = None;
- if (m_currentOp == Start) {
+ if (m_currentOp == Start)
start();
- } else if (m_currentOp == Cancel) {
+ else if (m_currentOp == Cancel)
stop();
- }
}
QT_END_NAMESPACE
-
diff --git a/src/bluetooth/qbluetoothdeviceinfo.cpp b/src/bluetooth/qbluetoothdeviceinfo.cpp
index 58d45e3b..1dd100e0 100644
--- a/src/bluetooth/qbluetoothdeviceinfo.cpp
+++ b/src/bluetooth/qbluetoothdeviceinfo.cpp
@@ -216,7 +216,6 @@ QT_BEGIN_NAMESPACE
\value HealthStepCounter A pedometer.
*/
-
/*!
\enum QBluetoothDeviceInfo::ServiceClass
@@ -257,22 +256,23 @@ QT_BEGIN_NAMESPACE
for standard and Low Energy device.
\value LowEnergyCoreCOnfiguration The device is a Bluetooth Low Energy device.
*/
-
-QBluetoothDeviceInfoPrivate::QBluetoothDeviceInfoPrivate()
- : valid(false), cached(false), rssi(1),
- serviceClasses(QBluetoothDeviceInfo::NoService),
- majorDeviceClass(QBluetoothDeviceInfo::MiscellaneousDevice),
- minorDeviceClass(0),
- serviceUuidsCompleteness(QBluetoothDeviceInfo::DataUnavailable),
- deviceCoreConfiguration(QBluetoothDeviceInfo::BaseRateCoreConfiguration)
+QBluetoothDeviceInfoPrivate::QBluetoothDeviceInfoPrivate() :
+ valid(false),
+ cached(false),
+ rssi(1),
+ serviceClasses(QBluetoothDeviceInfo::NoService),
+ majorDeviceClass(QBluetoothDeviceInfo::MiscellaneousDevice),
+ minorDeviceClass(0),
+ serviceUuidsCompleteness(QBluetoothDeviceInfo::DataUnavailable),
+ deviceCoreConfiguration(QBluetoothDeviceInfo::BaseRateCoreConfiguration)
{
}
/*!
Constructs an invalid QBluetoothDeviceInfo object.
*/
-QBluetoothDeviceInfo::QBluetoothDeviceInfo()
-: d_ptr(new QBluetoothDeviceInfoPrivate)
+QBluetoothDeviceInfo::QBluetoothDeviceInfo() :
+ d_ptr(new QBluetoothDeviceInfoPrivate)
{
}
@@ -290,8 +290,9 @@ QBluetoothDeviceInfo::QBluetoothDeviceInfo()
\row \li 13 - 23 \li 11 \li Service class.
\endtable
*/
-QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, quint32 classOfDevice)
-: d_ptr(new QBluetoothDeviceInfoPrivate)
+QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name,
+ quint32 classOfDevice) :
+ d_ptr(new QBluetoothDeviceInfoPrivate)
{
Q_D(QBluetoothDeviceInfo);
@@ -312,8 +313,8 @@ QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, con
/*!
Constructs a QBluetoothDeviceInfo that is a copy of \a other.
*/
-QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other)
-: d_ptr(new QBluetoothDeviceInfoPrivate)
+QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other) :
+ d_ptr(new QBluetoothDeviceInfoPrivate)
{
*this = other;
}
@@ -335,6 +336,7 @@ bool QBluetoothDeviceInfo::isValid() const
return d->valid;
}
+
/*!
Returns the signal strength when the device was last scanned
*/
@@ -407,7 +409,6 @@ bool QBluetoothDeviceInfo::operator==(const QBluetoothDeviceInfo &other) const
return false;
return true;
-
}
/*!
@@ -473,7 +474,8 @@ quint8 QBluetoothDeviceInfo::minorDeviceClass() const
/*!
Sets the list of service UUIDs to \a uuids and the completeness of the data to \a completeness.
*/
-void QBluetoothDeviceInfo::setServiceUuids(const QList<QBluetoothUuid> &uuids, DataCompleteness completeness)
+void QBluetoothDeviceInfo::setServiceUuids(const QList<QBluetoothUuid> &uuids,
+ DataCompleteness completeness)
{
Q_D(QBluetoothDeviceInfo);
diff --git a/src/bluetooth/qbluetoothdeviceinfo.h b/src/bluetooth/qbluetoothdeviceinfo.h
index a9aad493..2bfc8b55 100644
--- a/src/bluetooth/qbluetoothdeviceinfo.h
+++ b/src/bluetooth/qbluetoothdeviceinfo.h
@@ -204,7 +204,8 @@ public:
Q_DECLARE_FLAGS(CoreConfigurations, CoreConfiguration)
QBluetoothDeviceInfo();
- QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, quint32 classOfDevice);
+ QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name,
+ quint32 classOfDevice);
QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other);
~QBluetoothDeviceInfo();
diff --git a/src/bluetooth/qbluetoothhostinfo.cpp b/src/bluetooth/qbluetoothhostinfo.cpp
index 00ce0680..e20d52ac 100644
--- a/src/bluetooth/qbluetoothhostinfo.cpp
+++ b/src/bluetooth/qbluetoothhostinfo.cpp
@@ -56,16 +56,16 @@ QT_BEGIN_NAMESPACE
/*!
Constrcuts a null QBluetoothHostInfo object.
*/
-QBluetoothHostInfo::QBluetoothHostInfo()
- : d_ptr(new QBluetoothHostInfoPrivate)
+QBluetoothHostInfo::QBluetoothHostInfo() :
+ d_ptr(new QBluetoothHostInfoPrivate)
{
}
/*!
Constrcuts a new QBluetoothHostInfo which is a copy of \a other.
*/
-QBluetoothHostInfo::QBluetoothHostInfo(const QBluetoothHostInfo &other)
- : d_ptr(new QBluetoothHostInfoPrivate)
+QBluetoothHostInfo::QBluetoothHostInfo(const QBluetoothHostInfo &other) :
+ d_ptr(new QBluetoothHostInfoPrivate)
{
Q_D(QBluetoothHostInfo);
diff --git a/src/bluetooth/qbluetoothhostinfo.h b/src/bluetooth/qbluetoothhostinfo.h
index b4428a82..f51837fe 100644
--- a/src/bluetooth/qbluetoothhostinfo.h
+++ b/src/bluetooth/qbluetoothhostinfo.h
@@ -68,7 +68,6 @@ private:
QBluetoothHostInfoPrivate *d_ptr;
};
-
QT_END_NAMESPACE
#endif
diff --git a/src/bluetooth/qbluetoothhostinfo_p.h b/src/bluetooth/qbluetoothhostinfo_p.h
index 2ce603c6..a44b29dd 100644
--- a/src/bluetooth/qbluetoothhostinfo_p.h
+++ b/src/bluetooth/qbluetoothhostinfo_p.h
@@ -49,7 +49,9 @@ QT_BEGIN_NAMESPACE
class QBluetoothHostInfoPrivate
{
public:
- QBluetoothHostInfoPrivate() {}
+ QBluetoothHostInfoPrivate()
+ {
+ }
QBluetoothAddress m_address;
QString m_name;
diff --git a/src/bluetooth/qbluetoothlocaldevice.cpp b/src/bluetooth/qbluetoothlocaldevice.cpp
index 14140846..c5b68645 100644
--- a/src/bluetooth/qbluetoothlocaldevice.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice.cpp
@@ -102,18 +102,17 @@ QT_BEGIN_NAMESPACE
*/
-namespace
+namespace {
+class LocalDeviceRegisterMetaTypes
{
- class LocalDeviceRegisterMetaTypes
+public:
+ LocalDeviceRegisterMetaTypes()
{
- public:
- LocalDeviceRegisterMetaTypes()
- {
- qRegisterMetaType<QBluetoothLocalDevice::HostMode>("QBluetoothLocalDevice::HostMode");
- qRegisterMetaType<QBluetoothLocalDevice::Pairing>("QBluetoothLocalDevice::Pairing");
- qRegisterMetaType<QBluetoothLocalDevice::Error>("QBluetoothLocalDevice::Error");
- }
- } _registerLocalDeviceMetaTypes;
+ qRegisterMetaType<QBluetoothLocalDevice::HostMode>("QBluetoothLocalDevice::HostMode");
+ qRegisterMetaType<QBluetoothLocalDevice::Pairing>("QBluetoothLocalDevice::Pairing");
+ qRegisterMetaType<QBluetoothLocalDevice::Error>("QBluetoothLocalDevice::Error");
+ }
+} _registerLocalDeviceMetaTypes;
}
/*!
@@ -233,7 +232,6 @@ bool QBluetoothLocalDevice::isValid() const
Returns the current bluetooth pairing status of \a address, if it's unpaired, paired, or paired and authorized.
*/
-
/*!
\fn QBluetoothLocalDevice::pairingDisplayConfirmation(const QBluetoothAddress &address, QString pin)
@@ -286,7 +284,6 @@ bool QBluetoothLocalDevice::isValid() const
Signal emitted if there's an exceptional \a error while pairing.
*/
-
/*!
\fn QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = 0)
diff --git a/src/bluetooth/qbluetoothlocaldevice.h b/src/bluetooth/qbluetoothlocaldevice.h
index 597496b7..661e6a9c 100644
--- a/src/bluetooth/qbluetoothlocaldevice.h
+++ b/src/bluetooth/qbluetoothlocaldevice.h
@@ -39,7 +39,6 @@
**
****************************************************************************/
-
#ifndef QBLUETOOTHLOCALDEVICE_H
#define QBLUETOOTHLOCALDEVICE_H
@@ -76,9 +75,9 @@ public:
};
enum Error {
- NoError,
- PairingError,
- UnknownError = 100
+ NoError,
+ PairingError,
+ UnknownError = 100
};
QBluetoothLocalDevice(QObject *parent = 0);
explicit QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = 0);
diff --git a/src/bluetooth/qbluetoothlocaldevice_android.cpp b/src/bluetooth/qbluetoothlocaldevice_android.cpp
index ff36837b..475ecd95 100644
--- a/src/bluetooth/qbluetoothlocaldevice_android.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_android.cpp
@@ -55,23 +55,26 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(
- QBluetoothLocalDevice *q, const QBluetoothAddress &address)
- : q_ptr(q), obj(0), pendingHostModeTransition(false)
+ QBluetoothLocalDevice *q, const QBluetoothAddress &address) :
+ q_ptr(q),
+ obj(0),
+ pendingHostModeTransition(false)
{
initialize(address);
receiver = new LocalDeviceBroadcastReceiver(q_ptr);
- QObject::connect(receiver, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
- this, SLOT(processHostModeChange(QBluetoothLocalDevice::HostMode)));
- QObject::connect(receiver, SIGNAL(pairingStateChanged(QBluetoothAddress,QBluetoothLocalDevice::Pairing)),
- this, SLOT(processPairingStateChanged(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));
- QObject::connect(receiver, SIGNAL(connectDeviceChanges(QBluetoothAddress,bool)),
- this, SLOT(processConnectDeviceChanges(QBluetoothAddress,bool)));
- QObject::connect(receiver, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress,QString)),
- this, SLOT(processDisplayConfirmation(QBluetoothAddress,QString)));
+ connect(receiver, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
+ this, SLOT(processHostModeChange(QBluetoothLocalDevice::HostMode)));
+ connect(receiver, SIGNAL(pairingStateChanged(QBluetoothAddress,
+ QBluetoothLocalDevice::Pairing)),
+ this, SLOT(processPairingStateChanged(QBluetoothAddress,
+ QBluetoothLocalDevice::Pairing)));
+ connect(receiver, SIGNAL(connectDeviceChanges(QBluetoothAddress, bool)),
+ this, SLOT(processConnectDeviceChanges(QBluetoothAddress, bool)));
+ connect(receiver, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress, QString)),
+ this, SLOT(processDisplayConfirmation(QBluetoothAddress, QString)));
}
-
QBluetoothLocalDevicePrivate::~QBluetoothLocalDevicePrivate()
{
receiver->unregisterReceiver();
@@ -90,17 +93,21 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address)
jclass btAdapterClass = env->FindClass("android/bluetooth/BluetoothAdapter");
if (btAdapterClass == NULL) {
- qCWarning(QT_BT_ANDROID) << "Native registration unable to find class android/bluetooth/BluetoothAdapter";
+ qCWarning(QT_BT_ANDROID)
+ << "Native registration unable to find class android/bluetooth/BluetoothAdapter";
return;
}
- jmethodID getDefaultAdapterID = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;");
+ jmethodID getDefaultAdapterID
+ = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter",
+ "()Landroid/bluetooth/BluetoothAdapter;");
if (getDefaultAdapterID == NULL) {
- qCWarning(QT_BT_ANDROID) << "Native registration unable to get method ID: getDefaultAdapter of android/bluetooth/BluetoothAdapter";
+ qCWarning(QT_BT_ANDROID)
+ << "Native registration unable to get method ID: " \
+ "getDefaultAdapter of android/bluetooth/BluetoothAdapter";
return;
}
-
jobject btAdapterObject = env->CallStaticObjectMethod(btAdapterClass, getDefaultAdapterID);
if (btAdapterObject == NULL) {
qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth";
@@ -112,14 +119,13 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address)
if (!obj->isValid()) {
delete obj;
obj = 0;
- } else {
- if (!address.isNull()) {
- const QString localAddress = obj->callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
- if (localAddress != address.toString()) {
- //passed address not local one -> invalid
- delete obj;
- obj = 0;
- }
+ } else if (!address.isNull()) {
+ const QString localAddress
+ = obj->callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
+ if (localAddress != address.toString()) {
+ // passed address not local one -> invalid
+ delete obj;
+ obj = 0;
}
}
@@ -132,17 +138,16 @@ bool QBluetoothLocalDevicePrivate::isValid() const
return obj ? true : false;
}
-
void QBluetoothLocalDevicePrivate::processHostModeChange(QBluetoothLocalDevice::HostMode newMode)
{
if (!pendingHostModeTransition) {
- //if not in transition -> pass data on
+ // if not in transition -> pass data on
emit q_ptr->hostModeStateChanged(newMode);
return;
}
if (isValid() && newMode == QBluetoothLocalDevice::HostPoweredOff) {
- bool success = (bool) obj->callMethod<jboolean>("enable", "()Z");
+ bool success = (bool)obj->callMethod<jboolean>("enable", "()Z");
if (!success)
emit q_ptr->error(QBluetoothLocalDevice::UnknownError);
}
@@ -162,26 +167,25 @@ int QBluetoothLocalDevicePrivate::pendingPairing(const QBluetoothAddress &addres
return -1;
}
-
void QBluetoothLocalDevicePrivate::processPairingStateChanged(
- const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
+ const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
{
int index = pendingPairing(address);
if (index < 0)
- return; //ignore unrelated pairing signals
+ return; // ignore unrelated pairing signals
QPair<QBluetoothAddress, bool> entry = pendingPairings.takeAt(index);
- if ((entry.second && pairing == QBluetoothLocalDevice::Paired) ||
- (!entry.second && pairing == QBluetoothLocalDevice::Unpaired)) {
+ if ((entry.second && pairing == QBluetoothLocalDevice::Paired)
+ || (!entry.second && pairing == QBluetoothLocalDevice::Unpaired)) {
emit q_ptr->pairingFinished(address, pairing);
} else {
emit q_ptr->error(QBluetoothLocalDevice::PairingError);
}
-
}
-void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothAddress& address, bool isConnectEvent)
+void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothAddress &address,
+ bool isConnectEvent)
{
int index = -1;
for (int i = 0; i < connectedDevices.count(); i++) {
@@ -191,21 +195,22 @@ void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothA
}
}
- if (isConnectEvent) { //connect event
+ if (isConnectEvent) { // connect event
if (index >= 0)
return;
connectedDevices.append(address);
emit q_ptr->deviceConnected(address);
- } else { //disconnect event
+ } else { // disconnect event
connectedDevices.removeAll(address);
emit q_ptr->deviceDisconnected(address);
}
}
-void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAddress &address, const QString &pin)
+void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAddress &address,
+ const QString &pin)
{
- //only send pairing notification for pairing requests issued by
- //this QBluetoothLocalDevice instance
+ // only send pairing notification for pairing requests issued by
+ // this QBluetoothLocalDevice instance
if (pendingPairing(address) == -1)
return;
@@ -213,14 +218,14 @@ void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAd
emit q_ptr->pairingDisplayPinCode(address, pin);
}
-QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent)
-: QObject(parent),
+QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) :
+ QObject(parent),
d_ptr(new QBluetoothLocalDevicePrivate(this, QBluetoothAddress()))
{
}
-QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent)
-: QObject(parent),
+QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) :
+ QObject(parent),
d_ptr(new QBluetoothLocalDevicePrivate(this, address))
{
}
@@ -236,8 +241,10 @@ QString QBluetoothLocalDevice::name() const
QBluetoothAddress QBluetoothLocalDevice::address() const
{
QString result;
- if (d_ptr->adapter())
- result = d_ptr->adapter()->callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
+ if (d_ptr->adapter()) {
+ result
+ = d_ptr->adapter()->callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
+ }
QBluetoothAddress address(result);
return address;
@@ -249,7 +256,7 @@ void QBluetoothLocalDevice::powerOn()
return;
if (d_ptr->adapter()) {
- bool ret = (bool) d_ptr->adapter()->callMethod<jboolean>("enable", "()Z");
+ bool ret = (bool)d_ptr->adapter()->callMethod<jboolean>("enable", "()Z");
if (!ret)
emit error(QBluetoothLocalDevice::UnknownError);
}
@@ -267,23 +274,26 @@ void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode requeste
if (mode == QBluetoothLocalDevice::HostPoweredOff) {
bool success = false;
if (d_ptr->adapter())
- success = (bool) d_ptr->adapter()->callMethod<jboolean>("disable", "()Z");
+ success = (bool)d_ptr->adapter()->callMethod<jboolean>("disable", "()Z");
if (!success)
emit error(QBluetoothLocalDevice::UnknownError);
} else if (mode == QBluetoothLocalDevice::HostConnectable) {
if (hostMode() == QBluetoothLocalDevice::HostDiscoverable) {
- //cannot directly go from Discoverable to Connectable
- //we need to go to disabled mode and enable once disabling came through
+ // cannot directly go from Discoverable to Connectable
+ // we need to go to disabled mode and enable once disabling came through
setHostMode(QBluetoothLocalDevice::HostPoweredOff);
d_ptr->pendingHostModeTransition = true;
} else {
- QAndroidJniObject::callStaticMethod<void>("org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setConnectable");
+ QAndroidJniObject::callStaticMethod<void>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setConnectable");
}
- } else if (mode == QBluetoothLocalDevice::HostDiscoverable ||
- mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) {
- QAndroidJniObject::callStaticMethod<void>("org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setDiscoverable");
+ } else if (mode == QBluetoothLocalDevice::HostDiscoverable
+ || mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) {
+ QAndroidJniObject::callStaticMethod<void>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setDiscoverable");
}
}
@@ -293,14 +303,14 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const
jint scanMode = d_ptr->adapter()->callMethod<jint>("getScanMode");
switch (scanMode) {
- case 20: //BluetoothAdapter.SCAN_MODE_NONE
- return HostPoweredOff;
- case 21: //BluetoothAdapter.SCAN_MODE_CONNECTABLE
- return HostConnectable;
- case 23: //BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE
- return HostDiscoverable;
- default:
- break;
+ case 20: // BluetoothAdapter.SCAN_MODE_NONE
+ return HostPoweredOff;
+ case 21: // BluetoothAdapter.SCAN_MODE_CONNECTABLE
+ return HostConnectable;
+ case 23: // BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE
+ return HostDiscoverable;
+ default:
+ break;
}
}
@@ -309,24 +319,28 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const
QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
{
- //Android only supports max of one device (so far)
+ // Android only supports max of one device (so far)
QList<QBluetoothHostInfo> localDevices;
QAndroidJniEnvironment env;
jclass btAdapterClass = env->FindClass("android/bluetooth/BluetoothAdapter");
if (btAdapterClass == NULL) {
- qCWarning(QT_BT_ANDROID) << "Native registration unable to find class android/bluetooth/BluetoothAdapter";
+ qCWarning(QT_BT_ANDROID)
+ << "Native registration unable to find class android/bluetooth/BluetoothAdapter";
return localDevices;
}
- jmethodID getDefaultAdapterID = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;");
+ jmethodID getDefaultAdapterID
+ = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter",
+ "()Landroid/bluetooth/BluetoothAdapter;");
if (getDefaultAdapterID == NULL) {
- qCWarning(QT_BT_ANDROID) << "Native registration unable to get method ID: getDefaultAdapter of android/bluetooth/BluetoothAdapter";
+ qCWarning(QT_BT_ANDROID)
+ << "Native registration unable to get method ID: " \
+ "getDefaultAdapter of android/bluetooth/BluetoothAdapter";
env->DeleteLocalRef(btAdapterClass);
return localDevices;
}
-
jobject btAdapterObject = env->CallStaticObjectMethod(btAdapterClass, getDefaultAdapterID);
if (btAdapterObject == NULL) {
qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth";
@@ -338,7 +352,8 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
if (o.isValid()) {
QBluetoothHostInfo info;
info.setName(o.callObjectMethod("getName", "()Ljava/lang/String;").toString());
- info.setAddress(QBluetoothAddress(o.callObjectMethod("getAddress", "()Ljava/lang/String;").toString()));
+ info.setAddress(QBluetoothAddress(o.callObjectMethod("getAddress",
+ "()Ljava/lang/String;").toString()));
localDevices.append(info);
}
@@ -352,61 +367,60 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai
{
if (address.isNull()) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error,
- QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
const Pairing previousPairing = pairingStatus(address);
Pairing newPairing = pairing;
- if (pairing == AuthorizedPaired) //AuthorizedPaired same as Paired on Android
+ if (pairing == AuthorizedPaired) // AuthorizedPaired same as Paired on Android
newPairing = Paired;
if (previousPairing == newPairing) {
QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection,
- Q_ARG(QBluetoothAddress, address),
- Q_ARG(QBluetoothLocalDevice::Pairing, pairing));
+ Q_ARG(QBluetoothAddress, address),
+ Q_ARG(QBluetoothLocalDevice::Pairing, pairing));
return;
}
- //BluetoothDevice::createBond() requires Android API 19
+ // BluetoothDevice::createBond() requires Android API 19
if (QtAndroidPrivate::androidSdkVersion() < 19 || !d_ptr->adapter()) {
qCWarning(QT_BT_ANDROID) << "Unable to pair: requires Android API 19+";
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error,
- QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
QAndroidJniObject inputString = QAndroidJniObject::fromString(address.toString());
jboolean success = QAndroidJniObject::callStaticMethod<jboolean>(
- "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
- "setPairingMode",
- "(Ljava/lang/String;Z)Z",
- inputString.object<jstring>(),
- newPairing == Paired ? JNI_TRUE : JNI_FALSE);
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setPairingMode",
+ "(Ljava/lang/String;Z)Z",
+ inputString.object<jstring>(),
+ newPairing == Paired ? JNI_TRUE : JNI_FALSE);
if (!success) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error,
- QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
} else {
- d_ptr->pendingPairings.append(qMakePair(address,
- newPairing == Paired ? true : false));
+ d_ptr->pendingPairings.append(qMakePair(address, newPairing == Paired ? true : false));
}
-
}
-QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const
+QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(
+ const QBluetoothAddress &address) const
{
if (address.isNull() || !d_ptr->adapter())
return Unpaired;
QAndroidJniObject inputString = QAndroidJniObject::fromString(address.toString());
- QAndroidJniObject remoteDevice =
- d_ptr->adapter()->callObjectMethod("getRemoteDevice",
- "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;",
- inputString.object<jstring>());
+ QAndroidJniObject remoteDevice
+ = d_ptr->adapter()->callObjectMethod("getRemoteDevice",
+ "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;",
+ inputString.object<jstring>());
QAndroidJniEnvironment env;
if (env->ExceptionCheck()) {
env->ExceptionClear();
@@ -415,7 +429,7 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet
jint bondState = remoteDevice.callMethod<jint>("getBondState");
switch (bondState) {
- case 12: //BluetoothDevice.BOND_BONDED
+ case 12: // BluetoothDevice.BOND_BONDED
return Paired;
default:
break;
@@ -432,13 +446,46 @@ void QBluetoothLocalDevice::pairingConfirmation(bool confirmation)
bool success = d_ptr->receiver->pairingConfirmation(confirmation);
if (!success)
emit error(PairingError);
-
}
QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const
{
- //TODO Support BLuetoothManager::getConnectedDevices(int) from API 18 onwards
- return d_ptr->connectedDevices;
+ /*
+ * Android does not have an API to list all connected devices. We have to collect
+ * the information based on a few indicators.
+ *
+ * Primarily we detect connected devices by monitoring connect/disconnect signals.
+ * Unfortunately the list may only be complete after very long monitoring time.
+ * However there are some Android APIs which provide the list of connected devices
+ * for specific Bluetooth profiles. QtBluetoothBroadcastReceiver.getConnectedDevices()
+ * returns a few connections of common profiles. The returned list is not complete either
+ * but at least it can complement our already detected connections.
+ */
+ QAndroidJniObject connectedDevices = QAndroidJniObject::callStaticObjectMethod(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "getConnectedDevices",
+ "()[Ljava/lang/String;");
+
+ if (!connectedDevices.isValid())
+ return d_ptr->connectedDevices;
+
+ jobjectArray connectedDevicesArray = connectedDevices.object<jobjectArray>();
+ if (!connectedDevicesArray)
+ return d_ptr->connectedDevices;
+
+ QAndroidJniEnvironment env;
+ QList<QBluetoothAddress> knownAddresses = d_ptr->connectedDevices;
+ QAndroidJniObject p;
+
+ jint size = env->GetArrayLength(connectedDevicesArray);
+ for (int i = 0; i < size; i++) {
+ p = env->GetObjectArrayElement(connectedDevicesArray, i);
+ QBluetoothAddress address(p.toString());
+ if (!address.isNull() && !knownAddresses.contains(address))
+ knownAddresses.append(address);
+ }
+
+ return knownAddresses;
}
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
index 9f2e7fd3..98894dff 100644
--- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
@@ -50,6 +50,11 @@
#include "bluez/adapter_p.h"
#include "bluez/agent_p.h"
#include "bluez/device_p.h"
+#include "bluez/bluez5_helper_p.h"
+#include "bluez/objectmanager_p.h"
+#include "bluez/properties_p.h"
+#include "bluez/adapter1_bluez5_p.h"
+#include "bluez/device1_bluez5_p.h"
QT_BEGIN_NAMESPACE
@@ -63,101 +68,137 @@ inline uint qHash(const QBluetoothAddress &address)
}
QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) :
- QObject(parent), d_ptr(new QBluetoothLocalDevicePrivate(this))
+ QObject(parent),
+ d_ptr(new QBluetoothLocalDevicePrivate(this))
{
}
QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) :
- QObject(parent), d_ptr(new QBluetoothLocalDevicePrivate(this, address))
+ QObject(parent),
+ d_ptr(new QBluetoothLocalDevicePrivate(this, address))
{
}
QString QBluetoothLocalDevice::name() const
{
- if (!d_ptr || !d_ptr->adapter)
- return QString();
+ if (d_ptr->adapter) {
+ QDBusPendingReply<QVariantMap> reply = d_ptr->adapter->GetProperties();
+ reply.waitForFinished();
+ if (reply.isError())
+ return QString();
- QDBusPendingReply<QVariantMap> reply = d_ptr->adapter->GetProperties();
- reply.waitForFinished();
- if (reply.isError())
- return QString();
+ return reply.value().value(QStringLiteral("Name")).toString();
+ } else if (d_ptr->adapterBluez5) {
+ return d_ptr->adapterBluez5->alias();
+ }
- return reply.value().value(QLatin1String("Name")).toString();
+ return QString();
}
QBluetoothAddress QBluetoothLocalDevice::address() const
{
- if (!d_ptr || !d_ptr->adapter)
- return QBluetoothAddress();
+ if (d_ptr->adapter) {
+ QDBusPendingReply<QVariantMap> reply = d_ptr->adapter->GetProperties();
+ reply.waitForFinished();
+ if (reply.isError())
+ return QBluetoothAddress();
- QDBusPendingReply<QVariantMap> reply = d_ptr->adapter->GetProperties();
- reply.waitForFinished();
- if (reply.isError())
- return QBluetoothAddress();
+ return QBluetoothAddress(reply.value().value(QStringLiteral("Address")).toString());
+ } else if (d_ptr->adapterBluez5) {
+ return QBluetoothAddress(d_ptr->adapterBluez5->address());
+ }
- return QBluetoothAddress(reply.value().value(QLatin1String("Address")).toString());
+ return QBluetoothAddress();
}
void QBluetoothLocalDevice::powerOn()
{
- if (!d_ptr || !d_ptr->adapter)
- return;
-
- d_ptr->adapter->SetProperty(QLatin1String("Powered"), QDBusVariant(QVariant::fromValue(true)));
+ if (d_ptr->adapter)
+ d_ptr->adapter->SetProperty(QStringLiteral("Powered"), QDBusVariant(QVariant::fromValue(true)));
+ else if (d_ptr->adapterBluez5)
+ d_ptr->adapterBluez5->setPowered(true);
}
void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode mode)
{
- if (!d_ptr || !d_ptr->adapter)
+ if (!isValid())
return;
+ Q_D(QBluetoothLocalDevice);
+
switch (mode) {
case HostDiscoverableLimitedInquiry:
case HostDiscoverable:
if (hostMode() == HostPoweredOff) {
- //We first have to wait for BT to be powered on,
- //then we can set the host mode correctly
- d_ptr->pendingHostModeChange = (int) HostDiscoverable;
- d_ptr->adapter->SetProperty(QStringLiteral("Powered"),
+ // We first have to wait for BT to be powered on,
+ // then we can set the host mode correctly
+ d->pendingHostModeChange = static_cast<int>(HostDiscoverable);
+ if (d->adapter) {
+ d->adapter->SetProperty(QStringLiteral("Powered"),
QDBusVariant(QVariant::fromValue(true)));
+ } else {
+ d->adapterBluez5->setPowered(true);
+ }
} else {
- d_ptr->adapter->SetProperty(QStringLiteral("Discoverable"),
- QDBusVariant(QVariant::fromValue(true)));
+ if (d->adapter) {
+ d->adapter->SetProperty(QStringLiteral("Discoverable"),
+ QDBusVariant(QVariant::fromValue(true)));
+ } else {
+ d->adapterBluez5->setDiscoverable(true);
+ }
}
break;
case HostConnectable:
if (hostMode() == HostPoweredOff) {
- d_ptr->pendingHostModeChange = (int) HostConnectable;
- d_ptr->adapter->SetProperty(QStringLiteral("Powered"),
+ d->pendingHostModeChange = static_cast<int>(HostConnectable);
+ if (d->adapter) {
+ d->adapter->SetProperty(QStringLiteral("Powered"),
QDBusVariant(QVariant::fromValue(true)));
+ } else {
+ d->adapterBluez5->setPowered(true);
+ }
} else {
- d_ptr->adapter->SetProperty(QStringLiteral("Discoverable"),
- QDBusVariant(QVariant::fromValue(false)));
+ if (d->adapter) {
+ d->adapter->SetProperty(QStringLiteral("Discoverable"),
+ QDBusVariant(QVariant::fromValue(false)));
+ } else {
+ d->adapterBluez5->setDiscoverable(false);
+ }
}
break;
case HostPoweredOff:
- d_ptr->adapter->SetProperty(QLatin1String("Powered"),
- QDBusVariant(QVariant::fromValue(false)));
+ if (d->adapter) {
+ d->adapter->SetProperty(QStringLiteral("Powered"),
+ QDBusVariant(QVariant::fromValue(false)));
+ } else {
+ d->adapterBluez5->setPowered(false);
+ }
break;
}
}
QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const
{
- if (!d_ptr || !d_ptr->adapter)
- return HostPoweredOff;
-
- QDBusPendingReply<QVariantMap> reply = d_ptr->adapter->GetProperties();
- reply.waitForFinished();
- if (reply.isError())
- return HostPoweredOff;
-
- if (!reply.value().value(QLatin1String("Powered")).toBool())
- return HostPoweredOff;
- else if (reply.value().value(QLatin1String("Discoverable")).toBool())
- return HostDiscoverable;
- else if (reply.value().value(QLatin1String("Powered")).toBool())
- return HostConnectable;
+ if (d_ptr->adapter) {
+ QDBusPendingReply<QVariantMap> reply = d_ptr->adapter->GetProperties();
+ reply.waitForFinished();
+ if (reply.isError())
+ return HostPoweredOff;
+
+ if (!reply.value().value(QStringLiteral("Powered")).toBool())
+ return HostPoweredOff;
+ else if (reply.value().value(QStringLiteral("Discoverable")).toBool())
+ return HostDiscoverable;
+ else if (reply.value().value(QStringLiteral("Powered")).toBool())
+ return HostConnectable;
+ } else if (d_ptr->adapterBluez5) {
+ if (!d_ptr->adapterBluez5->powered())
+ return HostPoweredOff;
+ else if (d_ptr->adapterBluez5->discoverable())
+ return HostDiscoverable;
+ else if (d_ptr->adapterBluez5->powered())
+ return HostConnectable;
+ }
return HostPoweredOff;
}
@@ -171,194 +212,482 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
{
QList<QBluetoothHostInfo> localDevices;
- OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"),
- QDBusConnection::systemBus());
-
- QDBusPendingReply<QList<QDBusObjectPath> > reply = manager.ListAdapters();
- reply.waitForFinished();
- if (reply.isError())
- return localDevices;
-
-
- foreach (const QDBusObjectPath &path, reply.value()) {
- QBluetoothHostInfo hostinfo;
- OrgBluezAdapterInterface adapter(QLatin1String("org.bluez"), path.path(),
+ if (isBluez5()) {
+ OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"),
+ QStringLiteral("/"),
+ QDBusConnection::systemBus());
+ QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError())
+ return localDevices;
+
+ 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.Adapter1")) {
+ QBluetoothHostInfo hostInfo;
+ const QString temp = ifaceList.value(iface).value(QStringLiteral("Address")).toString();
+
+ hostInfo.setAddress(QBluetoothAddress(temp));
+ if (hostInfo.address().isNull())
+ continue;
+ hostInfo.setName(ifaceList.value(iface).value(QStringLiteral("Name")).toString());
+ localDevices.append(hostInfo);
+ }
+ }
+ }
+ } else {
+ OrgBluezManagerInterface manager(QStringLiteral("org.bluez"), QStringLiteral("/"),
QDBusConnection::systemBus());
- QDBusPendingReply<QVariantMap> reply = adapter.GetProperties();
+ QDBusPendingReply<QList<QDBusObjectPath> > reply = manager.ListAdapters();
reply.waitForFinished();
if (reply.isError())
- continue;
+ return localDevices;
+
+ foreach (const QDBusObjectPath &path, reply.value()) {
+ QBluetoothHostInfo hostinfo;
+ OrgBluezAdapterInterface adapter(QStringLiteral("org.bluez"), path.path(),
+ QDBusConnection::systemBus());
+
+ QDBusPendingReply<QVariantMap> reply = adapter.GetProperties();
+ reply.waitForFinished();
+ if (reply.isError())
+ continue;
- hostinfo.setAddress(QBluetoothAddress(reply.value().value(QLatin1String("Address")).toString()));
- hostinfo.setName(reply.value().value(QLatin1String("Name")).toString());
+ hostinfo.setAddress(QBluetoothAddress(
+ reply.value().value(QStringLiteral("Address")).toString()));
+ hostinfo.setName(reply.value().value(QStringLiteral("Name")).toString());
- localDevices.append(hostinfo);
+ localDevices.append(hostinfo);
+ }
}
return localDevices;
}
-static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &address, QBluetoothLocalDevicePrivate *d_ptr)
+static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &address,
+ QBluetoothLocalDevicePrivate *d_ptr)
{
if (!d_ptr || !d_ptr->adapter)
return 0;
QDBusPendingReply<QDBusObjectPath> reply = d_ptr->adapter->FindDevice(address.toString());
reply.waitForFinished();
- if(reply.isError()){
+ if (reply.isError()) {
qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "reply failed" << reply.error();
return 0;
}
QDBusObjectPath path = reply.value();
- return new OrgBluezDeviceInterface(QLatin1String("org.bluez"), path.path(),
- QDBusConnection::systemBus());
+ return new OrgBluezDeviceInterface(QStringLiteral("org.bluez"), path.path(),
+ QDBusConnection::systemBus());
}
void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing)
{
- if (address.isNull()) {
+ if (address.isNull() || !isValid()) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
const Pairing current_pairing = pairingStatus(address);
if (current_pairing == pairing) {
- QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
+ if (d_ptr->adapterBluez5) {
+ // A possibly running discovery or pending pairing request should be canceled
+ if (d_ptr->pairingDiscoveryTimer && d_ptr->pairingDiscoveryTimer->isActive()) {
+ d_ptr->pairingDiscoveryTimer->stop();
+ }
+
+ if (d_ptr->pairingTarget) {
+ qCDebug(QT_BT_BLUEZ) << "Cancelling pending pairing request to" << d_ptr->pairingTarget->address();
+ QDBusPendingReply<> cancelReply = d_ptr->pairingTarget->CancelPairing();
+ cancelReply.waitForFinished();
+ delete d_ptr->pairingTarget;
+ d_ptr->pairingTarget = 0;
+ }
+
+ }
+ QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection,
+ Q_ARG(QBluetoothAddress, address),
Q_ARG(QBluetoothLocalDevice::Pairing, pairing));
return;
}
- if(pairing == Paired || pairing == AuthorizedPaired) {
+ if (d_ptr->adapterBluez5) {
+ d_ptr->requestPairingBluez5(address, pairing);
+ return;
+ }
+ if (pairing == Paired || pairing == AuthorizedPaired) {
d_ptr->address = address;
d_ptr->pairing = pairing;
- if(!d_ptr->agent){
+ if (!d_ptr->agent) {
d_ptr->agent = new OrgBluezAgentAdaptor(d_ptr);
bool res = QDBusConnection::systemBus().registerObject(d_ptr->agent_path, d_ptr);
- if(!res){
+ if (!res) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
qCWarning(QT_BT_BLUEZ) << "Failed to register agent";
return;
}
}
- if(current_pairing == Paired && pairing == AuthorizedPaired){
+ if (current_pairing == Paired && pairing == AuthorizedPaired) {
OrgBluezDeviceInterface *device = getDevice(address, d_ptr);
if (!device) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
- QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(true));
+ QDBusPendingReply<> deviceReply
+ = device->SetProperty(QStringLiteral("Trusted"), QDBusVariant(true));
deviceReply.waitForFinished();
- if(deviceReply.isError()){
+ if (deviceReply.isError()) {
qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "reply failed" << deviceReply.error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
delete device;
- QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
- Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::AuthorizedPaired));
- }
- else if(current_pairing == AuthorizedPaired && pairing == Paired){
+ QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection,
+ Q_ARG(QBluetoothAddress, address),
+ Q_ARG(QBluetoothLocalDevice::Pairing,
+ QBluetoothLocalDevice::AuthorizedPaired));
+ } else if (current_pairing == AuthorizedPaired && pairing == Paired) {
OrgBluezDeviceInterface *device = getDevice(address, d_ptr);
if (!device) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
- QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(false));
+ QDBusPendingReply<> deviceReply
+ = device->SetProperty(QStringLiteral("Trusted"), QDBusVariant(false));
deviceReply.waitForFinished();
- if(deviceReply.isError()){
+ if (deviceReply.isError()) {
qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "reply failed" << deviceReply.error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
delete device;
- QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
- Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::Paired));
- }
- else {
- QDBusPendingReply<QDBusObjectPath> reply =
- d_ptr->adapter->CreatePairedDevice(address.toString(),
- QDBusObjectPath(d_ptr->agent_path),
- QLatin1String("NoInputNoOutput"));
+ QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection,
+ Q_ARG(QBluetoothAddress, address),
+ Q_ARG(QBluetoothLocalDevice::Pairing,
+ QBluetoothLocalDevice::Paired));
+ } else {
+ QDBusPendingReply<QDBusObjectPath> reply
+ = d_ptr->adapter->CreatePairedDevice(address.toString(),
+ QDBusObjectPath(d_ptr->agent_path),
+ QStringLiteral("NoInputNoOutput"));
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
- connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), d_ptr, SLOT(pairingCompleted(QDBusPendingCallWatcher*)));
+ connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)), d_ptr,
+ SLOT(pairingCompleted(QDBusPendingCallWatcher *)));
- if(reply.isError())
+ if (reply.isError())
qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << reply.error() << d_ptr->agent_path;
}
- }
- else if(pairing == Unpaired) {
- QDBusPendingReply<QDBusObjectPath> reply = this->d_ptr->adapter->FindDevice(address.toString());
+ } else if (pairing == Unpaired) {
+ QDBusPendingReply<QDBusObjectPath> reply = this->d_ptr->adapter->FindDevice(
+ address.toString());
reply.waitForFinished();
- if(reply.isError()) {
+ if (reply.isError()) {
qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to find device" << reply.error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
QDBusPendingReply<> removeReply = this->d_ptr->adapter->RemoveDevice(reply.value());
removeReply.waitForFinished();
- if(removeReply.isError()){
- qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to remove device" << removeReply.error();
+ if (removeReply.isError()) {
+ qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to remove device"
+ << removeReply.error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
} else {
- QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
- Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::Unpaired));
+ QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection,
+ Q_ARG(QBluetoothAddress, address),
+ Q_ARG(QBluetoothLocalDevice::Pairing,
+ QBluetoothLocalDevice::Unpaired));
+ }
+ }
+}
+
+void QBluetoothLocalDevicePrivate::requestPairingBluez5(const QBluetoothAddress &targetAddress,
+ QBluetoothLocalDevice::Pairing targetPairing)
+{
+ if (!managerBluez5)
+ return;
+
+ //are we already discovering something? -> abort those attempts
+ if (pairingDiscoveryTimer && pairingDiscoveryTimer->isActive()) {
+ pairingDiscoveryTimer->stop();
+ QtBluezDiscoveryManager::instance()->unregisterDiscoveryInterest(
+ adapterBluez5->path());
+ }
+
+ if (pairingTarget) {
+ delete pairingTarget;
+ pairingTarget = 0;
+ }
+
+ // pairing implies that the device was found
+ // if we cannot find it we may have to turn on Discovery mode for a limited amount of time
+
+ // check device doesn't already exist
+ QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError()) {
+ emit q_ptr->error(QBluetoothLocalDevice::PairingError);
+ return;
+ }
+
+
+ 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")) {
+
+ OrgBluezDevice1Interface device(QStringLiteral("org.bluez"),
+ path.path(),
+ QDBusConnection::systemBus());
+ if (targetAddress == QBluetoothAddress(device.address())) {
+ qCDebug(QT_BT_BLUEZ) << "Initiating direct pair to" << targetAddress.toString();
+ //device exist -> directly work with it
+ processPairingBluez5(path.path(), targetPairing);
+ return;
+ }
+ }
+ }
+ }
+
+ //no device matching -> turn on discovery
+ QtBluezDiscoveryManager::instance()->registerDiscoveryInterest(adapterBluez5->path());
+
+ address = targetAddress;
+ pairing = targetPairing;
+ if (!pairingDiscoveryTimer) {
+ pairingDiscoveryTimer = new QTimer(this);
+ pairingDiscoveryTimer->setSingleShot(true);
+ pairingDiscoveryTimer->setInterval(20000); //20s
+ connect(pairingDiscoveryTimer, SIGNAL(timeout()),
+ SLOT(pairingDiscoveryTimedOut()));
+ }
+
+ qCDebug(QT_BT_BLUEZ) << "Initiating discovery for pairing on" << targetAddress.toString();
+ pairingDiscoveryTimer->start();
+}
+
+/*!
+ * \internal
+ *
+ * Found a matching device. Now we must ensure its pairing/trusted state is as desired.
+ * If it has to be paired then we need another roundtrip through the event loop
+ * while we wait for the user to accept the pairing dialogs.
+ */
+void QBluetoothLocalDevicePrivate::processPairingBluez5(const QString &objectPath,
+ QBluetoothLocalDevice::Pairing target)
+{
+ if (pairingTarget)
+ delete pairingTarget;
+
+ //stop possibly running discovery
+ if (pairingDiscoveryTimer && pairingDiscoveryTimer->isActive()) {
+ pairingDiscoveryTimer->stop();
+
+ QtBluezDiscoveryManager::instance()->unregisterDiscoveryInterest(
+ adapterBluez5->path());
+ }
+
+ pairingTarget = new OrgBluezDevice1Interface(QStringLiteral("org.bluez"), objectPath,
+ QDBusConnection::systemBus(), this);
+ const QBluetoothAddress targetAddress(pairingTarget->address());
+
+ Q_Q(QBluetoothLocalDevice);
+
+ switch (target) {
+ case QBluetoothLocalDevice::Unpaired: {
+ delete pairingTarget;
+ pairingTarget = 0;
+
+ QDBusPendingReply<> removeReply = adapterBluez5->RemoveDevice(QDBusObjectPath(objectPath));
+ removeReply.waitForFinished();
+
+ if (removeReply.isError())
+ emit q->error(QBluetoothLocalDevice::PairingError);
+ else
+ emit q->pairingFinished(targetAddress, QBluetoothLocalDevice::Unpaired);
+
+ break;
+ }
+ case QBluetoothLocalDevice::Paired:
+ case QBluetoothLocalDevice::AuthorizedPaired:
+ pairing = target;
+
+ if (!pairingTarget->paired()) {
+ qCDebug(QT_BT_BLUEZ) << "Sending pairing request to" << pairingTarget->address();
+ //initiate the pairing
+ QDBusPendingReply<> pairReply = pairingTarget->Pair();
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pairReply, this);
+ connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ SLOT(pairingCompleted(QDBusPendingCallWatcher*)));
+ return;
}
+
+ //already paired but Trust level must be adjusted
+ if (target == QBluetoothLocalDevice::AuthorizedPaired && !pairingTarget->trusted())
+ pairingTarget->setTrusted(true);
+ else if (target == QBluetoothLocalDevice::Paired && pairingTarget->trusted())
+ pairingTarget->setTrusted(false);
+
+ delete pairingTarget;
+ pairingTarget = 0;
+
+ emit q->pairingFinished(targetAddress, target);
+
+ break;
+ default:
+ break;
}
- return;
}
-QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const
+void QBluetoothLocalDevicePrivate::pairingDiscoveryTimedOut()
+{
+ qCWarning(QT_BT_BLUEZ) << "Discovery for pairing purposes failed. Cannot find parable device.";
+
+ QtBluezDiscoveryManager::instance()->unregisterDiscoveryInterest(
+ adapterBluez5->path());
+
+ emit q_ptr->error(QBluetoothLocalDevice::PairingError);
+}
+
+QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(
+ const QBluetoothAddress &address) const
{
if (address.isNull())
return Unpaired;
- OrgBluezDeviceInterface *device = getDevice(address, d_ptr);
+ if (d_ptr->adapter) {
+ OrgBluezDeviceInterface *device = getDevice(address, d_ptr);
- if(!device)
- return Unpaired;
+ if (!device)
+ return Unpaired;
- QDBusPendingReply<QVariantMap> deviceReply = device->GetProperties();
- deviceReply.waitForFinished();
- if (deviceReply.isError())
- return Unpaired;
+ QDBusPendingReply<QVariantMap> deviceReply = device->GetProperties();
+ deviceReply.waitForFinished();
+ if (deviceReply.isError())
+ return Unpaired;
- QVariantMap map = deviceReply.value();
+ QVariantMap map = deviceReply.value();
- if (map.value(QLatin1String("Trusted")).toBool() && map.value(QLatin1String("Paired")).toBool())
- return AuthorizedPaired;
- else if (map.value(QLatin1String("Paired")).toBool())
+ if (map.value(QStringLiteral("Trusted")).toBool() && map.value(QStringLiteral("Paired")).toBool())
+ return AuthorizedPaired;
+ else if (map.value(QStringLiteral("Paired")).toBool())
return Paired;
- else
+ } else if (d_ptr->adapterBluez5) {
+
+ QDBusPendingReply<ManagedObjectList> reply = d_ptr->managerBluez5->GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError())
return Unpaired;
+
+ 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")) {
+
+ OrgBluezDevice1Interface device(QStringLiteral("org.bluez"),
+ path.path(),
+ QDBusConnection::systemBus());
+
+ if (address == QBluetoothAddress(device.address())) {
+ if (device.trusted() && device.paired())
+ return AuthorizedPaired;
+ else if (device.paired())
+ return Paired;
+ else
+ return Unpaired;
+ }
+ }
+ }
+ }
+ }
+
+ return Unpaired;
}
-QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress address)
- : adapter(0), agent(0), localAddress(address), pendingHostModeChange(-1), msgConnection(0), q_ptr(q), connectedCached(false)
+QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q,
+ QBluetoothAddress address) :
+ adapter(0),
+ adapterBluez5(0),
+ adapterProperties(0),
+ managerBluez5(0),
+ agent(0),
+ localAddress(address),
+ pairingTarget(0),
+ pairingDiscoveryTimer(0),
+ pendingHostModeChange(-1),
+ msgConnection(0),
+ q_ptr(q)
{
- initializeAdapter();
+ if (isBluez5())
+ initializeAdapterBluez5();
+ else
+ initializeAdapter();
+
connectDeviceChanges();
}
void QBluetoothLocalDevicePrivate::connectDeviceChanges()
{
- if (adapter) { //invalid QBluetoothLocalDevice due to wrong local adapter address
- 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)));
+ 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)));
+ } else if (adapterBluez5 && managerBluez5) {
+ //setup property change notifications for all existing devices
+ QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError())
+ return;
+
+ OrgFreedesktopDBusPropertiesInterface *monitor = 0;
+ 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")) {
+ monitor = new OrgFreedesktopDBusPropertiesInterface(QStringLiteral("org.bluez"),
+ path.path(),
+ QDBusConnection::systemBus(), this);
+ connect(monitor, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)),
+ SLOT(PropertiesChanged(QString,QVariantMap,QStringList)));
+ deviceChangeMonitors.insert(path.path(), monitor);
+
+ const QVariantMap ifaceValues = ifaceList.value(QStringLiteral("org.bluez.Device1"));
+ if (ifaceValues.value(QStringLiteral("Connected"), false).toBool()) {
+ QBluetoothAddress address(ifaceValues.value(QStringLiteral("Address")).toString());
+ connectedDevicesSet.insert(address);
+ }
+ }
+ }
+ }
}
}
@@ -366,8 +695,13 @@ QBluetoothLocalDevicePrivate::~QBluetoothLocalDevicePrivate()
{
delete msgConnection;
delete adapter;
+ delete adapterBluez5;
+ delete adapterProperties;
+ delete managerBluez5;
delete agent;
+ delete pairingTarget;
qDeleteAll(devices);
+ qDeleteAll(deviceChangeMonitors);
}
void QBluetoothLocalDevicePrivate::initializeAdapter()
@@ -375,7 +709,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter()
if (adapter)
return;
- OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"), QDBusConnection::systemBus());
+ OrgBluezManagerInterface manager(QStringLiteral("org.bluez"), QStringLiteral("/"),
+ QDBusConnection::systemBus());
if (localAddress == QBluetoothAddress()) {
QDBusPendingReply<QDBusObjectPath> reply = manager.DefaultAdapter();
@@ -383,7 +718,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter()
if (reply.isError())
return;
- adapter = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), reply.value().path(), QDBusConnection::systemBus());
+ adapter = new OrgBluezAdapterInterface(QStringLiteral("org.bluez"),
+ reply.value().path(), QDBusConnection::systemBus());
} else {
QDBusPendingReply<QList<QDBusObjectPath> > reply = manager.ListAdapters();
reply.waitForFinished();
@@ -391,14 +727,16 @@ void QBluetoothLocalDevicePrivate::initializeAdapter()
return;
foreach (const QDBusObjectPath &path, reply.value()) {
- OrgBluezAdapterInterface *tmpAdapter = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), path.path(), QDBusConnection::systemBus());
+ OrgBluezAdapterInterface *tmpAdapter
+ = new OrgBluezAdapterInterface(QStringLiteral("org.bluez"),
+ path.path(), QDBusConnection::systemBus());
QDBusPendingReply<QVariantMap> reply = tmpAdapter->GetProperties();
reply.waitForFinished();
if (reply.isError())
continue;
- QBluetoothAddress path_address(reply.value().value(QLatin1String("Address")).toString());
+ QBluetoothAddress path_address(reply.value().value(QStringLiteral("Address")).toString());
if (path_address == localAddress) {
adapter = tmpAdapter;
@@ -411,7 +749,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter()
currentMode = static_cast<QBluetoothLocalDevice::HostMode>(-1);
if (adapter) {
- connect(adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(PropertyChanged(QString,QDBusVariant)));
+ connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)),
+ SLOT(PropertyChanged(QString, QDBusVariant)));
qsrand(QTime::currentTime().msec());
agent_path = agentPath;
@@ -419,9 +758,197 @@ void QBluetoothLocalDevicePrivate::initializeAdapter()
}
}
+void QBluetoothLocalDevicePrivate::initializeAdapterBluez5()
+{
+ if (adapterBluez5)
+ return;
+
+ //get all local adapters
+ if (!managerBluez5)
+ managerBluez5 = new OrgFreedesktopDBusObjectManagerInterface(
+ QStringLiteral("org.bluez"),
+ QStringLiteral("/"),
+ QDBusConnection::systemBus(), this);
+
+ connect(managerBluez5, SIGNAL(InterfacesAdded(QDBusObjectPath,InterfaceList)),
+ SLOT(InterfacesAdded(QDBusObjectPath,InterfaceList)));
+ connect(managerBluez5, SIGNAL(InterfacesRemoved(QDBusObjectPath,QStringList)),
+ SLOT(InterfacesRemoved(QDBusObjectPath,QStringList)));
+
+ QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError())
+ return;
+
+ typedef QPair<QString, QBluetoothAddress> AddressForPathType;
+ QList<AddressForPathType> localAdapters;
+
+ 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.Adapter1")) {
+ AddressForPathType pair;
+ pair.first = path.path();
+ pair.second = QBluetoothAddress(ifaceList.value(iface).value(
+ QStringLiteral("Address")).toString());
+ if (!pair.second.isNull())
+ localAdapters.append(pair);
+ break;
+ }
+ }
+ }
+
+ if (localAdapters.isEmpty())
+ return;
+
+ if (localAddress.isNull()) {
+ //concept of DefaultAdapter doesn't exist anymore.
+ //we define the first adapter as default
+ adapterBluez5 = new OrgBluezAdapter1Interface(QStringLiteral("org.bluez"),
+ localAdapters.front().first,
+ QDBusConnection::systemBus(), this);
+ } else {
+ foreach (const AddressForPathType &pair, localAdapters) {
+ if (pair.second == localAddress) {
+ adapterBluez5 = new OrgBluezAdapter1Interface(QStringLiteral("org.bluez"),
+ pair.first,
+ QDBusConnection::systemBus(), this);
+ break;
+ }
+ }
+
+ if (!adapterBluez5) //no match
+ return;
+ }
+
+ if (adapterBluez5) {
+ //hook up propertiesChanged for current adapter
+ adapterProperties = new OrgFreedesktopDBusPropertiesInterface(
+ QStringLiteral("org.bluez"), adapterBluez5->path(),
+ QDBusConnection::systemBus(), this);
+ connect(adapterProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)),
+ SLOT(PropertiesChanged(QString,QVariantMap,QStringList)));
+ }
+
+ currentMode = static_cast<QBluetoothLocalDevice::HostMode>(-1);
+}
+
+// Bluez 5
+void QBluetoothLocalDevicePrivate::PropertiesChanged(const QString &interface,
+ const QVariantMap &changed_properties,
+ const QStringList &/*invalidated_properties*/)
+{
+ //qDebug() << "Change" << interface << changed_properties;
+ if (interface == QStringLiteral("org.bluez.Adapter1")) {
+ //update host mode
+ if (changed_properties.contains(QStringLiteral("Discoverable"))
+ || changed_properties.contains(QStringLiteral("Powered"))) {
+
+ QBluetoothLocalDevice::HostMode mode;
+
+ if (!adapterBluez5->powered()) {
+ mode = QBluetoothLocalDevice::HostPoweredOff;
+ } else {
+ if (adapterBluez5->discoverable())
+ mode = QBluetoothLocalDevice::HostDiscoverable;
+ else
+ mode = QBluetoothLocalDevice::HostConnectable;
+
+ if (pendingHostModeChange != -1) {
+
+ if (static_cast<int>(mode) != pendingHostModeChange) {
+ adapterBluez5->setDiscoverable(
+ pendingHostModeChange
+ == static_cast<int>(QBluetoothLocalDevice::HostDiscoverable));
+ pendingHostModeChange = -1;
+ return;
+ }
+ pendingHostModeChange = -1;
+ }
+ }
+
+ if (mode != currentMode)
+ emit q_ptr->hostModeStateChanged(mode);
+
+ currentMode = mode;
+ }
+ } else if (interface == QStringLiteral("org.bluez.Device1")
+ && changed_properties.contains(QStringLiteral("Connected"))) {
+ // update list of connected devices
+ OrgFreedesktopDBusPropertiesInterface *senderIface =
+ qobject_cast<OrgFreedesktopDBusPropertiesInterface*>(sender());
+ if (!senderIface)
+ return;
+
+ const QString currentPath = senderIface->path();
+ bool isConnected = changed_properties.value(QStringLiteral("Connected"), false).toBool();
+ OrgBluezDevice1Interface device(QStringLiteral("org.bluez"), currentPath,
+ QDBusConnection::systemBus());
+ const QBluetoothAddress changedAddress(device.address());
+ bool isInSet = connectedDevicesSet.contains(changedAddress);
+ if (isConnected && !isInSet) {
+ connectedDevicesSet.insert(changedAddress);
+ emit q_ptr->deviceConnected(changedAddress);
+ } else if (!isConnected && isInSet) {
+ connectedDevicesSet.remove(changedAddress);
+ emit q_ptr->deviceDisconnected(changedAddress);
+ }
+ }
+}
+
+void QBluetoothLocalDevicePrivate::InterfacesAdded(const QDBusObjectPath &object_path, InterfaceList interfaces_and_properties)
+{
+ if (interfaces_and_properties.contains(QStringLiteral("org.bluez.Device1"))
+ && !deviceChangeMonitors.contains(object_path.path())) {
+ // a new device was added which we need to add to list of known devices
+ OrgFreedesktopDBusPropertiesInterface *monitor = new OrgFreedesktopDBusPropertiesInterface(
+ QStringLiteral("org.bluez"),
+ object_path.path(),
+ QDBusConnection::systemBus());
+ connect(monitor, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)),
+ SLOT(PropertiesChanged(QString,QVariantMap,QStringList)));
+ deviceChangeMonitors.insert(object_path.path(), monitor);
+
+ const QVariantMap ifaceValues = interfaces_and_properties.value(QStringLiteral("org.bluez.Device1"));
+ if (ifaceValues.value(QStringLiteral("Connected"), false).toBool()) {
+ QBluetoothAddress address(ifaceValues.value(QStringLiteral("Address")).toString());
+ connectedDevicesSet.insert(address);
+ emit q_ptr->deviceConnected(address);
+ }
+ }
+
+ if (pairingDiscoveryTimer && pairingDiscoveryTimer->isActive()
+ && interfaces_and_properties.contains(QStringLiteral("org.bluez.Device1"))) {
+ //device discovery for pairing found new remote device
+ OrgBluezDevice1Interface device(QStringLiteral("org.bluez"),
+ object_path.path(), QDBusConnection::systemBus());
+ if (!address.isNull() && address == QBluetoothAddress(device.address()))
+ processPairingBluez5(object_path.path(), pairing);
+ }
+}
+
+void QBluetoothLocalDevicePrivate::InterfacesRemoved(const QDBusObjectPath &object_path, const QStringList &interfaces)
+{
+ if (deviceChangeMonitors.contains(object_path.path())
+ && interfaces.contains(QStringLiteral("org.bluez.Device1"))) {
+
+ //a device was removed
+ delete deviceChangeMonitors.take(object_path.path());
+
+ //the path contains the address (e.g.: /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX)
+ //-> use it to update current list of connected devices
+ QString addressString = object_path.path().right(17);
+ addressString.replace(QStringLiteral("_"), QStringLiteral(":"));
+ const QBluetoothAddress address(addressString);
+ bool found = connectedDevicesSet.remove(address);
+ if (found)
+ emit q_ptr->deviceDisconnected(address);
+ }
+}
+
bool QBluetoothLocalDevicePrivate::isValid() const
{
- return adapter;
+ return adapter || adapterBluez5;
}
void QBluetoothLocalDevicePrivate::RequestConfirmation(const QDBusObjectPath &in0, uint in1)
@@ -432,35 +959,36 @@ void QBluetoothLocalDevicePrivate::RequestConfirmation(const QDBusObjectPath &in
msgConfirmation = message();
msgConnection = new QDBusConnection(connection());
emit q->pairingDisplayConfirmation(address, QString::fromLatin1("%1").arg(in1));
- return;
}
void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &device)
{
- OrgBluezDeviceInterface *deviceInterface =
- new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus());
- connect(deviceInterface, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(_q_devicePropertyChanged(QString,QDBusVariant)));
+ OrgBluezDeviceInterface *deviceInterface
+ = new OrgBluezDeviceInterface(QStringLiteral("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(QStringLiteral("GetProperties"));
properties.waitForFinished();
if (!properties.isValid()) {
qCritical() << "Unable to get device properties from: " << device.path();
return;
}
- const QBluetoothAddress address = QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString());
- const bool connected = properties.value().value(QLatin1String("Connected")).toBool();
+ const QBluetoothAddress address
+ = QBluetoothAddress(properties.value().value(QStringLiteral("Address")).toString());
+ const bool connected = properties.value().value(QStringLiteral("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)
@@ -468,15 +996,16 @@ void QBluetoothLocalDevicePrivate::_q_deviceRemoved(const QDBusObjectPath &devic
foreach (OrgBluezDeviceInterface *deviceInterface, devices) {
if (deviceInterface->path() == device.path()) {
devices.remove(deviceInterface);
- delete deviceInterface; //deviceDisconnected is already emitted by _q_devicePropertyChanged
+ delete deviceInterface; // deviceDisconnected is already emitted by _q_devicePropertyChanged
break;
}
}
}
-void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &property, const QDBusVariant &value)
+void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &property,
+ const QDBusVariant &value)
{
- OrgBluezDeviceInterface *deviceInterface = qobject_cast<OrgBluezDeviceInterface*>(sender());
+ OrgBluezDeviceInterface *deviceInterface = qobject_cast<OrgBluezDeviceInterface *>(sender());
if (deviceInterface && property == QLatin1String("Connected")) {
QDBusPendingReply<QVariantMap> propertiesReply = deviceInterface->GetProperties();
propertiesReply.waitForFinished();
@@ -485,19 +1014,17 @@ void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &prope
return;
}
const QVariantMap properties = propertiesReply.value();
- const QBluetoothAddress address = QBluetoothAddress(properties.value(QLatin1String("Address")).toString());
+ const QBluetoothAddress address
+ = QBluetoothAddress(properties.value(QStringLiteral("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,43 +1040,48 @@ void QBluetoothLocalDevicePrivate::createCache()
return;
}
foreach (const QDBusObjectPath &device, reply.value()) {
- OrgBluezDeviceInterface deviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus());
-
- QDBusPendingReply<QVariantMap> properties = deviceInterface.asyncCall(QLatin1String("GetProperties"));
+ OrgBluezDeviceInterface *deviceInterface =
+ new OrgBluezDeviceInterface(QStringLiteral("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(QStringLiteral("GetProperties"));
properties.waitForFinished();
if (!properties.isValid()) {
qCWarning(QT_BT_BLUEZ) << "Unable to get properties for device " << device.path();
return;
}
- if (properties.value().value(QLatin1String("Connected")).toBool())
- connectedDevicesSet.insert(QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString()));
+ if (properties.value().value(QStringLiteral("Connected")).toBool()) {
+ connectedDevicesSet.insert(
+ QBluetoothAddress(properties.value().value(QStringLiteral("Address")).toString()));
+ }
}
- connectedCached = true;
}
QList<QBluetoothAddress> QBluetoothLocalDevicePrivate::connectedDevices() const
{
- if (!connectedCached)
- const_cast<QBluetoothLocalDevicePrivate *>(this)->createCache();
return connectedDevicesSet.toList();
}
void QBluetoothLocalDevice::pairingConfirmation(bool confirmation)
{
- if(!d_ptr ||
- !d_ptr->msgConfirmation.isReplyRequired() ||
- !d_ptr->msgConnection)
+ if (!d_ptr
+ || !d_ptr->msgConfirmation.isReplyRequired()
+ || !d_ptr->msgConnection)
return;
- if(confirmation){
+ if (confirmation) {
QDBusMessage msg = d_ptr->msgConfirmation.createReply(QVariant(true));
d_ptr->msgConnection->send(msg);
- }
- else {
- QDBusMessage error =
- d_ptr->msgConfirmation.createErrorReply(QDBusError::AccessDenied,
- QLatin1String("Pairing rejected"));
+ } else {
+ QDBusMessage error
+ = d_ptr->msgConfirmation.createErrorReply(QDBusError::AccessDenied,
+ QStringLiteral("Pairing rejected"));
d_ptr->msgConnection->send(error);
}
delete d_ptr->msgConnection;
@@ -574,62 +1106,90 @@ void QBluetoothLocalDevicePrivate::pairingCompleted(QDBusPendingCallWatcher *wat
Q_Q(QBluetoothLocalDevice);
QDBusPendingReply<> reply = *watcher;
- if(reply.isError()) {
- qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to create pairing" << reply.error();
- emit q->error(QBluetoothLocalDevice::PairingError);
- delete watcher;
+ if (reply.isError()) {
+ qCWarning(QT_BT_BLUEZ) << "Failed to create pairing" << reply.error().name();
+ if (reply.error().name() != QStringLiteral("org.bluez.Error.AuthenticationCanceled"))
+ emit q->error(QBluetoothLocalDevice::PairingError);
+ watcher->deleteLater();
return;
}
- QDBusPendingReply<QDBusObjectPath> findReply = adapter->FindDevice(address.toString());
- findReply.waitForFinished();
- if(findReply.isError()) {
- qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to find device" << findReply.error();
- emit q->error(QBluetoothLocalDevice::PairingError);
- delete watcher;
- return;
- }
+ if (adapter) {
+ QDBusPendingReply<QDBusObjectPath> findReply = adapter->FindDevice(address.toString());
+ findReply.waitForFinished();
+ if (findReply.isError()) {
+ qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to find device" << findReply.error();
+ emit q->error(QBluetoothLocalDevice::PairingError);
+ watcher->deleteLater();
+ return;
+ }
- OrgBluezDeviceInterface device(QLatin1String("org.bluez"), findReply.value().path(),
- QDBusConnection::systemBus());
+ OrgBluezDeviceInterface device(QStringLiteral("org.bluez"), findReply.value().path(),
+ QDBusConnection::systemBus());
- if(pairing == QBluetoothLocalDevice::AuthorizedPaired) {
- device.SetProperty(QLatin1String("Trusted"), QDBusVariant(QVariant(true)));
- emit q->pairingFinished(address, QBluetoothLocalDevice::AuthorizedPaired);
- }
- else {
- device.SetProperty(QLatin1String("Trusted"), QDBusVariant(QVariant(false)));
- emit q->pairingFinished(address, QBluetoothLocalDevice::Paired);
+ if (pairing == QBluetoothLocalDevice::AuthorizedPaired) {
+ device.SetProperty(QStringLiteral("Trusted"), QDBusVariant(QVariant(true)));
+ emit q->pairingFinished(address, QBluetoothLocalDevice::AuthorizedPaired);
+ }
+ else {
+ device.SetProperty(QStringLiteral("Trusted"), QDBusVariant(QVariant(false)));
+ emit q->pairingFinished(address, QBluetoothLocalDevice::Paired);
+ }
+ } else if (adapterBluez5) {
+ if (!pairingTarget) {
+ qCWarning(QT_BT_BLUEZ) << "Pairing target expected but found null pointer.";
+ emit q->error(QBluetoothLocalDevice::PairingError);
+ watcher->deleteLater();
+ return;
+ }
+
+ if (!pairingTarget->paired()) {
+ qCWarning(QT_BT_BLUEZ) << "Device was not paired as requested";
+ emit q->error(QBluetoothLocalDevice::PairingError);
+ watcher->deleteLater();
+ return;
+ }
+
+ const QBluetoothAddress targetAddress(pairingTarget->address());
+
+ if (pairing == QBluetoothLocalDevice::AuthorizedPaired && !pairingTarget->trusted())
+ pairingTarget->setTrusted(true);
+ else if (pairing == QBluetoothLocalDevice::Paired && pairingTarget->trusted())
+ pairingTarget->setTrusted(false);
+
+ delete pairingTarget;
+ pairingTarget = 0;
+
+ emit q->pairingFinished(targetAddress, pairing);
}
- delete watcher;
+ watcher->deleteLater();
}
void QBluetoothLocalDevicePrivate::Authorize(const QDBusObjectPath &in0, const QString &in1)
{
Q_UNUSED(in0)
Q_UNUSED(in1)
- //TODO implement this
+ // TODO implement this
qCDebug(QT_BT_BLUEZ) << "Got authorize for" << in0.path() << in1;
}
void QBluetoothLocalDevicePrivate::Cancel()
{
- //TODO implement this
+ // TODO implement this
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO;
}
void QBluetoothLocalDevicePrivate::Release()
{
- //TODO implement this
+ // TODO implement this
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO;
}
-
void QBluetoothLocalDevicePrivate::ConfirmModeChange(const QString &in0)
{
Q_UNUSED(in0)
- //TODO implement this
+ // TODO implement this
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << in0;
}
@@ -638,7 +1198,7 @@ void QBluetoothLocalDevicePrivate::DisplayPasskey(const QDBusObjectPath &in0, ui
Q_UNUSED(in0)
Q_UNUSED(in1)
Q_UNUSED(in2)
- //TODO implement this
+ // TODO implement this
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << in0.path() << in1 << in2;
}
@@ -649,13 +1209,13 @@ uint QBluetoothLocalDevicePrivate::RequestPasskey(const QDBusObjectPath &in0)
return qrand()&0x1000000;
}
-
+// Bluez 4
void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVariant value)
{
Q_UNUSED(value);
- if (property != QLatin1String("Powered") &&
- property != QLatin1String("Discoverable"))
+ if (property != QLatin1String("Powered")
+ && property != QLatin1String("Discoverable"))
return;
Q_Q(QBluetoothLocalDevice);
@@ -663,18 +1223,17 @@ void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVarian
QDBusPendingReply<QVariantMap> reply = adapter->GetProperties();
reply.waitForFinished();
- if (reply.isError()){
+ if (reply.isError()) {
qCWarning(QT_BT_BLUEZ) << "Failed to get bluetooth properties for mode change";
return;
}
QVariantMap map = reply.value();
- if(!map.value(QLatin1String("Powered")).toBool()){
+ if (!map.value(QStringLiteral("Powered")).toBool()) {
mode = QBluetoothLocalDevice::HostPoweredOff;
- }
- else {
- if (map.value(QLatin1String("Discoverable")).toBool())
+ } else {
+ if (map.value(QStringLiteral("Discoverable")).toBool())
mode = QBluetoothLocalDevice::HostDiscoverable;
else
mode = QBluetoothLocalDevice::HostConnectable;
@@ -685,10 +1244,10 @@ void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVarian
return;
if (pendingHostModeChange == (int)QBluetoothLocalDevice::HostDiscoverable) {
adapter->SetProperty(QStringLiteral("Discoverable"),
- QDBusVariant(QVariant::fromValue(true)));
+ QDBusVariant(QVariant::fromValue(true)));
} else {
adapter->SetProperty(QStringLiteral("Discoverable"),
- QDBusVariant(QVariant::fromValue(false)));
+ QDBusVariant(QVariant::fromValue(false)));
}
pendingHostModeChange = -1;
return;
@@ -696,7 +1255,7 @@ void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVarian
}
}
- if(mode != currentMode)
+ if (mode != currentMode)
emit q->hostModeStateChanged(mode);
currentMode = mode;
diff --git a/src/bluetooth/qbluetoothlocaldevice_p.cpp b/src/bluetooth/qbluetoothlocaldevice_p.cpp
index d40e6473..6fedafc7 100644
--- a/src/bluetooth/qbluetoothlocaldevice_p.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_p.cpp
@@ -39,19 +39,20 @@
**
****************************************************************************/
-
#include "qbluetoothlocaldevice.h"
#include "qbluetoothaddress.h"
QT_BEGIN_NAMESPACE
QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) :
- QObject(parent), d_ptr(0)
+ QObject(parent),
+ d_ptr(0)
{
}
QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &, QObject *parent) :
- QObject(parent), d_ptr(0)
+ QObject(parent),
+ d_ptr(0)
{
}
@@ -96,7 +97,8 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai
Q_UNUSED(pairing);
}
-QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const
+QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(
+ const QBluetoothAddress &address) const
{
Q_UNUSED(address);
return Unpaired;
diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h
index 61527d31..8edac58c 100644
--- a/src/bluetooth/qbluetoothlocaldevice_p.h
+++ b/src/bluetooth/qbluetoothlocaldevice_p.h
@@ -52,10 +52,15 @@
#include <QDBusObjectPath>
#include <QDBusMessage>
#include <QSet>
+#include "bluez/bluez5_helper_p.h"
class OrgBluezAdapterInterface;
+class OrgBluezAdapter1Interface;
+class OrgFreedesktopDBusPropertiesInterface;
+class OrgFreedesktopDBusObjectManagerInterface;
class OrgBluezAgentAdaptor;
class OrgBluezDeviceInterface;
+class OrgBluezDevice1Interface;
QT_BEGIN_NAMESPACE
class QDBusPendingCallWatcher;
@@ -83,22 +88,20 @@ class QBluetoothLocalDevicePrivate : public QObject
Q_OBJECT
public:
QBluetoothLocalDevicePrivate(
- QBluetoothLocalDevice *q,
- const QBluetoothAddress &address = QBluetoothAddress());
+ QBluetoothLocalDevice *q, const QBluetoothAddress &address = QBluetoothAddress());
~QBluetoothLocalDevicePrivate();
QAndroidJniObject *adapter();
- void initialize(const QBluetoothAddress& address);
+ void initialize(const QBluetoothAddress &address);
static bool startDiscovery();
static bool cancelDiscovery();
static bool isDiscovering();
bool isValid() const;
-
private slots:
void processHostModeChange(QBluetoothLocalDevice::HostMode newMode);
void processPairingStateChanged(const QBluetoothAddress &address,
- QBluetoothLocalDevice::Pairing pairing);
+ QBluetoothLocalDevice::Pairing pairing);
void processConnectDeviceChanges(const QBluetoothAddress &address, bool isConnectEvent);
void processDisplayConfirmation(const QBluetoothAddress &address, const QString &pin);
@@ -117,18 +120,22 @@ public:
};
#elif defined(QT_BLUEZ_BLUETOOTH)
-class QBluetoothLocalDevicePrivate : public QObject,
- protected QDBusContext
+class QBluetoothLocalDevicePrivate : public QObject, protected QDBusContext
{
Q_OBJECT
Q_DECLARE_PUBLIC(QBluetoothLocalDevice)
public:
- QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress localAddress = QBluetoothAddress());
+ QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q,
+ QBluetoothAddress localAddress = QBluetoothAddress());
~QBluetoothLocalDevicePrivate();
QSet<OrgBluezDeviceInterface *> devices;
QSet<QBluetoothAddress> connectedDevicesSet;
- OrgBluezAdapterInterface *adapter;
+ OrgBluezAdapterInterface *adapter; //Bluez 4
+ OrgBluezAdapter1Interface *adapterBluez5; //Bluez 5
+ OrgFreedesktopDBusPropertiesInterface *adapterProperties; //Bluez 5
+ OrgFreedesktopDBusObjectManagerInterface *managerBluez5; //Bluez 5
+ QMap<QString, OrgFreedesktopDBusPropertiesInterface *> deviceChangeMonitors; //Bluez 5
OrgBluezAgentAdaptor *agent;
QList<QBluetoothAddress> connectedDevices() const;
@@ -137,10 +144,12 @@ public:
QBluetoothAddress localAddress;
QBluetoothAddress address;
QBluetoothLocalDevice::Pairing pairing;
+ OrgBluezDevice1Interface *pairingTarget;
+ QTimer *pairingDiscoveryTimer;
QBluetoothLocalDevice::HostMode currentMode;
int pendingHostModeChange;
-public Q_SLOTS: // METHODS
+public slots:
void Authorize(const QDBusObjectPath &in0, const QString &in1);
void Cancel();
void ConfirmModeChange(const QString &in0);
@@ -151,14 +160,29 @@ public Q_SLOTS: // METHODS
void RequestConfirmation(const QDBusObjectPath &in0, uint in1);
QString RequestPinCode(const QDBusObjectPath &in0);
- void pairingCompleted(QDBusPendingCallWatcher*);
+ void pairingCompleted(QDBusPendingCallWatcher *);
- void PropertyChanged(QString,QDBusVariant);
+ void PropertyChanged(QString, QDBusVariant);
void _q_deviceCreated(const QDBusObjectPath &device);
void _q_deviceRemoved(const QDBusObjectPath &device);
void _q_devicePropertyChanged(const QString &property, const QDBusVariant &value);
bool isValid() const;
+ void requestPairingBluez5(const QBluetoothAddress &address,
+ QBluetoothLocalDevice::Pairing targetPairing);
+
+private Q_SLOTS:
+ void PropertiesChanged(const QString &interface,
+ const QVariantMap &changed_properties,
+ const QStringList &invalidated_properties);
+ void InterfacesAdded(const QDBusObjectPath &object_path,
+ InterfaceList interfaces_and_properties);
+ void InterfacesRemoved(const QDBusObjectPath &object_path,
+ const QStringList &interfaces);
+ void processPairingBluez5(const QString &objectPath,
+ QBluetoothLocalDevice::Pairing target);
+ void pairingDiscoveryTimedOut();
+
private:
void createCache();
void connectDeviceChanges();
@@ -168,9 +192,8 @@ private:
QBluetoothLocalDevice *q_ptr;
- bool connectedCached;
-
void initializeAdapter();
+ void initializeAdapterBluez5();
};
#elif defined(QT_QNX_BLUETOOTH)
diff --git a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp
index 8ed29437..6c6dc1aa 100644
--- a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp
@@ -49,21 +49,21 @@
QT_BEGIN_NAMESPACE
-QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent)
-: QObject(parent)
+QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) :
+ QObject(parent)
{
this->d_ptr = new QBluetoothLocalDevicePrivate(this);
- this->d_ptr->isValidDevice = true; //assume single local device on QNX
+ this->d_ptr->isValidDevice = true; // assume single local device on QNX
}
-QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent)
-: QObject(parent)
+QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) :
+ QObject(parent)
{
this->d_ptr = new QBluetoothLocalDevicePrivate(this);
- //works since we assume a single local device on QNX
- this->d_ptr->isValidDevice = (QBluetoothLocalDevicePrivate::address() == address ||
- address == QBluetoothAddress());
+ // works since we assume a single local device on QNX
+ this->d_ptr->isValidDevice = (QBluetoothLocalDevicePrivate::address() == address
+ || address == QBluetoothAddress());
}
QString QBluetoothLocalDevice::name() const
@@ -104,10 +104,12 @@ QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const
for (int i = 0; i < allFiles.size(); i++) {
qCDebug(QT_BT_QNX) << allFiles.at(i);
int fileId;
- const char *filePath = QByteArray("/pps/services/bluetooth/remote_devices/").append(allFiles.at(i).toUtf8().constData()).constData();
- if ((fileId = qt_safe_open(filePath, O_RDONLY)) == -1)
+ const char *filePath = QByteArray("/pps/services/bluetooth/remote_devices/").append(allFiles.at(
+ i).toUtf8().constData())
+ .constData();
+ if ((fileId = qt_safe_open(filePath, O_RDONLY)) == -1) {
qCWarning(QT_BT_QNX) << "Failed to open remote device file";
- else {
+ } else {
pps_decoder_t ppsDecoder;
pps_decoder_initialize(&ppsDecoder, 0);
@@ -124,11 +126,11 @@ QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const
if (a == PPS_DECODER_OK) {
if (connectedDevice)
devices.append(deviceAddr);
- }
- else if ( a == PPS_DECODER_BAD_TYPE)
+ } else if (a == PPS_DECODER_BAD_TYPE) {
qCDebug(QT_BT_QNX) << "Type missmatch";
- else
+ } else {
qCDebug(QT_BT_QNX) << "An unknown error occurred while checking connected status.";
+ }
pps_decoder_cleanup(&ppsDecoder);
}
}
@@ -138,7 +140,7 @@ QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const
QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
{
- //We only have one device
+ // We only have one device
QList<QBluetoothHostInfo> localDevices;
QBluetoothHostInfo hostInfo;
hostInfo.setName(QBluetoothLocalDevicePrivate::name());
@@ -151,20 +153,23 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai
{
if (address.isNull()) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
const Pairing current_pairing = pairingStatus(address);
if (current_pairing == pairing) {
- QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
+ QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection,
+ Q_ARG(QBluetoothAddress, address),
Q_ARG(QBluetoothLocalDevice::Pairing, pairing));
return;
}
d_ptr->requestPairing(address, pairing);
}
-QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const
+QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(
+ const QBluetoothAddress &address) const
{
if (!isValid())
return Unpaired;
@@ -173,7 +178,7 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet
QByteArray qnxPath("/pps/services/bluetooth/remote_devices/");
qnxPath.append(address.toString().toUtf8());
int m_rdfd;
- if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1){
+ if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1) {
btle = true;
qnxPath.append("-00");
if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1) {
@@ -211,8 +216,8 @@ void QBluetoothLocalDevice::pairingConfirmation(bool confirmation)
Q_UNUSED(confirmation);
}
-QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q)
- : q_ptr(q)
+QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q) :
+ q_ptr(q)
{
ppsRegisterControl();
ppsRegisterForEvent(QStringLiteral("access_changed"), this);
@@ -263,38 +268,36 @@ void QBluetoothLocalDevicePrivate::setHostMode(QBluetoothLocalDevice::HostMode m
return;
QBluetoothLocalDevice::HostMode currentHostMode = hostMode();
- if (currentHostMode == mode){
+ if (currentHostMode == mode)
return;
- }
- //If the device is in PowerOff state and the profile is changed then the power has to be turned on
+ // If the device is in PowerOff state and the profile is changed then the power has to be turned on
if (currentHostMode == QBluetoothLocalDevice::HostPoweredOff) {
qCDebug(QT_BT_QNX) << "Powering on";
powerOn();
}
- if (mode == QBluetoothLocalDevice::HostPoweredOff) {
+ if (mode == QBluetoothLocalDevice::HostPoweredOff)
powerOff();
- }
- else if (mode == QBluetoothLocalDevice::HostDiscoverable) { //General discoverable and connectable.
+ else if (mode == QBluetoothLocalDevice::HostDiscoverable) // General discoverable and connectable.
setAccess(1);
- }
- else if (mode == QBluetoothLocalDevice::HostConnectable) { //Connectable but not discoverable.
+ else if (mode == QBluetoothLocalDevice::HostConnectable) // Connectable but not discoverable.
setAccess(3);
- }
- else if (mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) { //Limited discoverable and connectable.
+ else if (mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) // Limited discoverable and connectable.
setAccess(2);
- }
}
void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &address,
QBluetoothLocalDevice::Pairing pairing)
{
- if (pairing == QBluetoothLocalDevice::Paired || pairing == QBluetoothLocalDevice::AuthorizedPaired) {
- ppsSendControlMessage("initiate_pairing", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()),
- this);
+ if (pairing == QBluetoothLocalDevice::Paired
+ || pairing == QBluetoothLocalDevice::AuthorizedPaired) {
+ ppsSendControlMessage("initiate_pairing",
+ QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()),
+ this);
} else {
- ppsSendControlMessage("remove_device", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()),
- this);
+ ppsSendControlMessage("remove_device",
+ QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()),
+ this);
}
}
@@ -308,11 +311,11 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevicePrivate::hostMode() const
int hostMode = ppsReadSetting("accessibility").toInt();
- if (hostMode == 1) //General discoverable and connectable.
+ if (hostMode == 1) // General discoverable and connectable.
return QBluetoothLocalDevice::HostDiscoverable;
- else if (hostMode == 3) //Connectable but not discoverable.
+ else if (hostMode == 3) // Connectable but not discoverable.
return QBluetoothLocalDevice::HostConnectable;
- else if (hostMode == 2) //Limited discoverable and connectable.
+ else if (hostMode == 2) // Limited discoverable and connectable.
return QBluetoothLocalDevice::HostDiscoverableLimitedInquiry;
else
return QBluetoothLocalDevice::HostPoweredOff;
@@ -322,25 +325,24 @@ extern int __newHostMode;
void QBluetoothLocalDevicePrivate::setAccess(int access)
{
- if (!ppsReadSetting("enabled").toBool()) { //We cannot set the host mode until BT is fully powered up
+ if (!ppsReadSetting("enabled").toBool()) // We cannot set the host mode until BT is fully powered up
__newHostMode = access;
- } else {
+ else
ppsSendControlMessage("set_access", QStringLiteral("{\"access\":%1}").arg(access), 0);
-
- }
}
void QBluetoothLocalDevicePrivate::connectedDevices()
{
QList<QBluetoothAddress> devices = q_ptr->connectedDevices();
- for (int i = 0; i < devices.size(); i ++) {
+ for (int i = 0; i < devices.size(); i++) {
if (!connectedDevicesSet.contains(devices.at(i))) {
QBluetoothAddress addr = devices.at(i);
connectedDevicesSet.append(addr);
emit q_ptr->deviceConnected(devices.at(i));
}
}
- for (int i = 0; i < connectedDevicesSet.size(); i ++) {
+
+ for (int i = 0; i < connectedDevicesSet.size(); i++) {
if (!devices.contains(connectedDevicesSet.at(i))) {
QBluetoothAddress addr = connectedDevicesSet.at(i);
emit q_ptr->deviceDisconnected(addr);
@@ -365,38 +367,39 @@ void QBluetoothLocalDevicePrivate::controlEvent(ppsResult result)
{
qCDebug(QT_BT_QNX) << Q_FUNC_INFO << "Control Event" << result.msg;
if (result.msg == QStringLiteral("access_changed")) {
- if (__newHostMode == -1 && result.dat.size() > 1 &&
- result.dat.first() == QStringLiteral("level")) {
+ if (__newHostMode == -1 && result.dat.size() > 1
+ && result.dat.first() == QStringLiteral("level")) {
QBluetoothLocalDevice::HostMode newHostMode = hostMode();
qCDebug(QT_BT_QNX) << "New Host mode" << newHostMode;
connectedDevices();
- Q_EMIT q_ptr->hostModeStateChanged(newHostMode);
+ emit q_ptr->hostModeStateChanged(newHostMode);
}
} else if (result.msg == QStringLiteral("pairing_complete")) {
qCDebug(QT_BT_QNX) << "pairing completed";
if (result.dat.contains(QStringLiteral("addr"))) {
const QBluetoothAddress address = QBluetoothAddress(
- result.dat.at(result.dat.indexOf(QStringLiteral("addr")) + 1));
+ result.dat.at(result.dat.indexOf(QStringLiteral("addr")) + 1));
QBluetoothLocalDevice::Pairing pairingStatus = QBluetoothLocalDevice::Paired;
- if (result.dat.contains(QStringLiteral("trusted")) &&
- result.dat.at(result.dat.indexOf(QStringLiteral("trusted")) + 1) == QStringLiteral("true")) {
+ if (result.dat.contains(QStringLiteral("trusted"))
+ && result.dat.at(result.dat.indexOf(QStringLiteral("trusted")) + 1)
+ == QStringLiteral("true")) {
pairingStatus = QBluetoothLocalDevice::AuthorizedPaired;
}
qCDebug(QT_BT_QNX) << "pairing completed" << address.toString();
- Q_EMIT q_ptr->pairingFinished(address, pairingStatus);
+ emit q_ptr->pairingFinished(address, pairingStatus);
}
} else if (result.msg == QStringLiteral("device_deleted")) {
qCDebug(QT_BT_QNX) << "device deleted";
if (result.dat.contains(QStringLiteral("addr"))) {
const QBluetoothAddress address = QBluetoothAddress(
- result.dat.at(result.dat.indexOf(QStringLiteral("addr")) + 1));
- Q_EMIT q_ptr->pairingFinished(address, QBluetoothLocalDevice::Unpaired);
+ result.dat.at(result.dat.indexOf(QStringLiteral("addr")) + 1));
+ emit q_ptr->pairingFinished(address, QBluetoothLocalDevice::Unpaired);
}
} else if (result.msg == QStringLiteral("radio_shutdown")) {
qCDebug(QT_BT_QNX) << "radio shutdown";
- Q_EMIT q_ptr->hostModeStateChanged(QBluetoothLocalDevice::HostPoweredOff);
+ emit q_ptr->hostModeStateChanged(QBluetoothLocalDevice::HostPoweredOff);
}
}
diff --git a/src/bluetooth/qbluetoothserver_p.h b/src/bluetooth/qbluetoothserver_p.h
index 4137986a..492ad489 100644
--- a/src/bluetooth/qbluetoothserver_p.h
+++ b/src/bluetooth/qbluetoothserver_p.h
@@ -97,6 +97,10 @@ public:
QBluetoothServiceInfo::Protocol serverType;
#ifdef QT_QNX_BLUETOOTH
+#ifdef QT_QNX_BT_BLUETOOTH
+ static void btCallback(long param, int socket);
+ Q_INVOKABLE void setBtCallbackParameters(int receivedSocket);
+#endif
QList<QBluetoothSocket *> activeSockets;
QString m_serviceName;
#endif
@@ -111,9 +115,11 @@ private:
bool serverRegistered;
QString nextClientAddress;
-private Q_SLOTS:
+private slots:
+#ifndef QT_QNX_BT_BLUETOOTH
void controlReply(ppsResult result);
void controlEvent(ppsResult result);
+#endif
#elif defined(QT_BLUEZ_BLUETOOTH)
QSocketNotifier *socketNotifier;
#elif defined(QT_ANDROID_BLUETOOTH)
diff --git a/src/bluetooth/qbluetoothserver_qnx.cpp b/src/bluetooth/qbluetoothserver_qnx.cpp
index 63e92f4f..2aefa041 100644
--- a/src/bluetooth/qbluetoothserver_qnx.cpp
+++ b/src/bluetooth/qbluetoothserver_qnx.cpp
@@ -48,7 +48,9 @@
#include <QSocketNotifier>
#include <QCoreApplication>
-
+#ifdef QT_QNX_BT_BLUETOOTH
+#include <btapi/btspp.h>
+#endif
QT_BEGIN_NAMESPACE
extern QHash<QBluetoothServerPrivate*, int> __fakeServerPorts;
@@ -70,6 +72,42 @@ QBluetoothServerPrivate::~QBluetoothServerPrivate()
activeSockets.clear();
}
+#ifdef QT_QNX_BT_BLUETOOTH
+void QBluetoothServerPrivate::btCallback(long param, int socket)
+{
+ QBluetoothServerPrivate *impl = reinterpret_cast<QBluetoothServerPrivate*>(param);
+ QMetaObject::invokeMethod(impl, "setBtCallbackParameters",
+ Qt::BlockingQueuedConnection,
+ Q_ARG(int, socket));
+}
+
+void QBluetoothServerPrivate::setBtCallbackParameters(int receivedSocket)
+{
+ Q_Q(QBluetoothServer);
+ if (receivedSocket == -1) {
+ qCDebug(QT_BT_QNX) << "Socket error: " << qt_error_string(errno);
+ m_lastError = QBluetoothServer::InputOutputError;
+ emit q->error(m_lastError);
+ return;
+ }
+ socket->setSocketDescriptor(receivedSocket, QBluetoothServiceInfo::RfcommProtocol,
+ QBluetoothSocket::ConnectedState,
+ QBluetoothSocket::ReadWrite);
+ char addr[18];
+ if (bt_spp_get_address(receivedSocket, addr) == -1) {
+ qCDebug(QT_BT_QNX) << "Could not obtain the remote address. "
+ << qt_error_string(errno);
+ m_lastError = QBluetoothServer::InputOutputError;
+ emit q->error(m_lastError);
+ return;
+ }
+ socket->d_ptr->m_peerAddress = QBluetoothAddress(addr);
+ activeSockets.append(socket);
+ socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol, this);
+ socket->setSocketState(QBluetoothSocket::ListeningState);
+ emit q->newConnection();
+}
+#else
void QBluetoothServerPrivate::controlReply(ppsResult result)
{
Q_Q(QBluetoothServer);
@@ -130,6 +168,7 @@ void QBluetoothServerPrivate::controlEvent(ppsResult result)
}
}
}
+#endif
void QBluetoothServer::close()
{
@@ -142,14 +181,19 @@ void QBluetoothServer::close()
}
if (d->socket) {
d->socket->close();
- delete d->socket;
- d->socket = 0;
if (__fakeServerPorts.contains(d)) {
- ppsSendControlMessage("deregister_server", 0x1101, d->m_uuid, QString(), QString(), 0);
+#ifdef QT_QNX_BT_BLUETOOTH
+ QByteArray b_uuid = d->m_uuid.toByteArray();
+ b_uuid = b_uuid.mid(1, b_uuid.length()-2);
+ bt_spp_close_server(b_uuid.data());
+#else
+ ppsSendControlMessage("deregister_server", 0x1101, d->m_uuid,
+ QString(), QString(), 0);
+#endif
__fakeServerPorts.remove(d);
}
- // force active object (socket) to run and shutdown socket.
- qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+ delete d->socket;
+ d->socket = 0;
}
}
@@ -208,9 +252,10 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
return false;
}
- d->socket->setSocketState(QBluetoothSocket::ListeningState);
-
+#ifndef QT_QNX_BT_BLUETOOTH
ppsRegisterForEvent(QStringLiteral("service_connected"),d);
+#endif
+ d->socket->setSocketState(QBluetoothSocket::ListeningState);
return true;
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index 615d0f4a..1d8809a8 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
@@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE
\li and call start().
\endlist
- \snippet doc_src_qtbluetooth.cpp discovery
+ \snippet doc_src_qtbluetooth.cpp service_discovery
By default a minimal service discovery is performed. In this mode, the QBluetotohServiceInfo
objects returned are guaranteed to contain only device and service UUID information. Depending
@@ -178,6 +178,8 @@ QBluetoothServiceDiscoveryAgent::~QBluetoothServiceDiscoveryAgent()
that if a remote Bluetooth device moves out of range in between two subsequent calls
to \l start() the list may contain stale entries.
+ \note The list of services should always be cleared before the discovery mode is changed.
+
\sa clear()
*/
QList<QBluetoothServiceInfo> QBluetoothServiceDiscoveryAgent::discoveredServices() const
@@ -276,6 +278,11 @@ void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode)
if (d->discoveryState() == QBluetoothServiceDiscoveryAgentPrivate::Inactive
&& d->error != InvalidBluetoothAdapterError) {
+#ifdef QT_BLUEZ_BLUETOOTH
+ // done to avoid repeated parsing for adapter address
+ // on Bluez5
+ d->foundHostAdapterPath.clear();
+#endif
d->setDiscoveryMode(mode);
if (d->deviceAddress.isNull()) {
d->startDeviceDiscovery();
@@ -501,6 +508,21 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_serviceDiscoveryFinished()
startServiceDiscovery();
}
+bool QBluetoothServiceDiscoveryAgentPrivate::isDuplicatedService(
+ const QBluetoothServiceInfo &serviceInfo) const
+{
+ //check the service is not already part of our known list
+ for (int j = 0; j < discoveredServices.count(); j++) {
+ const QBluetoothServiceInfo &info = discoveredServices.at(j);
+ if (info.device() == serviceInfo.device()
+ && info.serviceClassUuids() == serviceInfo.serviceClassUuids()
+ && info.serviceUuid() == serviceInfo.serviceUuid()) {
+ return true;
+ }
+ }
+ return false;
+}
+
#include "moc_qbluetoothservicediscoveryagent.cpp"
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h
index 90482048..f1e754db 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.h
@@ -116,6 +116,7 @@ private:
#ifdef QT_BLUEZ_BLUETOOTH
Q_PRIVATE_SLOT(d_func(), void _q_discoveredServices(QDBusPendingCallWatcher*))
Q_PRIVATE_SLOT(d_func(), void _q_createdDevice(QDBusPendingCallWatcher*))
+ Q_PRIVATE_SLOT(d_func(), void _q_finishSdpScan(QBluetoothServiceDiscoveryAgent::Error, const QString &, const QStringList &))
#endif
#ifdef QT_ANDROID_BLUETOOTH
Q_PRIVATE_SLOT(d_func(), void _q_processFetchedUuids(const QBluetoothAddress &address,
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
index 2e55d40e..35449720 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
@@ -55,8 +55,6 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
-Q_GLOBAL_STATIC_WITH_ARGS(QUuid, btBaseUuid, ("{00000000-0000-1000-8000-00805F9B34FB}"))
-
QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(
const QBluetoothAddress &deviceAdapter)
: error(QBluetoothServiceDiscoveryAgent::NoError),
@@ -246,6 +244,12 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids(
if (discoveredDevices.count() == 0)
return;
+ //could not find any service for the current address/device -> go to next one
+ if (address.isNull() || uuids.isEmpty()) {
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+
if (QT_BT_ANDROID().isDebugEnabled()) {
qCDebug(QT_BT_ANDROID) << "Found UUID for" << address.toString()
<< "\ncount: " << uuids.count();
@@ -298,80 +302,6 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids(
}
}
-
-static QString serviceNameForClassUuid(const uint value)
-{
- switch (value & 0xffff) {
- case QBluetoothUuid::ServiceDiscoveryServer: return QBluetoothServiceDiscoveryAgent::tr("Service Discovery");
- //case QBluetoothUuid::BrowseGroupDescriptor: return QString();
- //case QBluetoothUuid::PublicBrowseGroup: return QString();
- case QBluetoothUuid::SerialPort: return QBluetoothServiceDiscoveryAgent::tr("Serial Port Profile");
- case QBluetoothUuid::LANAccessUsingPPP: return QBluetoothServiceDiscoveryAgent::tr("LAN Access Profile");
- case QBluetoothUuid::DialupNetworking: return QBluetoothServiceDiscoveryAgent::tr("Dial-up Networking");
- case QBluetoothUuid::IrMCSync: return QBluetoothServiceDiscoveryAgent::tr("Synchronization");
- case QBluetoothUuid::ObexObjectPush: return QBluetoothServiceDiscoveryAgent::tr("Object Push");
- case QBluetoothUuid::OBEXFileTransfer: return QBluetoothServiceDiscoveryAgent::tr("File Transfer");
- case QBluetoothUuid::IrMCSyncCommand: return QBluetoothServiceDiscoveryAgent::tr("Synchronization Command");
- case QBluetoothUuid::Headset: return QBluetoothServiceDiscoveryAgent::tr("Headset");
- case QBluetoothUuid::AudioSource: return QBluetoothServiceDiscoveryAgent::tr("Advanced Audio Distribution Source");
- case QBluetoothUuid::AudioSink: return QBluetoothServiceDiscoveryAgent::tr("Advanced Audio Distribution Sink");
- case QBluetoothUuid::AV_RemoteControlTarget: return QBluetoothServiceDiscoveryAgent::tr("Audio/Video Remote Control Target");
- case QBluetoothUuid::AdvancedAudioDistribution: return QBluetoothServiceDiscoveryAgent::tr("Advanced Audio Distribution");
- case QBluetoothUuid::AV_RemoteControl: return QBluetoothServiceDiscoveryAgent::tr("Audio/Video Remote Control");
- case QBluetoothUuid::AV_RemoteControlController: return QBluetoothServiceDiscoveryAgent::tr("Audio/Video Remote Control Controller");
- case QBluetoothUuid::HeadsetAG: return QBluetoothServiceDiscoveryAgent::tr("Headset AG");
- case QBluetoothUuid::PANU: return QBluetoothServiceDiscoveryAgent::tr("Personal Area Networking (PANU)");
- case QBluetoothUuid::NAP: return QBluetoothServiceDiscoveryAgent::tr("Personal Area Networking (NAP)");
- case QBluetoothUuid::GN: return QBluetoothServiceDiscoveryAgent::tr("Personal Area Networking (GN)");
- case QBluetoothUuid::DirectPrinting: return QBluetoothServiceDiscoveryAgent::tr("Basic Direct Printing (BPP)");
- case QBluetoothUuid::ReferencePrinting: return QBluetoothServiceDiscoveryAgent::tr("Basic Reference Printing (BPP)");
- case QBluetoothUuid::BasicImage: return QBluetoothServiceDiscoveryAgent::tr("Basic Imaging Profile");
- case QBluetoothUuid::ImagingResponder: return QBluetoothServiceDiscoveryAgent::tr("Basic Imaging Responder");
- case QBluetoothUuid::ImagingAutomaticArchive: return QBluetoothServiceDiscoveryAgent::tr("Basic Imaging Archive");
- case QBluetoothUuid::ImagingReferenceObjects: return QBluetoothServiceDiscoveryAgent::tr("Basic Imaging Ref Objects");
- case QBluetoothUuid::Handsfree: return QBluetoothServiceDiscoveryAgent::tr("Hands-Free");
- case QBluetoothUuid::HandsfreeAudioGateway: return QBluetoothServiceDiscoveryAgent::tr("Hands-Free AG");
- case QBluetoothUuid::DirectPrintingReferenceObjectsService: return QBluetoothServiceDiscoveryAgent::tr("Basic Printing RefObject Service");
- case QBluetoothUuid::ReflectedUI: return QBluetoothServiceDiscoveryAgent::tr("Basic Printing Reflected UI");
- case QBluetoothUuid::BasicPrinting: return QBluetoothServiceDiscoveryAgent::tr("Basic Printing");
- case QBluetoothUuid::PrintingStatus: return QBluetoothServiceDiscoveryAgent::tr("Basic Printing Status");
- case QBluetoothUuid::HumanInterfaceDeviceService: return QBluetoothServiceDiscoveryAgent::tr("Human Interface Device");
- case QBluetoothUuid::HardcopyCableReplacement: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Cable Replacement");
- case QBluetoothUuid::HCRPrint: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Cable Replacement Print");
- case QBluetoothUuid::HCRScan: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Cable Replacement Scan");
- case QBluetoothUuid::SIMAccess: return QBluetoothServiceDiscoveryAgent::tr("SIM Access");
- case QBluetoothUuid::PhonebookAccessPCE: return QBluetoothServiceDiscoveryAgent::tr("Phonebook Access PCE");
- case QBluetoothUuid::PhonebookAccessPSE: return QBluetoothServiceDiscoveryAgent::tr("Phonebook Access PSE");
- case QBluetoothUuid::PhonebookAccess: return QBluetoothServiceDiscoveryAgent::tr("Phonebook Access");
- case QBluetoothUuid::HeadsetHS: return QBluetoothServiceDiscoveryAgent::tr("Headset HS");
- case QBluetoothUuid::MessageAccessServer: return QBluetoothServiceDiscoveryAgent::tr("Message Access Server");
- case QBluetoothUuid::MessageNotificationServer: return QBluetoothServiceDiscoveryAgent::tr("Message Notification Server");
- case QBluetoothUuid::MessageAccessProfile: return QBluetoothServiceDiscoveryAgent::tr("Message Access");
- case QBluetoothUuid::GNSS: return QBluetoothServiceDiscoveryAgent::tr("Global Navigation Satellite System");
- case QBluetoothUuid::GNSSServer: return QBluetoothServiceDiscoveryAgent::tr("Global Navigation Satellite System Server");
- case QBluetoothUuid::Display3D: return QBluetoothServiceDiscoveryAgent::tr("3D Synchronization Display");
- case QBluetoothUuid::Glasses3D: return QBluetoothServiceDiscoveryAgent::tr("3D Synchronization Glasses");
- case QBluetoothUuid::Synchronization3D: return QBluetoothServiceDiscoveryAgent::tr("3D Synchronization");
- case QBluetoothUuid::MPSProfile: return QBluetoothServiceDiscoveryAgent::tr("Multi-Profile Specification (Profile)");
- case QBluetoothUuid::MPSService: return QBluetoothServiceDiscoveryAgent::tr("Multi-Profile Specification");
- case QBluetoothUuid::PnPInformation: return QBluetoothServiceDiscoveryAgent::tr("Device Identification");
- //case QBluetoothUuid::GenericNetworking: return QBluetoothServiceDiscoveryAgent::tr("");
- //case QBluetoothUuid::GenericFileTransfer: return QBluetoothServiceDiscoveryAgent::tr("");
- //case QBluetoothUuid::GenericAudio: return QBluetoothServiceDiscoveryAgent::tr("");
- //case QBluetoothUuid::GenericTelephony: return QBluetoothServiceDiscoveryAgent::tr("");
- case QBluetoothUuid::VideoSource: return QBluetoothServiceDiscoveryAgent::tr("Video Source");
- case QBluetoothUuid::VideoSink: return QBluetoothServiceDiscoveryAgent::tr("Video Sink");
- case QBluetoothUuid::VideoDistribution: return QBluetoothServiceDiscoveryAgent::tr("Video Distribution");
- case QBluetoothUuid::HDP: return QBluetoothServiceDiscoveryAgent::tr("Health Device");
- case QBluetoothUuid::HDPSource: return QBluetoothServiceDiscoveryAgent::tr("Health Device Source");
- case QBluetoothUuid::HDPSink: return QBluetoothServiceDiscoveryAgent::tr("Health Device Sink");
- default:
- break;
- }
-
- return QString();
-}
-
void QBluetoothServiceDiscoveryAgentPrivate::populateDiscoveredServices(const QBluetoothDeviceInfo &remoteDevice, const QList<QBluetoothUuid> &uuids)
{
/* Android doesn't provide decent SDP data. A list of uuids is close to meaning-less
@@ -397,26 +327,19 @@ void QBluetoothServiceDiscoveryAgentPrivate::populateDiscoveredServices(const QB
if (uuid.isNull())
continue;
- bool isBaseUuuidSuffix = false;
- if (btBaseUuid()->data2 == uuid.data2 && btBaseUuid()->data3 == uuid.data3
- && btBaseUuid()->data4[0] == uuid.data4[0] && btBaseUuid()->data4[1] == uuid.data4[1]
- && btBaseUuid()->data4[2] == uuid.data4[2] && btBaseUuid()->data4[3] == uuid.data4[3]
- && btBaseUuid()->data4[4] == uuid.data4[4] && btBaseUuid()->data4[5] == uuid.data4[5]
- && btBaseUuid()->data4[6] == uuid.data4[6] && btBaseUuid()->data4[7] == uuid.data4[7])
- {
- isBaseUuuidSuffix = true;
- }
-
//check for SPP protocol
- if (isBaseUuuidSuffix && ((uuid.data1 & 0xffff) == QBluetoothUuid::SerialPort))
+ bool ok = false;
+ quint16 uuid16 = uuid.toUInt16(&ok);
+ if (ok && uuid16 == QBluetoothUuid::SerialPort)
sppIndex = i;
- if (!isBaseUuuidSuffix)
+ //check for custom uuid
+ if (uuid.minimumSize() == 16)
customUuids.append(i);
}
for (int i = 0; i < uuids.count(); i++) {
- if (i == sppIndex) //skip SPP service class id
+ if (i == sppIndex && !customUuids.isEmpty())
continue;
QBluetoothServiceInfo serviceInfo;
@@ -444,6 +367,21 @@ void QBluetoothServiceDiscoveryAgentPrivate::populateDiscoveredServices(const QB
serviceInfo.setServiceName(QBluetoothServiceDiscoveryAgent::tr("Serial Port Profile"));
serviceInfo.setServiceUuid(uuids.at(i));
+ } else if (sppIndex == i && customUuids.isEmpty()) {
+ //set rfcomm protocol
+ QBluetoothServiceInfo::Sequence protocol;
+ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
+ << QVariant::fromValue(0);
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+
+ QBluetoothServiceInfo::Sequence classId;
+ classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
+ serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,
+ classId);
+
+ //also we need to set the custom uuid to the SPP uuid
+ //otherwise QBluetoothSocket::connectToService() would fail due to a missing service uuid
+ serviceInfo.setServiceUuid(uuids.at(i));
} else if (customUuids.contains(i)) {
//custom uuid but no serial port
serviceInfo.setServiceUuid(uuids.at(i));
@@ -462,22 +400,13 @@ void QBluetoothServiceDiscoveryAgentPrivate::populateDiscoveredServices(const QB
QBluetoothServiceInfo::Sequence classId;
classId << QVariant::fromValue(uuids.at(i));
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
- serviceInfo.setServiceName(serviceNameForClassUuid(uuids.at(i).data1));
+ QBluetoothUuid::ServiceClassUuid clsId
+ = static_cast<QBluetoothUuid::ServiceClassUuid>(uuids.at(i).toUInt16());
+ serviceInfo.setServiceName(QBluetoothUuid::serviceClassToString(clsId));
}
//don't include the service if we already discovered it before
- bool alreadyDiscovered = false;
- for (int j = 0; j < discoveredServices.count(); j++) {
- const QBluetoothServiceInfo &info = discoveredServices.at(j);
- if (info.device() == serviceInfo.device()
- && info.serviceClassUuids() == serviceInfo.serviceClassUuids()
- && info.serviceUuid() == serviceInfo.serviceUuid()) {
- alreadyDiscovered = true;
- break;
- }
- }
-
- if (!alreadyDiscovered) {
+ if (!isDuplicatedService(serviceInfo)) {
discoveredServices << serviceInfo;
//qCDebug(QT_BT_ANDROID) << serviceInfo;
emit q->serviceDiscovered(serviceInfo);
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index fd0d9e3b..7d2f1b1c 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
@@ -48,31 +48,56 @@
#include "bluez/adapter_p.h"
#include "bluez/device_p.h"
#include "bluez/characteristic_p.h"
+#include "bluez/bluez5_helper_p.h"
+#include "bluez/objectmanager_p.h"
+#include "bluez/adapter1_bluez5_p.h"
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/sdp.h>
+#include <bluetooth/sdp_lib.h>
#include <QtCore/QLoggingCategory>
#include <QtDBus/QDBusPendingCallWatcher>
-#include <QtCore/QUuid>
+#include <QtConcurrent/QtConcurrentRun>
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
+static inline void convertAddress(quint64 from, quint8 (&to)[6])
+{
+ to[0] = (from >> 0) & 0xff;
+ to[1] = (from >> 8) & 0xff;
+ to[2] = (from >> 16) & 0xff;
+ to[3] = (from >> 24) & 0xff;
+ to[4] = (from >> 32) & 0xff;
+ to[5] = (from >> 40) & 0xff;
+}
+
QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter)
: error(QBluetoothServiceDiscoveryAgent::NoError), m_deviceAdapterAddress(deviceAdapter), state(Inactive), deviceDiscoveryAgent(0),
mode(QBluetoothServiceDiscoveryAgent::MinimalDiscovery), singleDevice(false),
- manager(0), adapter(0), device(0)
+ manager(0), managerBluez5(0), adapter(0), device(0)
{
- qRegisterMetaType<ServiceMap>("ServiceMap");
- qDBusRegisterMetaType<ServiceMap>();
+ if (isBluez5()) {
+ managerBluez5 = new OrgFreedesktopDBusObjectManagerInterface(
+ QStringLiteral("org.bluez"), QStringLiteral("/"),
+ QDBusConnection::systemBus());
+ qRegisterMetaType<QBluetoothServiceDiscoveryAgent::Error>("QBluetoothServiceDiscoveryAgent::Error");
+ } else {
+ qRegisterMetaType<ServiceMap>("ServiceMap");
+ qDBusRegisterMetaType<ServiceMap>();
- manager = new OrgBluezManagerInterface(QLatin1String("org.bluez"), QLatin1String("/"),
- QDBusConnection::systemBus());
+ manager = new OrgBluezManagerInterface(QStringLiteral("org.bluez"), QStringLiteral("/"),
+ QDBusConnection::systemBus());
+ }
}
QBluetoothServiceDiscoveryAgentPrivate::~QBluetoothServiceDiscoveryAgentPrivate()
{
delete device;
delete manager;
+ delete managerBluez5;
delete adapter;
}
@@ -80,7 +105,12 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
{
Q_Q(QBluetoothServiceDiscoveryAgent);
- qCDebug(QT_BT_BLUEZ) << "Full discovery on: " << address.toString();
+ qCDebug(QT_BT_BLUEZ) << "Discovery on: " << address.toString() << "Mode:" << DiscoveryMode();
+
+ if (managerBluez5) {
+ startBluez5(address);
+ return;
+ }
QDBusPendingReply<QDBusObjectPath> reply;
if (m_deviceAdapterAddress.isNull())
@@ -97,7 +127,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
return;
}
- adapter = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), reply.value().path(),
+ adapter = new OrgBluezAdapterInterface(QStringLiteral("org.bluez"), reply.value().path(),
QDBusConnection::systemBus());
if (m_deviceAdapterAddress.isNull()) {
@@ -118,6 +148,240 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
}
+void QBluetoothServiceDiscoveryAgentPrivate::startBluez5(const QBluetoothAddress &address)
+{
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+
+ if (foundHostAdapterPath.isEmpty()) {
+ // check that we match adapter addresses or use first if it wasn't specified
+
+ QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError()) {
+ discoveredDevices.clear();
+ error = QBluetoothServiceDiscoveryAgent::InputOutputError;
+ errorString = reply.error().message();
+ emit q->error(error);
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+
+ const QString desiredAdapter = m_deviceAdapterAddress.toString();
+ 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.Adapter1")) {
+ if (m_deviceAdapterAddress.isNull()
+ || desiredAdapter == ifaceList.value(iface).
+ value(QStringLiteral("Address")).toString()) {
+ // use first adapter or we just matched one
+ foundHostAdapterPath = path.path();
+ }
+
+ if (!foundHostAdapterPath.isEmpty())
+ break;
+ }
+ }
+
+ if (!foundHostAdapterPath.isEmpty())
+ break;
+ }
+
+ if (foundHostAdapterPath.isEmpty()) {
+ // Cannot find a local adapter
+ // Abort any outstanding discoveries
+ discoveredDevices.clear();
+
+ error = QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapterError;
+ errorString = QBluetoothServiceDiscoveryAgent::tr("Cannot find local Bluetooth adapter");
+ emit q->error(error);
+ _q_serviceDiscoveryFinished();
+
+ return;
+ }
+ }
+
+ // ensure we didn't go offline yet
+ OrgBluezAdapter1Interface adapter(QStringLiteral("org.bluez"),
+ foundHostAdapterPath, QDBusConnection::systemBus());
+ if (!adapter.powered()) {
+ discoveredDevices.clear();
+
+ error = QBluetoothServiceDiscoveryAgent::PoweredOffError;
+ errorString = QBluetoothServiceDiscoveryAgent::tr("Local device is powered off");
+ emit q->error(error);
+
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+
+ if (DiscoveryMode() == QBluetoothServiceDiscoveryAgent::MinimalDiscovery) {
+ performMinimalServiceDiscovery(address);
+ } else {
+ // we need to run the discovery in a different thread
+ // as it involves blocking calls
+ QtConcurrent::run(this, &QBluetoothServiceDiscoveryAgentPrivate::runSdpScan,
+ address, QBluetoothAddress(adapter.address()));
+ }
+}
+
+/*
+ * This function runs in a different thread. We need to be very careful what we
+ * access from here. That's why invokeMethod is used below.
+ */
+void QBluetoothServiceDiscoveryAgentPrivate::runSdpScan(
+ const QBluetoothAddress &remoteAddress, const QBluetoothAddress localAddress)
+{
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+
+ // connect to SDP server
+ bdaddr_t local, remote;
+ convertAddress(localAddress.toUInt64(), local.b);
+ convertAddress(remoteAddress.toUInt64(), remote.b);
+
+ /* We use singleshot timer below because this function runs in a different
+ * thread than the rest of this class.
+ */
+
+ sdp_session_t *session = sdp_connect( &local, &remote, SDP_RETRY_IF_BUSY);
+ // try one more time if first attempt fails
+ if (!session)
+ session = sdp_connect( &local, &remote, SDP_RETRY_IF_BUSY);
+
+ qCDebug(QT_BT_BLUEZ) << "SDP for" << remoteAddress.toString() << session << qt_error_string(errno);
+ if (!session) {
+ if (singleDevice) {
+ // was sole device without result -> error
+ QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
+ Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
+ QBluetoothServiceDiscoveryAgent::InputOutputError),
+ Q_ARG(QString,
+ QBluetoothServiceDiscoveryAgent::tr("Unable to access device")),
+ Q_ARG(QStringList, QStringList()));
+ } else {
+ // go to next device
+ QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
+ Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
+ QBluetoothServiceDiscoveryAgent::NoError),
+ Q_ARG(QString, QString()),
+ Q_ARG(QStringList, QStringList()));
+ }
+
+ return;
+ }
+
+
+ // set the filter for service matches
+ uuid_t publicBrowseGroupUuid;
+ sdp_uuid16_create(&publicBrowseGroupUuid, QBluetoothUuid::PublicBrowseGroup);
+ sdp_list_t *serviceFilter;
+ serviceFilter = sdp_list_append(0, &publicBrowseGroupUuid);
+
+ uint32_t attributeRange = 0x0000ffff; //all attributes
+ sdp_list_t *attributes;
+ attributes = sdp_list_append(0, &attributeRange);
+
+ sdp_list_t* sdpResults;
+ int result = sdp_service_search_attr_req(session, serviceFilter, SDP_ATTR_REQ_RANGE,
+ attributes, &sdpResults);
+ sdp_list_free(attributes, 0);
+ sdp_list_free(serviceFilter, 0);
+
+ if (result != 0) {
+ qCDebug(QT_BT_BLUEZ) << "SDP search failed" << qt_error_string(errno);
+ sdp_close(session);
+ if (singleDevice) {
+ QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
+ Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
+ QBluetoothServiceDiscoveryAgent::InputOutputError),
+ Q_ARG(QString,
+ QBluetoothServiceDiscoveryAgent::tr("Unable to access device")),
+ Q_ARG(QStringList, QStringList()));
+ } else {
+ QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
+ Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
+ QBluetoothServiceDiscoveryAgent::NoError),
+ Q_ARG(QString, QString()),
+ Q_ARG(QStringList, QStringList()));
+ }
+ return;
+ }
+
+ qCDebug(QT_BT_BLUEZ) << "SDP search a success. Iterating results" << sdpResults;
+ QStringList xmlRecords;
+
+ // process the results
+ for ( ; sdpResults; sdpResults = sdpResults->next) {
+ sdp_record_t *record = (sdp_record_t *) sdpResults->data;
+
+ QByteArray xml = parseSdpRecord(record);
+ if (xml.isEmpty())
+ continue;
+
+ //qDebug() << xml;
+ xmlRecords.append(QString::fromUtf8(xml));
+ }
+
+ sdp_close(session);
+
+ QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
+ Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
+ QBluetoothServiceDiscoveryAgent::NoError),
+ Q_ARG(QString, QString()),
+ Q_ARG(QStringList, xmlRecords));
+}
+
+void QBluetoothServiceDiscoveryAgentPrivate::_q_finishSdpScan(QBluetoothServiceDiscoveryAgent::Error errorCode,
+ const QString &errorDescription,
+ const QStringList &xmlRecords)
+{
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+
+ if (errorCode != QBluetoothServiceDiscoveryAgent::NoError) {
+ qCWarning(QT_BT_BLUEZ) << "SDP search failed for"
+ << discoveredDevices.at(0).address().toString();
+ // We have an error which we need to indicate and stop further processing
+ discoveredDevices.clear();
+ error = errorCode;
+ errorString = errorDescription;
+ emit q->error(error);
+ } else if (!xmlRecords.isEmpty() && discoveryState() != Inactive) {
+ foreach (const QString &record, xmlRecords) {
+ bool isBtleService = false;
+ const QBluetoothServiceInfo serviceInfo = parseServiceXml(record, &isBtleService);
+
+ //apply uuidFilter
+ if (!uuidFilter.isEmpty()) {
+ bool serviceNameMatched = uuidFilter.contains(serviceInfo.serviceUuid());
+ bool serviceClassMatched = false;
+ foreach (const QBluetoothUuid &id, serviceInfo.serviceClassUuids()) {
+ if (uuidFilter.contains(id)) {
+ serviceClassMatched = true;
+ break;
+ }
+ }
+
+ if (!serviceNameMatched && !serviceClassMatched)
+ continue;
+ }
+
+ if (!serviceInfo.isValid())
+ continue;
+
+ if (!isDuplicatedService(serviceInfo)) {
+ discoveredServices.append(serviceInfo);
+ qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString()
+ << serviceInfo.serviceName() << serviceInfo.serviceUuid()
+ << ">>>" << serviceInfo.serviceClassUuids();
+
+ emit q->serviceDiscovered(serviceInfo);
+ }
+ }
+ }
+
+ _q_serviceDiscoveryFinished();
+}
+
void QBluetoothServiceDiscoveryAgentPrivate::stop()
{
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "Stop called";
@@ -156,7 +420,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
QDBusPendingReply<QDBusObjectPath> deviceObjectPath = *watcher;
if (deviceObjectPath.isError()) {
- if (deviceObjectPath.error().name() != QLatin1String("org.bluez.Error.AlreadyExists")) {
+ if (deviceObjectPath.error().name() != QStringLiteral("org.bluez.Error.AlreadyExists")) {
delete adapter;
adapter = 0;
_q_serviceDiscoveryFinished();
@@ -180,7 +444,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
}
}
- device = new OrgBluezDeviceInterface(QLatin1String("org.bluez"),
+ device = new OrgBluezDeviceInterface(QStringLiteral("org.bluez"),
deviceObjectPath.value().path(),
QDBusConnection::systemBus());
delete adapter;
@@ -255,19 +519,20 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
}
}
+// Bluez 4
void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingCallWatcher *watcher)
{
if (!device)
return;
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO;
+ Q_Q(QBluetoothServiceDiscoveryAgent);
QDBusPendingReply<ServiceMap> reply = *watcher;
if (reply.isError()) {
qCDebug(QT_BT_BLUEZ) << "discoveredServices error: " << error << reply.error().message();
watcher->deleteLater();
if (singleDevice) {
- Q_Q(QBluetoothServiceDiscoveryAgent);
error = QBluetoothServiceDiscoveryAgent::UnknownError;
errorString = reply.error().message();
emit q->error(error);
@@ -282,60 +547,171 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC
qCDebug(QT_BT_BLUEZ) << "Parsing xml" << discoveredDevices.at(0).address().toString() << discoveredDevices.count() << map.count();
- Q_Q(QBluetoothServiceDiscoveryAgent);
+
foreach (const QString &record, reply.value()) {
- QXmlStreamReader xml(record);
+ bool isBtleService = false;
+ const QBluetoothServiceInfo serviceInfo = parseServiceXml(record, &isBtleService);
- QBluetoothServiceInfo serviceInfo;
+ if (isBtleService) {
+ qCDebug(QT_BT_BLUEZ) << "Discovered BLE services" << discoveredDevices.at(0).address().toString()
+ << serviceInfo.serviceName() << serviceInfo.serviceUuid() << serviceInfo.serviceClassUuids();
+ continue;
+ }
+
+ if (!serviceInfo.isValid())
+ continue;
+
+ // Don't need to apply uuidFilter because Bluez 4 applies
+ // search pattern during DiscoverServices() call
+
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+
+ if (!isDuplicatedService(serviceInfo)) {
+ discoveredServices.append(serviceInfo);
+ qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString()
+ << serviceInfo.serviceName();
+ emit q->serviceDiscovered(serviceInfo);
+ }
+
+ // could stop discovery, check for state
+ if (discoveryState() == Inactive)
+ qCDebug(QT_BT_BLUEZ) << "Exit discovery after stop";
+ }
+
+ watcher->deleteLater();
+ delete device;
+ device = 0;
+
+ _q_serviceDiscoveryFinished();
+}
- bool btle = false; // Detecting potential BTLE services
- while (!xml.atEnd()) {
- xml.readNext();
+QBluetoothServiceInfo QBluetoothServiceDiscoveryAgentPrivate::parseServiceXml(
+ const QString& xmlRecord, bool *isBtleService)
+{
+ QXmlStreamReader xml(xmlRecord);
- if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == QStringLiteral("attribute")) {
- quint16 attributeId = xml.attributes().value(QStringLiteral("id")).toString().toUShort(0, 0);
+ QBluetoothServiceInfo serviceInfo;
+ serviceInfo.setDevice(discoveredDevices.at(0));
- if (xml.readNextStartElement()) {
- QVariant value = readAttributeValue(xml);
+ while (!xml.atEnd()) {
+ xml.readNext();
+
+ if (xml.tokenType() == QXmlStreamReader::StartElement &&
+ xml.name() == QLatin1String("attribute")) {
+ quint16 attributeId =
+ xml.attributes().value(QLatin1String("id")).toString().toUShort(0, 0);
+
+ if (xml.readNextStartElement()) {
+ QVariant value = readAttributeValue(xml);
+ if (isBtleService) {
if (attributeId == 1) {// Attribute with id 1 contains UUID of the service
- const QBluetoothServiceInfo::Sequence seq = value.value<QBluetoothServiceInfo::Sequence>();
+ const QBluetoothServiceInfo::Sequence seq =
+ value.value<QBluetoothServiceInfo::Sequence>();
for (int i = 0; i < seq.count(); i++) {
const QBluetoothUuid uuid = seq.at(i).value<QBluetoothUuid>();
if ((uuid.data1 & 0x1800) == 0x1800) {// We are taking into consideration that LE services starts at 0x1800
+ //TODO don't emit in the middle of nowhere
+ Q_Q(QBluetoothServiceDiscoveryAgent);
QLowEnergyServiceInfo leService(uuid);
leService.setDevice(discoveredDevices.at(0));
- btle = true;
+ *isBtleService = true;
emit q->serviceDiscovered(leService);
break;
}
}
}
- serviceInfo.setAttribute(attributeId, value);
}
+ serviceInfo.setAttribute(attributeId, value);
}
}
+ }
- if (!btle) {
- serviceInfo.setDevice(discoveredDevices.at(0));
- if (!serviceInfo.isValid())
- continue;
+ return serviceInfo;
+}
+
+void QBluetoothServiceDiscoveryAgentPrivate::performMinimalServiceDiscovery(const QBluetoothAddress &deviceAddress)
+{
+ if (foundHostAdapterPath.isEmpty()) {
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+
+ QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError()) {
+ if (singleDevice) {
+ error = QBluetoothServiceDiscoveryAgent::InputOutputError;
+ errorString = reply.error().message();
+ emit q->error(error);
- discoveredServices.append(serviceInfo);
- qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString();
- emit q->serviceDiscovered(serviceInfo);
}
+ _q_serviceDiscoveryFinished();
+ return;
+ }
- // could stop discovery, check for state
- if(discoveryState() == Inactive){
- qCDebug(QT_BT_BLUEZ) << "Exit discovery after stop";
- break;
+ QStringList uuidStrings;
+ 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")) {
+ const QVariantMap details = ifaceList.value(iface);
+ if (deviceAddress.toString()
+ == details.value(QStringLiteral("Address")).toString()) {
+ uuidStrings = details.value(QStringLiteral("UUIDs")).toStringList();
+ break;
+ }
+ }
}
+ if (!uuidStrings.isEmpty())
+ break;
}
- watcher->deleteLater();
- delete device;
- device = 0;
+ if (uuidStrings.isEmpty() || discoveredDevices.isEmpty()) {
+ // nothing found -> go to next uuid
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+
+ qCDebug(QT_BT_BLUEZ) << "Minimal uuid list for" << deviceAddress.toString() << uuidStrings;
+
+ QBluetoothUuid uuid;
+ for (int i = 0; i < uuidStrings.count(); i++) {
+ uuid = QBluetoothUuid(uuidStrings.at(i));
+ if (uuid.isNull())
+ continue;
+
+ //apply uuidFilter
+ if (!uuidFilter.isEmpty() && !uuidFilter.contains(uuid))
+ continue;
+
+ // TODO deal with BTLE services under Bluez 5 -> right now they are normal services
+ QBluetoothServiceInfo serviceInfo;
+ serviceInfo.setDevice(discoveredDevices.at(0));
+
+ if (uuid.minimumSize() == 16) { // not derived from Bluetooth Base UUID
+ serviceInfo.setServiceUuid(uuid);
+ serviceInfo.setServiceName(QBluetoothServiceDiscoveryAgent::tr("Custom Service"));
+ } else {
+ // set uuid as service class id
+ QBluetoothServiceInfo::Sequence classId;
+ classId << QVariant::fromValue(uuid);
+ serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
+ QBluetoothUuid::ServiceClassUuid clsId
+ = static_cast<QBluetoothUuid::ServiceClassUuid>(uuid.data1 & 0xffff);
+ serviceInfo.setServiceName(QBluetoothUuid::serviceClassToString(clsId));
+ }
+
+ //don't include the service if we already discovered it before
+ if (!isDuplicatedService(serviceInfo)) {
+ discoveredServices << serviceInfo;
+ qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString()
+ << serviceInfo.serviceName();
+ emit q->serviceDiscovered(serviceInfo);
+ }
+ }
_q_serviceDiscoveryFinished();
}
@@ -467,29 +843,29 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredGattCharacteristic(QDB
QVariant QBluetoothServiceDiscoveryAgentPrivate::readAttributeValue(QXmlStreamReader &xml)
{
if (xml.name() == QLatin1String("boolean")) {
- const QString value = xml.attributes().value(QLatin1String("value")).toString();
+ const QString value = xml.attributes().value(QStringLiteral("value")).toString();
xml.skipCurrentElement();
return value == QLatin1String("true");
} else if (xml.name() == QLatin1String("uint8")) {
- quint8 value = xml.attributes().value(QLatin1String("value")).toString().toUShort(0, 0);
+ quint8 value = xml.attributes().value(QStringLiteral("value")).toString().toUShort(0, 0);
xml.skipCurrentElement();
return value;
} else if (xml.name() == QLatin1String("uint16")) {
- quint16 value = xml.attributes().value(QLatin1String("value")).toString().toUShort(0, 0);
+ quint16 value = xml.attributes().value(QStringLiteral("value")).toString().toUShort(0, 0);
xml.skipCurrentElement();
return value;
} else if (xml.name() == QLatin1String("uint32")) {
- quint32 value = xml.attributes().value(QLatin1String("value")).toString().toUInt(0, 0);
+ quint32 value = xml.attributes().value(QStringLiteral("value")).toString().toUInt(0, 0);
xml.skipCurrentElement();
return value;
} else if (xml.name() == QLatin1String("uint64")) {
- quint64 value = xml.attributes().value(QLatin1String("value")).toString().toULongLong(0, 0);
+ quint64 value = xml.attributes().value(QStringLiteral("value")).toString().toULongLong(0, 0);
xml.skipCurrentElement();
return value;
} else if (xml.name() == QLatin1String("uuid")) {
QBluetoothUuid uuid;
- const QString value = xml.attributes().value(QLatin1String("value")).toString();
- if (value.startsWith(QLatin1String("0x"))) {
+ const QString value = xml.attributes().value(QStringLiteral("value")).toString();
+ if (value.startsWith(QStringLiteral("0x"))) {
if (value.length() == 6) {
quint16 v = value.toUShort(0, 0);
uuid = QBluetoothUuid(v);
@@ -503,8 +879,8 @@ QVariant QBluetoothServiceDiscoveryAgentPrivate::readAttributeValue(QXmlStreamRe
xml.skipCurrentElement();
return QVariant::fromValue(uuid);
} else if (xml.name() == QLatin1String("text")) {
- QString value = xml.attributes().value(QLatin1String("value")).toString();
- if (xml.attributes().value(QLatin1String("encoding")) == QLatin1String("hex"))
+ QString value = xml.attributes().value(QStringLiteral("value")).toString();
+ if (xml.attributes().value(QStringLiteral("encoding")) == QLatin1String("hex"))
value = QString::fromUtf8(QByteArray::fromHex(value.toLatin1()));
xml.skipCurrentElement();
return value;
@@ -520,7 +896,7 @@ QVariant QBluetoothServiceDiscoveryAgentPrivate::readAttributeValue(QXmlStreamRe
} else {
qCWarning(QT_BT_BLUEZ) << "unknown attribute type"
<< xml.name().toString()
- << xml.attributes().value(QLatin1String("value")).toString();
+ << xml.attributes().value(QStringLiteral("value")).toString();
xml.skipCurrentElement();
return QVariant();
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_p.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_p.cpp
index 513d7ea7..86874a6c 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_p.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_p.cpp
@@ -45,7 +45,9 @@
QT_BEGIN_NAMESPACE
QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter)
- : error(QBluetoothServiceDiscoveryAgent::NoError), state(Inactive)
+ : error(QBluetoothServiceDiscoveryAgent::NoError), state(Inactive),
+ deviceDiscoveryAgent(0), mode(QBluetoothServiceDiscoveryAgent::MinimalDiscovery),
+ singleDevice(false)
{
Q_UNUSED(deviceAdapter);
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_p.h b/src/bluetooth/qbluetoothservicediscoveryagent_p.h
index 65082558..b316998b 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
@@ -56,6 +56,8 @@ class OrgBluezManagerInterface;
class OrgBluezAdapterInterface;
class OrgBluezDeviceInterface;
class OrgBluezCharacteristicInterface;
+class OrgFreedesktopDBusObjectManagerInterface;
+
QT_BEGIN_NAMESPACE
class QDBusPendingCallWatcher;
class QXmlStreamReader;
@@ -124,6 +126,9 @@ public:
void _q_discoverGattCharacteristics(QDBusPendingCallWatcher *watcher);
void _q_discoveredGattCharacteristic(QDBusPendingCallWatcher *watcher);
*/
+ void _q_finishSdpScan(QBluetoothServiceDiscoveryAgent::Error errorCode,
+ const QString &errorDescription,
+ const QStringList &xmlRecords);
#endif
#ifdef QT_ANDROID_BLUETOOTH
void _q_processFetchedUuids(const QBluetoothAddress &address, const QList<QBluetoothUuid> &uuids);
@@ -137,13 +142,19 @@ public:
private:
void start(const QBluetoothAddress &address);
void stop();
+ bool isDuplicatedService(const QBluetoothServiceInfo &serviceInfo) const;
#ifdef QT_BLUEZ_BLUETOOTH
+ void startBluez5(const QBluetoothAddress &address);
+ void runSdpScan(const QBluetoothAddress &remoteAddress,
+ const QBluetoothAddress localAddress);
QVariant readAttributeValue(QXmlStreamReader &xml);
+ QBluetoothServiceInfo parseServiceXml(const QString& xml, bool *isBtleService);
+ void performMinimalServiceDiscovery(const QBluetoothAddress &deviceAddress);
#endif
#ifdef QT_QNX_BLUETOOTH
-private Q_SLOTS:
+private slots:
void remoteDevicesChanged(int fd);
void controlReply(ppsResult result);
void controlEvent(ppsResult result);
@@ -178,7 +189,9 @@ private:
bool singleDevice;
#ifdef QT_BLUEZ_BLUETOOTH
+ QString foundHostAdapterPath;
OrgBluezManagerInterface *manager;
+ OrgFreedesktopDBusObjectManagerInterface *managerBluez5;
OrgBluezAdapterInterface *adapter;
OrgBluezDeviceInterface *device;
// variables below are used for discovering Bluetooth Low Energy devices
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
index 37fabfab..81d2c623 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
@@ -204,10 +204,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
const QString filePath = QStringLiteral("/pps/services/bluetooth/remote_devices/").append(address.toString());
bool hasError = false;
if ((m_rdfd = qt_safe_open(filePath.toLocal8Bit().constData(), O_RDONLY)) == -1) {
- if (QFile::exists(filePath + QLatin1String("-00")) ||
- QFile::exists(filePath + QLatin1String("-01")))
+ if (QFile::exists(filePath + QStringLiteral("-00")) ||
+ QFile::exists(filePath + QStringLiteral("-01")))
{
- qCDebug(QT_BT_QNX) << "LE device discovered...";
+ qCDebug(QT_BT_QNX) << "LE device discovered...skipping";
QString lePath = filePath + QStringLiteral("-00");
if ((m_rdfd = qt_safe_open(lePath.toLocal8Bit().constData(), O_RDONLY)) == -1) {
lePath = filePath + QStringLiteral("-01");
@@ -324,19 +324,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList,
QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
- bool entryExists = false;
//Did we already discover this service?
- foreach (QBluetoothServiceInfo sInfo, q_ptr->discoveredServices()) {
- if (sInfo.device() == serviceInfo.device()
- && sInfo.serviceUuid() == serviceInfo.serviceUuid()
- && sInfo.serviceClassUuids() == serviceInfo.serviceClassUuids()) {
- entryExists = true;
- //qCDebug(QT_BT_QNX) << "Entry exists" << serviceInfo.serviceClassUuids().first() << sInfo.serviceClassUuids().first();
- break;
- }
- }
-
- if (!entryExists) {
+ if (!isDuplicatedService(serviceInfo)) {
qCDebug(QT_BT_QNX) << "Adding service" << next_service << " " << serviceInfo.socketProtocol();
discoveredServices << serviceInfo;
q_ptr->serviceDiscovered(serviceInfo);
diff --git a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
index bde3e264..93fe22bf 100644
--- a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
@@ -54,104 +54,104 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
static void writeAttribute(QXmlStreamWriter *stream, const QVariant &attribute)
{
- const QString unsignedFormat(QLatin1String("0x%1"));
+ const QString unsignedFormat(QStringLiteral("0x%1"));
switch (int(attribute.type())) {
case QMetaType::Void:
- stream->writeEmptyElement(QLatin1String("nil"));
+ stream->writeEmptyElement(QStringLiteral("nil"));
break;
case QMetaType::UChar:
- stream->writeEmptyElement(QLatin1String("uint8"));
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeEmptyElement(QStringLiteral("uint8"));
+ stream->writeAttribute(QStringLiteral("value"),
unsignedFormat.arg(attribute.value<quint8>(), 2, 16,
QLatin1Char('0')));
- //stream->writeAttribute(QLatin1String("name"), foo);
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QMetaType::UShort:
- stream->writeEmptyElement(QLatin1String("uint16"));
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeEmptyElement(QStringLiteral("uint16"));
+ stream->writeAttribute(QStringLiteral("value"),
unsignedFormat.arg(attribute.value<quint16>(), 4, 16,
QLatin1Char('0')));
- //stream->writeAttribute(QLatin1String("name"), foo);
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QMetaType::UInt:
- stream->writeEmptyElement(QLatin1String("uint32"));
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeEmptyElement(QStringLiteral("uint32"));
+ stream->writeAttribute(QStringLiteral("value"),
unsignedFormat.arg(attribute.value<quint32>(), 8, 16,
QLatin1Char('0')));
- //stream->writeAttribute(QLatin1String("name"), foo);
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QMetaType::Char:
- stream->writeEmptyElement(QLatin1String("int8"));
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeEmptyElement(QStringLiteral("int8"));
+ stream->writeAttribute(QStringLiteral("value"),
QString::number(attribute.value<uchar>(), 16));
- //stream->writeAttribute(QLatin1String("name"), foo);
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QMetaType::Short:
- stream->writeEmptyElement(QLatin1String("int16"));
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeEmptyElement(QStringLiteral("int16"));
+ stream->writeAttribute(QStringLiteral("value"),
QString::number(attribute.value<qint16>(), 16));
- //stream->writeAttribute(QLatin1String("name"), foo);
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QMetaType::Int:
- stream->writeEmptyElement(QLatin1String("int32"));
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeEmptyElement(QStringLiteral("int32"));
+ stream->writeAttribute(QStringLiteral("value"),
QString::number(attribute.value<qint32>(), 16));
- //stream->writeAttribute(QLatin1String("name"), foo);
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QMetaType::QString:
- stream->writeEmptyElement(QLatin1String("text"));
+ stream->writeEmptyElement(QStringLiteral("text"));
if (/* require hex encoding */ false) {
- stream->writeAttribute(QLatin1String("value"), QString::fromLatin1(
+ stream->writeAttribute(QStringLiteral("value"), QString::fromLatin1(
attribute.value<QString>().toUtf8().toHex().constData()));
- stream->writeAttribute(QLatin1String("encoding"), QLatin1String("hex"));
+ stream->writeAttribute(QStringLiteral("encoding"), QStringLiteral("hex"));
} else {
- stream->writeAttribute(QLatin1String("value"), attribute.value<QString>());
- stream->writeAttribute(QLatin1String("encoding"), QLatin1String("normal"));
+ stream->writeAttribute(QStringLiteral("value"), attribute.value<QString>());
+ stream->writeAttribute(QStringLiteral("encoding"), QStringLiteral("normal"));
}
- //stream->writeAttribute(QLatin1String("name"), foo);
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QMetaType::Bool:
- stream->writeEmptyElement(QLatin1String("boolean"));
+ stream->writeEmptyElement(QStringLiteral("boolean"));
if (attribute.value<bool>())
- stream->writeAttribute(QLatin1String("value"), QLatin1String("true"));
+ stream->writeAttribute(QStringLiteral("value"), QStringLiteral("true"));
else
- stream->writeAttribute(QLatin1String("value"), QLatin1String("false"));
- //stream->writeAttribute(QLatin1String("name"), foo);
+ stream->writeAttribute(QStringLiteral("value"), QStringLiteral("false"));
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QMetaType::QUrl:
- stream->writeEmptyElement(QLatin1String("url"));
- stream->writeAttribute(QLatin1String("value"), attribute.value<QUrl>().toString());
- //stream->writeAttribute(QLatin1String("name"), foo);
+ stream->writeEmptyElement(QStringLiteral("url"));
+ stream->writeAttribute(QStringLiteral("value"), attribute.value<QUrl>().toString());
+ //stream->writeAttribute(QStringLiteral("name"), foo);
break;
case QVariant::UserType:
if (attribute.userType() == qMetaTypeId<QBluetoothUuid>()) {
- stream->writeEmptyElement(QLatin1String("uuid"));
+ stream->writeEmptyElement(QStringLiteral("uuid"));
QBluetoothUuid uuid = attribute.value<QBluetoothUuid>();
switch (uuid.minimumSize()) {
case 0:
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeAttribute(QStringLiteral("value"),
unsignedFormat.arg(quint16(0), 4, 16, QLatin1Char('0')));
break;
case 2:
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeAttribute(QStringLiteral("value"),
unsignedFormat.arg(uuid.toUInt16(), 4, 16,
QLatin1Char('0')));
break;
case 4:
- stream->writeAttribute(QLatin1String("value"),
+ stream->writeAttribute(QStringLiteral("value"),
unsignedFormat.arg(uuid.toUInt32(), 8, 16,
QLatin1Char('0')));
break;
case 16:
- stream->writeAttribute(QLatin1String("value"), uuid.toString().mid(1, 36));
+ stream->writeAttribute(QStringLiteral("value"), uuid.toString().mid(1, 36));
break;
default:
- stream->writeAttribute(QLatin1String("value"), uuid.toString().mid(1, 36));
+ stream->writeAttribute(QStringLiteral("value"), uuid.toString().mid(1, 36));
}
} else if (attribute.userType() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) {
- stream->writeStartElement(QLatin1String("sequence"));
+ stream->writeStartElement(QStringLiteral("sequence"));
const QBluetoothServiceInfo::Sequence *sequence =
static_cast<const QBluetoothServiceInfo::Sequence *>(attribute.data());
foreach (const QVariant &v, *sequence)
@@ -210,7 +210,7 @@ bool QBluetoothServiceInfoPrivate::ensureSdpConnection(const QBluetoothAddress &
delete service;
- OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"),
+ OrgBluezManagerInterface manager(QStringLiteral("org.bluez"), QStringLiteral("/"),
QDBusConnection::systemBus());
@@ -224,7 +224,7 @@ bool QBluetoothServiceInfoPrivate::ensureSdpConnection(const QBluetoothAddress &
return false;
currentLocalAdapter = localAdapter;
- service = new OrgBluezServiceInterface(QLatin1String("org.bluez"), reply.value().path(),
+ service = new OrgBluezServiceInterface(QStringLiteral("org.bluez"), reply.value().path(),
QDBusConnection::systemBus(), this);
return true;
@@ -246,16 +246,16 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
QXmlStreamWriter stream(&xmlServiceRecord);
stream.setAutoFormatting(true);
- stream.writeStartDocument(QLatin1String("1.0"));
+ stream.writeStartDocument(QStringLiteral("1.0"));
- stream.writeStartElement(QLatin1String("record"));
+ stream.writeStartElement(QStringLiteral("record"));
- const QString unsignedFormat(QLatin1String("0x%1"));
+ const QString unsignedFormat(QStringLiteral("0x%1"));
QMap<quint16, QVariant>::ConstIterator i = attributes.constBegin();
while (i != attributes.constEnd()) {
- stream.writeStartElement(QLatin1String("attribute"));
- stream.writeAttribute(QLatin1String("id"), unsignedFormat.arg(i.key(), 4, 16, QLatin1Char('0')));
+ stream.writeStartElement(QStringLiteral("attribute"));
+ stream.writeAttribute(QStringLiteral("id"), unsignedFormat.arg(i.key(), 4, 16, QLatin1Char('0')));
writeAttribute(&stream, i.value());
stream.writeEndElement();
diff --git a/src/bluetooth/qbluetoothserviceinfo_qnx.cpp b/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
index 30dac958..8767889b 100644
--- a/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
@@ -45,6 +45,11 @@
#include "qbluetoothserver_p.h"
#include "qbluetoothserver.h"
+#ifdef QT_QNX_BT_BLUETOOTH
+#include <btapi/btspp.h>
+#include <errno.h>
+#endif
+
QT_BEGIN_NAMESPACE
QBluetoothServiceInfoPrivate::QBluetoothServiceInfoPrivate()
@@ -70,11 +75,19 @@ bool QBluetoothServiceInfoPrivate::unregisterService()
if (serverChannel() == -1)
return false;
if ( __fakeServerPorts.key(serverChannel()) != 0) {
+#ifdef QT_QNX_BT_BLUETOOTH
+ QByteArray b_uuid = attributes.value(QBluetoothServiceInfo::ServiceId).
+ value<QBluetoothUuid>().toByteArray();
+ b_uuid = b_uuid.mid(1, b_uuid.length() - 2);
+ if (bt_spp_close_server(b_uuid.data()) == -1)
+ return false;
+#else
if (!ppsSendControlMessage("deregister_server", 0x1101, attributes.value(QBluetoothServiceInfo::ServiceId).value<QBluetoothUuid>(), QString(),
attributes.value(QBluetoothServiceInfo::ServiceName).toString(),
__fakeServerPorts.key(serverChannel()), BT_SPP_SERVER_SUBTYPE)) {
return false;
}
+#endif
else {
__fakeServerPorts.remove(__fakeServerPorts.key(serverChannel()));
registered = false;
@@ -98,10 +111,28 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress& loca
return false;
if (__fakeServerPorts.key(serverChannel()) != 0) {
+#ifdef QT_QNX_BT_BLUETOOTH
+ QByteArray b_uuid = attributes.value(QBluetoothServiceInfo::ServiceId)
+ .value<QBluetoothUuid>().toByteArray();
+ b_uuid = b_uuid.mid(1, b_uuid.length() - 2);
+ qCDebug(QT_BT_QNX) << "Registering server. " << b_uuid.data()
+ << attributes.value(QBluetoothServiceInfo::ServiceName)
+ .toString();
+ if (bt_spp_open_server(attributes.value(QBluetoothServiceInfo::ServiceName)
+ .toString().toUtf8().data(),
+ b_uuid.data(), true, &QBluetoothServerPrivate::btCallback,
+ reinterpret_cast<long>(__fakeServerPorts.key(serverChannel()))) == -1) {
+ qCDebug(QT_BT_QNX) << "Could not open the server. "
+ << qt_error_string(errno) << errno;
+ bt_spp_close_server(b_uuid.data());
+ return false;
+ }
+#else
if (!ppsSendControlMessage("register_server", 0x1101, attributes.value(QBluetoothServiceInfo::ServiceId).value<QBluetoothUuid>(), QString(),
attributes.value(QBluetoothServiceInfo::ServiceName).toString(),
__fakeServerPorts.key(serverChannel()), BT_SPP_SERVER_SUBTYPE))
return false;
+#endif
//The server needs to know the service name for the socket mount point path
__fakeServerPorts.key(serverChannel())->m_serviceName = attributes.value(QBluetoothServiceInfo::ServiceName).toString();
} else {
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp
index 6272ca1f..0c514887 100644
--- a/src/bluetooth/qbluetoothsocket.cpp
+++ b/src/bluetooth/qbluetoothsocket.cpp
@@ -600,7 +600,12 @@ void QBluetoothSocket::abort()
Q_D(QBluetoothSocket);
d->abort();
+
+#ifndef QT_ANDROID_BLUETOOTH
+ //Android closes when the Java event loop comes around
setSocketState(QBluetoothSocket::UnconnectedState);
+ emit disconnected();
+#endif
}
void QBluetoothSocket::disconnectFromService()
@@ -666,7 +671,11 @@ void QBluetoothSocket::close()
d->close();
+#ifndef QT_ANDROID_BLUETOOTH
+ //Android closes when the Java event loop comes around
setSocketState(UnconnectedState);
+ emit disconnected();
+#endif
}
/*!
diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp
index a894fed3..f2969da8 100644
--- a/src/bluetooth/qbluetoothsocket_android.cpp
+++ b/src/bluetooth/qbluetoothsocket_android.cpp
@@ -82,8 +82,9 @@ bool QBluetoothSocketPrivate::ensureNativeSocket(QBluetoothServiceInfo::Protocol
return false;
}
-//TODO Convert uuid parameter to const reference (affects QNX too)
-void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address, QBluetoothUuid uuid, QIODevice::OpenMode openMode)
+void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
+ const QBluetoothUuid &uuid,
+ QIODevice::OpenMode openMode)
{
Q_Q(QBluetoothSocket);
@@ -200,8 +201,8 @@ void QBluetoothSocketPrivate::connectToServiceConc(const QBluetoothAddress &addr
inputThread = new InputStreamThread(this);
QObject::connect(inputThread, SIGNAL(dataAvailable()),
q, SIGNAL(readyRead()), Qt::QueuedConnection);
- QObject::connect(inputThread, SIGNAL(error()),
- this, SLOT(inputThreadError()), Qt::QueuedConnection);
+ QObject::connect(inputThread, SIGNAL(error(int)),
+ this, SLOT(inputThreadError(int)), Qt::QueuedConnection);
if (!inputThread->run()) {
//close socket again
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp
index 6aad6603..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>
@@ -134,6 +137,12 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
Q_UNUSED(openMode);
int result = -1;
+ if (socket == -1 && !ensureNativeSocket(socketType)) {
+ errorString = QObject::tr("Unknown socket error");
+ q->setSocketError(QBluetoothSocket::UnknownSocketError);
+ return;
+ }
+
if (socketType == QBluetoothServiceInfo::RfcommProtocol) {
sockaddr_rc addr;
@@ -226,6 +235,7 @@ void QBluetoothSocketPrivate::_q_readNotify()
char *writePointer = buffer.reserve(QPRIVATELINEARBUFFER_BUFFERSIZE);
// qint64 readFromDevice = q->readData(writePointer, QPRIVATELINEARBUFFER_BUFFERSIZE);
int readFromDevice = ::read(socket, writePointer, QPRIVATELINEARBUFFER_BUFFERSIZE);
+ buffer.chop(QPRIVATELINEARBUFFER_BUFFERSIZE - (readFromDevice < 0 ? 0 : readFromDevice));
if(readFromDevice <= 0){
int errsv = errno;
readNotifier->setEnabled(false);
@@ -238,11 +248,8 @@ void QBluetoothSocketPrivate::_q_readNotify()
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->disconnectFromService();
- q->setSocketState(QBluetoothSocket::UnconnectedState);
}
else {
- buffer.chop(QPRIVATELINEARBUFFER_BUFFERSIZE - (readFromDevice < 0 ? 0 : readFromDevice));
-
emit q->readyRead();
}
}
@@ -259,9 +266,6 @@ void QBluetoothSocketPrivate::abort()
// QBluetoothSocket::close
QT_CLOSE(socket);
socket = -1;
-
- Q_Q(QBluetoothSocket);
- emit q->disconnected();
}
QString QBluetoothSocketPrivate::localName() const
@@ -270,23 +274,8 @@ QString QBluetoothSocketPrivate::localName() const
if (address.isNull())
return QString();
- OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"),
- QDBusConnection::systemBus());
-
- QDBusPendingReply<QDBusObjectPath> reply = manager.FindAdapter(address.toString());
- reply.waitForFinished();
- if (reply.isError())
- return QString();
-
- OrgBluezAdapterInterface adapter(QLatin1String("org.bluez"), reply.value().path(),
- QDBusConnection::systemBus());
-
- QDBusPendingReply<QVariantMap> properties = adapter.GetProperties();
- properties.waitForFinished();
- if (properties.isError())
- return QString();
-
- return properties.value().value(QLatin1String("Name")).toString();
+ QBluetoothLocalDevice device(address);
+ return device.name();
}
QBluetoothAddress QBluetoothSocketPrivate::localAddress() const
@@ -361,38 +350,60 @@ QString QBluetoothSocketPrivate::peerName() const
const QString peerAddress = QBluetoothAddress(bdaddr).toString();
const QString localAdapter = localAddress().toString();
- OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"),
- 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(QLatin1String("org.bluez"), reply.value().path(),
- QDBusConnection::systemBus());
-
- QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter.CreateDevice(peerAddress);
- deviceObjectPath.waitForFinished();
- if (deviceObjectPath.isError()) {
- if (deviceObjectPath.error().name() != QLatin1String("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(QLatin1String("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(QLatin1String("Alias")).toString();
+ return properties.value().value(QStringLiteral("Alias")).toString();
+ }
}
QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const
@@ -508,17 +519,7 @@ void QBluetoothSocketPrivate::close()
connectWriteNotifier->setEnabled(true);
}
else {
-
- delete readNotifier;
- readNotifier = 0;
- delete connectWriteNotifier;
- connectWriteNotifier = 0;
-
- // We are disconnected now, so go to unconnected.
- q->setSocketState(QBluetoothSocket::UnconnectedState);
- emit q->disconnected();
- QT_CLOSE(socket);
- socket = -1;
+ abort();
}
}
diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h
index 2fabeba1..63309069 100644
--- a/src/bluetooth/qbluetoothsocket_p.h
+++ b/src/bluetooth/qbluetoothsocket_p.h
@@ -96,7 +96,7 @@ public:
//On QNX and Android we connect using the uuid not the port
#if defined(QT_QNX_BLUETOOTH) || defined(QT_ANDROID_BLUETOOTH)
- void connectToService(const QBluetoothAddress &address, QBluetoothUuid uuid, QIODevice::OpenMode openMode);
+ void connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, QIODevice::OpenMode openMode);
#else
void connectToService(const QBluetoothAddress &address, quint16 port, QIODevice::OpenMode openMode);
#endif
@@ -169,7 +169,7 @@ public:
QAndroidJniObject outputStream;
InputStreamThread *inputThread;
-private Q_SLOTS:
+private slots:
void inputThreadError(int errorCode);
#endif
@@ -183,7 +183,7 @@ private:
QBluetoothUuid m_uuid;
bool isServerSocket;
-private Q_SLOTS:
+private slots:
void controlReply(ppsResult result);
void controlEvent(ppsResult result);
#endif
diff --git a/src/bluetooth/qbluetoothsocket_qnx.cpp b/src/bluetooth/qbluetoothsocket_qnx.cpp
index 4e277e28..10f08aa5 100644
--- a/src/bluetooth/qbluetoothsocket_qnx.cpp
+++ b/src/bluetooth/qbluetoothsocket_qnx.cpp
@@ -43,8 +43,15 @@
#include "qbluetoothsocket_p.h"
#include "qbluetoothlocaldevice.h"
#include <sys/stat.h>
+#ifdef QT_QNX_BT_BLUETOOTH
+#include <errno.h>
+#include <btapi/btspp.h>
+#endif
QT_BEGIN_NAMESPACE
+#ifdef QT_QNX_BT_BLUETOOTH
+static int initCounter = 0;
+#endif
QBluetoothSocketPrivate::QBluetoothSocketPrivate()
: socket(-1),
@@ -57,12 +64,28 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
discoveryAgent(0),
isServerSocket(false)
{
+#ifdef QT_QNX_BT_BLUETOOTH
+ if (!initCounter && (bt_spp_init() == -1))
+ qCDebug(QT_BT_QNX) << "Could not initialize Bluetooth library. "
+ << qt_error_string(errno);
+
+ initCounter++;
+#else
ppsRegisterControl();
+#endif
}
QBluetoothSocketPrivate::~QBluetoothSocketPrivate()
{
+#ifdef QT_QNX_BT_BLUETOOTH
+ if (initCounter == 1 && (bt_spp_deinit() == -1))
+ qCDebug(QT_BT_QNX) << "Could not deinitialize Bluetooth library."
+ "SPP connection is still open.";
+
+ initCounter--;
+#else
ppsUnregisterControl(this);
+#endif
close();
}
@@ -75,29 +98,51 @@ bool QBluetoothSocketPrivate::ensureNativeSocket(QBluetoothServiceInfo::Protocol
return false;
}
-void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address, QBluetoothUuid uuid, QIODevice::OpenMode openMode)
+void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
+ const QBluetoothUuid &uuid,
+ QIODevice::OpenMode openMode)
{
+ Q_Q(QBluetoothSocket);
Q_UNUSED(openMode);
qCDebug(QT_BT_QNX) << "Connecting socket";
- if (isServerSocket) {
- m_peerAddress = address;
- m_uuid = uuid;
+
+ m_peerAddress = address;
+#ifdef QT_QNX_BT_BLUETOOTH
+ QByteArray b_uuid = uuid.toByteArray();
+ b_uuid = b_uuid.mid(1, b_uuid.length() - 2);
+ socket = bt_spp_open(address.toString().toUtf8().data(), b_uuid.data(), false);
+ if (socket == -1) {
+ qCWarning(QT_BT_QNX) << "Could not connect to" << address.toString() << b_uuid << qt_error_string(errno);
+ errorString = qt_error_string(errno);
+ q->setSocketError(QBluetoothSocket::NetworkError);
return;
}
+ delete readNotifier;
+ delete connectWriteNotifier;
+
+ readNotifier = new QSocketNotifier(socket, QSocketNotifier::Read);
+ QObject::connect(readNotifier, SIGNAL(activated(int)), q, SLOT(_q_readNotify()));
+ connectWriteNotifier = new QSocketNotifier(socket, QSocketNotifier::Write, q);
+ QObject::connect(connectWriteNotifier, SIGNAL(activated(int)), q, SLOT(_q_writeNotify()));
+
+ connecting = true;
+ q->setOpenMode(openMode);
+#else
+ m_uuid = uuid;
+ if (isServerSocket)
+ return;
+
if (state != QBluetoothSocket::UnconnectedState) {
qCDebug(QT_BT_QNX) << "Socket already connected";
return;
}
- state = QBluetoothSocket::ConnectingState;
-
- m_uuid = uuid;
- m_peerAddress = address;
ppsSendControlMessage("connect_service", 0x1101, uuid, address.toString(), QString(), this, BT_SPP_CLIENT_SUBTYPE);
ppsRegisterForEvent(QStringLiteral("service_connected"),this);
ppsRegisterForEvent(QStringLiteral("get_mount_point_path"),this);
- socketType = QBluetoothServiceInfo::RfcommProtocol;
+#endif
+ q->setSocketState(QBluetoothSocket::ConnectingState);
}
void QBluetoothSocketPrivate::_q_writeNotify()
@@ -164,9 +209,16 @@ void QBluetoothSocketPrivate::abort()
{
Q_Q(QBluetoothSocket);
qCDebug(QT_BT_QNX) << "Disconnecting service";
+#ifdef QT_QNX_BT_BLUETOOTH
+ if (isServerSocket)
+ bt_spp_close_server(m_uuid.toString().toUtf8().data());
+ else
+ bt_spp_close(socket);
+#else
if (q->state() != QBluetoothSocket::ClosingState)
ppsSendControlMessage("disconnect_service", 0x1101, m_uuid, m_peerAddress.toString(), QString(), 0,
isServerSocket ? BT_SPP_SERVER_SUBTYPE : BT_SPP_CLIENT_SUBTYPE);
+#endif
delete readNotifier;
readNotifier = 0;
delete connectWriteNotifier;
@@ -174,8 +226,6 @@ void QBluetoothSocketPrivate::abort()
::close(socket);
- q->setSocketState(QBluetoothSocket::UnconnectedState);
- Q_EMIT q->disconnected();
isServerSocket = false;
}
@@ -229,7 +279,7 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize)
return -1;
}
- Q_EMIT q->bytesWritten(maxSize);
+ emit q->bytesWritten(maxSize);
return maxSize;
} else {
@@ -282,11 +332,6 @@ bool QBluetoothSocketPrivate::setSocketDescriptor(int socketDescriptor, QBluetoo
socket = socketDescriptor;
socketType = socketType_;
- // ensure that O_NONBLOCK is set on new connections.
- int flags = fcntl(socket, F_GETFL, 0);
- if (!(flags & O_NONBLOCK))
- fcntl(socket, F_SETFL, flags | O_NONBLOCK);
-
readNotifier = new QSocketNotifier(socket, QSocketNotifier::Read);
QObject::connect(readNotifier, SIGNAL(activated(int)), q, SLOT(_q_readNotify()));
connectWriteNotifier = new QSocketNotifier(socket, QSocketNotifier::Write, q);
@@ -299,7 +344,9 @@ bool QBluetoothSocketPrivate::setSocketDescriptor(int socketDescriptor, QBluetoo
emit q->connected();
isServerSocket = true;
+#ifndef QT_QNX_BT_BLUETOOTH
ppsRegisterForEvent(QStringLiteral("service_disconnected"),this);
+#endif
return true;
}
@@ -311,6 +358,7 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const
void QBluetoothSocketPrivate::controlReply(ppsResult result)
{
+#ifndef QT_QNX_BT_BLUETOOTH
Q_Q(QBluetoothSocket);
if (result.msg == QStringLiteral("connect_service")) {
@@ -356,19 +404,23 @@ void QBluetoothSocketPrivate::controlReply(ppsResult result)
connectWriteNotifier->setEnabled(true);
readNotifier->setEnabled(true);
+ state = QBluetoothSocket::ConnectedState;
emit q->connected();
ppsRegisterForEvent(QStringLiteral("service_disconnected"),this);
}
}
+#endif
}
void QBluetoothSocketPrivate::controlEvent(ppsResult result)
{
+#ifndef QT_QNX_BT_BLUETOOTH
Q_Q(QBluetoothSocket);
if (result.msg == QStringLiteral("service_disconnected")) {
q->setSocketState(QBluetoothSocket::ClosingState);
close();
}
+#endif
}
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothtransferreply.cpp b/src/bluetooth/qbluetoothtransferreply.cpp
index ae97c639..9acd917d 100644
--- a/src/bluetooth/qbluetoothtransferreply.cpp
+++ b/src/bluetooth/qbluetoothtransferreply.cpp
@@ -68,6 +68,8 @@ QT_BEGIN_NAMESPACE
\value FileNotFoundError Unable to open the file specified
\value HostNotFoundError Unable to connect to the target host
\value UserCanceledTransferError User terminated the transfer
+ \value IODeviceNotReadableError File was not open before initiating the sending command
+ \value ResourceBusyError Unable to access the resource.
*/
diff --git a/src/bluetooth/qbluetoothtransferreply.h b/src/bluetooth/qbluetoothtransferreply.h
index 42571ca4..33910fd9 100644
--- a/src/bluetooth/qbluetoothtransferreply.h
+++ b/src/bluetooth/qbluetoothtransferreply.h
@@ -61,7 +61,9 @@ public:
UnknownError,
FileNotFoundError,
HostNotFoundError,
- UserCanceledTransferError
+ UserCanceledTransferError,
+ IODeviceNotReadableError,
+ ResourceBusyError
};
diff --git a/src/bluetooth/qbluetoothtransferreply_bluez.cpp b/src/bluetooth/qbluetoothtransferreply_bluez.cpp
index 8b271789..e4395e2f 100644
--- a/src/bluetooth/qbluetoothtransferreply_bluez.cpp
+++ b/src/bluetooth/qbluetoothtransferreply_bluez.cpp
@@ -68,8 +68,8 @@ QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, con
{
setRequest(request);
setManager(parent);
- client = new OrgOpenobexClientInterface(QLatin1String("org.openobex.client"), QLatin1String("/"),
- QDBusConnection::sessionBus());
+ client = new OrgOpenobexClientInterface(QStringLiteral("org.openobex.client"), QStringLiteral("/"),
+ QDBusConnection::sessionBus());
qsrand(QTime::currentTime().msec());
m_agent_path = agentPath;
@@ -104,6 +104,15 @@ bool QBluetoothTransferReplyBluez::start()
tempfile = new QTemporaryFile(this );
tempfile->open();
qCDebug(QT_BT_BLUEZ) << "Not a QFile, making a copy" << tempfile->fileName();
+ if (!source->isReadable()) {
+ m_errorStr = QBluetoothTransferReply::tr("QIODevice cannot be read."
+ "Make sure it is open for reading.");
+ m_error = QBluetoothTransferReply::IODeviceNotReadableError;
+ m_finished = true;
+ m_running = false;
+ QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection, Q_ARG(QBluetoothTransferReply*, this));
+ return false;
+ }
QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>();
QObject::connect(watcher, SIGNAL(finished()), this, SLOT(copyDone()));
@@ -139,7 +148,7 @@ bool QBluetoothTransferReplyBluez::copyToTempFile(QIODevice *to, QIODevice *from
char *block = new char[4096];
int size;
- while((size = from->read(block, 4096))) {
+ while ((size = from->read(block, 4096)) > 0) {
if(size != to->write(block, size)){
return false;
}
@@ -270,7 +279,8 @@ bool QBluetoothTransferReplyBluez::isRunning() const
void QBluetoothTransferReplyBluez::abort()
{
if(!m_transfer_path.isEmpty()){
- OrgOpenobexTransferInterface *xfer = new OrgOpenobexTransferInterface(QLatin1String("org.openobex.client"), m_transfer_path,
+ OrgOpenobexTransferInterface *xfer = new OrgOpenobexTransferInterface(QStringLiteral("org.openobex.client"),
+ m_transfer_path,
QDBusConnection::sessionBus());
QDBusPendingReply<> reply = xfer->Cancel();
reply.waitForFinished();
diff --git a/src/bluetooth/qbluetoothtransferreply_bluez_p.h b/src/bluetooth/qbluetoothtransferreply_bluez_p.h
index b1fe795e..412959e5 100644
--- a/src/bluetooth/qbluetoothtransferreply_bluez_p.h
+++ b/src/bluetooth/qbluetoothtransferreply_bluez_p.h
@@ -71,7 +71,7 @@ public:
QBluetoothTransferReply::TransferError error() const;
QString errorString() const;
-private Q_SLOTS:
+private slots:
bool start();
private:
diff --git a/src/bluetooth/qbluetoothtransferreply_qnx.cpp b/src/bluetooth/qbluetoothtransferreply_qnx.cpp
index bc15fbde..f2fea315 100644
--- a/src/bluetooth/qbluetoothtransferreply_qnx.cpp
+++ b/src/bluetooth/qbluetoothtransferreply_qnx.cpp
@@ -56,8 +56,11 @@
#include <QtCore/private/qcore_unix_p.h>
#include <QTime>
+#include <QDir>
+#include <QCoreApplication>
-//static const QLatin1String agentPath("/shared/tmp/opp");
+static const QString agentPath(QStringLiteral("/accounts/1000/shared/misc/"));
+static bool busy;
QT_BEGIN_NAMESPACE
@@ -69,7 +72,6 @@ QBluetoothTransferReplyQnx::QBluetoothTransferReplyQnx(QIODevice *input, const Q
{
setRequest(request);
setManager(parent);
-
ppsRegisterControl();
//qsrand(QTime::currentTime().msec());
//m_agent_path = agentPath;
@@ -87,6 +89,8 @@ QBluetoothTransferReplyQnx::QBluetoothTransferReplyQnx(QIODevice *input, const Q
*/
QBluetoothTransferReplyQnx::~QBluetoothTransferReplyQnx()
{
+ removeTempFile();
+ delete tempfile;
ppsUnregisterControl(this);
}
@@ -98,19 +102,39 @@ bool QBluetoothTransferReplyQnx::start()
QFile *file = qobject_cast<QFile *>(source);
if (!file){
-// tempfile = new QTemporaryFile(this );
-// tempfile->open();
-
-// QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>();
-// QObject::connect(watcher, SIGNAL(finished()), this, SLOT(copyDone()));
+ // Deleting temporary files in case of app crash
+ QDir directory(agentPath);
+ QString appName = QStringLiteral("Qt5OPP_tmp") + QCoreApplication::applicationName();
+ if (directory.exists(appName) && !busy) {
+ QFile file(agentPath + appName);
+ file.remove();
+ }
+ else if (directory.exists(appName) && busy) {
+ m_errorStr = QBluetoothTransferReply::tr("Resurce busy.");
+ m_error = QBluetoothTransferReply::ResourceBusyError;
+ m_finished = true;
+ m_running = false;
+ emit finished(this);
+ return false;
+ }
+ if (!source->isReadable()) {
+ m_errorStr = QBluetoothTransferReply::tr("QIODevice cannot be read."
+ "Make sure it is open for reading.");
+ m_error = QBluetoothTransferReply::IODeviceNotReadableError;
+ m_finished = true;
+ m_running = false;
+ emit finished(this);
+ return false;
+ }
+ QString fileName = agentPath + QStringLiteral("Qt5OPP_tmp");
+ tempfile = new QFile(fileName);
+ tempfile->open(QIODevice::WriteOnly);
-// QFuture<bool> results = QtConcurrent::run(QBluetoothTransferReplyQnx::copyToTempFile, tempfile, source);
-// watcher->setFuture(results);
- //QTemporaryFile does not work properly yet
- m_error = QBluetoothTransferReply::UnknownError;
- m_finished = true;
- m_running = false;
- Q_EMIT finished(this);
+ QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>();
+ QObject::connect(watcher, SIGNAL(finished()), this, SLOT(copyDone()));
+ QFuture<bool> results = QtConcurrent::run(QBluetoothTransferReplyQnx::copyToTempFile, tempfile, source);
+ watcher->setFuture(results);
+ busy = true;
} else {
if (!file->exists()) {
@@ -139,7 +163,7 @@ bool QBluetoothTransferReplyQnx::copyToTempFile(QIODevice *to, QIODevice *from)
char *block = new char[4096];
int size;
- while ((size = from->read(block, 4096))) {
+ while ((size = from->read(block, 4096)) > 0) {
if (size != to->write(block, size))
return false;
}
@@ -150,14 +174,14 @@ bool QBluetoothTransferReplyQnx::copyToTempFile(QIODevice *to, QIODevice *from)
void QBluetoothTransferReplyQnx::copyDone()
{
- qCDebug(QT_BT_QNX) << "Copy done";
startOPP(tempfile->fileName());
QObject::sender()->deleteLater();
}
void QBluetoothTransferReplyQnx::startOPP(QString filename)
{
- qCDebug(QT_BT_QNX) << "Sending Push object command";
+ qCDebug(QT_BT_QNX) << "Sending push object command"
+ << request().address().toString() << filename;
ppsSendOpp("push_object", filename.toUtf8(), request().address(), this);
}
@@ -183,6 +207,7 @@ void QBluetoothTransferReplyQnx::controlEvent(ppsResult result)
{
if (result.msg == QStringLiteral("opp_cancelled")) {
qCDebug(QT_BT_QNX) << "opp cancelled" << result.errorMsg << result.error;
+ removeTempFile();
if (m_running)
return;
m_finished = true;
@@ -198,7 +223,7 @@ void QBluetoothTransferReplyQnx::controlEvent(ppsResult result)
m_errorStr = result.errorMsg;
m_error = QBluetoothTransferReply::UnknownError;
// }
- Q_EMIT finished(this);
+ emit finished(this);
} else if (result.msg == QStringLiteral("opp_update")) {
bool ok;
qint64 sentBytes = result.dat.at(result.dat.indexOf(QStringLiteral("sent")) + 1).toDouble(&ok);
@@ -212,12 +237,13 @@ void QBluetoothTransferReplyQnx::controlEvent(ppsResult result)
return;
}
qCDebug(QT_BT_QNX) << "opp update" << sentBytes << totalBytes;
- Q_EMIT transferProgress(sentBytes, totalBytes);
+ emit transferProgress(sentBytes, totalBytes);
} else if (result.msg == QStringLiteral("opp_complete")) {
qCDebug(QT_BT_QNX) << "opp complete";
+ removeTempFile();
m_finished = true;
m_running = false;
- Q_EMIT finished(this);
+ emit finished(this);
}
}
@@ -242,6 +268,16 @@ void QBluetoothTransferReplyQnx::abort()
//not supported yet
}
+void QBluetoothTransferReplyQnx::removeTempFile()
+{
+ if (tempfile) {
+ if (tempfile->exists()) {
+ tempfile->remove();
+ busy = false;
+ }
+ }
+}
+
#include "moc_qbluetoothtransferreply_qnx_p.cpp"
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothtransferreply_qnx_p.h b/src/bluetooth/qbluetoothtransferreply_qnx_p.h
index 4522c8bf..391f41af 100644
--- a/src/bluetooth/qbluetoothtransferreply_qnx_p.h
+++ b/src/bluetooth/qbluetoothtransferreply_qnx_p.h
@@ -43,18 +43,16 @@
#ifndef QBLUETOOTHTRANSFERREPLY_QNX_P_H
#define QBLUETOOTHTRANSFERREPLY_QNX_P_H
-#include <QtCore/QIODevice>
-
#include <qbluetoothtransferrequest.h>
#include <qbluetoothtransfermanager.h>
#include "qbluetoothtransferreply.h"
-#include <QTemporaryFile>
-#include <QSocketNotifier>
-
#include "qnx/ppshelpers_p.h"
+QT_FORWARD_DECLARE_CLASS(QFile)
+QT_FORWARD_DECLARE_CLASS(QIODevice)
+
QT_BEGIN_NAMESPACE
class Q_BLUETOOTH_EXPORT QBluetoothTransferReplyQnx : public QBluetoothTransferReply
@@ -72,7 +70,7 @@ public:
QBluetoothTransferReply::TransferError error() const;
QString errorString() const;
-private Q_SLOTS:
+private slots:
void controlReply(ppsResult result);
void controlEvent(ppsResult result);
void copyDone();
@@ -80,7 +78,8 @@ private Q_SLOTS:
private:
void startOPP(QString filename);
- QTemporaryFile *tempfile;
+ void removeTempFile();
+ QFile *tempfile;
QIODevice *source;
bool m_running;
diff --git a/src/bluetooth/qbluetoothuuid.cpp b/src/bluetooth/qbluetoothuuid.cpp
index 92b20f2a..18402bb1 100644
--- a/src/bluetooth/qbluetoothuuid.cpp
+++ b/src/bluetooth/qbluetoothuuid.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qbluetoothuuid.h"
+#include "qbluetoothservicediscoveryagent.h"
#include <QStringList>
#include <QtEndian>
@@ -594,6 +595,130 @@ quint128 QBluetoothUuid::toUInt128() const
}
/*!
+ Returns a human-readable and translated name for the given service class
+ represented by \a uuid.
+
+ \sa QBluetoothUuid::ServiceClassUuid
+ \since Qt 5.4
+ */
+QString QBluetoothUuid::serviceClassToString(QBluetoothUuid::ServiceClassUuid uuid)
+{
+ switch (uuid) {
+ case QBluetoothUuid::ServiceDiscoveryServer: return QBluetoothServiceDiscoveryAgent::tr("Service Discovery");
+ case QBluetoothUuid::BrowseGroupDescriptor: return QBluetoothServiceDiscoveryAgent::tr("Browse Group Descriptor");
+ case QBluetoothUuid::PublicBrowseGroup: return QBluetoothServiceDiscoveryAgent::tr("Public Browse Group");
+ case QBluetoothUuid::SerialPort: return QBluetoothServiceDiscoveryAgent::tr("Serial Port Profile");
+ case QBluetoothUuid::LANAccessUsingPPP: return QBluetoothServiceDiscoveryAgent::tr("LAN Access Profile");
+ case QBluetoothUuid::DialupNetworking: return QBluetoothServiceDiscoveryAgent::tr("Dial-Up Networking");
+ case QBluetoothUuid::IrMCSync: return QBluetoothServiceDiscoveryAgent::tr("Synchronization");
+ case QBluetoothUuid::ObexObjectPush: return QBluetoothServiceDiscoveryAgent::tr("Object Push");
+ case QBluetoothUuid::OBEXFileTransfer: return QBluetoothServiceDiscoveryAgent::tr("File Transfer");
+ case QBluetoothUuid::IrMCSyncCommand: return QBluetoothServiceDiscoveryAgent::tr("Synchronization Command");
+ case QBluetoothUuid::Headset: return QBluetoothServiceDiscoveryAgent::tr("Headset");
+ case QBluetoothUuid::AudioSource: return QBluetoothServiceDiscoveryAgent::tr("Audio Source");
+ case QBluetoothUuid::AudioSink: return QBluetoothServiceDiscoveryAgent::tr("Audio Sink");
+ case QBluetoothUuid::AV_RemoteControlTarget: return QBluetoothServiceDiscoveryAgent::tr("Audio/Video Remote Control Target");
+ case QBluetoothUuid::AdvancedAudioDistribution: return QBluetoothServiceDiscoveryAgent::tr("Advanced Audio Distribution");
+ case QBluetoothUuid::AV_RemoteControl: return QBluetoothServiceDiscoveryAgent::tr("Audio/Video Remote Control");
+ case QBluetoothUuid::AV_RemoteControlController: return QBluetoothServiceDiscoveryAgent::tr("Audio/Video Remote Control Controller");
+ case QBluetoothUuid::HeadsetAG: return QBluetoothServiceDiscoveryAgent::tr("Headset AG");
+ case QBluetoothUuid::PANU: return QBluetoothServiceDiscoveryAgent::tr("Personal Area Networking (PANU)");
+ case QBluetoothUuid::NAP: return QBluetoothServiceDiscoveryAgent::tr("Personal Area Networking (NAP)");
+ case QBluetoothUuid::GN: return QBluetoothServiceDiscoveryAgent::tr("Personal Area Networking (GN)");
+ case QBluetoothUuid::DirectPrinting: return QBluetoothServiceDiscoveryAgent::tr("Basic Direct Printing (BPP)");
+ case QBluetoothUuid::ReferencePrinting: return QBluetoothServiceDiscoveryAgent::tr("Basic Reference Printing (BPP)");
+ case QBluetoothUuid::BasicImage: return QBluetoothServiceDiscoveryAgent::tr("Basic Imaging Profile");
+ case QBluetoothUuid::ImagingResponder: return QBluetoothServiceDiscoveryAgent::tr("Basic Imaging Responder");
+ case QBluetoothUuid::ImagingAutomaticArchive: return QBluetoothServiceDiscoveryAgent::tr("Basic Imaging Archive");
+ case QBluetoothUuid::ImagingReferenceObjects: return QBluetoothServiceDiscoveryAgent::tr("Basic Imaging Ref Objects");
+ case QBluetoothUuid::Handsfree: return QBluetoothServiceDiscoveryAgent::tr("Hands-Free");
+ case QBluetoothUuid::HandsfreeAudioGateway: return QBluetoothServiceDiscoveryAgent::tr("Hands-Free AG");
+ case QBluetoothUuid::DirectPrintingReferenceObjectsService: return QBluetoothServiceDiscoveryAgent::tr("Basic Printing RefObject Service");
+ case QBluetoothUuid::ReflectedUI: return QBluetoothServiceDiscoveryAgent::tr("Basic Printing Reflected UI");
+ case QBluetoothUuid::BasicPrinting: return QBluetoothServiceDiscoveryAgent::tr("Basic Printing");
+ case QBluetoothUuid::PrintingStatus: return QBluetoothServiceDiscoveryAgent::tr("Basic Printing Status");
+ case QBluetoothUuid::HumanInterfaceDeviceService: return QBluetoothServiceDiscoveryAgent::tr("Human Interface Device");
+ case QBluetoothUuid::HardcopyCableReplacement: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Cable Replacement");
+ case QBluetoothUuid::HCRPrint: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Cable Replacement Print");
+ case QBluetoothUuid::HCRScan: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Cable Replacement Scan");
+ case QBluetoothUuid::SIMAccess: return QBluetoothServiceDiscoveryAgent::tr("SIM Access Server");
+ case QBluetoothUuid::PhonebookAccessPCE: return QBluetoothServiceDiscoveryAgent::tr("Phonebook Access PCE");
+ case QBluetoothUuid::PhonebookAccessPSE: return QBluetoothServiceDiscoveryAgent::tr("Phonebook Access PSE");
+ case QBluetoothUuid::PhonebookAccess: return QBluetoothServiceDiscoveryAgent::tr("Phonebook Access");
+ case QBluetoothUuid::HeadsetHS: return QBluetoothServiceDiscoveryAgent::tr("Headset HS");
+ case QBluetoothUuid::MessageAccessServer: return QBluetoothServiceDiscoveryAgent::tr("Message Access Server");
+ case QBluetoothUuid::MessageNotificationServer: return QBluetoothServiceDiscoveryAgent::tr("Message Notification Server");
+ case QBluetoothUuid::MessageAccessProfile: return QBluetoothServiceDiscoveryAgent::tr("Message Access");
+ case QBluetoothUuid::GNSS: return QBluetoothServiceDiscoveryAgent::tr("Global Navigation Satellite System");
+ case QBluetoothUuid::GNSSServer: return QBluetoothServiceDiscoveryAgent::tr("Global Navigation Satellite System Server");
+ case QBluetoothUuid::Display3D: return QBluetoothServiceDiscoveryAgent::tr("3D Synchronization Display");
+ case QBluetoothUuid::Glasses3D: return QBluetoothServiceDiscoveryAgent::tr("3D Synchronization Glasses");
+ case QBluetoothUuid::Synchronization3D: return QBluetoothServiceDiscoveryAgent::tr("3D Synchronization");
+ case QBluetoothUuid::MPSProfile: return QBluetoothServiceDiscoveryAgent::tr("Multi-Profile Specification (Profile)");
+ case QBluetoothUuid::MPSService: return QBluetoothServiceDiscoveryAgent::tr("Multi-Profile Specification");
+ case QBluetoothUuid::PnPInformation: return QBluetoothServiceDiscoveryAgent::tr("Device Identification");
+ case QBluetoothUuid::GenericNetworking: return QBluetoothServiceDiscoveryAgent::tr("Generic Networking");
+ case QBluetoothUuid::GenericFileTransfer: return QBluetoothServiceDiscoveryAgent::tr("Generic File Transfer");
+ case QBluetoothUuid::GenericAudio: return QBluetoothServiceDiscoveryAgent::tr("Generic Audio");
+ case QBluetoothUuid::GenericTelephony: return QBluetoothServiceDiscoveryAgent::tr("Generic Telephony");
+ case QBluetoothUuid::VideoSource: return QBluetoothServiceDiscoveryAgent::tr("Video Source");
+ case QBluetoothUuid::VideoSink: return QBluetoothServiceDiscoveryAgent::tr("Video Sink");
+ case QBluetoothUuid::VideoDistribution: return QBluetoothServiceDiscoveryAgent::tr("Video Distribution");
+ case QBluetoothUuid::HDP: return QBluetoothServiceDiscoveryAgent::tr("Health Device");
+ case QBluetoothUuid::HDPSource: return QBluetoothServiceDiscoveryAgent::tr("Health Device Source");
+ case QBluetoothUuid::HDPSink: return QBluetoothServiceDiscoveryAgent::tr("Health Device Sink");
+ default:
+ break;
+ }
+
+ return QString();
+}
+
+
+/*!
+ Returns a human-readable and translated name for the given protocol
+ represented by \a uuid.
+
+ \sa QBluetoothUuid::ProtocolUuid
+
+ \since Qt 5.4
+ */
+QString QBluetoothUuid::protocolToString(QBluetoothUuid::ProtocolUuid uuid)
+{
+ switch (uuid) {
+ case QBluetoothUuid::Sdp: return QBluetoothServiceDiscoveryAgent::tr("Service Discovery Protocol");
+ case QBluetoothUuid::Udp: return QBluetoothServiceDiscoveryAgent::tr("User Datagram Protocol");
+ case QBluetoothUuid::Rfcomm: return QBluetoothServiceDiscoveryAgent::tr("Radio Frequency Communication");
+ case QBluetoothUuid::Tcp: return QBluetoothServiceDiscoveryAgent::tr("Transmission Control Protocol");
+ case QBluetoothUuid::TcsBin: return QBluetoothServiceDiscoveryAgent::tr("Telephony Control Specification - Binary");
+ case QBluetoothUuid::TcsAt: return QBluetoothServiceDiscoveryAgent::tr("Telephony Control Specification - AT");
+ case QBluetoothUuid::Att: return QBluetoothServiceDiscoveryAgent::tr("Attribute Protocol");
+ case QBluetoothUuid::Obex: return QBluetoothServiceDiscoveryAgent::tr("Object Exchange Protocol");
+ case QBluetoothUuid::Ip: return QBluetoothServiceDiscoveryAgent::tr("Internet Protocol");
+ case QBluetoothUuid::Ftp: return QBluetoothServiceDiscoveryAgent::tr("File Transfer Protocol");
+ case QBluetoothUuid::Http: return QBluetoothServiceDiscoveryAgent::tr("Hypertext Transfer Protocol");
+ case QBluetoothUuid::Wsp: return QBluetoothServiceDiscoveryAgent::tr("Wireless Short Packet Protocol");
+ case QBluetoothUuid::Bnep: return QBluetoothServiceDiscoveryAgent::tr("Bluetooth Network Encapsulation Protocol");
+ case QBluetoothUuid::Upnp: return QBluetoothServiceDiscoveryAgent::tr("Extended Service Discovery Protocol");
+ case QBluetoothUuid::Hidp: return QBluetoothServiceDiscoveryAgent::tr("Human Interface Device Protocol");
+ case QBluetoothUuid::HardcopyControlChannel: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Control Channel");
+ case QBluetoothUuid::HardcopyDataChannel: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Data Channel");
+ case QBluetoothUuid::HardcopyNotification: return QBluetoothServiceDiscoveryAgent::tr("Hardcopy Notification");
+ case QBluetoothUuid::Avctp: return QBluetoothServiceDiscoveryAgent::tr("Audio/Video Control Transport Protocol");
+ case QBluetoothUuid::Avdtp: return QBluetoothServiceDiscoveryAgent::tr("Audio/Video Distribution Transport Protocol");
+ case QBluetoothUuid::Cmtp: return QBluetoothServiceDiscoveryAgent::tr("Common ISDN Access Protocol");
+ case QBluetoothUuid::UdiCPlain: return QBluetoothServiceDiscoveryAgent::tr("UdiCPlain");
+ case QBluetoothUuid::McapControlChannel: return QBluetoothServiceDiscoveryAgent::tr("Multi-Channel Adaptation Protocol -Conrol");
+ case QBluetoothUuid::McapDataChannel: return QBluetoothServiceDiscoveryAgent::tr("Multi-Channel Adaptation Protocol - Data");
+ case QBluetoothUuid::L2cap: return QBluetoothServiceDiscoveryAgent::tr("Layer 2 Control Protocol");
+ default:
+ break;
+ }
+
+ return QString();
+}
+
+/*!
Returns true if \a other is equal to this Bluetooth UUID, otherwise false.
*/
bool QBluetoothUuid::operator==(const QBluetoothUuid &other) const
diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h
index c67d2e31..ee3477ac 100644
--- a/src/bluetooth/qbluetoothuuid.h
+++ b/src/bluetooth/qbluetoothuuid.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
@@ -291,13 +291,19 @@ public:
quint16 toUInt16(bool *ok = 0) const;
quint32 toUInt32(bool *ok = 0) const;
quint128 toUInt128() const;
+
+ static QString serviceClassToString(ServiceClassUuid uuid);
+ static QString protocolToString(ProtocolUuid uuid);
};
+#ifndef QT_NO_DEBUG_STREAM
+/// TODO: Move implementation to .cpp, uninline and add Q_BLUETOOTH_EXPORT for Qt 6
inline QDebug operator<<(QDebug debug, const QBluetoothUuid &uuid)
{
debug << uuid.toString();
return debug;
}
+#endif
QT_END_NAMESPACE
diff --git a/src/bluetooth/qnx/ppshelpers_p.h b/src/bluetooth/qnx/ppshelpers_p.h
index 0eaea981..b552f91a 100644
--- a/src/bluetooth/qnx/ppshelpers_p.h
+++ b/src/bluetooth/qnx/ppshelpers_p.h
@@ -74,7 +74,7 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_QNX)
class BBSocketNotifier : public QObject
{
Q_OBJECT
-public Q_SLOTS:
+public slots:
void distribute();
void closeControlFD();
};
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
index bec7b717..d4974967 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
@@ -270,9 +270,11 @@ QVariant QDeclarativeBluetoothDiscoveryModel::data(const QModelIndex &index, int
/*!
\qmlsignal BluetoothDiscoveryModel::serviceDiscovered(BluetoothService service)
- This handler is called when a new service is discovered. The \a service
+ This signal is emitted when a new service is discovered. The \a service
parameter contains the service details.
+ The corresponding handler is \c onServiceDiscovered.
+
\sa BluetoothService
*/
@@ -301,8 +303,10 @@ void QDeclarativeBluetoothDiscoveryModel::serviceDiscovered(const QBluetoothServ
/*!
\qmlsignal BluetoothDiscoveryModel::deviceDiscovered(string device)
- This handler is called when a new device is discovered. \a device contains
+ This signal is emitted when a new device is discovered. \a device contains
the Bluetooth address of the discovred device.
+
+ The corresponding handler is \c onDeviceDiscovered.
*/
void QDeclarativeBluetoothDiscoveryModel::deviceDiscovered(const QBluetoothDeviceInfo &device)
@@ -399,6 +403,7 @@ void QDeclarativeBluetoothDiscoveryModel::setRunning(bool running)
}
d->m_serviceAgent->setRemoteAddress(QBluetoothAddress(d->m_remoteAddress));
+ d->m_serviceAgent->clear();
if (!d->m_uuid.isEmpty())
d->m_serviceAgent->setUuidFilter(QBluetoothUuid(d->m_uuid));
@@ -413,7 +418,7 @@ void QDeclarativeBluetoothDiscoveryModel::setRunning(bool running)
}
}
- Q_EMIT runningChanged();
+ emit runningChanged();
}
/*!
@@ -467,5 +472,5 @@ QString QDeclarativeBluetoothDiscoveryModel::remoteAddress()
void QDeclarativeBluetoothDiscoveryModel::setRemoteAddress(QString address)
{
d->m_remoteAddress = address;
- Q_EMIT remoteAddressChanged();
+ emit remoteAddressChanged();
}
diff --git a/src/imports/bluetooth/qdeclarativebluetoothservice.cpp b/src/imports/bluetooth/qdeclarativebluetoothservice.cpp
index 6d4e3dc0..e246ca8d 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothservice.cpp
+++ b/src/imports/bluetooth/qdeclarativebluetoothservice.cpp
@@ -69,7 +69,7 @@
/*!
\qmlsignal BluetoothService::detailsChanged()
- This handler is called when any of the following properties changes:
+ This signal is emitted when any of the following properties changes:
\list
\li deviceAddress
@@ -80,6 +80,8 @@
\li serviceProtocol
\li serviceUuid
\endlist
+
+ The corresponding handler is \c onDetailsChanged.
*/
Q_DECLARE_LOGGING_CATEGORY(QT_BT_QML)
@@ -100,8 +102,6 @@ public:
delete m_service;
}
- int listen();
-
bool m_componentComplete;
QBluetoothServiceInfo *m_service;
QDeclarativeBluetoothService::Protocol m_protocol;
@@ -269,28 +269,6 @@ bool QDeclarativeBluetoothService::isRegistered() const
return d->m_service->isRegistered();
}
-
-int QDeclarativeBluetoothServicePrivate::listen() {
-
- if (m_service->socketProtocol() == QBluetoothServiceInfo::UnknownProtocol) {
- qCWarning(QT_BT_QML) << "Unknown protocol, can't make service" << m_protocol;
- return -1;
- }
- QBluetoothServiceInfo::Protocol serverType = QBluetoothServiceInfo::UnknownProtocol;
- if (m_service->socketProtocol() == QBluetoothServiceInfo::L2capProtocol)
- serverType = QBluetoothServiceInfo::L2capProtocol;
- else if (m_service->socketProtocol() == QBluetoothServiceInfo::RfcommProtocol)
- serverType = QBluetoothServiceInfo::RfcommProtocol;
-
- QBluetoothServer *server = new QBluetoothServer(serverType);
- server->setMaxPendingConnections(1);
- server->listen(QBluetoothAddress());
- server->serverPort();
- m_server = server;
-
- return server->serverPort();
-}
-
void QDeclarativeBluetoothService::setRegistered(bool registered)
{
if (!d->m_componentComplete) {
@@ -306,9 +284,21 @@ void QDeclarativeBluetoothService::setRegistered(bool registered)
return;
}
- d->listen();
- connect(d->m_server, SIGNAL(newConnection()), this, SLOT(new_connection()));
+ if (d->m_protocol == UnknownProtocol) {
+ qCWarning(QT_BT_QML) << "Unknown protocol, can't make service" << d->m_protocol;
+ return;
+ }
+
+ QBluetoothServer *server
+ = new QBluetoothServer(static_cast<QBluetoothServiceInfo::Protocol>(d->m_protocol));
+ server->setMaxPendingConnections(1);
+ if (!server->listen()) {
+ qCWarning(QT_BT_QML) << "Could not start server. Error:" << server->error();
+ return;
+ }
+ d->m_server = server;
+ connect(d->m_server, SIGNAL(newConnection()), this, SLOT(new_connection()));
d->m_service->setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010);
@@ -319,7 +309,7 @@ void QDeclarativeBluetoothService::setRegistered(bool registered)
//qDebug() << "name/uuid" << d->m_name << d->m_uuid << d->m_port;
d->m_service->setAttribute(QBluetoothServiceInfo::BrowseGroupList,
- QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
+ QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
QBluetoothServiceInfo::Sequence protocolDescriptorList;
QBluetoothServiceInfo::Sequence protocol;
@@ -327,26 +317,19 @@ void QDeclarativeBluetoothService::setRegistered(bool registered)
if (d->m_protocol == L2CapProtocol) {
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap))
<< QVariant::fromValue(quint16(d->m_server->serverPort()));
- protocolDescriptorList.append(QVariant::fromValue(protocol));
- }
- else if (d->m_protocol == RfcommProtocol) {
+ } else if (d->m_protocol == RfcommProtocol) {
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
<< QVariant::fromValue(quint8(d->m_server->serverPort()));
- protocolDescriptorList.append(QVariant::fromValue(protocol));
- }
- else {
- qCWarning(QT_BT_QML) << "No protocol specified for bluetooth service";
}
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+
d->m_service->setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
- protocolDescriptorList);
+ protocolDescriptorList);
- if (d->m_service->registerService()) {
+ if (d->m_service->registerService())
emit registeredChanged();
- }
- else {
- qCWarning(QT_BT_QML) << "Register service failed";
- //TODO propaget this error to the user
- }
+ else
+ qCWarning(QT_BT_QML) << "Register service failed"; // TODO: propagate this error to the user
}
QBluetoothServiceInfo *QDeclarativeBluetoothService::serviceInfo() const
diff --git a/src/imports/bluetooth/qdeclarativebluetoothservice_p.h b/src/imports/bluetooth/qdeclarativebluetoothservice_p.h
index e7e861c7..644e8905 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothservice_p.h
+++ b/src/imports/bluetooth/qdeclarativebluetoothservice_p.h
@@ -68,6 +68,7 @@ class QDeclarativeBluetoothService : public QObject, public QQmlParserStatus
Q_ENUMS(Protocol)
public:
+ /// TODO: Merge/Replace with QBluetoothServiceInfo::Protocol in Qt 6
enum Protocol {
RfcommProtocol = QBluetoothServiceInfo::RfcommProtocol,
L2CapProtocol = QBluetoothServiceInfo::L2capProtocol,
diff --git a/src/imports/bluetooth/qmldir b/src/imports/bluetooth/qmldir
index 159d2422..2f5b2fac 100644
--- a/src/imports/bluetooth/qmldir
+++ b/src/imports/bluetooth/qmldir
@@ -1,3 +1,4 @@
module QtBluetooth
plugin declarative_bluetooth
+classname QBluetoothQmlPlugin
typeinfo plugins.qmltypes
diff --git a/src/imports/nfc/qdeclarativendeffilter.cpp b/src/imports/nfc/qdeclarativendeffilter.cpp
index 5d1dd43f..74191f3e 100644
--- a/src/imports/nfc/qdeclarativendeffilter.cpp
+++ b/src/imports/nfc/qdeclarativendeffilter.cpp
@@ -129,7 +129,7 @@ void QDeclarativeNdefFilter::setTypeNameFormat(QQmlNdefRecord::TypeNameFormat fo
return;
m_typeNameFormat = format;
- Q_EMIT(typeNameFormatChanged());
+ emit typeNameFormatChanged();
}
int QDeclarativeNdefFilter::minimum() const
diff --git a/src/imports/nfc/qmldir b/src/imports/nfc/qmldir
index 3afa926d..0025f3e6 100644
--- a/src/imports/nfc/qmldir
+++ b/src/imports/nfc/qmldir
@@ -1,3 +1,4 @@
module QtNfc
plugin declarative_nfc
+classname QNfcQmlPlugin
typeinfo plugins.qmltypes
diff --git a/src/nfc/doc/src/nfc-index.qdoc b/src/nfc/doc/src/nfc-index.qdoc
index 2944a6ab..bd375ea8 100644
--- a/src/nfc/doc/src/nfc-index.qdoc
+++ b/src/nfc/doc/src/nfc-index.qdoc
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -29,6 +30,13 @@
\page qtnfc-index.html
\title Qt NFC
\brief Enables connectivity between NFC enabled devices.
+\ingroup technology-apis
+
+The NFC API provides connectivity between NFC enabled devices.
+
+Currently the API is supported on \l{Qt for BlackBerry}{BlackBerry 10}.
+
+\section1 Overview
NFC is an extremely short-range (less than 20 centimeters) wireless technology and has a
maximum transfer rate of 424 kbit/s. NFC is ideal for transferring small packets of data when two
@@ -38,7 +46,6 @@ The NFC API provides APIs for interacting with NFC Forum Tags and NFC Forum Devi
target detection and loss, registering NDEF message handlers, reading and writing NDEF messages
on NFC Forum Tags and sending tag specific commands.
-Currently the API is supported on BlackBerry 10.
\section1 Getting started
diff --git a/src/nfc/qllcpserver_p.h b/src/nfc/qllcpserver_p.h
index 5d72f558..e409a1cd 100644
--- a/src/nfc/qllcpserver_p.h
+++ b/src/nfc/qllcpserver_p.h
@@ -84,7 +84,7 @@ public:
QLlcpSocket::SocketError serverError() const;
-Q_SIGNALS:
+signals:
void newConnection();
private:
diff --git a/src/nfc/qllcpsocket_p.h b/src/nfc/qllcpsocket_p.h
index 6bda57be..cc0d26cb 100644
--- a/src/nfc/qllcpsocket_p.h
+++ b/src/nfc/qllcpsocket_p.h
@@ -121,7 +121,7 @@ public:
virtual bool waitForDisconnected(int msecs = 30000);
bool isSequential() const;
-Q_SIGNALS:
+signals:
void connected();
void disconnected();
void error(QLlcpSocket::SocketError socketError);
diff --git a/src/nfc/qllcpsocket_qnx_p.h b/src/nfc/qllcpsocket_qnx_p.h
index 32968695..f6e50215 100644
--- a/src/nfc/qllcpsocket_qnx_p.h
+++ b/src/nfc/qllcpsocket_qnx_p.h
@@ -94,7 +94,7 @@ public:
void dataRead(QByteArray&);
void dataWritten();
-public Q_SLOTS:
+public slots:
void disconnectFromService();
private:
@@ -115,7 +115,7 @@ private:
Idle, Reading, Writing
} socketState;
-private Q_SLOTS:
+private slots:
void read();
void enteringIdle();
};
diff --git a/src/nfc/qnearfieldmanager_qnx.cpp b/src/nfc/qnearfieldmanager_qnx.cpp
index 14dfc755..df8619a7 100644
--- a/src/nfc/qnearfieldmanager_qnx.cpp
+++ b/src/nfc/qnearfieldmanager_qnx.cpp
@@ -193,7 +193,7 @@ void QNearFieldManagerPrivateImpl::updateNdefFilter()
} else if (ndefFilterHandlers.size() > 0){
for (int i = 0; i < ndefFilterHandlers.count(); i++) {
QByteArray filter = "ndef://" + QByteArray::number(ndefFilterHandlers.at(i).second.first.recordAt(0).typeNameFormat)
- + "/" + ndefFilterHandlers.at(i).second.first.recordAt(0).type;
+ + '/' + ndefFilterHandlers.at(i).second.first.recordAt(0).type;
if (!filterList.contains(filter))
filterList.append(filter);
}
diff --git a/src/nfc/qnearfieldmanager_qnx_p.h b/src/nfc/qnearfieldmanager_qnx_p.h
index 323f85b8..a344c37a 100644
--- a/src/nfc/qnearfieldmanager_qnx_p.h
+++ b/src/nfc/qnearfieldmanager_qnx_p.h
@@ -74,7 +74,7 @@ public:
void releaseAccess(QNearFieldManager::TargetAccessModes accessModes);
-private Q_SLOTS:
+private slots:
void handleMessage(const QNdefMessage&, QNearFieldTarget *);
void newTarget(QNearFieldTarget *target, const QList<QNdefMessage> &);
diff --git a/src/nfc/qnearfieldsharemanager_qnx_p.h b/src/nfc/qnearfieldsharemanager_qnx_p.h
index 5d973bcf..9cb4b48e 100644
--- a/src/nfc/qnearfieldsharemanager_qnx_p.h
+++ b/src/nfc/qnearfieldsharemanager_qnx_p.h
@@ -62,7 +62,7 @@ public:
QNearFieldShareManager::ShareModes shareModes() const;
QNearFieldShareManager::ShareError shareError() const;
-private Q_SLOTS:
+private slots:
void onShareModeChanged(bb::system::NfcShareMode::Type mode);
void onError(bb::system::NfcShareError::Type error);
void onFinished(bb::system::NfcShareSuccess::Type result);
diff --git a/src/nfc/qnearfieldsharetarget_qnx_p.h b/src/nfc/qnearfieldsharetarget_qnx_p.h
index 16bf429f..e0925110 100644
--- a/src/nfc/qnearfieldsharetarget_qnx_p.h
+++ b/src/nfc/qnearfieldsharetarget_qnx_p.h
@@ -65,7 +65,7 @@ public:
bool isShareInProgress() const;
QNearFieldShareManager::ShareError shareError() const;
-private Q_SLOTS:
+private slots:
void onShareModeChanged(bb::system::NfcShareMode::Type mode);
void onError(bb::system::NfcShareError::Type error);
void onFinished(bb::system::NfcShareSuccess::Type result);
diff --git a/src/nfc/qnearfieldtarget_emulator.cpp b/src/nfc/qnearfieldtarget_emulator.cpp
index 80953ce6..f261846f 100644
--- a/src/nfc/qnearfieldtarget_emulator.cpp
+++ b/src/nfc/qnearfieldtarget_emulator.cpp
@@ -212,15 +212,15 @@ void TagActivator::initialize()
if (!tagMap.isEmpty())
return;
- QDirIterator nfcTargets(QDir::currentPath(), QStringList(QLatin1String("*.nfc")), QDir::Files);
+ QDirIterator nfcTargets(QDir::currentPath(), QStringList(QStringLiteral("*.nfc")), QDir::Files);
while (nfcTargets.hasNext()) {
const QString targetFilename = nfcTargets.next();
QSettings target(targetFilename, QSettings::IniFormat);
- target.beginGroup(QLatin1String("Target"));
+ target.beginGroup(QStringLiteral("Target"));
- const QString tagType = target.value(QLatin1String("Type")).toString();
+ const QString tagType = target.value(QStringLiteral("Type")).toString();
target.endGroup();
diff --git a/src/nfc/qnearfieldtarget_qnx_p.h b/src/nfc/qnearfieldtarget_qnx_p.h
index faff94e2..f3029fb1 100644
--- a/src/nfc/qnearfieldtarget_qnx_p.h
+++ b/src/nfc/qnearfieldtarget_qnx_p.h
@@ -124,7 +124,7 @@ public:
QNearFieldTarget::RequestId readNdefMessages()
{
for (int i = 0; i < m_ndefMessages.size(); i++) {
- Q_EMIT QNearFieldTarget::ndefMessageRead(m_ndefMessages.at(i));
+ emit QNearFieldTarget::ndefMessageRead(m_ndefMessages.at(i));
}
QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
QMetaObject::invokeMethod(this, "requestCompleted", Qt::QueuedConnection,
@@ -149,7 +149,7 @@ public:
tagType = TAG_TYPE_ISO_15693_3;
//We don't support this tag
if (!isSupported) {
- Q_EMIT QNearFieldTarget::error(QNearFieldTarget::UnsupportedError, QNearFieldTarget::RequestId());
+ emit QNearFieldTarget::error(QNearFieldTarget::UnsupportedError, QNearFieldTarget::RequestId());
return QNearFieldTarget::RequestId();
}
}
@@ -157,11 +157,11 @@ public:
m_cmdRespons = reinterpret_cast<char *> malloc (max_nfc_command_length);
nfc_result_t result = nfc_tag_transceive (m_target, tagType, command.data(), command.length(), m_cmdRespons, max_nfc_command_length, &m_cmdResponseLength);
if (result != NFC_RESULT_SUCCESS) {
- Q_EMIT QNearFieldTarget::error(QNearFieldTarget::UnknownError, QNearFieldTarget::RequestId());
+ emit QNearFieldTarget::error(QNearFieldTarget::UnknownError, QNearFieldTarget::RequestId());
qWarning() << Q_FUNC_INFO << "nfc_tag_transceive failed"
}
#else
- Q_EMIT QNearFieldTarget::error(QNearFieldTarget::UnsupportedError, QNearFieldTarget::RequestId());
+ emit QNearFieldTarget::error(QNearFieldTarget::UnsupportedError, QNearFieldTarget::RequestId());
return QNearFieldTarget::RequestId();
#endif
}
@@ -185,7 +185,7 @@ public:
if (result != NFC_RESULT_SUCCESS) {
qWarning() << Q_FUNC_INFO << "Could not convert QNdefMessage to byte array" << result;
nfc_delete_ndef_message(newMessage, true);
- Q_EMIT QNearFieldTarget::error(QNearFieldTarget::UnknownError,
+ emit QNearFieldTarget::error(QNearFieldTarget::UnknownError,
QNearFieldTarget::RequestId());
return QNearFieldTarget::RequestId();
}
@@ -195,7 +195,7 @@ public:
if (result != NFC_RESULT_SUCCESS) {
qWarning() << Q_FUNC_INFO << "Could not write message";
- Q_EMIT QNearFieldTarget::error(QNearFieldTarget::NdefWriteError,
+ emit QNearFieldTarget::error(QNearFieldTarget::NdefWriteError,
QNearFieldTarget::RequestId());
return QNearFieldTarget::RequestId();
diff --git a/src/nfc/qnx/qnxnfceventfilter.cpp b/src/nfc/qnx/qnxnfceventfilter.cpp
index eed1a280..907fdccf 100644
--- a/src/nfc/qnx/qnxnfceventfilter.cpp
+++ b/src/nfc/qnx/qnxnfceventfilter.cpp
@@ -94,7 +94,7 @@ bool QNXNFCEventFilter::nativeEventFilter(const QByteArray &eventType, void *mes
qQNXNFCDebug() << "Got Invoke event" << uri << "Type" << type;
- Q_EMIT ndefEvent(message);
+ emit ndefEvent(message);
}
return false;
diff --git a/src/nfc/qnx/qnxnfceventfilter_p.h b/src/nfc/qnx/qnxnfceventfilter_p.h
index 9b10ed57..afcd0777 100644
--- a/src/nfc/qnx/qnxnfceventfilter_p.h
+++ b/src/nfc/qnx/qnxnfceventfilter_p.h
@@ -66,7 +66,7 @@ private:
QAbstractNativeEventFilter *prevFilter;
-Q_SIGNALS:
+signals:
void ndefEvent(const QNdefMessage &msg);
};
diff --git a/src/nfc/qnx/qnxnfcmanager.cpp b/src/nfc/qnx/qnxnfcmanager.cpp
index 92152c26..2ba1029b 100644
--- a/src/nfc/qnx/qnxnfcmanager.cpp
+++ b/src/nfc/qnx/qnxnfcmanager.cpp
@@ -221,7 +221,7 @@ void QNXNFCManager::newNfcEvent(int fd)
void QNXNFCManager::invokeNdefMessage(const QNdefMessage &msg)
{
- Q_EMIT ndefMessage(msg, 0);
+ emit ndefMessage(msg, 0);
}
void QNXNFCManager::llcpReadComplete(nfc_event_t *nfcEvent)
@@ -350,9 +350,9 @@ void QNXNFCManager::setupInvokeTarget() {
}
uriFilter.append(absNdefFilters.at(i));
if (i==absNdefFilters.size()-1)
- uriFilter += ";";
+ uriFilter += ';';
else
- uriFilter += ",";
+ uriFilter += ',';
}
if (registerAll) {
uriFilter = "uris=ndef://;";
diff --git a/src/nfc/qnx/qnxnfcmanager_p.h b/src/nfc/qnx/qnxnfcmanager_p.h
index 70729c41..1fc6205d 100644
--- a/src/nfc/qnx/qnxnfcmanager_p.h
+++ b/src/nfc/qnx/qnxnfcmanager_p.h
@@ -114,7 +114,7 @@ private:
void setupInvokeTarget();
-private Q_SLOTS:
+private slots:
void newNfcEvent(int fd);
void invokeNdefMessage(const QNdefMessage &);
@@ -126,7 +126,7 @@ public:
QNdefMessage decodeMessage(nfc_ndef_message_t *nextMessage);
-Q_SIGNALS:
+signals:
void newLlcpConnection(nfc_target_t *);
void ndefMessage(const QNdefMessage &, QNearFieldTarget *);
void targetDetected(QNearFieldTarget *, const QList<QNdefMessage> &);
diff --git a/src/nfc/qnx/qnxnfcsharemanager_p.h b/src/nfc/qnx/qnxnfcsharemanager_p.h
index ae6511eb..4b143653 100644
--- a/src/nfc/qnx/qnxnfcsharemanager_p.h
+++ b/src/nfc/qnx/qnxnfcsharemanager_p.h
@@ -77,7 +77,7 @@ private:
bb::system::NfcShareManager *_manager;
static const char *RECORD_NDEF;
-Q_SIGNALS:
+signals:
void shareModeChanged(bb::system::NfcShareMode::Type);
void error(bb::system::NfcShareError::Type);
void finished(bb::system::NfcShareSuccess::Type);
diff --git a/src/nfc/qqmlndefrecord.cpp b/src/nfc/qqmlndefrecord.cpp
index c94578eb..3a8934c1 100644
--- a/src/nfc/qqmlndefrecord.cpp
+++ b/src/nfc/qqmlndefrecord.cpp
@@ -186,11 +186,11 @@ static QString urnForRecordType(QNdefRecord::TypeNameFormat typeNameFormat, cons
{
switch (typeNameFormat) {
case QNdefRecord::NfcRtd:
- return QLatin1String("urn:nfc:wkt:") + QString::fromLatin1(type);
+ return QStringLiteral("urn:nfc:wkt:") + QString::fromLatin1(type);
case QNdefRecord::ExternalRtd:
- return QLatin1String("urn:nfc:ext:") + QString::fromLatin1(type);
+ return QStringLiteral("urn:nfc:ext:") + QString::fromLatin1(type);
case QNdefRecord::Mime:
- return QLatin1String("urn:nfc:mime:") + QString::fromLatin1(type);
+ return QStringLiteral("urn:nfc:mime:") + QString::fromLatin1(type);
default:
return QString();
}
diff --git a/src/nfc/targetemulator.cpp b/src/nfc/targetemulator.cpp
index e1d21e87..f6ccfccf 100644
--- a/src/nfc/targetemulator.cpp
+++ b/src/nfc/targetemulator.cpp
@@ -79,18 +79,18 @@ NfcTagType1::~NfcTagType1()
void NfcTagType1::load(QSettings *settings)
{
- settings->beginGroup(QLatin1String("TagType1"));
+ settings->beginGroup(QStringLiteral("TagType1"));
- hr0 = settings->value(QLatin1String("HR0"), 0x11).toUInt();
+ hr0 = settings->value(QStringLiteral("HR0"), 0x11).toUInt();
if (!(hr0 & 0x10)) {
settings->endGroup();
return;
}
- hr1 = settings->value(QLatin1String("HR1"), 0x00).toUInt();
+ hr1 = settings->value(QStringLiteral("HR1"), 0x00).toUInt();
- memory = settings->value(QLatin1String("Data")).toByteArray();
+ memory = settings->value(QStringLiteral("Data")).toByteArray();
//quint8 nmn = memory.at(8);
@@ -302,9 +302,9 @@ NfcTagType2::~NfcTagType2()
void NfcTagType2::load(QSettings *settings)
{
- settings->beginGroup(QLatin1String("TagType2"));
+ settings->beginGroup(QStringLiteral("TagType2"));
- memory = settings->value(QLatin1String("Data")).toByteArray();
+ memory = settings->value(QStringLiteral("Data")).toByteArray();
settings->endGroup();
}
diff --git a/src/src.pro b/src/src.pro
index e2ed3c88..e017d34b 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -3,13 +3,15 @@ TEMPLATE = subdirs
SUBDIRS += bluetooth nfc
android: SUBDIRS += android
-bluetooth_doc_snippets.subdir = bluetooth/doc/snippets
-bluetooth_doc_snippets.depends = bluetooth
-SUBDIRS += bluetooth_doc_snippets
+contains(QT_CONFIG, private_tests) {
+ bluetooth_doc_snippets.subdir = bluetooth/doc/snippets
+ bluetooth_doc_snippets.depends = bluetooth
-nfc_doc_snippets.subdir = nfc/doc/snippets
-nfc_doc_snippets.depends = nfc
-SUBDIRS += nfc_doc_snippets
+ nfc_doc_snippets.subdir = nfc/doc/snippets
+ nfc_doc_snippets.depends = nfc
+
+ SUBDIRS += bluetooth_doc_snippets nfc_doc_snippets
+}
qtHaveModule(quick) {
imports.depends += bluetooth nfc