diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-08-13 17:07:07 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-08-13 17:07:15 +0200 |
commit | 81b3178cede7fad5360755a1186071548d139198 (patch) | |
tree | fd5ba8e786edaa969299be35996edc15d15cc3da /src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp | |
parent | d5422ad7c9806e6a105ae9918fae650e38aad601 (diff) | |
parent | 687c885b8625374433f4ccc8b6442ea72ea62d46 (diff) | |
download | qtconnectivity-81b3178cede7fad5360755a1186071548d139198.tar.gz |
Merge remote-tracking branch 'gerrit/5.4' into btle
Change-Id: I1e79c96602d0da2c2d36d6217bdfe7ff183e6df9
Diffstat (limited to 'src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp | 99 |
1 files changed, 36 insertions, 63 deletions
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index 1d7a6327..2f2f26d8 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -50,11 +50,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> @@ -205,76 +204,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), @@ -284,23 +260,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), |