summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-07-17 16:33:21 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-08-12 11:24:54 +0200
commit687c885b8625374433f4ccc8b6442ea72ea62d46 (patch)
tree64cea73ad7162b24b7ac3463056bf267dfd9e7a8 /src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
parent3ee0be10135f46fd482987a5229a0f199b7bf7c1 (diff)
Remove Bluez as link and include dependency from QtBluetooth
Change-Id: Ieecf341918ffdc51c359fed4969ef6c3998d83b8 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp')
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp99
1 files changed, 36 insertions, 63 deletions
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index 4752a0ab..3610d7bc 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -49,11 +49,10 @@
#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/QFile>
+#include <QtCore/QLibraryInfo>
#include <QtCore/QLoggingCategory>
+#include <QtCore/QProcess>
#include <QtDBus/QDBusPendingCallWatcher>
#include <QtConcurrent/QtConcurrentRun>
@@ -195,76 +194,53 @@ void QBluetoothServiceDiscoveryAgentPrivate::startBluez5(const QBluetoothAddress
/*
* 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.
+ *
+ * src/tools/sdpscanner performs an SDP scan. This is
+ * done out-of-process to avoid license issues. At this stage Bluez uses GPLv2.
*/
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);
+ const QString binPath = QLibraryInfo::location(QLibraryInfo::BinariesPath);
- 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,
+ QFileInfo fileInfo(binPath, QStringLiteral("sdpscanner"));
+ if (!fileInfo.exists() || !fileInfo.isExecutable()) {
+ QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
QBluetoothServiceDiscoveryAgent::InputOutputError),
Q_ARG(QString,
- QBluetoothServiceDiscoveryAgent::tr("Unable to access device")),
+ QBluetoothServiceDiscoveryAgent::tr("Unable to find sdpscanner")),
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()));
- }
-
+ qCWarning(QT_BT_BLUEZ) << "Cannot find sdpscanner:"
+ << fileInfo.canonicalFilePath();
return;
}
+ QStringList arguments;
+ arguments << remoteAddress.toString() << localAddress.toString();
- // 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);
+ QProcess process;
+ process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
+ process.setReadChannel(QProcess::StandardOutput);
+ process.start(fileInfo.canonicalFilePath(), arguments);
+ process.waitForFinished();
- 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 (process.exitStatus() != QProcess::NormalExit
+ || process.exitCode() != 0) {
+ qCWarning(QT_BT_BLUEZ) << "SDP scan failure"
+ << process.exitStatus() << process.exitCode()
+ << remoteAddress;
if (singleDevice) {
QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
QBluetoothServiceDiscoveryAgent::InputOutputError),
Q_ARG(QString,
- QBluetoothServiceDiscoveryAgent::tr("Unable to access device")),
+ QBluetoothServiceDiscoveryAgent::tr("Unable to perform SDP scan")),
Q_ARG(QStringList, QStringList()));
} else {
+ // go to next device
QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
QBluetoothServiceDiscoveryAgent::NoError),
@@ -274,23 +250,20 @@ void QBluetoothServiceDiscoveryAgentPrivate::runSdpScan(
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;
+ int size, index = 0;
+ const QByteArray output = QByteArray::fromBase64(process.readAll());
+ const char *data = output.constData();
- QByteArray xml = parseSdpRecord(record);
- if (xml.isEmpty())
- continue;
-
- //qDebug() << xml;
- xmlRecords.append(QString::fromUtf8(xml));
+ // separate the individial SDP records
+ // each record starts with 4 byte size indicator
+ while (index < output.size()) {
+ memcpy(&size, &data[index], sizeof(int));
+ xmlRecords.append(QString::fromUtf8(output.mid(index+sizeof(int), size)));
+ index += sizeof(int) + size;
}
- sdp_close(session);
-
QMetaObject::invokeMethod(q, "_q_finishSdpScan", Qt::QueuedConnection,
Q_ARG(QBluetoothServiceDiscoveryAgent::Error,
QBluetoothServiceDiscoveryAgent::NoError),