summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-11-01 13:43:02 +0100
committerAlex Blasche <alexander.blasche@qt.io>2017-11-03 13:09:12 +0000
commit284da0e67a59879c71691a893c65da0f581a023d (patch)
tree2883e634c98aad9fe74bde67dbcf2193efa8cb36 /src/bluetooth/qlowenergycontroller.cpp
parent40214a8c8d35bb15cbe6874cc33d90344f4c533c (diff)
Consolidate the QLEControllerPrivate instanciations
This patch removes repeated code patterns. Change-Id: Ica931958b1d4072429ed197d5e44ad77670c3485 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller.cpp')
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp72
1 files changed, 23 insertions, 49 deletions
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
index ddf3c9ec..cdb16939 100644
--- a/src/bluetooth/qlowenergycontroller.cpp
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -292,6 +292,25 @@ void registerQLowEnergyControllerMetaType()
}
}
+static QLowEnergyControllerPrivate *privateController()
+{
+#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
+ if (isBluez5DbusGatt()) {
+ qCWarning(QT_BT) << "Using BlueZ DBus API";
+ return new QLowEnergyControllerPrivateBluezDBus();
+ } else {
+ qCWarning(QT_BT) << "Using BlueZ kernel ATT interface";
+ return new QLowEnergyControllerPrivateBluez();
+ }
+#elif defined(QT_ANDROID_BLUETOOTH)
+ return new QLowEnergyControllerPrivateAndroid();
+#elif defined(QT_WINRT_BLUETOOTH)
+ return new QLowEnergyControllerPrivateWinRT();
+#else
+ return new QLowEnergyControllerPrivateCommon();
+#endif
+}
+
/*!
Constructs a new instance of this class with \a parent.
@@ -309,21 +328,9 @@ QLowEnergyController::QLowEnergyController(
QObject *parent)
: QObject(parent)
{
-#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
- if (isBluez5DbusGatt())
- d_ptr = new QLowEnergyControllerPrivateBluezDBus();
- else
- d_ptr = new QLowEnergyControllerPrivateBluez();
-#elif defined(QT_ANDROID_BLUETOOTH)
- d_ptr = new QLowEnergyControllerPrivateAndroid();
-#elif defined(QT_WINRT_BLUETOOTH)
- d_ptr = new QLowEnergyControllerPrivateWinRT();
-#else
- d_ptr = new QLowEnergyControllerPrivateCommon();
-#endif
+ d_ptr = privateController();
Q_D(QLowEnergyController);
-
d->q_ptr = this;
d->role = CentralRole;
d->remoteDevice = remoteDevice;
@@ -350,18 +357,7 @@ QLowEnergyController::QLowEnergyController(
QObject *parent)
: QObject(parent)
{
-#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
- if (isBluez5DbusGatt())
- d_ptr = new QLowEnergyControllerPrivateBluezDBus();
- else
- d_ptr = new QLowEnergyControllerPrivateBluez();
-#elif defined(QT_ANDROID_BLUETOOTH)
- d_ptr = new QLowEnergyControllerPrivateAndroid();
-#elif defined(QT_WINRT_BLUETOOTH)
- d_ptr = new QLowEnergyControllerPrivateWinRT();
-#else
- d_ptr = new QLowEnergyControllerPrivateCommon();
-#endif
+ d_ptr = privateController();
Q_D(QLowEnergyController);
d->q_ptr = this;
@@ -394,18 +390,7 @@ QLowEnergyController::QLowEnergyController(
QObject *parent)
: QObject(parent)
{
-#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
- if (isBluez5DbusGatt())
- d_ptr = new QLowEnergyControllerPrivateBluezDBus();
- else
- d_ptr = new QLowEnergyControllerPrivateBluez();
-#elif defined(QT_ANDROID_BLUETOOTH)
- d_ptr = new QLowEnergyControllerPrivateAndroid();
-#elif defined(QT_WINRT_BLUETOOTH)
- d_ptr = new QLowEnergyControllerPrivateWinRT();
-#else
- d_ptr = new QLowEnergyControllerPrivateCommon();
-#endif
+ d_ptr = privateController();
Q_D(QLowEnergyController);
d->q_ptr = this;
@@ -450,18 +435,7 @@ QLowEnergyController *QLowEnergyController::createPeripheral(QObject *parent)
QLowEnergyController::QLowEnergyController(QObject *parent)
: QObject(parent)
{
-#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
- if (isBluez5DbusGatt())
- d_ptr = new QLowEnergyControllerPrivateBluezDBus();
- else
- d_ptr = new QLowEnergyControllerPrivateBluez();
-#elif defined(QT_ANDROID_BLUETOOTH)
- d_ptr = new QLowEnergyControllerPrivateAndroid();
-#elif defined(QT_WINRT_BLUETOOTH)
- d_ptr = new QLowEnergyControllerPrivateWinRT();
-#else
- d_ptr = new QLowEnergyControllerPrivateCommon();
-#endif
+ d_ptr = privateController();
Q_D(QLowEnergyController);
d->q_ptr = this;