summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNedim Hadzic <nhadzic@blackberry.com>2013-11-24 22:48:31 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-27 16:53:04 +0100
commitfd5b74810c54cfc0a0ab916d836fbf8566f17233 (patch)
treec58ccb59b86cff08b7a917766ede1a3dd3954228 /src
parentca92806296fe37cba4b427f7e26395a6d8a1bd37 (diff)
Implemented QNX API for device "connected" status
The feature allows to know whether QBluetoothLocalDevice is currently connected to any other device using connectedDevices() method for QNX platform. Change-Id: Id103f66321de52c2bc63e2bdbead85f11f9108a9 Reviewed-by: Fabian Bumberger <fbumberger@rim.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_p.h3
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_qnx.cpp61
2 files changed, 62 insertions, 2 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h
index 7d5ed926..76a7e460 100644
--- a/src/bluetooth/qbluetoothlocaldevice_p.h
+++ b/src/bluetooth/qbluetoothlocaldevice_p.h
@@ -149,6 +149,8 @@ public:
void requestPairing(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing);
void setAccess(int);
+ // This method will be used for emitting signals.
+ void connectedDevices();
Q_INVOKABLE void controlReply(ppsResult res);
Q_INVOKABLE void controlEvent(ppsResult res);
@@ -158,6 +160,7 @@ public:
private:
QBluetoothLocalDevice *q_ptr;
bool isValidDevice;
+ QList<QBluetoothAddress> connectedDevicesSet;
};
#else
class QBluetoothLocalDevicePrivate : public QObject
diff --git a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp
index d1460b6a..860df8c3 100644
--- a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp
@@ -42,7 +42,10 @@
#include "qbluetoothlocaldevice.h"
#include "qbluetoothaddress.h"
#include "qbluetoothlocaldevice_p.h"
+#include <sys/pps.h>
#include "qnx/ppshelpers_p.h"
+#include <QDir>
+#include <QtCore/private/qcore_unix_p.h>
QT_BEGIN_NAMESPACE
@@ -95,8 +98,42 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const
QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const
{
- qWarning() << Q_FUNC_INFO << " is not implemented for QNX backend yet.";
- return QList<QBluetoothAddress>(); //TODO: implement
+ QList<QBluetoothAddress> devices;
+ QDir bluetoothDevices(QStringLiteral("/pps/services/bluetooth/remote_devices/"));
+ QStringList allFiles = bluetoothDevices.entryList(QDir::NoDotAndDotDot| QDir::Files);
+ for (int i = 0; i < allFiles.size(); i++) {
+ qBBBluetoothDebug() << 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)
+ qWarning() << "Failed to open remote device file";
+ else {
+ pps_decoder_t ppsDecoder;
+ pps_decoder_initialize(&ppsDecoder, 0);
+
+ QBluetoothAddress deviceAddr;
+ QString deviceName;
+
+ if (!ppsReadRemoteDevice(fileId, &ppsDecoder, &deviceAddr, &deviceName)) {
+ pps_decoder_cleanup(&ppsDecoder);
+ qDebug() << "Failed to open remote device file";
+ }
+
+ bool connectedDevice = false;
+ int a = pps_decoder_get_bool(&ppsDecoder, "acl_connected", &connectedDevice);
+ if (a == PPS_DECODER_OK) {
+ if (connectedDevice)
+ devices.append(deviceAddr);
+ }
+ else if ( a == PPS_DECODER_BAD_TYPE)
+ qBBBluetoothDebug() << "Type missmatch";
+ else
+ qBBBluetoothDebug() << "An unknown error occurred while checking connected status.";
+ pps_decoder_cleanup(&ppsDecoder);
+ }
+ }
+
+ return devices;
}
QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
@@ -262,6 +299,25 @@ void QBluetoothLocalDevicePrivate::setAccess(int access)
}
}
+void QBluetoothLocalDevicePrivate::connectedDevices()
+{
+ QList<QBluetoothAddress> devices = q_ptr->connectedDevices();
+ 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 ++) {
+ if (!devices.contains(connectedDevicesSet.at(i))) {
+ QBluetoothAddress addr = connectedDevicesSet.at(i);
+ emit q_ptr->deviceDisconnected(addr);
+ connectedDevicesSet.removeOne(addr);
+ }
+ }
+}
+
void QBluetoothLocalDevicePrivate::controlReply(ppsResult result)
{
qBBBluetoothDebug() << Q_FUNC_INFO << result.msg << result.dat;
@@ -282,6 +338,7 @@ void QBluetoothLocalDevicePrivate::controlEvent(ppsResult result)
result.dat.first() == QStringLiteral("level")) {
QBluetoothLocalDevice::HostMode newHostMode = hostMode();
qBBBluetoothDebug() << "New Host mode" << newHostMode;
+ connectedDevices();
Q_EMIT q_ptr->hostModeStateChanged(newHostMode);
}
} else if (result.msg == QStringLiteral("pairing_complete")) {