summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-03-14 15:59:26 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-15 20:59:25 +0100
commit8ba83c809febcc38d72f69d8ca206ba5402e5f4d (patch)
tree0b92b792f65cba44582339167e673094be2a57cb
parent946db397b2cbbaca7880a804dac6aa3b2dddd87f (diff)
Cleanup of BtLE code
1.) Remove dead pieces of code 2.) Fix warnings 3.) Optimize some code lines Change-Id: I952fe34e8966a501a54c9ef42e9624c1fc46a2a1 Reviewed-by: Nedim Hadzic <nhadzic@blackberry.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--examples/bluetooth/lowenergyscanner/main.cpp2
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp30
-rw-r--r--src/bluetooth/qlowenergyprocess_bluez.cpp3
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_bluez.cpp13
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_p.h11
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_qnx.cpp1
6 files changed, 16 insertions, 44 deletions
diff --git a/examples/bluetooth/lowenergyscanner/main.cpp b/examples/bluetooth/lowenergyscanner/main.cpp
index 1a8487c8..89f7153d 100644
--- a/examples/bluetooth/lowenergyscanner/main.cpp
+++ b/examples/bluetooth/lowenergyscanner/main.cpp
@@ -38,6 +38,7 @@
**
****************************************************************************/
+#include <QtCore/QLoggingCategory>
#include <QQmlContext>
#include <QGuiApplication>
#include <QQuickView>
@@ -46,6 +47,7 @@
int main(int argc, char *argv[])
{
+ QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
QGuiApplication app(argc, argv);
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index 0ad8d875..eba8bad5 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -329,8 +329,7 @@ void QLowEnergyControllerPrivate::disconnectAllServices()
void QLowEnergyControllerPrivate::connectToTerminal()
{
- process->executeCommand(QStringLiteral("connect"));
- process->executeCommand(QStringLiteral("\n"));
+ process->executeCommand(QStringLiteral("connect\n"));
for (int i = 0; i < m_leServices.size(); i++)
m_leServices.at(i).d_ptr->m_step = 1;
m_step++;
@@ -338,8 +337,7 @@ void QLowEnergyControllerPrivate::connectToTerminal()
void QLowEnergyControllerPrivate::setHandles()
{
- process->executeCommand(QStringLiteral("primary"));
- process->executeCommand(QStringLiteral("\n"));
+ process->executeCommand(QStringLiteral("primary\n"));
m_step++;
}
@@ -353,8 +351,7 @@ void QLowEnergyControllerPrivate::setCharacteristics(int a)
void QLowEnergyControllerPrivate::setNotifications()
{
- process->executeCommand(QStringLiteral("char-read-uuid 2902"));
- process->executeCommand(QStringLiteral("\n"));
+ process->executeCommand(QStringLiteral("char-read-uuid 2902\n"));
}
void QLowEnergyControllerPrivate::readCharacteristicValue(int index)
@@ -381,16 +378,12 @@ void QLowEnergyControllerPrivate::writeValue(const QString &handle, const QByteA
bool QLowEnergyControllerPrivate::enableNotification(const QLowEnergyCharacteristicInfo &characteristic)
{
- bool foundCharacteristic = false;
- bool foundDescriptor = false;
const QBluetoothUuid descUuid((ushort)0x2902);
for (int i = 0; i < m_leServices.size(); i++) {
for (int j = 0; j < m_leServices.at(i).characteristics().size(); j++) {
if (m_leServices.at(i).characteristics().at(j).uuid() == characteristic.uuid()) {
- foundCharacteristic = true;
for (int k = 0; k < m_leServices.at(i).characteristics().at(j).descriptors().size(); k++) {
if (m_leServices.at(i).characteristics().at(j).descriptors().at(k).uuid() == descUuid){
- foundDescriptor = true;
QByteArray val;
val.append(48);
val.append(49);
@@ -403,12 +396,10 @@ bool QLowEnergyControllerPrivate::enableNotification(const QLowEnergyCharacteris
}
}
}
- if (!foundDescriptor || !foundCharacteristic) {
- errorString = QStringLiteral("Characteristic or notification descriptor not found.");
- emit q_ptr->error(characteristic);
- return false;
- }
+ errorString = QStringLiteral("Characteristic or notification descriptor not found.");
+ emit q_ptr->error(characteristic);
+ return false;
}
void QLowEnergyControllerPrivate::disableNotification(const QLowEnergyCharacteristicInfo &characteristic)
@@ -440,14 +431,13 @@ bool QLowEnergyControllerPrivate::write(const QLowEnergyCharacteristicInfo &char
return true;
} else {
errorString = QStringLiteral("This characteristic does not support write operations.");
- emit q_ptr->error(characteristic);
- return false;
}
} else {
errorString = QStringLiteral("The device is not connected or characteristic is not valid");
- emit q_ptr->error(characteristic);
- return false;
}
+
+ emit q_ptr->error(characteristic);
+ return false;
}
bool QLowEnergyControllerPrivate::write(const QLowEnergyDescriptorInfo &descriptor)
@@ -456,6 +446,8 @@ bool QLowEnergyControllerPrivate::write(const QLowEnergyDescriptorInfo &descript
writeValue(descriptor.handle(), descriptor.value());
return true;
}
+
+ return false;
}
QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergyprocess_bluez.cpp b/src/bluetooth/qlowenergyprocess_bluez.cpp
index 26013273..508672eb 100644
--- a/src/bluetooth/qlowenergyprocess_bluez.cpp
+++ b/src/bluetooth/qlowenergyprocess_bluez.cpp
@@ -125,8 +125,7 @@ void QLowEnergyProcess::endProcess()
{
m_counter--;
if (m_counter == 0) {
- executeCommand(QStringLiteral("disconnect"));
- executeCommand(QStringLiteral("\n"));
+ executeCommand(QStringLiteral("disconnect\n"));
connected = false;
}
}
diff --git a/src/bluetooth/qlowenergyserviceinfo_bluez.cpp b/src/bluetooth/qlowenergyserviceinfo_bluez.cpp
index 9e34fee4..8d4b7b08 100644
--- a/src/bluetooth/qlowenergyserviceinfo_bluez.cpp
+++ b/src/bluetooth/qlowenergyserviceinfo_bluez.cpp
@@ -45,12 +45,9 @@
#include "qlowenergycharacteristicinfo_p.h"
#include "qlowenergyprocess_p.h"
#include "qbluetoothlocaldevice.h"
-#include "bluez/characteristic_p.h"
#include "qlowenergydescriptorinfo.h"
#include "qlowenergydescriptorinfo_p.h"
-//#define QT_LOWENERGYSERVICE_DEBUG
-
#ifdef QT_LOWENERGYSERVICE_DEBUG
#include <QtCore/QDebug>
#endif
@@ -58,22 +55,16 @@
QT_BEGIN_NAMESPACE
QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate():
- serviceType(QLowEnergyServiceInfo::PrimaryService), connected(false), characteristic(0), m_valueCounter(0), m_readCounter(0)
+ serviceType(QLowEnergyServiceInfo::PrimaryService), connected(false),
+ m_valueCounter(0), m_readCounter(0)
{
m_step = 0;
QBluetoothLocalDevice localDevice;
adapterAddress = localDevice.address();
}
-QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate(const QString &servicePath):
- serviceType(QLowEnergyServiceInfo::PrimaryService), connected(false), path(servicePath), characteristic(0)
-{
- m_step = 0;
-}
-
QLowEnergyServiceInfoPrivate::~QLowEnergyServiceInfoPrivate()
{
- delete characteristic;
}
bool QLowEnergyServiceInfoPrivate::valid()
diff --git a/src/bluetooth/qlowenergyserviceinfo_p.h b/src/bluetooth/qlowenergyserviceinfo_p.h
index cee55534..56a35ef6 100644
--- a/src/bluetooth/qlowenergyserviceinfo_p.h
+++ b/src/bluetooth/qlowenergyserviceinfo_p.h
@@ -46,10 +46,6 @@
#include "qlowenergycharacteristicinfo.h"
#include <QPointer>
-#ifdef QT_BLUEZ_BLUETOOTH
-class OrgBluezCharacteristicInterface;
-#endif
-
QT_BEGIN_NAMESPACE
class QBluetoothUuid;
@@ -63,9 +59,6 @@ class QLowEnergyServiceInfoPrivate
public:
QLowEnergyServiceInfoPrivate();
-#ifdef QT_BLUEZ_BLUETOOTH
- QLowEnergyServiceInfoPrivate(const QString &servicePath);
-#endif
~QLowEnergyServiceInfoPrivate();
bool valid();
@@ -81,7 +74,6 @@ public:
#ifdef QT_BLUEZ_BLUETOOTH
QString startingHandle;
QString endingHandle;
- QString path;
QBluetoothAddress adapterAddress;
#endif
@@ -90,14 +82,11 @@ public:
#endif
private:
- QLowEnergyProcess *process;
#ifdef QT_BLUEZ_BLUETOOTH
- OrgBluezCharacteristicInterface *characteristic;
int m_step;
int m_valueCounter;
int m_readCounter;
#endif
- int m_instance;
};
QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergyserviceinfo_qnx.cpp b/src/bluetooth/qlowenergyserviceinfo_qnx.cpp
index f09e1124..a866bcb9 100644
--- a/src/bluetooth/qlowenergyserviceinfo_qnx.cpp
+++ b/src/bluetooth/qlowenergyserviceinfo_qnx.cpp
@@ -59,7 +59,6 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_QNX)
QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate():
- m_instance(0)
{
}