summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothlocaldevice_qnx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bluetooth/qbluetoothlocaldevice_qnx.cpp')
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_qnx.cpp107
1 files changed, 55 insertions, 52 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp
index 8ed29437..b2e46194 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,8 +367,8 @@ 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();
@@ -376,12 +378,13 @@ void QBluetoothLocalDevicePrivate::controlEvent(ppsResult result)
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();
@@ -391,7 +394,7 @@ void QBluetoothLocalDevicePrivate::controlEvent(ppsResult result)
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));
+ result.dat.at(result.dat.indexOf(QStringLiteral("addr")) + 1));
Q_EMIT q_ptr->pairingFinished(address, QBluetoothLocalDevice::Unpaired);
}
} else if (result.msg == QStringLiteral("radio_shutdown")) {