summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-10-25 13:59:39 +0200
committerAlex Blasche <alexander.blasche@qt.io>2017-11-03 13:08:48 +0000
commit7a9d2e77befb13c1f714f842d4b0ee3fea2d4a6c (patch)
treed95662929b254a4bcd421e7ee2082b8433f360a7 /src
parent59ae3cc2ac7baee7e9df1e6ceffcfc882fbe6121 (diff)
Move common helper function from QLECPrivate to QLECPrivateBase
Change-Id: I5f126fabebf36b61a25e23ddc12c4dae21156cbc Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qlowenergycharacteristic.h1
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp117
-rw-r--r--src/bluetooth/qlowenergycontroller_p.h16
-rw-r--r--src/bluetooth/qlowenergycontrollerbase.cpp116
-rw-r--r--src/bluetooth/qlowenergycontrollerbase_p.h13
-rw-r--r--src/bluetooth/qlowenergydescriptor.h1
6 files changed, 128 insertions, 136 deletions
diff --git a/src/bluetooth/qlowenergycharacteristic.h b/src/bluetooth/qlowenergycharacteristic.h
index 154c9936..7ce05343 100644
--- a/src/bluetooth/qlowenergycharacteristic.h
+++ b/src/bluetooth/qlowenergycharacteristic.h
@@ -97,6 +97,7 @@ protected:
friend class QLowEnergyService;
friend class QLowEnergyControllerPrivate;
+ friend class QLowEnergyControllerPrivateBase;
friend class QLowEnergyControllerPrivateOSX;
QLowEnergyCharacteristicPrivate *data;
QLowEnergyCharacteristic(QSharedPointer<QLowEnergyServicePrivate> p,
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
index 4d0d78b6..b026e4a0 100644
--- a/src/bluetooth/qlowenergycontroller.cpp
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -284,123 +284,6 @@ void registerQLowEnergyControllerMetaType()
}
}
-void QLowEnergyControllerPrivate::invalidateServices()
-{
- foreach (const QSharedPointer<QLowEnergyServicePrivate> service, serviceList.values()) {
- service->setController(0);
- service->setState(QLowEnergyService::InvalidService);
- }
-
- serviceList.clear();
-}
-
-
-/*!
- Returns a valid characteristic if the given handle is the
- handle of the characteristic itself or one of its descriptors
- */
-QLowEnergyCharacteristic QLowEnergyControllerPrivate::characteristicForHandle(
- QLowEnergyHandle handle)
-{
- QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(handle);
- if (service.isNull())
- return QLowEnergyCharacteristic();
-
- if (service->characteristicList.isEmpty())
- return QLowEnergyCharacteristic();
-
- // check whether it is the handle of a characteristic header
- if (service->characteristicList.contains(handle))
- return QLowEnergyCharacteristic(service, handle);
-
- // check whether it is the handle of the characteristic value or its descriptors
- QList<QLowEnergyHandle> charHandles = service->characteristicList.keys();
- std::sort(charHandles.begin(), charHandles.end());
- for (int i = charHandles.size() - 1; i >= 0; i--) {
- if (charHandles.at(i) > handle)
- continue;
-
- return QLowEnergyCharacteristic(service, charHandles.at(i));
- }
-
- return QLowEnergyCharacteristic();
-}
-
-/*!
- Returns a valid descriptor if \a handle belongs to a descriptor;
- otherwise an invalid one.
- */
-QLowEnergyDescriptor QLowEnergyControllerPrivate::descriptorForHandle(
- QLowEnergyHandle handle)
-{
- const QLowEnergyCharacteristic matchingChar = characteristicForHandle(handle);
- if (!matchingChar.isValid())
- return QLowEnergyDescriptor();
-
- const QLowEnergyServicePrivate::CharData charData = matchingChar.
- d_ptr->characteristicList[matchingChar.attributeHandle()];
-
- if (charData.descriptorList.contains(handle))
- return QLowEnergyDescriptor(matchingChar.d_ptr, matchingChar.attributeHandle(),
- handle);
-
- return QLowEnergyDescriptor();
-}
-
-/*!
- Returns the length of the updated characteristic value.
- */
-quint16 QLowEnergyControllerPrivate::updateValueOfCharacteristic(
- QLowEnergyHandle charHandle,const QByteArray &value, bool appendValue)
-{
- QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
- if (!service.isNull()) {
- CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
- if (charIt != service->characteristicList.end()) {
- QLowEnergyServicePrivate::CharData &charDetails = charIt.value();
-
- if (appendValue)
- charDetails.value += value;
- else
- charDetails.value = value;
-
- return charDetails.value.size();
- }
- }
-
- return 0;
-}
-
-/*!
- Returns the length of the updated descriptor value.
- */
-quint16 QLowEnergyControllerPrivate::updateValueOfDescriptor(
- QLowEnergyHandle charHandle, QLowEnergyHandle descriptorHandle,
- const QByteArray &value, bool appendValue)
-{
- QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
- if (!service.isNull()) {
- CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
- if (charIt != service->characteristicList.end()) {
- QLowEnergyServicePrivate::CharData &charDetails = charIt.value();
-
- DescriptorDataMap::iterator descIt = charDetails.descriptorList.find(descriptorHandle);
- if (descIt != charDetails.descriptorList.end()) {
- QLowEnergyServicePrivate::DescData &descDetails = descIt.value();
-
- if (appendValue)
- descDetails.value += value;
- else
- descDetails.value = value;
-
- return descDetails.value.size();
- }
- }
- }
-
- return 0;
-}
-
/*!
Constructs a new instance of this class with \a parent.
diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h
index a9bd23fc..c00a56a0 100644
--- a/src/bluetooth/qlowenergycontroller_p.h
+++ b/src/bluetooth/qlowenergycontroller_p.h
@@ -122,8 +122,6 @@ public:
void disconnectFromDevice() override;
void discoverServices() override;
- void invalidateServices();
-
void discoverServiceDetails(const QBluetoothUuid &service) override;
void startAdvertising(const QLowEnergyAdvertisingParameters &params,
@@ -134,22 +132,8 @@ public:
void requestConnectionUpdate(const QLowEnergyConnectionParameters &params) override;
// misc helpers
-
- QLowEnergyCharacteristic characteristicForHandle(
- QLowEnergyHandle handle);
- QLowEnergyDescriptor descriptorForHandle(
- QLowEnergyHandle handle);
QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service) override;
-
- quint16 updateValueOfCharacteristic(QLowEnergyHandle charHandle,
- const QByteArray &value,
- bool appendValue);
- quint16 updateValueOfDescriptor(QLowEnergyHandle charHandle,
- QLowEnergyHandle descriptorHandle,
- const QByteArray &value,
- bool appendValue);
-
// read data
void readCharacteristic(const QSharedPointer<QLowEnergyServicePrivate> service,
const QLowEnergyHandle charHandle) override;
diff --git a/src/bluetooth/qlowenergycontrollerbase.cpp b/src/bluetooth/qlowenergycontrollerbase.cpp
index 5e9228e2..0b8218e9 100644
--- a/src/bluetooth/qlowenergycontrollerbase.cpp
+++ b/src/bluetooth/qlowenergycontrollerbase.cpp
@@ -141,4 +141,120 @@ QSharedPointer<QLowEnergyServicePrivate> QLowEnergyControllerPrivateBase::servic
return QSharedPointer<QLowEnergyServicePrivate>();
}
+/*!
+ Returns a valid characteristic if the given handle is the
+ handle of the characteristic itself or one of its descriptors
+ */
+QLowEnergyCharacteristic QLowEnergyControllerPrivateBase::characteristicForHandle(
+ QLowEnergyHandle handle)
+{
+ QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(handle);
+ if (service.isNull())
+ return QLowEnergyCharacteristic();
+
+ if (service->characteristicList.isEmpty())
+ return QLowEnergyCharacteristic();
+
+ // check whether it is the handle of a characteristic header
+ if (service->characteristicList.contains(handle))
+ return QLowEnergyCharacteristic(service, handle);
+
+ // check whether it is the handle of the characteristic value or its descriptors
+ QList<QLowEnergyHandle> charHandles = service->characteristicList.keys();
+ std::sort(charHandles.begin(), charHandles.end());
+ for (int i = charHandles.size() - 1; i >= 0; i--) {
+ if (charHandles.at(i) > handle)
+ continue;
+
+ return QLowEnergyCharacteristic(service, charHandles.at(i));
+ }
+
+ return QLowEnergyCharacteristic();
+}
+
+/*!
+ Returns a valid descriptor if \a handle belongs to a descriptor;
+ otherwise an invalid one.
+ */
+QLowEnergyDescriptor QLowEnergyControllerPrivateBase::descriptorForHandle(
+ QLowEnergyHandle handle)
+{
+ const QLowEnergyCharacteristic matchingChar = characteristicForHandle(handle);
+ if (!matchingChar.isValid())
+ return QLowEnergyDescriptor();
+
+ const QLowEnergyServicePrivate::CharData charData = matchingChar.
+ d_ptr->characteristicList[matchingChar.attributeHandle()];
+
+ if (charData.descriptorList.contains(handle))
+ return QLowEnergyDescriptor(matchingChar.d_ptr, matchingChar.attributeHandle(),
+ handle);
+
+ return QLowEnergyDescriptor();
+}
+
+/*!
+ Returns the length of the updated characteristic value.
+ */
+quint16 QLowEnergyControllerPrivateBase::updateValueOfCharacteristic(
+ QLowEnergyHandle charHandle,const QByteArray &value, bool appendValue)
+{
+ QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
+ if (!service.isNull()) {
+ CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
+ if (charIt != service->characteristicList.end()) {
+ QLowEnergyServicePrivate::CharData &charDetails = charIt.value();
+
+ if (appendValue)
+ charDetails.value += value;
+ else
+ charDetails.value = value;
+
+ return charDetails.value.size();
+ }
+ }
+
+ return 0;
+}
+
+/*!
+ Returns the length of the updated descriptor value.
+ */
+quint16 QLowEnergyControllerPrivateBase::updateValueOfDescriptor(
+ QLowEnergyHandle charHandle, QLowEnergyHandle descriptorHandle,
+ const QByteArray &value, bool appendValue)
+{
+ QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
+ if (!service.isNull()) {
+ CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
+ if (charIt != service->characteristicList.end()) {
+ QLowEnergyServicePrivate::CharData &charDetails = charIt.value();
+
+ DescriptorDataMap::iterator descIt = charDetails.descriptorList.find(descriptorHandle);
+ if (descIt != charDetails.descriptorList.end()) {
+ QLowEnergyServicePrivate::DescData &descDetails = descIt.value();
+
+ if (appendValue)
+ descDetails.value += value;
+ else
+ descDetails.value = value;
+
+ return descDetails.value.size();
+ }
+ }
+ }
+
+ return 0;
+}
+
+void QLowEnergyControllerPrivateBase::invalidateServices()
+{
+ foreach (const QSharedPointer<QLowEnergyServicePrivate> service, serviceList.values()) {
+ service->setController(0);
+ service->setState(QLowEnergyService::InvalidService);
+ }
+
+ serviceList.clear();
+}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontrollerbase_p.h b/src/bluetooth/qlowenergycontrollerbase_p.h
index 8c16bc9f..3555e7e8 100644
--- a/src/bluetooth/qlowenergycontrollerbase_p.h
+++ b/src/bluetooth/qlowenergycontrollerbase_p.h
@@ -134,10 +134,17 @@ public:
ServiceDataMap localServices;
//common helper functions
-
QSharedPointer<QLowEnergyServicePrivate> serviceForHandle(QLowEnergyHandle handle);
-
-
+ QLowEnergyCharacteristic characteristicForHandle(QLowEnergyHandle handle);
+ QLowEnergyDescriptor descriptorForHandle(QLowEnergyHandle handle);
+ quint16 updateValueOfCharacteristic(QLowEnergyHandle charHandle,
+ const QByteArray &value,
+ bool appendValue);
+ quint16 updateValueOfDescriptor(QLowEnergyHandle charHandle,
+ QLowEnergyHandle descriptorHandle,
+ const QByteArray &value,
+ bool appendValue);
+ void invalidateServices();
protected:
QLowEnergyController::ControllerState state = QLowEnergyController::UnconnectedState;
diff --git a/src/bluetooth/qlowenergydescriptor.h b/src/bluetooth/qlowenergydescriptor.h
index 9e71fc56..efc748a3 100644
--- a/src/bluetooth/qlowenergydescriptor.h
+++ b/src/bluetooth/qlowenergydescriptor.h
@@ -79,6 +79,7 @@ protected:
friend class QLowEnergyCharacteristic;
friend class QLowEnergyService;
friend class QLowEnergyControllerPrivate;
+ friend class QLowEnergyControllerPrivateBase;
friend class QLowEnergyControllerPrivateOSX;
QLowEnergyDescriptorPrivate *data;