diff options
Diffstat (limited to 'src/bluetooth')
24 files changed, 512 insertions, 447 deletions
diff --git a/src/bluetooth/qbluetooth.cpp b/src/bluetooth/qbluetooth.cpp index 4ba14dba..de1e5629 100644 --- a/src/bluetooth/qbluetooth.cpp +++ b/src/bluetooth/qbluetooth.cpp @@ -45,7 +45,6 @@ QT_BEGIN_NAMESPACE namespace QBluetooth { - /*! \namespace QBluetooth \inmodule QtBluetooth diff --git a/src/bluetooth/qbluetooth.h b/src/bluetooth/qbluetooth.h index b13c0043..3d92e1f8 100644 --- a/src/bluetooth/qbluetooth.h +++ b/src/bluetooth/qbluetooth.h @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #ifndef QBLUETOOTH_H #define QBLUETOOTH_H @@ -48,16 +47,16 @@ QT_BEGIN_NAMESPACE namespace QBluetooth { - enum Security { - NoSecurity = 0x00, - Authorization = 0x01, - Authentication = 0x02, - Encryption = 0x04, - Secure = 0x08 - }; +enum Security { + NoSecurity = 0x00, + Authorization = 0x01, + Authentication = 0x02, + Encryption = 0x04, + Secure = 0x08 +}; - Q_DECLARE_FLAGS(SecurityFlags, Security) - Q_DECLARE_OPERATORS_FOR_FLAGS(SecurityFlags) +Q_DECLARE_FLAGS(SecurityFlags, Security) +Q_DECLARE_OPERATORS_FOR_FLAGS(SecurityFlags) } QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothaddress.cpp b/src/bluetooth/qbluetoothaddress.cpp index 9213a431..798b325b 100644 --- a/src/bluetooth/qbluetoothaddress.cpp +++ b/src/bluetooth/qbluetoothaddress.cpp @@ -62,8 +62,7 @@ QT_BEGIN_NAMESPACE Returns true if the Bluetooth addresses are not equal, otherwise returns false. */ -namespace -{ +namespace { class BluetoothAddressRegisterMetaTypes { public: @@ -77,16 +76,16 @@ public: /*! Constructs an null Bluetooth address. */ -QBluetoothAddress::QBluetoothAddress() - : d_ptr(new QBluetoothAddressPrivate) +QBluetoothAddress::QBluetoothAddress() : + d_ptr(new QBluetoothAddressPrivate) { } /*! Constructs a new Bluetooth address and assigns \a address to it. */ -QBluetoothAddress::QBluetoothAddress(quint64 address) - : d_ptr(new QBluetoothAddressPrivate) +QBluetoothAddress::QBluetoothAddress(quint64 address) : + d_ptr(new QBluetoothAddressPrivate) { Q_D(QBluetoothAddress); d->m_address = address; @@ -98,8 +97,8 @@ QBluetoothAddress::QBluetoothAddress(quint64 address) The format of \a address can be either XX:XX:XX:XX:XX:XX or XXXXXXXXXXXX, where X is a hexadecimal digit. Case is not important. */ -QBluetoothAddress::QBluetoothAddress(const QString &address) - : d_ptr(new QBluetoothAddressPrivate) +QBluetoothAddress::QBluetoothAddress(const QString &address) : + d_ptr(new QBluetoothAddressPrivate) { Q_D(QBluetoothAddress); @@ -121,8 +120,8 @@ QBluetoothAddress::QBluetoothAddress(const QString &address) /*! Constructs a new Bluetooth address which is a copy of \a other. */ -QBluetoothAddress::QBluetoothAddress(const QBluetoothAddress &other) - : d_ptr(new QBluetoothAddressPrivate) +QBluetoothAddress::QBluetoothAddress(const QBluetoothAddress &other) : + d_ptr(new QBluetoothAddressPrivate) { *this = other; } diff --git a/src/bluetooth/qbluetoothaddress.h b/src/bluetooth/qbluetoothaddress.h index db9e0a1a..27c5412d 100644 --- a/src/bluetooth/qbluetoothaddress.h +++ b/src/bluetooth/qbluetoothaddress.h @@ -69,7 +69,10 @@ public: bool operator<(const QBluetoothAddress &other) const; bool operator==(const QBluetoothAddress &other) const; - inline bool operator!=(const QBluetoothAddress &other) const { return !operator==(other); } + inline bool operator!=(const QBluetoothAddress &other) const + { + return !operator==(other); + } quint64 toUInt64() const; QString toString() const; diff --git a/src/bluetooth/qbluetoothaddress_p.h b/src/bluetooth/qbluetoothaddress_p.h index bb25629e..20408b05 100644 --- a/src/bluetooth/qbluetoothaddress_p.h +++ b/src/bluetooth/qbluetoothaddress_p.h @@ -51,9 +51,7 @@ class QBluetoothAddressPrivate public: QBluetoothAddressPrivate(); - quint64 m_address; - }; QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp index eeac8f11..2c2cba11 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp @@ -132,8 +132,9 @@ QT_BEGIN_NAMESPACE /*! Constructs a new Bluetooth device discovery agent with parent \a parent. */ -QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject *parent) - : QObject(parent), d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(QBluetoothAddress())) +QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject *parent) : + QObject(parent), + d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(QBluetoothAddress())) { d_ptr->q_ptr = this; } @@ -150,8 +151,10 @@ QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject *parent) \sa error() */ -QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent) - : QObject(parent), d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(deviceAdapter)) +QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent( + const QBluetoothAddress &deviceAdapter, QObject *parent) : + QObject(parent), + d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(deviceAdapter)) { d_ptr->q_ptr = this; if (!deviceAdapter.isNull()) { @@ -238,7 +241,6 @@ bool QBluetoothDeviceDiscoveryAgent::isActive() const return d->isActive(); } - /*! Returns the last error. */ @@ -261,4 +263,3 @@ QString QBluetoothDeviceDiscoveryAgent::errorString() const #include "moc_qbluetoothdevicediscoveryagent.cpp" QT_END_NAMESPACE - diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h index 4ac1685e..4ce8074f 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h @@ -45,9 +45,7 @@ #include <QtBluetooth/qbluetoothglobal.h> #include <QObject> - #include <QtBluetooth/QBluetoothDeviceInfo> - #include <QtBluetooth/QBluetoothAddress> QT_BEGIN_NAMESPACE @@ -57,7 +55,8 @@ class QBluetoothDeviceDiscoveryAgentPrivate; class Q_BLUETOOTH_EXPORT QBluetoothDeviceDiscoveryAgent : public QObject { Q_OBJECT - Q_PROPERTY(QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType READ inquiryType WRITE setInquiryType) + Q_PROPERTY(QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType + READ inquiryType WRITE setInquiryType) public: // FIXME: add more errors @@ -67,7 +66,7 @@ public: InputOutputError, PoweredOffError, InvalidBluetoothAdapterError, - UnknownError = 100 //New errors must be added before Unknown error + UnknownError = 100 // New errors must be added before Unknown error }; enum InquiryType { @@ -76,7 +75,8 @@ public: }; QBluetoothDeviceDiscoveryAgent(QObject *parent = 0); - explicit QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent = 0); + explicit QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, + QObject *parent = 0); ~QBluetoothDeviceDiscoveryAgent(); QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType() const; diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index 4f8ecdff..f38fa914 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -51,14 +51,15 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID) QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( - const QBluetoothAddress &deviceAdapter) - : inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry), - lastError(QBluetoothDeviceDiscoveryAgent::NoError), errorString(QStringLiteral()), - receiver(0), - m_adapterAddress(deviceAdapter), - m_active(false), - pendingCancel(false), - pendingStart(false) + const QBluetoothAddress &deviceAdapter) : + inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry), + lastError(QBluetoothDeviceDiscoveryAgent::NoError), + errorString(QStringLiteral()), + receiver(0), + m_adapterAddress(deviceAdapter), + m_active(false), + pendingCancel(false), + pendingStart(false) { adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter", "getDefaultAdapter", @@ -102,8 +103,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() return; } - if (!m_adapterAddress.isNull() && - adapter.callObjectMethod<jstring>("getAddress").toString() != m_adapterAddress.toString()) { + if (!m_adapterAddress.isNull() + && adapter.callObjectMethod<jstring>("getAddress").toString() + != m_adapterAddress.toString()) { qCWarning(QT_BT_ANDROID) << "Incorrect local adapter passed."; lastError = QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError; errorString = QBluetoothDeviceDiscoveryAgent::tr("Passed address is not a local device."); @@ -112,14 +114,14 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() } const int state = adapter.callMethod<jint>("getState"); - if (state != 12 ) { //BluetoothAdapter.STATE_ON + if (state != 12) { // BluetoothAdapter.STATE_ON lastError = QBluetoothDeviceDiscoveryAgent::PoweredOffError; errorString = QBluetoothDeviceDiscoveryAgent::tr("Device is powered off"); emit q->error(lastError); return; } - //install Java BroadcastReceiver + // install Java BroadcastReceiver if (!receiver) { receiver = new DeviceDiscoveryBroadcastReceiver(); qRegisterMetaType<QBluetoothDeviceInfo>("QBluetoothDeviceInfo"); @@ -140,7 +142,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() m_active = true; - qCDebug(QT_BT_ANDROID) << "QBluetoothDeviceDiscoveryAgentPrivate::start() - successfully executed."; + qCDebug(QT_BT_ANDROID) + << "QBluetoothDeviceDiscoveryAgentPrivate::start() - successfully executed."; } void QBluetoothDeviceDiscoveryAgentPrivate::stop() @@ -163,9 +166,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop() void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveryFinished() { - //We need to guard because Android sends two DISCOVERY_FINISHED when cancelling - //Also if we have two active agents both receive the same signal. - //If this one is not active ignore the device information + // We need to guard because Android sends two DISCOVERY_FINISHED when cancelling + // Also if we have two active agents both receive the same signal. + // If this one is not active ignore the device information if (!m_active) return; @@ -180,9 +183,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveryFinished() pendingStart = pendingCancel = false; start(); } else { - //check that it didn't finish due to turned off Bluetooth Device + // check that it didn't finish due to turned off Bluetooth Device const int state = adapter.callMethod<jint>("getState"); - if (state != 12 ) { //BluetoothAdapter.STATE_ON + if (state != 12) { // BluetoothAdapter.STATE_ON lastError = QBluetoothDeviceDiscoveryAgent::PoweredOffError; errorString = QBluetoothDeviceDiscoveryAgent::tr("Device is powered off"); emit q->error(lastError); @@ -192,9 +195,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveryFinished() } } -void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices(const QBluetoothDeviceInfo &info) +void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices( + const QBluetoothDeviceInfo &info) { - //If we have two active agents both receive the same signal. + // If we have two active agents both receive the same signal. // If this one is not active ignore the device information if (!m_active) return; @@ -205,4 +209,5 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices(const QBlue qCDebug(QT_BT_ANDROID) << "Device found: " << info.name() << info.address().toString(); emit q->deviceDiscovered(info); } + QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index 83b83fbd..1d6e6799 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -53,9 +53,13 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ) -QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter) - : lastError(QBluetoothDeviceDiscoveryAgent::NoError), m_adapterAddress(deviceAdapter), pendingCancel(false), pendingStart(false), - adapter(0) +QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( + const QBluetoothAddress &deviceAdapter) : + lastError(QBluetoothDeviceDiscoveryAgent::NoError), + m_adapterAddress(deviceAdapter), + pendingCancel(false), + pendingStart(false), + adapter(0) { manager = new OrgBluezManagerInterface(QLatin1String("org.bluez"), QLatin1String("/"), QDBusConnection::systemBus()); @@ -70,17 +74,16 @@ QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate() bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const { - if(pendingStart) + if (pendingStart) return true; - if(pendingCancel) + if (pendingCancel) return false; return adapter != 0; } void QBluetoothDeviceDiscoveryAgentPrivate::start() { - - if(pendingCancel == true) { + if (pendingCancel == true) { pendingStart = true; return; } @@ -107,14 +110,14 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() QDBusConnection::systemBus()); Q_Q(QBluetoothDeviceDiscoveryAgent); - QObject::connect(adapter, SIGNAL(DeviceFound(QString,QVariantMap)), - q, SLOT(_q_deviceFound(QString,QVariantMap))); - QObject::connect(adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)), - q, SLOT(_q_propertyChanged(QString,QDBusVariant))); + QObject::connect(adapter, SIGNAL(DeviceFound(QString, QVariantMap)), + q, SLOT(_q_deviceFound(QString, QVariantMap))); + QObject::connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)), + q, SLOT(_q_propertyChanged(QString, QDBusVariant))); QDBusPendingReply<QVariantMap> propertiesReply = adapter->GetProperties(); propertiesReply.waitForFinished(); - if(propertiesReply.isError()) { + if (propertiesReply.isError()) { errorString = propertiesReply.error().message(); delete adapter; adapter = 0; @@ -169,23 +172,22 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres quint32 btClass = dict.value(QLatin1String("Class")).toUInt(); qCDebug(QT_BT_BLUEZ) << "Discovered: " << address << btName - << "Num UUIDs" << dict.value(QLatin1String("UUIDs")).toStringList().count() - << "total device" << discoveredDevices.count() << "cached" - << dict.value(QLatin1String("Cached")).toBool() - << "RSSI" << dict.value(QLatin1String("RSSI")).toInt(); + << "Num UUIDs" << dict.value(QLatin1String("UUIDs")).toStringList().count() + << "total device" << discoveredDevices.count() << "cached" + << dict.value(QLatin1String("Cached")).toBool() + << "RSSI" << dict.value(QLatin1String("RSSI")).toInt(); QBluetoothDeviceInfo device(btAddress, btName, btClass); - if(dict.value(QLatin1String("RSSI")).isValid()) + if (dict.value(QLatin1String("RSSI")).isValid()) device.setRssi(dict.value(QLatin1String("RSSI")).toInt()); QList<QBluetoothUuid> uuids; - foreach (const QString &u, dict.value(QLatin1String("UUIDs")).toStringList()) { + foreach (const QString &u, dict.value(QLatin1String("UUIDs")).toStringList()) uuids.append(QBluetoothUuid(u)); - } device.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete); device.setCached(dict.value(QLatin1String("Cached")).toBool()); - for(int i = 0; i < discoveredDevices.size(); i++){ - if(discoveredDevices[i].address() == device.address()) { - if(discoveredDevices[i] == device) { + for (int i = 0; i < discoveredDevices.size(); i++) { + if (discoveredDevices[i].address() == device.address()) { + if (discoveredDevices[i] == device) { qCDebug(QT_BT_BLUEZ) << "Duplicate: " << address; return; } @@ -212,16 +214,14 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_propertyChanged(const QString &na Q_Q(QBluetoothDeviceDiscoveryAgent); adapter->deleteLater(); adapter = 0; - if(pendingCancel && !pendingStart){ + if (pendingCancel && !pendingStart) { emit q->canceled(); pendingCancel = false; - } - else if(pendingStart){ + } else if (pendingStart) { pendingStart = false; pendingCancel = false; start(); - } - else { + } else { emit q->finished(); } } diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp index 72a3e853..56912c4f 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp @@ -48,7 +48,8 @@ QT_BEGIN_NAMESPACE -QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter) +QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( + const QBluetoothAddress &deviceAdapter) { Q_UNUSED(deviceAdapter); inquiryType = QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry; @@ -75,6 +76,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() void QBluetoothDeviceDiscoveryAgentPrivate::stop() { } + #ifdef QT_BLUEZ_BLUETOOTH void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &address, const QVariantMap &dict) @@ -89,6 +91,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_propertyChanged(const QString &na Q_UNUSED(name); Q_UNUSED(value); } + #endif QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h index 71dec409..3583af5f 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h @@ -69,7 +69,8 @@ QT_BEGIN_NAMESPACE class QBluetoothDeviceDiscoveryAgentPrivate #if defined(QT_QNX_BLUETOOTH) || defined(QT_ANDROID_BLUETOOTH) -: public QObject { + : public QObject +{ Q_OBJECT #else { @@ -98,10 +99,10 @@ private: #ifdef QT_ANDROID_BLUETOOTH private Q_SLOTS: void processDiscoveryFinished(); - void processDiscoveredDevices(const QBluetoothDeviceInfo& info); + void processDiscoveredDevices(const QBluetoothDeviceInfo &info); private: - DeviceDiscoveryBroadcastReceiver* receiver; + DeviceDiscoveryBroadcastReceiver *receiver; QBluetoothAddress m_adapterAddress; bool m_active; QAndroidJniObject adapter; @@ -114,7 +115,7 @@ private: OrgBluezManagerInterface *manager; OrgBluezAdapterInterface *adapter; #elif defined(QT_QNX_BLUETOOTH) - private Q_SLOTS: +private Q_SLOTS: void finished(); void remoteDevicesChanged(int); void controlReply(ppsResult result); @@ -127,7 +128,7 @@ private: int m_rdfd; bool m_active; - enum Ops{ + enum Ops { None, Cancel, Start @@ -139,7 +140,6 @@ private: #endif QBluetoothDeviceDiscoveryAgent *q_ptr; - }; QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp index 390faf50..f562486b 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp @@ -46,12 +46,16 @@ #include <QtCore/private/qcore_unix_p.h> - QT_BEGIN_NAMESPACE -QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter): - QObject(0), lastError(QBluetoothDeviceDiscoveryAgent::NoError), - m_rdfd(-1), m_active(false), m_nextOp(None), m_currentOp(None) +QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( + const QBluetoothAddress &deviceAdapter) : + QObject(0), + lastError(QBluetoothDeviceDiscoveryAgent::NoError), + m_rdfd(-1), + m_active(false), + m_nextOp(None), + m_currentOp(None) { Q_UNUSED(deviceAdapter); inquiryType = QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry; @@ -86,16 +90,18 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() m_nextOp = Start; return; } - if (m_nextOp == Cancel) { + if (m_nextOp == Cancel) m_nextOp = None; - } m_currentOp = Start; if (m_rdfd != -1) { qCDebug(QT_BT_QNX) << "RDev FD still open"; - } else if ((m_rdfd = qt_safe_open("/pps/services/bluetooth/remote_devices/.all", O_RDONLY)) == -1) { - qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "rdfd - failed to open /pps/services/bluetooth/remote_devices/.all" - << m_rdfd; + } else if ((m_rdfd + = qt_safe_open("/pps/services/bluetooth/remote_devices/.all", + O_RDONLY)) == -1) { + qCWarning(QT_BT_QNX) << Q_FUNC_INFO + << "rdfd - failed to open /pps/services/bluetooth/remote_devices/.all" + << m_rdfd; lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; errorString = QBluetoothDeviceDiscoveryAgent::tr("Cannot open remote device socket"); emit q->error(lastError); @@ -106,7 +112,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() if (!m_rdNotifier) { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "failed to connect to m_rdNotifier"; lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; - errorString = QBluetoothDeviceDiscoveryAgent::tr("Cannot connect to Bluetooth socket notifier"); + errorString = QBluetoothDeviceDiscoveryAgent::tr( + "Cannot connect to Bluetooth socket notifier"); emit q->error(lastError); stop(); return; @@ -114,7 +121,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() } if (ppsSendControlMessage("device_search", this)) { - //If there is no new results after 7 seconds, the device inquire will be stopped + // If there is no new results after 7 seconds, the device inquire will be stopped m_finishedTimer.start(10000); connect(m_rdNotifier, SIGNAL(activated(int)), this, SLOT(remoteDevicesChanged(int))); } else { @@ -138,7 +145,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop() m_currentOp = Cancel; qCDebug(QT_BT_QNX) << "Stopping device search"; - ppsSendControlMessage("cancel_device_search",this); + ppsSendControlMessage("cancel_device_search", this); if (m_rdNotifier) { delete m_rdNotifier; @@ -160,9 +167,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd) QBluetoothAddress deviceAddr; QString deviceName; - if (!ppsReadRemoteDevice(fd, &ppsDecoder, &deviceAddr, &deviceName)) { + if (!ppsReadRemoteDevice(fd, &ppsDecoder, &deviceAddr, &deviceName)) return; - } bool paired = false; int cod = 0; @@ -179,8 +185,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd) deviceInfo.setRssi(rssi); bool updated = false; - //Prevent a device from being listed twice - for (int i=0; i < discoveredDevices.size(); i++) { + // Prevent a device from being listed twice + for (int i = 0; i < discoveredDevices.size(); i++) { if (discoveredDevices.at(i).address() == deviceInfo.address()) { updated = true; if (discoveredDevices.at(i) == deviceInfo) { @@ -191,12 +197,12 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd) } } } - //Starts the timer again + // Starts the timer again m_finishedTimer.start(7000); if (!deviceAddr.isNull()) { qCDebug(QT_BT_QNX) << "Device discovered: " << deviceName << deviceAddr.toString(); discoveredDevices.append(deviceInfo); - if (!updated)//We are not allowed to emit a signal with the updated version + if (!updated) // We are not allowed to emit a signal with the updated version emit q_ptr->deviceDiscovered(discoveredDevices.last()); } } @@ -206,11 +212,11 @@ void QBluetoothDeviceDiscoveryAgentPrivate::controlReply(ppsResult result) Q_Q(QBluetoothDeviceDiscoveryAgent); if (result.msg == QStringLiteral("device_search") && m_currentOp == Start) { if (result.dat.size() > 0 && result.dat.first() == QStringLiteral("EOK")) { - //Do nothing. We can not be certain, that the device search is over yet + // Do nothing. We can not be certain, that the device search is over yet } else if (result.error == 16) { qCDebug(QT_BT_QNX) << "Could not start device inquire bc resource is busy"; - if (m_nextOp == None) { //We try again - ppsSendControlMessage("cancel_device_search",this); + if (m_nextOp == None) { // We try again + ppsSendControlMessage("cancel_device_search", this); QTimer::singleShot(5000, this, SLOT(startDeviceSearch())); m_finishedTimer.start(20000); } @@ -223,13 +229,14 @@ void QBluetoothDeviceDiscoveryAgentPrivate::controlReply(ppsResult result) stop(); } processNextOp(); - } else if (result.msg == QStringLiteral("cancel_device_search") && m_currentOp == Cancel && !isFinished) { + } else if (result.msg == QStringLiteral("cancel_device_search") && m_currentOp == Cancel + && !isFinished) { qCDebug(QT_BT_QNX) << "Cancel device search"; -// if (!result.errorMsg.isEmpty()) { -// lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; -// errorString = result.errorMsg; -// q_ptr->error(QBluetoothDeviceDiscoveryAgent::InputOutputError); -// } +// if (!result.errorMsg.isEmpty()) { +// lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; +// errorString = result.errorMsg; +// q_ptr->error(QBluetoothDeviceDiscoveryAgent::InputOutputError); +// } emit q->canceled(); processNextOp(); } @@ -237,9 +244,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::controlReply(ppsResult result) void QBluetoothDeviceDiscoveryAgentPrivate::controlEvent(ppsResult result) { - if (result.msg == QStringLiteral("device_added")) { + if (result.msg == QStringLiteral("device_added")) qCDebug(QT_BT_QNX) << "Device was added" << result.dat.first(); - } } void QBluetoothDeviceDiscoveryAgentPrivate::finished() @@ -254,9 +260,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::finished() void QBluetoothDeviceDiscoveryAgentPrivate::startDeviceSearch() { - if (m_currentOp == Start) { - ppsSendControlMessage("device_search", this); //Try again - } + if (m_currentOp == Start) + ppsSendControlMessage("device_search", this); // Try again } void QBluetoothDeviceDiscoveryAgentPrivate::processNextOp() @@ -268,12 +273,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processNextOp() m_currentOp = m_nextOp; m_nextOp = None; - if (m_currentOp == Start) { + if (m_currentOp == Start) start(); - } else if (m_currentOp == Cancel) { + else if (m_currentOp == Cancel) stop(); - } } QT_END_NAMESPACE - diff --git a/src/bluetooth/qbluetoothdeviceinfo.cpp b/src/bluetooth/qbluetoothdeviceinfo.cpp index f10ec133..408222bd 100644 --- a/src/bluetooth/qbluetoothdeviceinfo.cpp +++ b/src/bluetooth/qbluetoothdeviceinfo.cpp @@ -216,7 +216,6 @@ QT_BEGIN_NAMESPACE \value HealthStepCounter A pedometer. */ - /*! \enum QBluetoothDeviceInfo::ServiceClass @@ -247,20 +246,22 @@ QT_BEGIN_NAMESPACE \value DataUnavailable No data is available. */ -QBluetoothDeviceInfoPrivate::QBluetoothDeviceInfoPrivate() - : valid(false), cached(false), rssi(1), - serviceClasses(QBluetoothDeviceInfo::NoService), - majorDeviceClass(QBluetoothDeviceInfo::MiscellaneousDevice), - minorDeviceClass(0), - serviceUuidsCompleteness(QBluetoothDeviceInfo::DataUnavailable) +QBluetoothDeviceInfoPrivate::QBluetoothDeviceInfoPrivate() : + valid(false), + cached(false), + rssi(1), + serviceClasses(QBluetoothDeviceInfo::NoService), + majorDeviceClass(QBluetoothDeviceInfo::MiscellaneousDevice), + minorDeviceClass(0), + serviceUuidsCompleteness(QBluetoothDeviceInfo::DataUnavailable) { } /*! Constructs an invalid QBluetoothDeviceInfo object. */ -QBluetoothDeviceInfo::QBluetoothDeviceInfo() -: d_ptr(new QBluetoothDeviceInfoPrivate) +QBluetoothDeviceInfo::QBluetoothDeviceInfo() : + d_ptr(new QBluetoothDeviceInfoPrivate) { } @@ -278,8 +279,9 @@ QBluetoothDeviceInfo::QBluetoothDeviceInfo() \row \li 13 - 23 \li 11 \li Service class. \endtable */ -QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, quint32 classOfDevice) -: d_ptr(new QBluetoothDeviceInfoPrivate) +QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, + quint32 classOfDevice) : + d_ptr(new QBluetoothDeviceInfoPrivate) { Q_D(QBluetoothDeviceInfo); @@ -300,8 +302,8 @@ QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, con /*! Constructs a QBluetoothDeviceInfo that is a copy of \a other. */ -QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other) -: d_ptr(new QBluetoothDeviceInfoPrivate) +QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other) : + d_ptr(new QBluetoothDeviceInfoPrivate) { *this = other; } @@ -323,6 +325,7 @@ bool QBluetoothDeviceInfo::isValid() const return d->valid; } + /*! Returns the signal strength when the device was last scanned */ @@ -370,29 +373,28 @@ bool QBluetoothDeviceInfo::operator==(const QBluetoothDeviceInfo &other) const { Q_D(const QBluetoothDeviceInfo); - if(d->cached != other.d_func()->cached) + if (d->cached != other.d_func()->cached) return false; - if(d->valid != other.d_func()->valid) + if (d->valid != other.d_func()->valid) return false; - if(d->majorDeviceClass != other.d_func()->majorDeviceClass) + if (d->majorDeviceClass != other.d_func()->majorDeviceClass) return false; - if(d->minorDeviceClass != other.d_func()->minorDeviceClass) + if (d->minorDeviceClass != other.d_func()->minorDeviceClass) return false; - if(d->serviceClasses != other.d_func()->serviceClasses) + if (d->serviceClasses != other.d_func()->serviceClasses) return false; - if(d->name != other.d_func()->name) + if (d->name != other.d_func()->name) return false; - if(d->address != other.d_func()->address) + if (d->address != other.d_func()->address) return false; - if(d->serviceUuidsCompleteness != other.d_func()->serviceUuidsCompleteness) + if (d->serviceUuidsCompleteness != other.d_func()->serviceUuidsCompleteness) return false; - if(d->serviceUuids.count() != other.d_func()->serviceUuids.count()) + if (d->serviceUuids.count() != other.d_func()->serviceUuids.count()) return false; - if(d->serviceUuids != other.d_func()->serviceUuids) + if (d->serviceUuids != other.d_func()->serviceUuids) return false; return true; - } /*! @@ -458,7 +460,8 @@ quint8 QBluetoothDeviceInfo::minorDeviceClass() const /*! Sets the list of service UUIDs to \a uuids and the completeness of the data to \a completeness. */ -void QBluetoothDeviceInfo::setServiceUuids(const QList<QBluetoothUuid> &uuids, DataCompleteness completeness) +void QBluetoothDeviceInfo::setServiceUuids(const QList<QBluetoothUuid> &uuids, + DataCompleteness completeness) { Q_D(QBluetoothDeviceInfo); diff --git a/src/bluetooth/qbluetoothdeviceinfo.h b/src/bluetooth/qbluetoothdeviceinfo.h index be605f8d..13892990 100644 --- a/src/bluetooth/qbluetoothdeviceinfo.h +++ b/src/bluetooth/qbluetoothdeviceinfo.h @@ -197,7 +197,8 @@ public: }; QBluetoothDeviceInfo(); - QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, quint32 classOfDevice); + QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, + quint32 classOfDevice); QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other); ~QBluetoothDeviceInfo(); diff --git a/src/bluetooth/qbluetoothhostinfo.cpp b/src/bluetooth/qbluetoothhostinfo.cpp index 00ce0680..e20d52ac 100644 --- a/src/bluetooth/qbluetoothhostinfo.cpp +++ b/src/bluetooth/qbluetoothhostinfo.cpp @@ -56,16 +56,16 @@ QT_BEGIN_NAMESPACE /*! Constrcuts a null QBluetoothHostInfo object. */ -QBluetoothHostInfo::QBluetoothHostInfo() - : d_ptr(new QBluetoothHostInfoPrivate) +QBluetoothHostInfo::QBluetoothHostInfo() : + d_ptr(new QBluetoothHostInfoPrivate) { } /*! Constrcuts a new QBluetoothHostInfo which is a copy of \a other. */ -QBluetoothHostInfo::QBluetoothHostInfo(const QBluetoothHostInfo &other) - : d_ptr(new QBluetoothHostInfoPrivate) +QBluetoothHostInfo::QBluetoothHostInfo(const QBluetoothHostInfo &other) : + d_ptr(new QBluetoothHostInfoPrivate) { Q_D(QBluetoothHostInfo); diff --git a/src/bluetooth/qbluetoothhostinfo.h b/src/bluetooth/qbluetoothhostinfo.h index b4428a82..f51837fe 100644 --- a/src/bluetooth/qbluetoothhostinfo.h +++ b/src/bluetooth/qbluetoothhostinfo.h @@ -68,7 +68,6 @@ private: QBluetoothHostInfoPrivate *d_ptr; }; - QT_END_NAMESPACE #endif diff --git a/src/bluetooth/qbluetoothhostinfo_p.h b/src/bluetooth/qbluetoothhostinfo_p.h index 2ce603c6..a44b29dd 100644 --- a/src/bluetooth/qbluetoothhostinfo_p.h +++ b/src/bluetooth/qbluetoothhostinfo_p.h @@ -49,7 +49,9 @@ QT_BEGIN_NAMESPACE class QBluetoothHostInfoPrivate { public: - QBluetoothHostInfoPrivate() {} + QBluetoothHostInfoPrivate() + { + } QBluetoothAddress m_address; QString m_name; diff --git a/src/bluetooth/qbluetoothlocaldevice.cpp b/src/bluetooth/qbluetoothlocaldevice.cpp index 14140846..c5b68645 100644 --- a/src/bluetooth/qbluetoothlocaldevice.cpp +++ b/src/bluetooth/qbluetoothlocaldevice.cpp @@ -102,18 +102,17 @@ QT_BEGIN_NAMESPACE */ -namespace +namespace { +class LocalDeviceRegisterMetaTypes { - class LocalDeviceRegisterMetaTypes +public: + LocalDeviceRegisterMetaTypes() { - public: - LocalDeviceRegisterMetaTypes() - { - qRegisterMetaType<QBluetoothLocalDevice::HostMode>("QBluetoothLocalDevice::HostMode"); - qRegisterMetaType<QBluetoothLocalDevice::Pairing>("QBluetoothLocalDevice::Pairing"); - qRegisterMetaType<QBluetoothLocalDevice::Error>("QBluetoothLocalDevice::Error"); - } - } _registerLocalDeviceMetaTypes; + qRegisterMetaType<QBluetoothLocalDevice::HostMode>("QBluetoothLocalDevice::HostMode"); + qRegisterMetaType<QBluetoothLocalDevice::Pairing>("QBluetoothLocalDevice::Pairing"); + qRegisterMetaType<QBluetoothLocalDevice::Error>("QBluetoothLocalDevice::Error"); + } +} _registerLocalDeviceMetaTypes; } /*! @@ -233,7 +232,6 @@ bool QBluetoothLocalDevice::isValid() const Returns the current bluetooth pairing status of \a address, if it's unpaired, paired, or paired and authorized. */ - /*! \fn QBluetoothLocalDevice::pairingDisplayConfirmation(const QBluetoothAddress &address, QString pin) @@ -286,7 +284,6 @@ bool QBluetoothLocalDevice::isValid() const Signal emitted if there's an exceptional \a error while pairing. */ - /*! \fn QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = 0) diff --git a/src/bluetooth/qbluetoothlocaldevice.h b/src/bluetooth/qbluetoothlocaldevice.h index 597496b7..661e6a9c 100644 --- a/src/bluetooth/qbluetoothlocaldevice.h +++ b/src/bluetooth/qbluetoothlocaldevice.h @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #ifndef QBLUETOOTHLOCALDEVICE_H #define QBLUETOOTHLOCALDEVICE_H @@ -76,9 +75,9 @@ public: }; enum Error { - NoError, - PairingError, - UnknownError = 100 + NoError, + PairingError, + UnknownError = 100 }; QBluetoothLocalDevice(QObject *parent = 0); explicit QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = 0); diff --git a/src/bluetooth/qbluetoothlocaldevice_android.cpp b/src/bluetooth/qbluetoothlocaldevice_android.cpp index a6d2b5d6..475ecd95 100644 --- a/src/bluetooth/qbluetoothlocaldevice_android.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_android.cpp @@ -55,23 +55,26 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID) QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate( - QBluetoothLocalDevice *q, const QBluetoothAddress &address) - : q_ptr(q), obj(0), pendingHostModeTransition(false) + QBluetoothLocalDevice *q, const QBluetoothAddress &address) : + q_ptr(q), + obj(0), + pendingHostModeTransition(false) { initialize(address); receiver = new LocalDeviceBroadcastReceiver(q_ptr); - QObject::connect(receiver, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)), - this, SLOT(processHostModeChange(QBluetoothLocalDevice::HostMode))); - QObject::connect(receiver, SIGNAL(pairingStateChanged(QBluetoothAddress,QBluetoothLocalDevice::Pairing)), - this, SLOT(processPairingStateChanged(QBluetoothAddress,QBluetoothLocalDevice::Pairing))); - QObject::connect(receiver, SIGNAL(connectDeviceChanges(QBluetoothAddress,bool)), - this, SLOT(processConnectDeviceChanges(QBluetoothAddress,bool))); - QObject::connect(receiver, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress,QString)), - this, SLOT(processDisplayConfirmation(QBluetoothAddress,QString))); + connect(receiver, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)), + this, SLOT(processHostModeChange(QBluetoothLocalDevice::HostMode))); + connect(receiver, SIGNAL(pairingStateChanged(QBluetoothAddress, + QBluetoothLocalDevice::Pairing)), + this, SLOT(processPairingStateChanged(QBluetoothAddress, + QBluetoothLocalDevice::Pairing))); + connect(receiver, SIGNAL(connectDeviceChanges(QBluetoothAddress, bool)), + this, SLOT(processConnectDeviceChanges(QBluetoothAddress, bool))); + connect(receiver, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress, QString)), + this, SLOT(processDisplayConfirmation(QBluetoothAddress, QString))); } - QBluetoothLocalDevicePrivate::~QBluetoothLocalDevicePrivate() { receiver->unregisterReceiver(); @@ -90,17 +93,21 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address) jclass btAdapterClass = env->FindClass("android/bluetooth/BluetoothAdapter"); if (btAdapterClass == NULL) { - qCWarning(QT_BT_ANDROID) << "Native registration unable to find class android/bluetooth/BluetoothAdapter"; + qCWarning(QT_BT_ANDROID) + << "Native registration unable to find class android/bluetooth/BluetoothAdapter"; return; } - jmethodID getDefaultAdapterID = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;"); + jmethodID getDefaultAdapterID + = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter", + "()Landroid/bluetooth/BluetoothAdapter;"); if (getDefaultAdapterID == NULL) { - qCWarning(QT_BT_ANDROID) << "Native registration unable to get method ID: getDefaultAdapter of android/bluetooth/BluetoothAdapter"; + qCWarning(QT_BT_ANDROID) + << "Native registration unable to get method ID: " \ + "getDefaultAdapter of android/bluetooth/BluetoothAdapter"; return; } - jobject btAdapterObject = env->CallStaticObjectMethod(btAdapterClass, getDefaultAdapterID); if (btAdapterObject == NULL) { qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth"; @@ -112,14 +119,13 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address) if (!obj->isValid()) { delete obj; obj = 0; - } else { - if (!address.isNull()) { - const QString localAddress = obj->callObjectMethod("getAddress", "()Ljava/lang/String;").toString(); - if (localAddress != address.toString()) { - //passed address not local one -> invalid - delete obj; - obj = 0; - } + } else if (!address.isNull()) { + const QString localAddress + = obj->callObjectMethod("getAddress", "()Ljava/lang/String;").toString(); + if (localAddress != address.toString()) { + // passed address not local one -> invalid + delete obj; + obj = 0; } } @@ -132,17 +138,16 @@ bool QBluetoothLocalDevicePrivate::isValid() const return obj ? true : false; } - void QBluetoothLocalDevicePrivate::processHostModeChange(QBluetoothLocalDevice::HostMode newMode) { if (!pendingHostModeTransition) { - //if not in transition -> pass data on + // if not in transition -> pass data on emit q_ptr->hostModeStateChanged(newMode); return; } if (isValid() && newMode == QBluetoothLocalDevice::HostPoweredOff) { - bool success = (bool) obj->callMethod<jboolean>("enable", "()Z"); + bool success = (bool)obj->callMethod<jboolean>("enable", "()Z"); if (!success) emit q_ptr->error(QBluetoothLocalDevice::UnknownError); } @@ -162,26 +167,25 @@ int QBluetoothLocalDevicePrivate::pendingPairing(const QBluetoothAddress &addres return -1; } - void QBluetoothLocalDevicePrivate::processPairingStateChanged( - const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing) + const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing) { int index = pendingPairing(address); if (index < 0) - return; //ignore unrelated pairing signals + return; // ignore unrelated pairing signals QPair<QBluetoothAddress, bool> entry = pendingPairings.takeAt(index); - if ((entry.second && pairing == QBluetoothLocalDevice::Paired) || - (!entry.second && pairing == QBluetoothLocalDevice::Unpaired)) { + if ((entry.second && pairing == QBluetoothLocalDevice::Paired) + || (!entry.second && pairing == QBluetoothLocalDevice::Unpaired)) { emit q_ptr->pairingFinished(address, pairing); } else { emit q_ptr->error(QBluetoothLocalDevice::PairingError); } - } -void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothAddress& address, bool isConnectEvent) +void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothAddress &address, + bool isConnectEvent) { int index = -1; for (int i = 0; i < connectedDevices.count(); i++) { @@ -191,21 +195,22 @@ void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothA } } - if (isConnectEvent) { //connect event + if (isConnectEvent) { // connect event if (index >= 0) return; connectedDevices.append(address); emit q_ptr->deviceConnected(address); - } else { //disconnect event + } else { // disconnect event connectedDevices.removeAll(address); emit q_ptr->deviceDisconnected(address); } } -void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAddress &address, const QString &pin) +void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAddress &address, + const QString &pin) { - //only send pairing notification for pairing requests issued by - //this QBluetoothLocalDevice instance + // only send pairing notification for pairing requests issued by + // this QBluetoothLocalDevice instance if (pendingPairing(address) == -1) return; @@ -213,14 +218,14 @@ void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAd emit q_ptr->pairingDisplayPinCode(address, pin); } -QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) -: QObject(parent), +QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) : + QObject(parent), d_ptr(new QBluetoothLocalDevicePrivate(this, QBluetoothAddress())) { } -QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) -: QObject(parent), +QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) : + QObject(parent), d_ptr(new QBluetoothLocalDevicePrivate(this, address)) { } @@ -236,8 +241,10 @@ QString QBluetoothLocalDevice::name() const QBluetoothAddress QBluetoothLocalDevice::address() const { QString result; - if (d_ptr->adapter()) - result = d_ptr->adapter()->callObjectMethod("getAddress", "()Ljava/lang/String;").toString(); + if (d_ptr->adapter()) { + result + = d_ptr->adapter()->callObjectMethod("getAddress", "()Ljava/lang/String;").toString(); + } QBluetoothAddress address(result); return address; @@ -249,7 +256,7 @@ void QBluetoothLocalDevice::powerOn() return; if (d_ptr->adapter()) { - bool ret = (bool) d_ptr->adapter()->callMethod<jboolean>("enable", "()Z"); + bool ret = (bool)d_ptr->adapter()->callMethod<jboolean>("enable", "()Z"); if (!ret) emit error(QBluetoothLocalDevice::UnknownError); } @@ -267,23 +274,26 @@ void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode requeste if (mode == QBluetoothLocalDevice::HostPoweredOff) { bool success = false; if (d_ptr->adapter()) - success = (bool) d_ptr->adapter()->callMethod<jboolean>("disable", "()Z"); + success = (bool)d_ptr->adapter()->callMethod<jboolean>("disable", "()Z"); if (!success) emit error(QBluetoothLocalDevice::UnknownError); } else if (mode == QBluetoothLocalDevice::HostConnectable) { if (hostMode() == QBluetoothLocalDevice::HostDiscoverable) { - //cannot directly go from Discoverable to Connectable - //we need to go to disabled mode and enable once disabling came through + // cannot directly go from Discoverable to Connectable + // we need to go to disabled mode and enable once disabling came through setHostMode(QBluetoothLocalDevice::HostPoweredOff); d_ptr->pendingHostModeTransition = true; } else { - QAndroidJniObject::callStaticMethod<void>("org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setConnectable"); + QAndroidJniObject::callStaticMethod<void>( + "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", + "setConnectable"); } - } else if (mode == QBluetoothLocalDevice::HostDiscoverable || - mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) { - QAndroidJniObject::callStaticMethod<void>("org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setDiscoverable"); + } else if (mode == QBluetoothLocalDevice::HostDiscoverable + || mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) { + QAndroidJniObject::callStaticMethod<void>( + "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setDiscoverable"); } } @@ -293,14 +303,14 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const jint scanMode = d_ptr->adapter()->callMethod<jint>("getScanMode"); switch (scanMode) { - case 20: //BluetoothAdapter.SCAN_MODE_NONE - return HostPoweredOff; - case 21: //BluetoothAdapter.SCAN_MODE_CONNECTABLE - return HostConnectable; - case 23: //BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE - return HostDiscoverable; - default: - break; + case 20: // BluetoothAdapter.SCAN_MODE_NONE + return HostPoweredOff; + case 21: // BluetoothAdapter.SCAN_MODE_CONNECTABLE + return HostConnectable; + case 23: // BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE + return HostDiscoverable; + default: + break; } } @@ -309,24 +319,28 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() { - //Android only supports max of one device (so far) + // Android only supports max of one device (so far) QList<QBluetoothHostInfo> localDevices; QAndroidJniEnvironment env; jclass btAdapterClass = env->FindClass("android/bluetooth/BluetoothAdapter"); if (btAdapterClass == NULL) { - qCWarning(QT_BT_ANDROID) << "Native registration unable to find class android/bluetooth/BluetoothAdapter"; + qCWarning(QT_BT_ANDROID) + << "Native registration unable to find class android/bluetooth/BluetoothAdapter"; return localDevices; } - jmethodID getDefaultAdapterID = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;"); + jmethodID getDefaultAdapterID + = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter", + "()Landroid/bluetooth/BluetoothAdapter;"); if (getDefaultAdapterID == NULL) { - qCWarning(QT_BT_ANDROID) << "Native registration unable to get method ID: getDefaultAdapter of android/bluetooth/BluetoothAdapter"; + qCWarning(QT_BT_ANDROID) + << "Native registration unable to get method ID: " \ + "getDefaultAdapter of android/bluetooth/BluetoothAdapter"; env->DeleteLocalRef(btAdapterClass); return localDevices; } - jobject btAdapterObject = env->CallStaticObjectMethod(btAdapterClass, getDefaultAdapterID); if (btAdapterObject == NULL) { qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth"; @@ -338,7 +352,8 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() if (o.isValid()) { QBluetoothHostInfo info; info.setName(o.callObjectMethod("getName", "()Ljava/lang/String;").toString()); - info.setAddress(QBluetoothAddress(o.callObjectMethod("getAddress", "()Ljava/lang/String;").toString())); + info.setAddress(QBluetoothAddress(o.callObjectMethod("getAddress", + "()Ljava/lang/String;").toString())); localDevices.append(info); } @@ -352,61 +367,60 @@ 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 previousPairing = pairingStatus(address); Pairing newPairing = pairing; - if (pairing == AuthorizedPaired) //AuthorizedPaired same as Paired on Android + if (pairing == AuthorizedPaired) // AuthorizedPaired same as Paired on Android newPairing = Paired; if (previousPairing == newPairing) { QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, - Q_ARG(QBluetoothAddress, address), - Q_ARG(QBluetoothLocalDevice::Pairing, pairing)); + Q_ARG(QBluetoothAddress, address), + Q_ARG(QBluetoothLocalDevice::Pairing, pairing)); return; } - //BluetoothDevice::createBond() requires Android API 19 + // BluetoothDevice::createBond() requires Android API 19 if (QtAndroidPrivate::androidSdkVersion() < 19 || !d_ptr->adapter()) { qCWarning(QT_BT_ANDROID) << "Unable to pair: requires Android API 19+"; QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, - QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); return; } QAndroidJniObject inputString = QAndroidJniObject::fromString(address.toString()); jboolean success = QAndroidJniObject::callStaticMethod<jboolean>( - "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", - "setPairingMode", - "(Ljava/lang/String;Z)Z", - inputString.object<jstring>(), - newPairing == Paired ? JNI_TRUE : JNI_FALSE); + "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", + "setPairingMode", + "(Ljava/lang/String;Z)Z", + inputString.object<jstring>(), + newPairing == Paired ? JNI_TRUE : JNI_FALSE); if (!success) { QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, - QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); } else { - d_ptr->pendingPairings.append(qMakePair(address, - newPairing == Paired ? true : false)); + d_ptr->pendingPairings.append(qMakePair(address, newPairing == Paired ? true : false)); } - } -QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const +QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus( + const QBluetoothAddress &address) const { if (address.isNull() || !d_ptr->adapter()) return Unpaired; QAndroidJniObject inputString = QAndroidJniObject::fromString(address.toString()); - QAndroidJniObject remoteDevice = - d_ptr->adapter()->callObjectMethod("getRemoteDevice", - "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;", - inputString.object<jstring>()); + QAndroidJniObject remoteDevice + = d_ptr->adapter()->callObjectMethod("getRemoteDevice", + "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;", + inputString.object<jstring>()); QAndroidJniEnvironment env; if (env->ExceptionCheck()) { env->ExceptionClear(); @@ -415,7 +429,7 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet jint bondState = remoteDevice.callMethod<jint>("getBondState"); switch (bondState) { - case 12: //BluetoothDevice.BOND_BONDED + case 12: // BluetoothDevice.BOND_BONDED return Paired; default: break; @@ -432,7 +446,6 @@ void QBluetoothLocalDevice::pairingConfirmation(bool confirmation) bool success = d_ptr->receiver->pairingConfirmation(confirmation); if (!success) emit error(PairingError); - } QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const @@ -449,9 +462,9 @@ QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const * but at least it can complement our already detected connections. */ QAndroidJniObject connectedDevices = QAndroidJniObject::callStaticObjectMethod( - "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", - "getConnectedDevices", - "()[Ljava/lang/String;"); + "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", + "getConnectedDevices", + "()[Ljava/lang/String;"); if (!connectedDevices.isValid()) return d_ptr->connectedDevices; diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index 9f2e7fd3..348378f3 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -63,12 +63,14 @@ inline uint qHash(const QBluetoothAddress &address) } QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) : - QObject(parent), d_ptr(new QBluetoothLocalDevicePrivate(this)) + QObject(parent), + d_ptr(new QBluetoothLocalDevicePrivate(this)) { } QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) : - QObject(parent), d_ptr(new QBluetoothLocalDevicePrivate(this, address)) + QObject(parent), + d_ptr(new QBluetoothLocalDevicePrivate(this, address)) { } @@ -115,29 +117,29 @@ void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode mode) case HostDiscoverableLimitedInquiry: case HostDiscoverable: if (hostMode() == HostPoweredOff) { - //We first have to wait for BT to be powered on, - //then we can set the host mode correctly - d_ptr->pendingHostModeChange = (int) HostDiscoverable; + // We first have to wait for BT to be powered on, + // then we can set the host mode correctly + d_ptr->pendingHostModeChange = (int)HostDiscoverable; d_ptr->adapter->SetProperty(QStringLiteral("Powered"), QDBusVariant(QVariant::fromValue(true))); } else { d_ptr->adapter->SetProperty(QStringLiteral("Discoverable"), - QDBusVariant(QVariant::fromValue(true))); + QDBusVariant(QVariant::fromValue(true))); } break; case HostConnectable: if (hostMode() == HostPoweredOff) { - d_ptr->pendingHostModeChange = (int) HostConnectable; + d_ptr->pendingHostModeChange = (int)HostConnectable; d_ptr->adapter->SetProperty(QStringLiteral("Powered"), QDBusVariant(QVariant::fromValue(true))); } else { d_ptr->adapter->SetProperty(QStringLiteral("Discoverable"), - QDBusVariant(QVariant::fromValue(false))); + QDBusVariant(QVariant::fromValue(false))); } break; case HostPoweredOff: d_ptr->adapter->SetProperty(QLatin1String("Powered"), - QDBusVariant(QVariant::fromValue(false))); + QDBusVariant(QVariant::fromValue(false))); break; } } @@ -179,7 +181,6 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() if (reply.isError()) return localDevices; - foreach (const QDBusObjectPath &path, reply.value()) { QBluetoothHostInfo hostinfo; OrgBluezAdapterInterface adapter(QLatin1String("org.bluez"), path.path(), @@ -190,7 +191,8 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() if (reply.isError()) continue; - hostinfo.setAddress(QBluetoothAddress(reply.value().value(QLatin1String("Address")).toString())); + hostinfo.setAddress(QBluetoothAddress( + reply.value().value(QLatin1String("Address")).toString())); hostinfo.setName(reply.value().value(QLatin1String("Name")).toString()); localDevices.append(hostinfo); @@ -199,13 +201,14 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() return localDevices; } -static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &address, QBluetoothLocalDevicePrivate *d_ptr) +static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &address, + QBluetoothLocalDevicePrivate *d_ptr) { if (!d_ptr || !d_ptr->adapter) return 0; QDBusPendingReply<QDBusObjectPath> reply = d_ptr->adapter->FindDevice(address.toString()); reply.waitForFinished(); - if(reply.isError()){ + if (reply.isError()) { qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "reply failed" << reply.error(); return 0; } @@ -213,122 +216,138 @@ static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &addres QDBusObjectPath path = reply.value(); return new OrgBluezDeviceInterface(QLatin1String("org.bluez"), path.path(), - QDBusConnection::systemBus()); + QDBusConnection::systemBus()); } void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing) { 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; } - if(pairing == Paired || pairing == AuthorizedPaired) { - + if (pairing == Paired || pairing == AuthorizedPaired) { d_ptr->address = address; d_ptr->pairing = pairing; - if(!d_ptr->agent){ + if (!d_ptr->agent) { d_ptr->agent = new OrgBluezAgentAdaptor(d_ptr); bool res = QDBusConnection::systemBus().registerObject(d_ptr->agent_path, d_ptr); - if(!res){ + if (!res) { QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); qCWarning(QT_BT_BLUEZ) << "Failed to register agent"; return; } } - if(current_pairing == Paired && pairing == AuthorizedPaired){ + if (current_pairing == Paired && pairing == AuthorizedPaired) { OrgBluezDeviceInterface *device = getDevice(address, d_ptr); if (!device) { QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); return; } - QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(true)); + QDBusPendingReply<> deviceReply + = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(true)); deviceReply.waitForFinished(); - if(deviceReply.isError()){ + if (deviceReply.isError()) { qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "reply failed" << deviceReply.error(); QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); return; } delete device; - QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address), - Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::AuthorizedPaired)); - } - else if(current_pairing == AuthorizedPaired && pairing == Paired){ + QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, + Q_ARG(QBluetoothAddress, address), + Q_ARG(QBluetoothLocalDevice::Pairing, + QBluetoothLocalDevice::AuthorizedPaired)); + } else if (current_pairing == AuthorizedPaired && pairing == Paired) { OrgBluezDeviceInterface *device = getDevice(address, d_ptr); if (!device) { QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); return; } - QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(false)); + QDBusPendingReply<> deviceReply + = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(false)); deviceReply.waitForFinished(); - if(deviceReply.isError()){ + if (deviceReply.isError()) { qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "reply failed" << deviceReply.error(); QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); return; } delete device; - QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address), - Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::Paired)); - } - else { - QDBusPendingReply<QDBusObjectPath> reply = - d_ptr->adapter->CreatePairedDevice(address.toString(), - QDBusObjectPath(d_ptr->agent_path), - QLatin1String("NoInputNoOutput")); + QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, + Q_ARG(QBluetoothAddress, address), + Q_ARG(QBluetoothLocalDevice::Pairing, + QBluetoothLocalDevice::Paired)); + } else { + QDBusPendingReply<QDBusObjectPath> reply + = d_ptr->adapter->CreatePairedDevice(address.toString(), + QDBusObjectPath(d_ptr->agent_path), + QLatin1String("NoInputNoOutput")); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), d_ptr, SLOT(pairingCompleted(QDBusPendingCallWatcher*))); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)), d_ptr, + SLOT(pairingCompleted(QDBusPendingCallWatcher *))); - if(reply.isError()) + if (reply.isError()) qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << reply.error() << d_ptr->agent_path; } - } - else if(pairing == Unpaired) { - QDBusPendingReply<QDBusObjectPath> reply = this->d_ptr->adapter->FindDevice(address.toString()); + } else if (pairing == Unpaired) { + QDBusPendingReply<QDBusObjectPath> reply = this->d_ptr->adapter->FindDevice( + address.toString()); reply.waitForFinished(); - if(reply.isError()) { + if (reply.isError()) { qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to find device" << reply.error(); QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); return; } QDBusPendingReply<> removeReply = this->d_ptr->adapter->RemoveDevice(reply.value()); removeReply.waitForFinished(); - if(removeReply.isError()){ - qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to remove device" << removeReply.error(); + if (removeReply.isError()) { + qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to remove device" + << removeReply.error(); QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); + Q_ARG(QBluetoothLocalDevice::Error, + QBluetoothLocalDevice::PairingError)); } else { - QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address), - Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::Unpaired)); + QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, + Q_ARG(QBluetoothAddress, address), + Q_ARG(QBluetoothLocalDevice::Pairing, + QBluetoothLocalDevice::Unpaired)); } } - return; } -QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const +QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus( + const QBluetoothAddress &address) const { if (address.isNull()) return Unpaired; OrgBluezDeviceInterface *device = getDevice(address, d_ptr); - if(!device) + if (!device) return Unpaired; QDBusPendingReply<QVariantMap> deviceReply = device->GetProperties(); @@ -341,13 +360,20 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet if (map.value(QLatin1String("Trusted")).toBool() && map.value(QLatin1String("Paired")).toBool()) return AuthorizedPaired; else if (map.value(QLatin1String("Paired")).toBool()) - return Paired; + return Paired; else - return Unpaired; + return Unpaired; } -QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress address) - : adapter(0), agent(0), localAddress(address), pendingHostModeChange(-1), msgConnection(0), q_ptr(q), connectedCached(false) +QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, + QBluetoothAddress address) : + adapter(0), + agent(0), + localAddress(address), + pendingHostModeChange(-1), + msgConnection(0), + q_ptr(q), + connectedCached(false) { initializeAdapter(); connectDeviceChanges(); @@ -355,10 +381,13 @@ QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice void QBluetoothLocalDevicePrivate::connectDeviceChanges() { - if (adapter) { //invalid QBluetoothLocalDevice due to wrong local adapter address - connect(adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(PropertyChanged(QString,QDBusVariant))); - connect(adapter, SIGNAL(DeviceCreated(QDBusObjectPath)), SLOT(_q_deviceCreated(QDBusObjectPath))); - connect(adapter, SIGNAL(DeviceRemoved(QDBusObjectPath)), SLOT(_q_deviceRemoved(QDBusObjectPath))); + if (adapter) { // invalid QBluetoothLocalDevice due to wrong local adapter address + connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)), + SLOT(PropertyChanged(QString, QDBusVariant))); + connect(adapter, SIGNAL(DeviceCreated(QDBusObjectPath)), + SLOT(_q_deviceCreated(QDBusObjectPath))); + connect(adapter, SIGNAL(DeviceRemoved(QDBusObjectPath)), + SLOT(_q_deviceRemoved(QDBusObjectPath))); } } @@ -375,7 +404,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() if (adapter) return; - OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"), QDBusConnection::systemBus()); + OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"), + QDBusConnection::systemBus()); if (localAddress == QBluetoothAddress()) { QDBusPendingReply<QDBusObjectPath> reply = manager.DefaultAdapter(); @@ -383,7 +413,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() if (reply.isError()) return; - adapter = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), reply.value().path(), QDBusConnection::systemBus()); + adapter = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), + reply.value().path(), QDBusConnection::systemBus()); } else { QDBusPendingReply<QList<QDBusObjectPath> > reply = manager.ListAdapters(); reply.waitForFinished(); @@ -391,7 +422,9 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() return; foreach (const QDBusObjectPath &path, reply.value()) { - OrgBluezAdapterInterface *tmpAdapter = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), path.path(), QDBusConnection::systemBus()); + OrgBluezAdapterInterface *tmpAdapter + = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), + path.path(), QDBusConnection::systemBus()); QDBusPendingReply<QVariantMap> reply = tmpAdapter->GetProperties(); reply.waitForFinished(); @@ -411,7 +444,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() currentMode = static_cast<QBluetoothLocalDevice::HostMode>(-1); if (adapter) { - connect(adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(PropertyChanged(QString,QDBusVariant))); + connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)), + SLOT(PropertyChanged(QString, QDBusVariant))); qsrand(QTime::currentTime().msec()); agent_path = agentPath; @@ -432,23 +466,26 @@ void QBluetoothLocalDevicePrivate::RequestConfirmation(const QDBusObjectPath &in msgConfirmation = message(); msgConnection = new QDBusConnection(connection()); emit q->pairingDisplayConfirmation(address, QString::fromLatin1("%1").arg(in1)); - return; } void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &device) { - OrgBluezDeviceInterface *deviceInterface = - new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus()); - connect(deviceInterface, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(_q_devicePropertyChanged(QString,QDBusVariant))); + OrgBluezDeviceInterface *deviceInterface + = new OrgBluezDeviceInterface(QLatin1String("org.bluez"), + device.path(), QDBusConnection::systemBus()); + connect(deviceInterface, SIGNAL(PropertyChanged(QString, QDBusVariant)), + SLOT(_q_devicePropertyChanged(QString, QDBusVariant))); devices << deviceInterface; - QDBusPendingReply<QVariantMap> properties = deviceInterface->asyncCall(QLatin1String("GetProperties")); + QDBusPendingReply<QVariantMap> properties + = deviceInterface->asyncCall(QLatin1String("GetProperties")); properties.waitForFinished(); if (!properties.isValid()) { qCritical() << "Unable to get device properties from: " << device.path(); return; } - const QBluetoothAddress address = QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString()); + const QBluetoothAddress address + = QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString()); const bool connected = properties.value().value(QLatin1String("Connected")).toBool(); if (connectedCached) { @@ -468,15 +505,16 @@ void QBluetoothLocalDevicePrivate::_q_deviceRemoved(const QDBusObjectPath &devic foreach (OrgBluezDeviceInterface *deviceInterface, devices) { if (deviceInterface->path() == device.path()) { devices.remove(deviceInterface); - delete deviceInterface; //deviceDisconnected is already emitted by _q_devicePropertyChanged + delete deviceInterface; // deviceDisconnected is already emitted by _q_devicePropertyChanged break; } } } -void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &property, const QDBusVariant &value) +void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &property, + const QDBusVariant &value) { - OrgBluezDeviceInterface *deviceInterface = qobject_cast<OrgBluezDeviceInterface*>(sender()); + OrgBluezDeviceInterface *deviceInterface = qobject_cast<OrgBluezDeviceInterface *>(sender()); if (deviceInterface && property == QLatin1String("Connected")) { QDBusPendingReply<QVariantMap> propertiesReply = deviceInterface->GetProperties(); propertiesReply.waitForFinished(); @@ -485,7 +523,8 @@ void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &prope return; } const QVariantMap properties = propertiesReply.value(); - const QBluetoothAddress address = QBluetoothAddress(properties.value(QLatin1String("Address")).toString()); + const QBluetoothAddress address + = QBluetoothAddress(properties.value(QLatin1String("Address")).toString()); const bool connected = value.variant().toBool(); if (connectedCached) { @@ -513,17 +552,22 @@ void QBluetoothLocalDevicePrivate::createCache() return; } foreach (const QDBusObjectPath &device, reply.value()) { - OrgBluezDeviceInterface deviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus()); + OrgBluezDeviceInterface deviceInterface(QLatin1String("org.bluez"), + device.path(), QDBusConnection::systemBus()); - QDBusPendingReply<QVariantMap> properties = deviceInterface.asyncCall(QLatin1String("GetProperties")); + QDBusPendingReply<QVariantMap> properties + = deviceInterface.asyncCall(QLatin1String("GetProperties")); properties.waitForFinished(); if (!properties.isValid()) { qCWarning(QT_BT_BLUEZ) << "Unable to get properties for device " << device.path(); return; } - if (properties.value().value(QLatin1String("Connected")).toBool()) - connectedDevicesSet.insert(QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString())); + if (properties.value().value(QLatin1String("Connected")).toBool()) { + connectedDevicesSet.insert(QBluetoothAddress(properties.value().value(QLatin1String( + "Address")). + toString())); + } } connectedCached = true; } @@ -537,19 +581,18 @@ QList<QBluetoothAddress> QBluetoothLocalDevicePrivate::connectedDevices() const void QBluetoothLocalDevice::pairingConfirmation(bool confirmation) { - if(!d_ptr || - !d_ptr->msgConfirmation.isReplyRequired() || - !d_ptr->msgConnection) + if (!d_ptr + || !d_ptr->msgConfirmation.isReplyRequired() + || !d_ptr->msgConnection) return; - if(confirmation){ + if (confirmation) { QDBusMessage msg = d_ptr->msgConfirmation.createReply(QVariant(true)); d_ptr->msgConnection->send(msg); - } - else { - QDBusMessage error = - d_ptr->msgConfirmation.createErrorReply(QDBusError::AccessDenied, - QLatin1String("Pairing rejected")); + } else { + QDBusMessage error + = d_ptr->msgConfirmation.createErrorReply(QDBusError::AccessDenied, + QLatin1String("Pairing rejected")); d_ptr->msgConnection->send(error); } delete d_ptr->msgConnection; @@ -574,7 +617,7 @@ void QBluetoothLocalDevicePrivate::pairingCompleted(QDBusPendingCallWatcher *wat Q_Q(QBluetoothLocalDevice); QDBusPendingReply<> reply = *watcher; - if(reply.isError()) { + if (reply.isError()) { qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to create pairing" << reply.error(); emit q->error(QBluetoothLocalDevice::PairingError); delete watcher; @@ -583,7 +626,7 @@ void QBluetoothLocalDevicePrivate::pairingCompleted(QDBusPendingCallWatcher *wat QDBusPendingReply<QDBusObjectPath> findReply = adapter->FindDevice(address.toString()); findReply.waitForFinished(); - if(findReply.isError()) { + if (findReply.isError()) { qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << "failed to find device" << findReply.error(); emit q->error(QBluetoothLocalDevice::PairingError); delete watcher; @@ -593,43 +636,40 @@ void QBluetoothLocalDevicePrivate::pairingCompleted(QDBusPendingCallWatcher *wat OrgBluezDeviceInterface device(QLatin1String("org.bluez"), findReply.value().path(), QDBusConnection::systemBus()); - if(pairing == QBluetoothLocalDevice::AuthorizedPaired) { + if (pairing == QBluetoothLocalDevice::AuthorizedPaired) { device.SetProperty(QLatin1String("Trusted"), QDBusVariant(QVariant(true))); emit q->pairingFinished(address, QBluetoothLocalDevice::AuthorizedPaired); - } - else { + } else { device.SetProperty(QLatin1String("Trusted"), QDBusVariant(QVariant(false))); emit q->pairingFinished(address, QBluetoothLocalDevice::Paired); } delete watcher; - } void QBluetoothLocalDevicePrivate::Authorize(const QDBusObjectPath &in0, const QString &in1) { Q_UNUSED(in0) Q_UNUSED(in1) - //TODO implement this + // TODO implement this qCDebug(QT_BT_BLUEZ) << "Got authorize for" << in0.path() << in1; } void QBluetoothLocalDevicePrivate::Cancel() { - //TODO implement this + // TODO implement this qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO; } void QBluetoothLocalDevicePrivate::Release() { - //TODO implement this + // TODO implement this qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO; } - void QBluetoothLocalDevicePrivate::ConfirmModeChange(const QString &in0) { Q_UNUSED(in0) - //TODO implement this + // TODO implement this qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << in0; } @@ -638,7 +678,7 @@ void QBluetoothLocalDevicePrivate::DisplayPasskey(const QDBusObjectPath &in0, ui Q_UNUSED(in0) Q_UNUSED(in1) Q_UNUSED(in2) - //TODO implement this + // TODO implement this qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << in0.path() << in1 << in2; } @@ -649,13 +689,12 @@ uint QBluetoothLocalDevicePrivate::RequestPasskey(const QDBusObjectPath &in0) return qrand()&0x1000000; } - void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVariant value) { Q_UNUSED(value); - if (property != QLatin1String("Powered") && - property != QLatin1String("Discoverable")) + if (property != QLatin1String("Powered") + && property != QLatin1String("Discoverable")) return; Q_Q(QBluetoothLocalDevice); @@ -663,17 +702,16 @@ void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVarian QDBusPendingReply<QVariantMap> reply = adapter->GetProperties(); reply.waitForFinished(); - if (reply.isError()){ + if (reply.isError()) { qCWarning(QT_BT_BLUEZ) << "Failed to get bluetooth properties for mode change"; return; } QVariantMap map = reply.value(); - if(!map.value(QLatin1String("Powered")).toBool()){ + if (!map.value(QLatin1String("Powered")).toBool()) { mode = QBluetoothLocalDevice::HostPoweredOff; - } - else { + } else { if (map.value(QLatin1String("Discoverable")).toBool()) mode = QBluetoothLocalDevice::HostDiscoverable; else @@ -685,10 +723,10 @@ void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVarian return; if (pendingHostModeChange == (int)QBluetoothLocalDevice::HostDiscoverable) { adapter->SetProperty(QStringLiteral("Discoverable"), - QDBusVariant(QVariant::fromValue(true))); + QDBusVariant(QVariant::fromValue(true))); } else { adapter->SetProperty(QStringLiteral("Discoverable"), - QDBusVariant(QVariant::fromValue(false))); + QDBusVariant(QVariant::fromValue(false))); } pendingHostModeChange = -1; return; @@ -696,7 +734,7 @@ void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVarian } } - if(mode != currentMode) + if (mode != currentMode) emit q->hostModeStateChanged(mode); currentMode = mode; diff --git a/src/bluetooth/qbluetoothlocaldevice_p.cpp b/src/bluetooth/qbluetoothlocaldevice_p.cpp index d40e6473..6fedafc7 100644 --- a/src/bluetooth/qbluetoothlocaldevice_p.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_p.cpp @@ -39,19 +39,20 @@ ** ****************************************************************************/ - #include "qbluetoothlocaldevice.h" #include "qbluetoothaddress.h" QT_BEGIN_NAMESPACE QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) : - QObject(parent), d_ptr(0) + QObject(parent), + d_ptr(0) { } QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &, QObject *parent) : - QObject(parent), d_ptr(0) + QObject(parent), + d_ptr(0) { } @@ -96,7 +97,8 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai Q_UNUSED(pairing); } -QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const +QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus( + const QBluetoothAddress &address) const { Q_UNUSED(address); return Unpaired; diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h index 61527d31..53d09f6f 100644 --- a/src/bluetooth/qbluetoothlocaldevice_p.h +++ b/src/bluetooth/qbluetoothlocaldevice_p.h @@ -83,22 +83,20 @@ class QBluetoothLocalDevicePrivate : public QObject Q_OBJECT public: QBluetoothLocalDevicePrivate( - QBluetoothLocalDevice *q, - const QBluetoothAddress &address = QBluetoothAddress()); + QBluetoothLocalDevice *q, const QBluetoothAddress &address = QBluetoothAddress()); ~QBluetoothLocalDevicePrivate(); QAndroidJniObject *adapter(); - void initialize(const QBluetoothAddress& address); + void initialize(const QBluetoothAddress &address); static bool startDiscovery(); static bool cancelDiscovery(); static bool isDiscovering(); bool isValid() const; - private slots: void processHostModeChange(QBluetoothLocalDevice::HostMode newMode); void processPairingStateChanged(const QBluetoothAddress &address, - QBluetoothLocalDevice::Pairing pairing); + QBluetoothLocalDevice::Pairing pairing); void processConnectDeviceChanges(const QBluetoothAddress &address, bool isConnectEvent); void processDisplayConfirmation(const QBluetoothAddress &address, const QString &pin); @@ -117,13 +115,13 @@ public: }; #elif defined(QT_BLUEZ_BLUETOOTH) -class QBluetoothLocalDevicePrivate : public QObject, - protected QDBusContext +class QBluetoothLocalDevicePrivate : public QObject, protected QDBusContext { Q_OBJECT Q_DECLARE_PUBLIC(QBluetoothLocalDevice) public: - QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress localAddress = QBluetoothAddress()); + QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, + QBluetoothAddress localAddress = QBluetoothAddress()); ~QBluetoothLocalDevicePrivate(); QSet<OrgBluezDeviceInterface *> devices; @@ -151,9 +149,9 @@ public Q_SLOTS: // METHODS void RequestConfirmation(const QDBusObjectPath &in0, uint in1); QString RequestPinCode(const QDBusObjectPath &in0); - void pairingCompleted(QDBusPendingCallWatcher*); + void pairingCompleted(QDBusPendingCallWatcher *); - void PropertyChanged(QString,QDBusVariant); + void PropertyChanged(QString, QDBusVariant); void _q_deviceCreated(const QDBusObjectPath &device); void _q_deviceRemoved(const QDBusObjectPath &device); void _q_devicePropertyChanged(const QString &property, const QDBusVariant &value); 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")) { |