summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller_osx_p.h
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@theqtcompany.com>2015-11-26 18:04:58 +0100
committerTimur Pocheptsov <timur.pocheptsov@theqtcompany.com>2015-12-10 13:41:42 +0000
commit5e73fbe10d14cc1fedba4c2e327ebf2b07bc1a9e (patch)
tree1ed50be64e67a40530f1ea41702c5ee29fea2977 /src/bluetooth/qlowenergycontroller_osx_p.h
parent2402bb9421ab8ba4479b7a4e9566b682146f70ff (diff)
qlowenergycontroller_osx - move delegate to the qt_LE_queue
ATM CBCentralManager's delegate does its work on the main queue. With CoreFoundation event dispatcher it's now possible to use QtBluetooth from non-gui thread (more generally - from a thread other than main). This makes main queue useless - and we have to move to a dedicated dispatch queue. Also, we have to make sure we do not have race conditioins/dead-locks. This patch: 1. decouples OSXBTLECentralManager and QLowEnergyController so that these two objects working (potentially) on different threads do not share any data and do not have to use locks, removes the explicit 'delegate' interface/inheritance and replaces them with LECentralNotifier class - to be able to use Qt's signal/slot mechanics for inter-thread communication. 2. all OSXBTLECentralManager's are now executed on qt_LE_queue queue to avoid any race-conditions (since they potentially update manager's internal state). 3. Results/errors are now reported using LECentralNotifier's object (QLowEnergyController has corresponding slots connected to the notifier) Task-number: QTBUG-49476 Change-Id: Ie07cdc13ad559c96a7d2ff010843fb7bcce07c99 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_osx_p.h')
-rw-r--r--src/bluetooth/qlowenergycontroller_osx_p.h58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/bluetooth/qlowenergycontroller_osx_p.h b/src/bluetooth/qlowenergycontroller_osx_p.h
index 1c1cb1cd..2d1b2e95 100644
--- a/src/bluetooth/qlowenergycontroller_osx_p.h
+++ b/src/bluetooth/qlowenergycontroller_osx_p.h
@@ -49,6 +49,7 @@
#include "osx/osxbtcentralmanager_p.h"
#include "qlowenergycontroller_p.h"
#include "qlowenergycontroller.h"
+#include "osx/osxbtnotifier_p.h"
#include "osx/osxbtutility_p.h"
#include "qbluetoothaddress.h"
#include "qbluetoothuuid.h"
@@ -60,14 +61,22 @@
QT_BEGIN_NAMESPACE
+namespace OSXBluetooth
+{
+
+class LECentralNotifier;
+
+}
+
class QByteArray;
-// The suffix OSX is not the very right, it's also iOS.
-class QLowEnergyControllerPrivateOSX : public QLowEnergyControllerPrivate,
- public OSXBluetooth::CentralManagerDelegate
+// While suffix 'OSX', it's also for iOS.
+class QLowEnergyControllerPrivateOSX : public QLowEnergyControllerPrivate
{
friend class QLowEnergyController;
friend class QLowEnergyService;
+
+ Q_OBJECT
public:
QLowEnergyControllerPrivateOSX(QLowEnergyController *q);
QLowEnergyControllerPrivateOSX(QLowEnergyController *q,
@@ -76,30 +85,25 @@ public:
bool isValid() const;
-private:
- // CentralManagerDelegate:
- void LEnotSupported() Q_DECL_OVERRIDE;
- void connectSuccess() Q_DECL_OVERRIDE;
-
- void serviceDiscoveryFinished(LEServices services) Q_DECL_OVERRIDE;
- void serviceDetailsDiscoveryFinished(LEService service) Q_DECL_OVERRIDE;
- void characteristicReadNotification(QLowEnergyHandle charHandle,
- const QByteArray &value) Q_DECL_OVERRIDE;
- void characteristicWriteNotification(QLowEnergyHandle charHandle,
- const QByteArray &newValue) Q_DECL_OVERRIDE;
- void characteristicUpdateNotification(QLowEnergyHandle charHandle,
- const QByteArray &value) Q_DECL_OVERRIDE;
- void descriptorReadNotification(QLowEnergyHandle descHandle,
- const QByteArray &value) Q_DECL_OVERRIDE;
- void descriptorWriteNotification(QLowEnergyHandle descHandle,
- const QByteArray &newValue) Q_DECL_OVERRIDE;
- void disconnected() Q_DECL_OVERRIDE;
- void error(QLowEnergyController::Error errorCode) Q_DECL_OVERRIDE;
- void error(const QBluetoothUuid &serviceUuid,
- QLowEnergyController::Error errorCode) Q_DECL_OVERRIDE;
- void error(const QBluetoothUuid &serviceUuid,
- QLowEnergyService::ServiceError error) Q_DECL_OVERRIDE;
+private Q_SLOTS:
+ void _q_connected();
+ void _q_disconnected();
+
+ void _q_serviceDiscoveryFinished();
+ void _q_serviceDetailsDiscoveryFinished(QSharedPointer<QLowEnergyServicePrivate> service);
+
+ void _q_characteristicRead(QLowEnergyHandle charHandle, const QByteArray &value);
+ void _q_characteristicWritten(QLowEnergyHandle charHandle, const QByteArray &value);
+ void _q_characteristicUpdated(QLowEnergyHandle charHandle, const QByteArray &value);
+ void _q_descriptorRead(QLowEnergyHandle descHandle, const QByteArray &value);
+ void _q_descriptorWritten(QLowEnergyHandle charHandle, const QByteArray &value);
+ void _q_LEnotSupported();
+ void _q_CBCentralManagerError(QLowEnergyController::Error error);
+ void _q_CBCentralManagerError(const QBluetoothUuid &serviceUuid, QLowEnergyController::Error error);
+ void _q_CBCentralManagerError(const QBluetoothUuid &serviceUuid, QLowEnergyService::ServiceError error);
+
+private:
void connectToDevice();
void discoverServices();
void discoverServiceDetails(const QBluetoothUuid &serviceUuid);
@@ -139,6 +143,7 @@ private:
void setErrorDescription(QLowEnergyController::Error errorCode);
void invalidateServices();
+ bool connectSlots(OSXBluetooth::LECentralNotifier *notifier);
QLowEnergyController *q_ptr;
QBluetoothUuid deviceUuid;
@@ -159,6 +164,7 @@ private:
QLowEnergyController::ControllerState controllerState;
QLowEnergyController::RemoteAddressType addressType;
+ typedef QT_MANGLE_NAMESPACE(OSXBTCentralManager) ObjCCentralManager;
typedef OSXBluetooth::ObjCScopedPointer<ObjCCentralManager> CentralManager;
CentralManager centralManager;