summaryrefslogtreecommitdiffstats
path: root/src/bluetooth
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2012-11-19 18:18:24 +0100
committerPeter Hartmann <phartmann@rim.com>2012-11-22 09:54:04 +0100
commit72ace1ae61b16ae8c50521dab14b176a96e29e0c (patch)
treeecac5d3784885d35407012d43f3e93ac9a0952c7 /src/bluetooth
parent23d47eb487107bd0a66949a3962c6c3d5403c0ef (diff)
QNX adding device discovery agent
Change-Id: Id21ee613489c7b7079a32812340046443d4868a9 Reviewed-by: Alex <ablasche@gmail.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r--src/bluetooth/bluetooth.pro2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.h22
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp207
-rw-r--r--src/bluetooth/qnx/ppshelpers.cpp2
-rw-r--r--src/bluetooth/qnx/ppshelpers_p.h2
5 files changed, 232 insertions, 3 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 4f2af002..6e52a032 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -85,7 +85,7 @@ config_bluez:contains(QT_CONFIG, dbus) {
include(qnx/qnx.pri)
SOURCES += \
- qbluetoothdevicediscoveryagent_p.cpp \
+ qbluetoothdevicediscoveryagent_qnx.cpp \
qbluetoothlocaldevice_qnx.cpp \
qbluetoothserviceinfo_p.cpp \
qbluetoothservicediscoveryagent_p.cpp \
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
index 113a1d32..0f4f1d0a 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
@@ -53,6 +53,9 @@ class OrgBluezAdapterInterface;
QT_BEGIN_NAMESPACE
class QDBusVariant;
QT_END_NAMESPACE
+#elif defined(QTM_QNX_BLUETOOTH)
+#include "qnx/ppshelpers_p.h"
+#include <QTimer>
#endif
QT_BEGIN_HEADER
@@ -60,7 +63,12 @@ QT_BEGIN_HEADER
QTBLUETOOTH_BEGIN_NAMESPACE
class QBluetoothDeviceDiscoveryAgentPrivate
+#if defined(QTM_QNX_BLUETOOTH)
+: public QObject {
+ Q_OBJECT
+#else
{
+#endif
Q_DECLARE_PUBLIC(QBluetoothDeviceDiscoveryAgent)
public:
QBluetoothDeviceDiscoveryAgentPrivate();
@@ -88,6 +96,20 @@ private:
#ifdef QT_BLUEZ_BLUETOOTH
OrgBluezManagerInterface *manager;
OrgBluezAdapterInterface *adapter;
+#elif defined(QTM_QNX_BLUETOOTH)
+ private Q_SLOTS:
+ void finished();
+ void remoteDevicesChanged(int);
+ void controlReply(ppsResult result);
+ void controlEvent(ppsResult result);
+
+private:
+ QSocketNotifier *rdNotifier;
+ QTimer finishedTimer;
+
+ bool started;
+
+ int m_rdfd;
#endif
QBluetoothDeviceDiscoveryAgent *q_ptr;
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
new file mode 100644
index 00000000..2e0a4aba
--- /dev/null
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
@@ -0,0 +1,207 @@
+/***************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** 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 "qbluetoothdevicediscoveryagent.h"
+#include "qbluetoothdevicediscoveryagent_p.h"
+#include "qbluetoothaddress.h"
+#include "qbluetoothuuid.h"
+
+#include <QtCore/private/qcore_unix_p.h>
+
+
+QTBLUETOOTH_BEGIN_NAMESPACE
+
+QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate():
+ QObject(0), lastError(QBluetoothDeviceDiscoveryAgent::NoError), pendingCancel(false), pendingStart(false), m_rdfd(-1)
+{
+}
+
+QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate()
+{
+ if (pendingStart)
+ stop();
+}
+
+bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const
+{
+ return pendingStart;
+}
+
+void QBluetoothDeviceDiscoveryAgentPrivate::start()
+{
+ Q_Q(QBluetoothDeviceDiscoveryAgent);
+ if (pendingStart)
+ return;
+
+ if (m_rdfd != -1 || (m_rdfd = qt_safe_open("/pps/services/bluetooth/remote_devices/.all", O_RDONLY)) == -1) {
+ qWarning() << Q_FUNC_INFO << "rdfd - failed to open /pps/services/bluetooth/remote_devices/.all";
+ lastError = QBluetoothDeviceDiscoveryAgent::IOFailure;
+ emit q->error(lastError);
+ stop();
+ return;
+ } else {
+ rdNotifier = new QSocketNotifier(m_rdfd, QSocketNotifier::Read, this);
+ if (rdNotifier) {
+ connect(rdNotifier, SIGNAL(activated(int)), this, SLOT(remoteDevicesChanged(int)));
+ } else {
+ qWarning() << Q_FUNC_INFO << "failed to connect to rdNotifier";
+ lastError = QBluetoothDeviceDiscoveryAgent::IOFailure;
+ emit q->error(lastError);
+ stop();
+ return;
+ }
+ }
+
+ //If there is no new results after 10 sekonds, the device inquire will be stopped
+ finishedTimer.start(10000);
+ connect(&finishedTimer, SIGNAL(timeout()), this, SLOT(finished()));
+
+ pendingStart = true;
+
+ ppsRegisterControl();
+
+ ppsSendControlMessage("device_search", this);
+ ppsRegisterForEvent(QStringLiteral("device_added"), this);
+
+ ppsRegisterForEvent(QStringLiteral("device_search"), this);
+}
+
+void QBluetoothDeviceDiscoveryAgentPrivate::stop()
+{
+ qBBBluetoothDebug() << "Stopping device search";
+
+ ppsSendControlMessage("cancel_device_search",this);
+
+ pendingStart = false;
+ if (rdNotifier)
+ delete rdNotifier;
+ qt_safe_close(m_rdfd);
+ m_rdfd = -1;
+}
+
+void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
+{
+ pps_decoder_t ppsDecoder;
+ pps_decoder_initialize(&ppsDecoder, NULL);
+
+ QBluetoothAddress deviceAddr;
+ QString deviceName;
+
+ if (!ppsReadRemoteDevice(fd, &ppsDecoder, &deviceAddr, &deviceName)) {
+ return;
+ }
+
+ bool paired = false;
+ int cod = 0;
+ int dev_type = 0;
+ int rssi = 0;
+
+ pps_decoder_get_bool(&ppsDecoder, "paired", &paired);
+ pps_decoder_get_int(&ppsDecoder, "cod", &cod);
+ pps_decoder_get_int(&ppsDecoder, "dev_type", &dev_type);
+ pps_decoder_get_int(&ppsDecoder, "rssi", &rssi);
+ pps_decoder_cleanup(&ppsDecoder);
+
+ QBluetoothDeviceInfo deviceInfo(deviceAddr, deviceName, cod);
+ deviceInfo.setRssi(rssi);
+
+ //Prevent a device from beeing listed twice
+ for (int i=0; i < discoveredDevices.size(); i++) {
+ if (discoveredDevices.at(i).address() == deviceInfo.address()) {
+ if (discoveredDevices.at(i) == deviceInfo) {
+ return;
+ } else {
+ discoveredDevices.removeAt(i);
+ break;
+ }
+ }
+ }
+ //Starts the timer again
+ finishedTimer.start(10000);
+
+ if (!deviceAddr.isNull()) {
+ discoveredDevices.append(deviceInfo);
+ qBBBluetoothDebug() << "Device discovered: " << deviceName << deviceAddr.toString();
+ emit q_ptr->deviceDiscovered(discoveredDevices.last());
+ }
+}
+
+void QBluetoothDeviceDiscoveryAgentPrivate::controlReply(ppsResult result)
+{
+ if (result.msg == QStringLiteral("device_search")) {
+ if (result.dat.size() > 0 && result.dat.first() == QStringLiteral("EOK")) {
+ //Do nothing. We can not be certain, that the device search is over yet
+ }
+ else {
+ qWarning() << "A PPS Bluetooth error occured:" << result.errorMsg;
+ q_ptr->error(QBluetoothDeviceDiscoveryAgent::UnknownError);
+ lastError = QBluetoothDeviceDiscoveryAgent::UnknownError;
+ errorString = result.errorMsg;
+ stop();
+ }
+ } else if (result.msg == QStringLiteral("cancel_device_search")) {
+ qBBBluetoothDebug() << "Cancel device search";
+ if (result.error == 16) {
+ qWarning() << Q_FUNC_INFO << "Resource is busy. Is Bluetooth enabled?";
+ lastError = QBluetoothDeviceDiscoveryAgent::PoweredOff;
+ errorString = result.errorMsg;
+ }
+ //stop();
+ }
+}
+
+void QBluetoothDeviceDiscoveryAgentPrivate::controlEvent(ppsResult result)
+{
+ if (result.msg == QStringLiteral("device_added")) {
+ qBBBluetoothDebug() << "Device was added" << result.dat.first();
+ }
+}
+
+
+void QBluetoothDeviceDiscoveryAgentPrivate::finished()
+{
+ qBBBluetoothDebug() << "Device discovery finished";
+ finishedTimer.stop();
+ q_ptr->finished();
+}
+
+QTBLUETOOTH_END_NAMESPACE
+
diff --git a/src/bluetooth/qnx/ppshelpers.cpp b/src/bluetooth/qnx/ppshelpers.cpp
index ad4c8d05..c3e5cae3 100644
--- a/src/bluetooth/qnx/ppshelpers.cpp
+++ b/src/bluetooth/qnx/ppshelpers.cpp
@@ -49,6 +49,8 @@ static int count = 0;
static int ppsCtrlFD = -1;
+static QSocketNotifier *ppsCtrlNotifier = 0;
+
static const char btControlFDPath[] = "/pps/services/bluetooth/public/control";
static const char btSettingsFDPath[] = "/pps/services/bluetooth/settings";
static const char btRemoteDevFDPath[] = "/pps/services/bluetooth/remote_devices/";
diff --git a/src/bluetooth/qnx/ppshelpers_p.h b/src/bluetooth/qnx/ppshelpers_p.h
index 68746abc..0e95216a 100644
--- a/src/bluetooth/qnx/ppshelpers_p.h
+++ b/src/bluetooth/qnx/ppshelpers_p.h
@@ -82,8 +82,6 @@ public Q_SLOTS:
static BBSocketNotifier bbSocketNotifier;
-static QSocketNotifier *ppsCtrlNotifier = 0;
-
enum ResultType {UNKNOWN, EVENT, MESSAGE, RESPONSE};
struct ppsResult {