diff options
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android.cpp | 51 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android_p.h | 4 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_bluez.cpp | 52 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_bluez_p.h | 3 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_p.cpp | 7 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_p.h | 3 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_winrt.cpp | 50 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_winrt_p.h | 6 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontrollerbase.cpp | 56 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontrollerbase_p.h | 3 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyservice.h | 5 |
11 files changed, 60 insertions, 180 deletions
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 592f6c70..8dccb859 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -1258,55 +1258,4 @@ void QLowEnergyControllerPrivateAndroid::addToGenericAttributeList(const QLowEne service->androidService.object()); } -QLowEnergyService *QLowEnergyControllerPrivateAndroid::addServiceHelper( - const QLowEnergyServiceData &service) -{ - // Spec says services "should" be grouped by uuid length (16-bit first, then 128-bit). - // Since this is not mandatory, we ignore it here and let the caller take responsibility - // for it. - - const auto servicePrivate = QSharedPointer<QLowEnergyServicePrivate>::create(); - servicePrivate->state = QLowEnergyService::LocalService; - servicePrivate->setController(this); - servicePrivate->uuid = service.uuid(); - servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary - ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService; - foreach (QLowEnergyService * const includedService, service.includedServices()) { - servicePrivate->includedServices << includedService->serviceUuid(); - includedService->d_ptr->type |= QLowEnergyService::IncludedService; - } - - // Spec v4.2, Vol 3, Part G, Section 3. - const QLowEnergyHandle oldLastHandle = this->lastLocalHandle; - servicePrivate->startHandle = ++this->lastLocalHandle; // Service declaration. - this->lastLocalHandle += servicePrivate->includedServices.count(); // Include declarations. - foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { - const QLowEnergyHandle declHandle = ++this->lastLocalHandle; - QLowEnergyServicePrivate::CharData charData; - charData.valueHandle = ++this->lastLocalHandle; - charData.uuid = cd.uuid(); - charData.properties = cd.properties(); - charData.value = cd.value(); - foreach (const QLowEnergyDescriptorData &dd, cd.descriptors()) { - QLowEnergyServicePrivate::DescData descData; - descData.uuid = dd.uuid(); - descData.value = dd.value(); - charData.descriptorList.insert(++this->lastLocalHandle, descData); - } - servicePrivate->characteristicList.insert(declHandle, charData); - } - servicePrivate->endHandle = this->lastLocalHandle; - const bool handleOverflow = this->lastLocalHandle <= oldLastHandle; - if (handleOverflow) { - qCWarning(QT_BT_ANDROID) << "Not enough attribute handles left to create this service"; - this->lastLocalHandle = oldLastHandle; - return nullptr; - } - - this->localServices.insert(servicePrivate->uuid, servicePrivate); - this->addToGenericAttributeList(service, servicePrivate->startHandle); - return new QLowEnergyService(servicePrivate); -} - - QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycontroller_android_p.h b/src/bluetooth/qlowenergycontroller_android_p.h index ba56ad4c..e575d96e 100644 --- a/src/bluetooth/qlowenergycontroller_android_p.h +++ b/src/bluetooth/qlowenergycontroller_android_p.h @@ -114,9 +114,6 @@ public: void requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms) override; - // misc helpers - QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service) override; - // read data void readCharacteristic(const QSharedPointer<QLowEnergyServicePrivate> service, const QLowEnergyHandle charHandle) override; @@ -136,7 +133,6 @@ public: void addToGenericAttributeList(const QLowEnergyServiceData &service, QLowEnergyHandle startHandle) override; - QLowEnergyHandle lastLocalHandle; private: LowEnergyNotificationHub *hub; diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 0aac1fda..7a1cd0df 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -265,7 +265,6 @@ template<> void putDataAndIncrement(const QByteArray &value, char *&dst) QLowEnergyControllerPrivateBluez::QLowEnergyControllerPrivateBluez() : QLowEnergyControllerPrivate(), - lastLocalHandle(0), l2cpSocket(0), requestPending(false), mtuSize(ATT_DEFAULT_LE_MTU), securityLevelValue(-1), @@ -3433,55 +3432,4 @@ bool QLowEnergyControllerPrivateBluez::verifyMac(const QByteArray &message, cons expectedMac); } -QLowEnergyService *QLowEnergyControllerPrivateBluez::addServiceHelper( - const QLowEnergyServiceData &service) -{ - // Spec says services "should" be grouped by uuid length (16-bit first, then 128-bit). - // Since this is not mandatory, we ignore it here and let the caller take responsibility - // for it. - - const auto servicePrivate = QSharedPointer<QLowEnergyServicePrivate>::create(); - servicePrivate->state = QLowEnergyService::LocalService; - servicePrivate->setController(this); - servicePrivate->uuid = service.uuid(); - servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary - ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService; - foreach (QLowEnergyService * const includedService, service.includedServices()) { - servicePrivate->includedServices << includedService->serviceUuid(); - includedService->d_ptr->type |= QLowEnergyService::IncludedService; - } - - // Spec v4.2, Vol 3, Part G, Section 3. - const QLowEnergyHandle oldLastHandle = this->lastLocalHandle; - servicePrivate->startHandle = ++this->lastLocalHandle; // Service declaration. - this->lastLocalHandle += servicePrivate->includedServices.count(); // Include declarations. - foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { - const QLowEnergyHandle declHandle = ++this->lastLocalHandle; - QLowEnergyServicePrivate::CharData charData; - charData.valueHandle = ++this->lastLocalHandle; - charData.uuid = cd.uuid(); - charData.properties = cd.properties(); - charData.value = cd.value(); - foreach (const QLowEnergyDescriptorData &dd, cd.descriptors()) { - QLowEnergyServicePrivate::DescData descData; - descData.uuid = dd.uuid(); - descData.value = dd.value(); - charData.descriptorList.insert(++this->lastLocalHandle, descData); - } - servicePrivate->characteristicList.insert(declHandle, charData); - } - servicePrivate->endHandle = this->lastLocalHandle; - const bool handleOverflow = this->lastLocalHandle <= oldLastHandle; - if (handleOverflow) { - qCWarning(QT_BT_BLUEZ) << "Not enough attribute handles left to create this service"; - this->lastLocalHandle = oldLastHandle; - return nullptr; - } - - this->localServices.insert(servicePrivate->uuid, servicePrivate); - this->addToGenericAttributeList(service, servicePrivate->startHandle); - return new QLowEnergyService(servicePrivate); -} - - QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycontroller_bluez_p.h b/src/bluetooth/qlowenergycontroller_bluez_p.h index 76d3bb87..55a8a482 100644 --- a/src/bluetooth/qlowenergycontroller_bluez_p.h +++ b/src/bluetooth/qlowenergycontroller_bluez_p.h @@ -116,8 +116,6 @@ public: void addToGenericAttributeList(const QLowEnergyServiceData &service, QLowEnergyHandle startHandle) override; - QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service) override; - struct Attribute { Attribute() : handle(0) {} @@ -133,7 +131,6 @@ public: int maxLength; }; QVector<Attribute> localAttributes; - QLowEnergyHandle lastLocalHandle; private: quint16 connectionHandle = 0; diff --git a/src/bluetooth/qlowenergycontroller_p.cpp b/src/bluetooth/qlowenergycontroller_p.cpp index b9f825af..c3605f05 100644 --- a/src/bluetooth/qlowenergycontroller_p.cpp +++ b/src/bluetooth/qlowenergycontroller_p.cpp @@ -134,11 +134,4 @@ void QLowEnergyControllerPrivateCommon::addToGenericAttributeList(const QLowEner { } -QLowEnergyService *QLowEnergyControllerPrivateCommon::addServiceHelper( - const QLowEnergyServiceData &/*service*/) -{ - return nullptr; -} - - QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h index 01e9420a..623c71a2 100644 --- a/src/bluetooth/qlowenergycontroller_p.h +++ b/src/bluetooth/qlowenergycontroller_p.h @@ -87,9 +87,6 @@ public: void requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms) override; - // misc helpers - QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service) override; - // read data void readCharacteristic(const QSharedPointer<QLowEnergyServicePrivate> service, const QLowEnergyHandle charHandle) override; diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp index 741eebf6..13cb3eab 100644 --- a/src/bluetooth/qlowenergycontroller_winrt.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt.cpp @@ -1106,56 +1106,6 @@ void QLowEnergyControllerPrivateWinRT::characteristicChanged( emit service->characteristicChanged(characteristic, data); } -QLowEnergyService *QLowEnergyControllerPrivateWinRT::addServiceHelper( - const QLowEnergyServiceData &service) -{ - // Spec says services "should" be grouped by uuid length (16-bit first, then 128-bit). - // Since this is not mandatory, we ignore it here and let the caller take responsibility - // for it. - - const auto servicePrivate = QSharedPointer<QLowEnergyServicePrivate>::create(); - servicePrivate->state = QLowEnergyService::LocalService; - servicePrivate->setController(this); - servicePrivate->uuid = service.uuid(); - servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary - ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService; - foreach (QLowEnergyService * const includedService, service.includedServices()) { - servicePrivate->includedServices << includedService->serviceUuid(); - includedService->d_ptr->type |= QLowEnergyService::IncludedService; - } - - // Spec v4.2, Vol 3, Part G, Section 3. - const QLowEnergyHandle oldLastHandle = this->lastLocalHandle; - servicePrivate->startHandle = ++this->lastLocalHandle; // Service declaration. - this->lastLocalHandle += servicePrivate->includedServices.count(); // Include declarations. - foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { - const QLowEnergyHandle declHandle = ++this->lastLocalHandle; - QLowEnergyServicePrivate::CharData charData; - charData.valueHandle = ++this->lastLocalHandle; - charData.uuid = cd.uuid(); - charData.properties = cd.properties(); - charData.value = cd.value(); - foreach (const QLowEnergyDescriptorData &dd, cd.descriptors()) { - QLowEnergyServicePrivate::DescData descData; - descData.uuid = dd.uuid(); - descData.value = dd.value(); - charData.descriptorList.insert(++this->lastLocalHandle, descData); - } - servicePrivate->characteristicList.insert(declHandle, charData); - } - servicePrivate->endHandle = this->lastLocalHandle; - const bool handleOverflow = this->lastLocalHandle <= oldLastHandle; - if (handleOverflow) { - qCWarning(QT_BT_WINRT) << "Not enough attribute handles left to create this service"; - this->lastLocalHandle = oldLastHandle; - return nullptr; - } - - this->localServices.insert(servicePrivate->uuid, servicePrivate); - this->addToGenericAttributeList(service, servicePrivate->startHandle); - return new QLowEnergyService(servicePrivate); -} - QT_END_NAMESPACE #include "qlowenergycontroller_winrt.moc" diff --git a/src/bluetooth/qlowenergycontroller_winrt_p.h b/src/bluetooth/qlowenergycontroller_winrt_p.h index f0625bcb..7edc4702 100644 --- a/src/bluetooth/qlowenergycontroller_winrt_p.h +++ b/src/bluetooth/qlowenergycontroller_winrt_p.h @@ -95,9 +95,6 @@ public: void requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms) override; - // misc helpers - QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service) override; - // read data void readCharacteristic(const QSharedPointer<QLowEnergyServicePrivate> service, const QLowEnergyHandle charHandle) override; @@ -117,9 +114,6 @@ public: void addToGenericAttributeList(const QLowEnergyServiceData &service, QLowEnergyHandle startHandle) override; - - QLowEnergyHandle lastLocalHandle; - private slots: void characteristicChanged(int charHandle, const QByteArray &data); diff --git a/src/bluetooth/qlowenergycontrollerbase.cpp b/src/bluetooth/qlowenergycontrollerbase.cpp index 22fdd52b..687f5b9e 100644 --- a/src/bluetooth/qlowenergycontrollerbase.cpp +++ b/src/bluetooth/qlowenergycontrollerbase.cpp @@ -39,11 +39,17 @@ #include "qlowenergycontrollerbase_p.h" +#include <QtCore/QLoggingCategory> + #include <QtBluetooth/QBluetoothLocalDevice> +#include <QtBluetooth/QLowEnergyCharacteristicData> +#include <QtBluetooth/QLowEnergyDescriptorData> #include <QtBluetooth/QLowEnergyServiceData> QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(QT_BT) + QLowEnergyControllerPrivate::QLowEnergyControllerPrivate() : QObject() { @@ -257,4 +263,54 @@ void QLowEnergyControllerPrivate::invalidateServices() serviceList.clear(); } +QLowEnergyService *QLowEnergyControllerPrivate::addServiceHelper( + const QLowEnergyServiceData &service) +{ + // Spec says services "should" be grouped by uuid length (16-bit first, then 128-bit). + // Since this is not mandatory, we ignore it here and let the caller take responsibility + // for it. + + const auto servicePrivate = QSharedPointer<QLowEnergyServicePrivate>::create(); + servicePrivate->state = QLowEnergyService::LocalService; + servicePrivate->setController(this); + servicePrivate->uuid = service.uuid(); + servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary + ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService; + foreach (QLowEnergyService * const includedService, service.includedServices()) { + servicePrivate->includedServices << includedService->serviceUuid(); + includedService->d_ptr->type |= QLowEnergyService::IncludedService; + } + + // Spec v4.2, Vol 3, Part G, Section 3. + const QLowEnergyHandle oldLastHandle = this->lastLocalHandle; + servicePrivate->startHandle = ++this->lastLocalHandle; // Service declaration. + this->lastLocalHandle += servicePrivate->includedServices.count(); // Include declarations. + foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { + const QLowEnergyHandle declHandle = ++this->lastLocalHandle; + QLowEnergyServicePrivate::CharData charData; + charData.valueHandle = ++this->lastLocalHandle; + charData.uuid = cd.uuid(); + charData.properties = cd.properties(); + charData.value = cd.value(); + foreach (const QLowEnergyDescriptorData &dd, cd.descriptors()) { + QLowEnergyServicePrivate::DescData descData; + descData.uuid = dd.uuid(); + descData.value = dd.value(); + charData.descriptorList.insert(++this->lastLocalHandle, descData); + } + servicePrivate->characteristicList.insert(declHandle, charData); + } + servicePrivate->endHandle = this->lastLocalHandle; + const bool handleOverflow = this->lastLocalHandle <= oldLastHandle; + if (handleOverflow) { + qCWarning(QT_BT) << "Not enough attribute handles left to create this service"; + this->lastLocalHandle = oldLastHandle; + return nullptr; + } + + this->localServices.insert(servicePrivate->uuid, servicePrivate); + this->addToGenericAttributeList(service, servicePrivate->startHandle); + return new QLowEnergyService(servicePrivate); +} + QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycontrollerbase_p.h b/src/bluetooth/qlowenergycontrollerbase_p.h index 54f306ff..a8d1c676 100644 --- a/src/bluetooth/qlowenergycontrollerbase_p.h +++ b/src/bluetooth/qlowenergycontrollerbase_p.h @@ -133,7 +133,7 @@ public: virtual QLowEnergyService *addServiceHelper( - const QLowEnergyServiceData &service) = 0; + const QLowEnergyServiceData &service); // common backend methods @@ -171,6 +171,7 @@ protected: QBluetoothAddress remoteDevice; QBluetoothAddress localAdapter; + QLowEnergyHandle lastLocalHandle{}; QString remoteName; // device name of the remote diff --git a/src/bluetooth/qlowenergyservice.h b/src/bluetooth/qlowenergyservice.h index 23545b11..f413e7f7 100644 --- a/src/bluetooth/qlowenergyservice.h +++ b/src/bluetooth/qlowenergyservice.h @@ -134,10 +134,9 @@ private: // QLowEnergyController is the factory for this class friend class QLowEnergyController; - friend class QLowEnergyControllerPrivateAndroid; + friend class QLowEnergyControllerPrivate; friend class QLowEnergyControllerPrivateBluez; - friend class QLowEnergyControllerPrivateCommon; - friend class QLowEnergyControllerPrivateWinRT; + friend class QLowEnergyControllerPrivateAndroid; QLowEnergyService(QSharedPointer<QLowEnergyServicePrivate> p, QObject *parent = nullptr); }; |